Repository navigation
fix(chat): keep a send that lands while a hard Stop settles - #18822
Conversation
A message sent while a second Stop press hard-killed a dashboard turn could be acknowledged as queued and then discarded. Nothing ran it and nothing said so. stop_slot_turn's hard-kill branch read the queued contents, awaited _settle_discarded_stage_deliveries with them, and only then cleared the queue. When an entry owes a sub-agent completion, that settle suspends: it can wait on the child's teardown and writes the delivered records on a worker thread. A send that landed in that window took the busy branch, was queued and acknowledged, and was then removed by the clear, unsettled. The branch now takes the queue and clears it in one step, with no await between them, and settles what it took. The kill discards what was queued when it was pressed; a send that lands during the settle stays queued, as one landing a moment later already did.
UX Review (Opus 5.5, fork) — ⏭️ skippedRevision |
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing to check. [DESIGN-REVIEWED] 99b33bb Description read[DESCRIPTION-READ] 572e5c328a1a88a1f1a4bfab717811444126702cb7cbde3aaea4e3fa9383a148 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 |
First Principles Review (Opus 5.5, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS The tests only check that the late send is still in the queue, not that it runs. Confirm the finalizer's What this change shipsInventory (2 items) — 2 justifiedIntent: when someone sends a message while a hard Stop is settling, the message should run as the next turn instead of being accepted and then quietly lost. FIX.
[FIRST-PRINCIPLES-REVIEWED] 99b33bb Description read[DESCRIPTION-READ] e2ec5645a39097e51fbf11a5048360fbca359f668709e7348ab8260943dc2e5a That sha256 names the PR description this verdict read. Recompute it with |
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed |
iamwhatever
left a comment
There was a problem hiding this comment.
This fixes a send that is acknowledged as queued during a hard Stop and then silently discarded. The root cause is solved: stop_slot_turn's hard-kill branch read the queue, awaited _settle_discarded_stage_deliveries (which can suspend), and only then cleared the queue, which wiped any entry queued during that await. The queue is now copied and cleared with no await between them, and the copy is settled. I read the diff against main's stop branch. A send that lands during the settle now behaves exactly like one that lands right after the clear, which already stayed queued. Nothing queued before the press survives, and the steer handling is unchanged. The new test drives the real stop_slot_turn and queue_for_next_turn with a settle that suspends, and the body shows it red on base. The control test pins that the soft stop still keeps the queue and that the hard kill still settles owed deliveries. All lanes PASS, checks are green, base is main, and the change is small. — crew-pr-reviewer
Problem / Motivation
Goal: A message sent while a hard Stop is settling the discarded queue stays queued for the next turn, instead of being acknowledged and then silently discarded.
The second Stop press (or
?force=true) takes the hard-kill branch ofstop_slot_turn(src/kiro_crew/dashboard/chat_handlers.py). That branch read the queued contents, awaited_settle_discarded_stage_deliverieswith them, and only then ranslot._queue.clear().When a queued entry owes a sub-agent completion, the settle suspends:
SubagentManager.settle_queued_deliverycan wait on the child's teardown gate and writes the delivered records throughasyncio.to_thread(src/kiro_crew/subagent_manager/waves.py). A send that landed in that window tookapi_chat's busy branch, because the turn being killed was still running. It was appended byqueue_for_next_turn, broadcast asqueue_pushand acknowledged with{"queued": true, "queue_id": ...}. The clear then removed it. It had not been part of the read contents, so it was neither settled nor run.Why it matters
The user presses Stop twice, types the next instruction, sees it accepted as queued, and it never runs, with no notice. The same send arriving a moment later, after the clear, stays queued. So one action has two outcomes depending on timing. The reach is narrow: a hard stop, a queue holding a sub-agent completion owed to the parent, and a send inside the settle's suspension.
Not a goal
_pending_steersafter the await too, but a steer it drops loses its delivery id, whichsteer_into_running_turnreads as not delivered, so its sender is told (the comment at that clear describes this). That outcome is by design and is unchanged.What changed (motivation → approach → change)
Symptom: a send acknowledged as queued during a hard stop is discarded (see Tests).
Root cause:
stop_slot_turn's hard-kill branch separated reading the queue from clearing it with an await, so the clear removed entries the settle never saw.Change, in
stop_slot_turnonly: take the queue and clear it in one step, with no await between them (discarded = list(slot._queue), thenslot._queue.clear()), then await_settle_discarded_stage_deliverieswith the taken entries. The kill discards what was queued when it was pressed. A send that lands during the settle stays in the emptied queue, as one landing after the clear already did, and the turn's end starts it as the next queued turn (the finalizer drains the queue whenever the turn's memory was admitted and setup did not fail,_run_chat'sdrain=insrc/kiro_crew/dashboard/chat_runner.py).Rejected alternatives:
Backwards compatibility
Compatible: the hard kill still discards every entry queued when it was pressed and settles the sub-agent deliveries they owed (
test_a_hard_stop_still_discards_and_settles_what_was_queued_before_it, and the existingtest_the_stop_button_still_escalates_on_a_second_press).Compatible: the soft Stop keeps the queue, as before (asserted in the control test after the first press).
Removes nothing: no function, field or outcome is removed; the only difference is that a send made during the settle is no longer discarded.
Tests
New tests in
test/test_session_control.py, besidetest_the_stop_button_still_escalates_on_a_second_press, with an_owed_completionhelper and a_SettlingManagerstand-in whosesettle_queued_deliverysuspends once:test_a_send_that_lands_while_a_hard_stop_settles_stays_queued: two presses through the realstop_slot_turn; inside the settle, a send is made through the realqueue_for_next_turn, the callapi_chat's busy branch makes. After the kill the queue holds exactly that send.test_a_hard_stop_still_discards_and_settles_what_was_queued_before_it(control): the first press keeps both queued entries and settles nothing; the second clears them and settles the owed delivery.Red on origin/main d32c084, with only the test file copied onto it (3 of 3 serial runs; the control passes there):
Green on this branch (rebased onto origin/main d32c084), the new tests 3 of 3 serial runs:
pytest -n 0 test/test_session_control.py -k hard_stop: 2 passed each run.pytest -n 0overtest/test_session_control.pyfirst and then the 8 other test files that usestop_slot_turnor the delivery settle (test_chat_handlers_composition_contract.py,test_compaction_stop_declined.py,test_session_broadcast.py,test_session_control_doc.py,test_slot_running_readers.py,test_stop_handler_idempotent.py,test_stop_wedged_dispatched_turn.py,test_work_ledger_board.py): 610 passed.scripts/check_black_formatting.py,COMMENT_HISTORY_BASE_REF=origin/main scripts/check_comment_history.pyand./scripts/docs-lint.sh: all exit 0.Manual verification
Ran the new tests against the unchanged source (red, above) and on this branch (green), with
pytest -n 0. They drivestop_slot_turnin-process on a slot from the shared dashboard test state, with a fake sub-agent manager; no gateway, model or network.Related Issues
Related: open #13354 (the same clear drops a cross-session delivery queued before the kill without telling its sender), merged #13303. Open #10098 replaces this
slot._queue.clear()withslot.queue_discard_all(), and open #10690 adds lines next to the steer clear; whichever lands second rebases.Pattern harvest
Rule candidate: review-prompt
Pattern: a snapshot of shared state handed to an await, and the state cleared after the await returns; whatever was added during the await is cleared without being handled.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)