Repository navigation
fix(session-control): tell the sender when a queued delivery is discarded - #18913
Conversation
…rded A queue-card cancel and a hard stop both discard a queued cross-session delivery without reading its sender stamp, so the sender's last word stays the started:false receipt. Both sites now call notify_send_origin_discarded, which shares the drop notice's recipient check and words the notice for the discard. Fixes #13354
8601d2d to
1a721d8
Compare
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
UX Review (Opus 5.5) — ⏭️ skippedRevision |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Check before merge: a rewind ( What this change shipsInventory (6 items) — 6 justifiedIntent: a session that queued a message to another session learns when that message is discarded and will never run. FIX (#13354; tests fail on base).
[FIRST-PRINCIPLES-REVIEWED] f617397 Description read[DESCRIPTION-READ] d06a293e5d4e9cc054f5ed0cf2a40921aebe364334c2c65d0386b08b24834d1e That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing to check. [DESIGN-REVIEWED] f617397 Description read[DESCRIPTION-READ] 3cff6a9675f174bc00dd338858facdbd5821f5021b343b6afe5e55bb757fe322 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 |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
bolichen97
left a comment
There was a problem hiding this comment.
Approved at head f617397: PR Readiness is green, no open change requests, and the review lanes passed. (AI-assisted review at bolichen97's request.)
Problem / Motivation
Goal: A session whose queued message to another session is cancelled from that session's queue, or discarded by a hard stop, is told in its own transcript that the message will not run.
session_sendinto a busy target answersstarted: false: the message is on the target's queue and will run later. Two deliberate actions take it off that queue unrun, and neither tells the sender:api_chat_slot_queue_cancel(dashboard/chat_handlers.py) takes only the text out throughslot.queue_remove_by_id(queue_id), so the entry's sender stamp is discarded unread.stop_slot_turncallsslot._queue.clear()after_settle_discarded_stage_deliveries, which settles sub-agent delivery debt but never reads the sender stamp.Only the drain's re-check (
_drop_stale_admissions) reads the stamp and writes a sender notice today.Why it matters
A session coordinating others is told its message is queued. If the target's queue card is cancelled or the target is hard-stopped, that receipt is the last thing the sender hears, and it is false: the message will never run, and the sender keeps waiting for a reply that cannot come. Every sign of the discard is on the target's transcript, which the sender does not read.
Not a goal
CHANNEL_RECIPIENT_META_KEY). Its notice is a network write with its own recipient ladder; the issue scopes to the session-to-session sender stamp./stopunder a unifieddm_scope(messaging: /stop under a unified dm_scope discards other senders queued messages #12660), which clears a different queue.What changed (motivation → approach → change)
Symptom: a cross-session delivery cancelled from the queue or cleared by a hard stop leaves its sender with a "queued" receipt and no further word (see Tests).
Root cause: the sender stamp (
send_origin_meta) is read at only one of the three places a stamped entry leaves the queue unrun.Change:
session_control.notify_send_origin_discarded(state, *, entry_meta, target_slot, text, cause)reads the stamp off the entry's meta and appends to the sender:⚠️ Message you sent to <target> was discarded before it ran: <reason>. It was not delivered and will not run. Text: "<excerpt>".causeisSEND_DISCARD_QUEUE_CANCEL("it was cancelled from that session's queue") orSEND_DISCARD_HARD_STOP("a hard stop of that session discarded its queue").notify_send_origin_droppedinto_send_origin_recipient, used by both notifiers, so the four no-write cases (no stamp, self-send, closed sender, reused key held by a different tab) hold identically on all three discard paths.notify_send_origin_droppedkeeps its signature, wording and behaviour.api_chat_slot_queue_cancelkeeps the entry it already looks up for the user-origin check and notifies after a successful removal.stop_slot_turnalready takes the queue and empties it in one step before the sub-agent settle (merged fix(chat): keep a send that lands while a hard Stop settles #18822). This change notifies the sender of each taken entry right after that clear, synchronously, before the settle can suspend, so a cancelled stop cannot leave a discarded entry unreported._queue.clear()stays the module's single clear, astest_session_control_doc.pypins.docs/system-specs/modules/session-control.mdand the module docstring describe the discard notice.Rejected alternatives:
constraints=[]or a synthetic constraint tonotify_send_origin_dropped: its wording explains a changed authorization, which a deliberate discard is not, and an empty list renders an explanation of nothing.reasonkeyword onnotify_send_origin_droppedthat switches its wording: one function with two mutually exclusive argument sets. A second notifier sharing the recipient resolver keeps each signature honest and the identity check in one place.Backwards compatibility
Compatible: both discards still remove exactly what they removed before; the only addition is a notice row on a live sending session.
Removes nothing: no function, field, key or outcome is removed, and
notify_send_origin_droppedkeeps its signature and wording.Tests
New
test/test_queue_discard_sender_notice.py(12 tests), driving the real queue-cancel route handler and the realstop_slot_turnwith realsession_senddeliveries:test_cancelling_a_queued_delivery_tells_its_sender: names the target, says it will not run, quotes the text, and does not use the drain's authorization wording.test_cancelling_one_entry_tells_only_its_own_sender,test_cancelling_a_human_typed_entry_tells_nobody,test_a_cancel_of_an_unknown_id_tells_nobody.test_a_hard_stop_tells_every_sender_its_message_was_discarded: each sender learns about its own message only.test_a_soft_stop_keeps_the_queue_and_tells_nobody(control).test_a_hard_stop_reports_only_the_entries_it_took: the entry the kill took is reported; a send made inside the settle await stays queued and its sender is told nothing.test_a_hard_stop_of_a_human_typed_queue_tells_nobody,test_a_hard_stop_tells_a_closed_sender_nothing,test_a_hard_stop_does_not_reach_the_next_tenant_of_a_reused_key.test_discard_notifier_writes_nothing_without_a_live_matching_sender,test_an_unknown_discard_cause_writes_nothing_and_does_not_raise.Red with
chat_handlers.pyreset to origin/main bf1723d (4 failed, 8 passed; the controls pass):Green on this branch:
pytest -n 0 test/test_queue_discard_sender_notice.py: 12 passed.pytest -n 8over the new file plustest_queue_drop_sender_notice.py,test_queue_cancel.py,test_session_control.py,test_session_control_doc.py,test_stop_handler_idempotent.py,test_compaction_stop_declined.py,test_chat_handlers_composition_contract.py,test_slot_running_readers.py,test_stop_wedged_dispatched_turn.py,test_session_broadcast.py,test_queued_prompt_durability.py,test_discord_resumed_busy.py,test_work_ledger_board.py: 867 passed.scripts/check_comment_history.py,scripts/check_black_formatting.py,scripts/check_sync_io_in_async.py,scripts/check_subprocess_encoding.py,scripts/check_feature_map.py,./scripts/docs-lint.sh: all pass.Manual verification
N/A — unit coverage sufficient: the tests drive both real handlers in-process, and the notice is a transcript row with no rendering change.
Related Issues
Fixes #13354
Related: merged #13303 (the drain-side sender notice). Merged #18822 (keeps a send that lands while a hard stop settles; this branch is rebased onto it). Open #10098 touches the same hard-kill clear; whichever lands second rebases.
Pattern harvest
Rule candidate: review-prompt
Pattern: a per-entry stamp read at one removal site of a collection while sibling removal sites discard the entry unread.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributed under the project's Apache-2.0 license.