Skip to content

refactor(dashboard): route peer session_send through session_deliver.deliver - #23028

Merged
iamwhatever merged 1 commit into
mainfrom
refactor/22747-deliver-peer
Oct 22, 2026
Merged

iamwhatever merged 1 commit into
mainfrom
refactor/22747-deliver-peer

Conversation

@iamwhatever

@iamwhatever iamwhatever commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A peer session's session_send reaches its target through the same session-side deliver() that cron, app and work-ledger text already use, with every guard it has today unchanged.

send_to_target still called steer_into_running_turn and enqueue_or_run_prompt itself, so the peer sender kept its own copy of the steer-or-queue choice. #22937 moved cron, app messages and the work-ledger wake onto session_deliver.deliver; this is slice B of #22747.

Why it matters

With two places owning the choice, a later change to how a delivery lands has to be made twice, and the peer copy is the one with the most guards around it.

Not a goal

  • Changing the peer path's audience fence, cancellation shield, per-target budget, post-RPC re-gate, containment stop or audit. They stay in send_to_target, around the calls.
  • Changing any row, queue entry or turn a peer send produces.
  • Moving the idle autonudge fire (slice C) or a cron's api_send_message.

What changed (motivation → approach → change)

Approach: add a peer origin to deliver() and replace the three delivery calls in send_to_target with it. Everything between those calls stays where it is.

  • dashboard/session_deliver.py: ORIGIN_PEER, peer(steer=...), a queue_meta argument, and _deliver_peer. peer(steer=True) is the steer arm only (user_origin=False, the caller's admission); if the turn ended before it ran it returns NOT_DELIVERED and writes nothing, so the caller's re-gated fallback stays the one delivery. peer(steer=False) is enqueue_or_run_prompt with queue_meta as its extra_meta.
  • dashboard/session_control_parts/session_messaging.py (send_to_target): the shielded steer task, the orphaned-unavailable fallback and the queue-or-run arm call deliver with the peer origin, and read DELIVERED_* outcomes instead of STEER_*. The non-steer call has no suspension inside, so it adds no cancellation point.
  • Spec: monitor-architecture.md.

Known limit: send_to_target still chooses steer first, then queue. Its audience fence, shield and post-RPC re-gate sit between those two calls, so the choice cannot move into one deliver() call without moving those guards too. This PR keeps them where they are; deliver() owns how each arm lands.

Size: about 75 production lines in 2 files.

Backwards compatibility

Compatible: a peer send writes the same user row, steer row, queue entry and sendOrigin stamp it wrote before, with the same user_origin=False. The existing test_session_control_send.py and test_session_control_steer_delivery.py suites pass unchanged except one source-scan anchor.

Removes nothing: the moved calls keep their behavior; no key, route or guard goes away.

Tests

  • test/test_session_deliver.py TestPeer: a steer that finds the turn ended delivers nothing (fails if the steer arm falls through to queue-or-run); idle runs a user row and a turn with no human stamp; a running slot queues a non-steer send with its queue_meta; a running slot steers a send as a user steer row (no nudge); steer outcomes map to delivery outcomes and pass user_origin=False and the admission.
  • test/test_session_control_send.py: send_to_target calls deliver with peer(steer=True), then on an unavailable steer peer(steer=False) with the sender stamp, and the text lands on the queue.
  • test_session_control_steer_delivery.py (source-scan anchor) and test_slot_running_readers.py (new slot.running reader) updated.

Proof: on origin/main with only session_deliver.py and the new tests added, the send_to_target routing test fails. Related set: 3202 passed (-n 4), including the facade and flake ratchets. No clock, sleep or network in the new tests.

Manual verification

N/A — unit coverage sufficient: rows, queue entries and turns are unchanged and pinned by the existing peer suites.

Related Issues

Part of #22747

Remaining on #22747:

  • Slice C: the idle autonudge fire (_fire_dashboard_nudge) onto deliver, so the idle automation path stops returning NOT_DELIVERED.
  • A cron's own send_message (api_send_message in handlers/messaging.py) onto deliver with the cron origin.

Pattern harvest

Not generalizable: this moves one more sender onto the entry point slice A added; the pattern was harvested there.

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 22, 2026 05:05
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

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

@github-actions

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Nothing blocks: it is a reversible refactor with the same rows, queue entries and guards, and nothing is taken away.

Notes

  • send_to_target still decides between steer and queue: it calls peer(steer=True) and then falls back to peer(steer=False) itself. The peer branch in deliver() runs before the slot.running dispatch and only passes the call through. So the "two places owning the choice" problem named in Why it matters is mostly not removed yet. Say so in the spec, or move the fallback into _deliver_peer in a follow-up.
  • Origin.steer is read only by the peer branch, so on the cron, app and automation origins it is a field that does nothing. Keep it on peer() only. Do not let other origins start reading it unless the spec says how it applies to them.

[DESIGN-REVIEWED] 52518e9

Description read

[DESCRIPTION-READ] 0dfbc84380d8b4d6958cdf8f16b563a2d6cdb4d8e88585d5f779f0cd1aaf643c

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

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 52518e9457d837bae8a69c823a93ffee3bab4300 — 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

The refactor is reversible and changes no behaviour, but it only half-removes its stated harm: the peer arm forks off before deliver() makes its idle-or-running choice, and the caller still picks steer or queue.

Notes

  • Item 2 — symptom-level: the Goal says "With two places owning the choice", but send_to_target still makes the steer-or-queue choice and hands it in as peer(steer=...). deliver() then sends ORIGIN_PEER to its own branch (session_deliver.py:129) ahead of the shared if slot.running: dispatch, so the choice still lives in two places. Subtraction: delete Origin.steer, which only _deliver_peer reads (1 reader, grepped origin\.steer), and let deliver()'s existing slot.running dispatch pick the arm.
  • Item 3 — duplicate of session_deliver.py:181-185: _deliver_peer restates the STEER_STEERED/STEER_REQUEUED → DELIVERED_* mapping that the automation arm already has. That makes 2 copies in one file (grepped STEER_STEERED in session_deliver.py). Subtraction: send the peer steer through _deliver_running's steer call with nudge_meta unset, and drop the second mapping.

What this change ships

Inventory (5 items) — 3 justified

Intent: let a peer session's message reach its target through the same delivery entry point that cron, app and work-ledger messages use. REFACTOR, which works as an ADDITION to deliver().

  1. A peer session_send now goes through session_deliver.deliver instead of calling steer and queue directly — justified
  2. A new peer origin with a steer flag that the caller sets — symptom-level: the caller still owns the steer-or-queue choice
  3. A separate _deliver_peer branch that maps steer outcomes itself — duplicate of session_deliver.py:181-185
  4. A queue_meta parameter on deliver() that only the peer path uses — justified
  5. The spec paragraph and the slot-running reader list are updated — justified

[FIRST-PRINCIPLES-REVIEWED] 52518e9

Description read

[DESCRIPTION-READ] 5ff22297c841b4e48892e6c80183e2422ec69f23b3751c3a8e6b70ab7577d1b7

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

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 52518e9457d837bae8a69c823a93ffee3bab4300 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 52518e9

Verdict parsed from the review's SHA-scoped output markers for commit 52518e9457d837bae8a69c823a93ffee3bab4300.

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

@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 52518e9457d837bae8a69c823a93ffee3bab4300 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 52518e9

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

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Oct 22, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Review-ready on head 52518e9: pr_status.py exits 0 (114 checks, 0 failing, readiness: passed), GPT and Opus clean on this head, Design / First Principles / UX PASS. Part of #22747 (slice B): peer session_send now goes through session_deliver.deliver with its fence, shield and re-gate unchanged. Remaining: slice C (idle autonudge fire) and a cron's api_send_message. Waiting for a maintainer review.

@iamwhatever
iamwhatever enabled auto-merge (squash) October 22, 2026 07:20

@buluoray buluoray 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 at 52518e9457d837bae8a69c823a93ffee3bab4300.

Peer session_send now goes through session_deliver.deliver() with a peer origin. The audience fence, cancellation shield, post-RPC re-gate and containment stop stay in send_to_target.

What I checked:

  • The outcome mapping in _deliver_peer is complete. steer_into_running_turn returns only steered / requeued / unavailable (chat_delivery.py:48-50), so unavailable → NOT_DELIVERED loses nothing.
  • The new not slot.running early return only covers the gap between the caller's synchronous steer and slot.running check and the steer task starting. Main got unavailable there and fell to the queue arm; this gets NOT_DELIVERED and falls to the same arm. No double delivery.
  • The steer=False arm calls enqueue_or_run_prompt synchronously, so await deliver(...) adds no cancellation point. user_origin=False and the admission baseline pass through unchanged.

Tests: 600 passed across the 19 test files that touch send_to_target / session_deliver / broadcast_to_targets. Ten single-line mutations of the new guards each turn a named test red (ended-turn steer, user_origin, admission, requeued mapping, both queue_meta sites in the main arm, the orphaned-fallback outcome, the peer dispatch).

Non-blocking follow-up: setting the orphaned fallback's queue_meta to None survives. test_an_orphaned_delivery_that_comes_back_unavailable_is_queued asserts the text is queued but not its sender stamp. Same gap on main.

CI on this head: 87 success, 14 skipped, 0 failing. Opus, GPT, Design and First Principles are clean.

@iamwhatever
iamwhatever merged commit d98094f into main Oct 22, 2026
114 of 115 checks passed
@iamwhatever
iamwhatever deleted the refactor/22747-deliver-peer branch October 22, 2026 07:57
@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