Skip to content

refactor(dashboard): one session-side deliver() for cron, app and wake text - #22937

Merged
bolichen97 merged 1 commit into
mainfrom
refactor/22747-deliver-entry
Oct 22, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
refactor/22747-deliver-entry

Conversation

@iamwhatever

@iamwhatever iamwhatever commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Cron notifications, app messages and work-ledger wakes reach a session through one entry point that picks the row from who sent the text, not from whether the session was busy.

Each of these senders decided for itself whether the session was idle or running, and wrote its own row on each branch. That is how the same work-ledger wake text got two different roles (#22747): the role came from which branch the sender happened to pick. #22812 fixed the visible symptom on the steer path; the senders still own the branch choice.

Why it matters

Every new sender, or every edit to an existing one, has to get both branches and both rows right by hand. A miss shows automation text as something the person typed, in a thread they read as their own record.

Not a goal

  • Moving the peer session_send path (slice B), the idle autonudge fire (slice C) or a cron's send_message (api_send_message) onto deliver. This PR moves the script-cron result path only. Both are named under Related Issues.
  • Changing how the person's own typing is delivered or drawn.
  • Changing any row, queue entry or turn these senders already produce.

What changed (motivation → approach → change)

Cause → approach: the branch choice and the row lived in each sender. The sender now names its origin; the session owns the branch and the row.

  • New dashboard/session_deliver.py: Origin (automation, cron, app), origin_row() (the one origin → row mapping) and deliver(). Idle: append the origin's row and start the turn. Running: steer an automation wake (the nudge row from fix(dashboard): a work-ledger wake steered into a running turn stays a nudge row #22812), queue a cron notification or an app message with its queued card. An idle automation wake returns NOT_DELIVERED, because that turn is still the autonudge fire's own path.
  • slack/gateway_runtime/cron_exec.py (_deliver_script_result), dashboard/handlers/mcp_apps.py (api_mcp_apps_message) and slack/gateway_runtime/nudge_dashboard_fire.py (_steer_work_ledger_wake) call deliver instead of branching.
  • The app handler keeps its gate, redaction, rate-limit commit and audit; the queue_full 429 is now deliver's QUEUE_FULL outcome, and nothing is written in that case.
  • Spec: monitor-architecture.md.

Size: about 190 production lines in 4 files (the new module is ~120 lines of code, ~70 of docstring; the three callers net about -110).

Backwards compatibility

Compatible: every sender writes the same row, queue entry and turn it wrote before (same role, cls, meta, kind, actor, origin flags). The tests below pin each.

Removes nothing: no key, row, route or validator goes away. The three callers lose their inline branches; the behavior moved, it did not change.

Tests

  • test/test_session_deliver.py (new): idle cron and app each write their inject row and start a turn with the right actor and flags; an idle wake is left to the fire; a running slot queues a cron notification, queues an app message with its admission stamp, refuses a full queue without writing, and steers a wake as a nudge row; steer outcomes map to delivery outcomes; the cron and wake callers route through deliver with their origin.
  • test/test_mcp_apps_message_endpoint.py: the app handler routes through deliver with the app origin and its admission; the idle-turn test now patches the turn launch where deliver reads it.
  • Seam lists updated for the moved call sites: test_chat_turn_timeout_consistency.py, test_slot_running_readers.py, test_slack_gateway_composition_contract.py, test_slack_gateway_cron_exec_coverage.py.

Proof: on origin/main with only session_deliver.py and the new tests added, the three caller-routing tests fail. Related set: 61 test files plus the facade and flake ratchets, 3144 passed (-n 4). The new tests use no clock, sleep or network.

Manual verification

N/A — unit coverage sufficient: the rows and turns are unchanged and pinned by tests.

Related Issues

Part of #22747

Remaining on #22747:

  • Slice B: peer session_send (session_messaging.py) onto deliver with a peer origin. It has its own audience fence, cancellation shield and per-target budget.
  • A cron's own send_message to its origin session (api_send_message in handlers/messaging.py) still branches on slot.running itself; it moves onto deliver with the cron origin in a follow-up slice.
  • Slice C: the idle autonudge fire (_fire_dashboard_nudge) onto deliver, so the automation idle path stops returning NOT_DELIVERED. It needs a seam for the fire's completion hook and admission gate.

Pattern harvest

Rule candidate: review-prompt
Pattern: a sender that branches on slot.running and writes its own row instead of calling the session's delivery entry point.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@iamwhatever
iamwhatever requested review from a team and KiroCrewCaptain as code owners October 21, 2026 22:47
@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 4a886bb7f6207cfdb5d0e323893fa780b0d1b81b touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 21, 2026
@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 4a886bb7f6207cfdb5d0e323893fa780b0d1b81b — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

No design-level concerns: moving the idle-or-running choice and the row role out of each sender and into deliver() fixes the cause behind #22747, and each of the three callers keeps its gate and audit.

Notes

  • admission does three different jobs: the steer records it for a requeue, the app's queue entry stamps it, and the cron path drops it. When slices B and C land, make each origin carry its own running-path payload so admission is not stretched further.
  • If the turn ends just before the call, _steer_work_ledger_wake now gets NOT_DELIVERED from deliver's idle branch instead of a steer outcome. The wake still stays owed, but the log line now shows a delivery outcome string where it used to show a STEER_* one.

[DESIGN-REVIEWED] 4a886bb

Description read

[DESCRIPTION-READ] 4c06f32dfbad9bee4d837cd33f6bbfa15558b129aada9431d6fc56cc28f3492b

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 4a886bb7f6207cfdb5d0e323893fa780b0d1b81b — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

This moves existing behaviour without changing it, and it fixes the cause behind #22747. The two siblings it leaves are named and deferred. One branch nothing reaches yet.

Notes

  • Item 2 — zero consumers: origin_row's ORIGIN_AUTOMATION arm (("nudge", "msg msg-nudge", …)) can't be reached. deliver returns NOT_DELIVERED for an idle automation before it calls origin_row, and the running steer writes its own row. Subtraction: delete that arm until slice C actually moves the idle fire onto deliver.

What this change ships

Inventory (5 items) — 4 justified

Intent: Cron, app and work-ledger-wake text should always show up as the same row no matter whether the session was busy. FIX (cause-level refactor).

  1. Script-cron results, MCP App messages and work-ledger steers now go through one session_deliver.deliver that picks idle vs running — justified
  2. One origin→row mapping (origin_row) for cron/app/automation — zero consumers (automation arm)
  3. The app handler's full-queue 429 now comes from deliver's QUEUE_FULL, and nothing is written — justified
  4. Steer outcomes now come back as DELIVERED_* values, read by _steer_work_ledger_wake — justified
  5. A monitor-architecture.md paragraph on the delivery entry point — justified

Siblings still unmoved, all declared and deferred: handlers/messaging.py:804 (cron send_message), peer session_send, the idle autonudge fire (2 grep hits for queue_cron_notification( outside the module, 1 already moved).

[FIRST-PRINCIPLES-REVIEWED] 4a886bb

Description read

[DESCRIPTION-READ] fe8d0b2f1964bf2b2f5ea61388fb9c4ec79e3334df15223126e1c7bfcf2036fe

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 4a886bb7f6207cfdb5d0e323893fa780b0d1b81b — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 4a886bb

Verdict parsed from the review's SHA-scoped output markers for commit 4a886bb7f6207cfdb5d0e323893fa780b0d1b81b.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 4a886bb7f6207cfdb5d0e323893fa780b0d1b81b: <one-sentence reason>

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 4a886bb7f6207cfdb5d0e323893fa780b0d1b81b and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 4a886bb

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 4a886bb7f6207cfdb5d0e323893fa780b0d1b81b: <one-sentence reason>

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to ship. Head reviewed: 0fe873c.

What I checked by hand, against the base each caller had:

  • Cron script result: the idle row (role, cls, meta) and the turn kwargs match the old branch. _synthetic_payload stays False because _run_chat defaults it to False. The running path still calls queue_cron_notification.
  • App message: the idle row still comes from app_inject_row. The queued entry keeps appLabel plus the containment stamp in its meta. A full queue still returns 429 and writes nothing. The admission is released on that path because _adm.commit() now runs only after a delivered outcome. The only new work on the idle path is the containment_meta read, which the running path already did.
  • Work-ledger wake: the steer gets the same nudge_meta and user_origin=False. If the turn ends during the earlier mode check, deliver now returns not delivered without calling the steer. The caller already treats that as "the wake stays owed".
  • The facade _run_chat and spawn_guarded_turn are the same objects as the ones deliver imports, so the seam list edits are correct.
  • The First Principles note about api_send_message is answered: the description lists it under the remaining work on the linked issue.
  • main has not changed any touched file since the merge base.

No must-fix or should-fix findings.

Remaining maintainer checks before approval: PR Readiness is still pending, and the backend test shards are still running on this head. Real Adapter Contract Tests is red. Its annotations show the sandbox backend was not available on the runner, and the failing tests are not in this diff. A rerun after the shards finish should clear it.

@iamwhatever

Copy link
Copy Markdown
Contributor Author

The only red check on head 0fe873c is Real Adapter Contract Tests: the main-wide failure from #22807 (every test_pi_real_adapter.py test fails at setup with SandboxUnavailableError). It is tracked in #22958, with fix PR #22951. This PR touches no pi or sandbox code and needs no change. Once #22951 merges I will re-run that check once.

@iamwhatever
iamwhatever force-pushed the refactor/22747-deliver-entry branch from 0fe873c to 4a886bb Compare October 22, 2026 01:57
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Rebased onto the #22951 fix: 0fe873c -> 4a886bb, base 398772f. No code change; scoped tests green locally (513 passed). CI re-running.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 22, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Review-ready on head 4a886bb: pr_status.py exits 0 (105 checks, 0 failing, readiness: passed), GPT and Opus clean on this head, Design / First Principles / UX PASS. Part of #22747: cron, app message and work-ledger wake now go through session_deliver.deliver; slice B (peer session_send), slice C (idle autonudge fire) and a cron's api_send_message stay as the remaining work. Waiting for a maintainer review.

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving head 4a886bb.

Gates checked on this head:

  • Readiness label is passed and PR Readiness is green.
  • Required checks are green, including Coverage Gate.
  • All AI review lanes name this head. None of them blocks.
  • No open change request. No security path is touched.

This head is a rebase only. The range diff matches the commit I reviewed before, so my earlier review stands. One deliver() helper now serves cron, app and wake text.

@bolichen97
bolichen97 enabled auto-merge (squash) October 22, 2026 04:11
@bolichen97
bolichen97 merged commit 0cf2bc6 into main Oct 22, 2026
106 checks passed
@bolichen97
bolichen97 deleted the refactor/22747-deliver-entry branch October 22, 2026 04:36
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants