Skip to content

fix(chat): keep a send that lands while a hard Stop settles - #18822

Merged
iamwhatever merged 1 commit into
kirodotdev:mainfrom
javenciu:fix/chat-hard-stop-keeps-new-send
Oct 10, 2026
Merged

iamwhatever merged 1 commit into
kirodotdev:mainfrom
javenciu:fix/chat-hard-stop-keeps-new-send

Conversation

@javenciu

Copy link
Copy Markdown
Contributor

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 of stop_slot_turn (src/kiro_crew/dashboard/chat_handlers.py). That branch read the queued contents, awaited _settle_discarded_stage_deliveries with them, and only then ran slot._queue.clear().

When a queued entry owes a sub-agent completion, the settle suspends: SubagentManager.settle_queued_delivery can wait on the child's teardown gate and writes the delivered records through asyncio.to_thread (src/kiro_crew/subagent_manager/waves.py). A send that landed in that window took api_chat's busy branch, because the turn being killed was still running. It was appended by queue_for_next_turn, broadcast as queue_push and 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

  • A cross-session delivery queued before the kill is still discarded without telling its sender. That is open issue dashboard: a queue-cancel or hard-kill discard strands the sender of a queued cross-session delivery #13354, about the same clear; this change does not fix it.
  • Pending steers. The same branch clears _pending_steers after the await too, but a steer it drops loses its delivery id, which steer_into_running_turn reads as not delivered, so its sender is told (the comment at that clear describes this). That outcome is by design and is unchanged.
  • The soft (first-press) Stop, which keeps the queue. 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_turn only: take the queue and clear it in one step, with no await between them (discarded = list(slot._queue), then slot._queue.clear()), then await _settle_discarded_stage_deliveries with 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's drain= in src/kiro_crew/dashboard/chat_runner.py).

Rejected alternatives:

  • Removing only the read entries by id after the await: the same result with more code.
  • Refusing sends while the stop is killing: changes the busy-branch contract for every surface.

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 existing test_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, beside test_the_stop_button_still_escalates_on_a_second_press, with an _owed_completion helper and a _SettlingManager stand-in whose settle_queued_delivery suspends once:

  • test_a_send_that_lands_while_a_hard_stop_settles_stays_queued: two presses through the real stop_slot_turn; inside the settle, a send is made through the real queue_for_next_turn, the call api_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):

E       AssertionError: the send acknowledged during the hard stop was discarded: queue = []
FAILED test/test_session_control.py::test_a_send_that_lands_while_a_hard_stop_settles_stays_queued
1 failed, 1 passed

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 0 over test/test_session_control.py first and then the 8 other test files that use stop_slot_turn or 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.
  • mypy, flake8, isort, black (neither file is in the black baseline), scripts/check_black_formatting.py, COMMENT_HISTORY_BASE_REF=origin/main scripts/check_comment_history.py and ./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 drive stop_slot_turn in-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() with slot.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

  • 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

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.
@javenciu
javenciu requested review from a team and KiroCrewCaptain as code owners October 10, 2026 10:33
@javenciu
javenciu requested a review from CrysisDeu October 10, 2026 10:33
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5, fork) — ⏭️ skipped

Revision 99b33bb141c214aacc7a6be021ad061fc92710f7 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Advisory — does not block merge.

@github-actions

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — ✅ PASS

Design-level review of 99b33bb141c214aacc7a6be021ad061fc92710f7 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

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 .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, fork) — ✅ PASS

Premise-level review of 99b33bb141c214aacc7a6be021ad061fc92710f7 via the fork AI-review pipeline — 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/CONCERNS are advisory.

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 drain= actually starts it after a hard kill.

What this change ships

Inventory (2 items) — 2 justified

Intent: 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.

  1. A message sent while a hard Stop settles stays queued for the next turn instead of being thrown away — justified
  2. Two new tests: one that fails on base, plus a control showing the hard kill still discards and settles what was queued before it — justified

[FIRST-PRINCIPLES-REVIEWED] 99b33bb

Description read

[DESCRIPTION-READ] e2ec5645a39097e51fbf11a5048360fbca359f668709e7348ab8260943dc2e5a

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

GPT 6.1 Review (fork) — ✅ no blocking findings

Reviewed 99b33bb141c214aacc7a6be021ad061fc92710f7 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 99b33bb

@github-actions

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

Reviewed 99b33bb141c214aacc7a6be021ad061fc92710f7 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 99b33bb

@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 10, 2026

@iamwhatever iamwhatever 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.

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

@iamwhatever
iamwhatever merged commit 3525227 into kirodotdev:main Oct 10, 2026
103 checks passed
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 10, 2026
@javenciu
javenciu deleted the fix/chat-hard-stop-keeps-new-send branch October 11, 2026 04:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants