Skip to content

fix: let a queued reset wait for a completion already in the tab queue - #36601

Open
bolichen97 wants to merge 1 commit into
mainfrom
fix/35237-reset-waits-queued-completion
Open

bolichen97 wants to merge 1 commit into
mainfrom
fix/35237-reset-waits-queued-completion

Conversation

@bolichen97

@bolichen97 bolichen97 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A conversation reset queued during a turn lands only after a sub-agent completion already waiting in the tab's queue has run in the conversation it was queued for, and failure notices still pending when it lands are not handed to the fresh conversation.

When the agent resets its conversation during a turn while one of its sub-agent completions waits in the tab's queue, the reset lands at the turn's end and the queue hand-off then starts the fresh conversation with that completion. Failure notices pending for the old conversation are drained into the fresh conversation's next prompt.

Why it matters

When the agent resets its conversation mid-turn (the reset_conversation tool, or a /clear the dashboard answers itself) while one of its sub-agent completions waits in the tab's queue, the fresh conversation's first turn is that old run's result. The new conversation spends a turn, and its context, on work that belonged to the conversation that was just dropped, and failure notices for the old conversation reach the new one's next prompt the same way.

Not a goal

What changed (motivation → approach → change)

A reset queued during a turn now waits for a sub-agent completion already in the tab's queue: the completion runs in the conversation it was queued for, then the reset lands. A landed reset also settles the tab's pending failure notices instead of leaving them for the fresh conversation's next prompt. A /clear that waits this way drops the checklist where the reset lands, so the fresh conversation does not rebuild the old plan.

The queued reset already waited for attached sub-agent work (running children, store-queued rows, deliveries in flight), but not for a completion sitting in the tab's queue, so it landed at the turn's end and the queue hand-off gave that completion to the new conversation.

In _consume_pending_reset's discard branch (the shape decided on #12069), the own_turn consumes (the end-of-turn one and the dashboard-answered /clear) leave the discard armed while the queue holds a SUBAGENT_COMPLETION_KIND entry (the test the drain's user hold already makes) or a verbatim requeue of a completion turn (_REPLAYS_COMPLETION_KEY); one helper, _a_completion_is_queued, makes that test. The hand-off still drains system entries behind an armed discard, so the completion runs in the old conversation and the consume at that turn's end lands the reset. The armed-reset retry does not wait on a queued completion, so a held queue (sign-in, memory preparation, Pause all) still gets its reset a few seconds after the turn ends. A discard that lands settles the pending notices with settle_drained_subagent_notices, the helper both notice drains use.

A dashboard-answered /clear whose discard waits only on a queued completion (no children attached) marks it with one slot flag, _pending_discard_drops_plan, and the consume drops the plan (slot.set_todo(None) and its todo_update) where that discard lands, as a /clear that lands at once does. It cannot drop it at the /clear: the completion turn runs in the old conversation, whose todo_list can send its whole plan again. Its reply text and recorded outcome (queued) stay as they are. The hold giving the discard up clears the flag.

session.md records the wait, the plan drop, why the immediate route's 409 does not share the wait, and the settle; its two #12069 pointers and the two in subagent.md say the conversation-incarnation counter was declined there.

Backwards compatibility

Compatible: a reset with no completion queued lands exactly as before; one with completions queued lands once those completions have run, and the route, the retry and the shared check are unchanged. A /clear waiting on a queued completion drops the plan where its reset lands, as a /clear that lands at once does; a /clear deferred for attached children or a busy session, and a reset_conversation reset, keep the plan as before.

Removes nothing: the change only defers a reset until the completions already queued have run, settles notices a landed reset used to leave for the next prompt, and drops a /clear's plan where its reset lands; no key, path, record or function goes away.

Tests

test/test_queued_reset_waits_for_queued_completion.py, driving the real _consume_pending_reset, _answer_slash_without_channel and _start_next_queued_turn against a dashboard slot:

  • a completion queued at the end-of-turn consume runs in the old conversation, and the consume at its turn's end lands the reset (the real order, not the predicate alone);
  • a verbatim requeue of a completion counts; another recovery entry does not;
  • with the queue held by a sign-in hold, the retry's consume lands the reset and the completion stays queued;
  • a landed reset settles the pending failure notices and empties the list;
  • with no completion queued, the reset lands at the turn's end as before;
  • a /clear with a completion queued and no children attached records queued and keeps the plan shown; the completion runs in the old conversation and sends its plan again; its turn end lands the discard, drops the plan with one todo_update of None, clears the flag and leaves todo_recovery_prompt() empty;
  • a /clear deferred because children are attached, with or without a completion queued, keeps the plan, sends no todo_update and sets no flag;
  • a reset_conversation discard keeps the plan when it lands.

test/test_state_parts_facade.py: the fresh-slot default table lists _pending_discard_drops_plan: False.

Proof: PROVEN test/test_queued_reset_waits_for_queued_completion.py::test_a_queued_completion_runs_in_the_old_conversation_before_the_reset_lands, test/test_queued_reset_waits_for_queued_completion.py::test_a_verbatim_requeue_of_a_completion_counts, test/test_queued_reset_waits_for_queued_completion.py::test_a_held_queue_does_not_strand_the_reset, test/test_queued_reset_waits_for_queued_completion.py::test_a_landed_reset_settles_the_pending_failure_notices, test/test_queued_reset_waits_for_queued_completion.py::test_a_clear_waiting_on_a_queued_completion_drops_the_plan_where_it_lands (head cc19139186c6)

Determinism: the file ran 20 times at -n0 (10 passed each, 0 failures) and 10 times at -n 4 --dist loadgroup --max-worker-restart=2 with test_queue_hold_gate.py and test_slot_running_readers.py (66 passed each); the 64 node ids of this file and test_queue_hold_gate.py ran once in a shuffled order (seed 20083, -n0): 64 passed. No sleeps, ports or real clock; every await is bounded by the existing turn-end helpers. test_flake_pattern_ratchet.py passes (68), the repository semgrep rules (1.78.0) find nothing on the diff, and scripts/local-gate.py passed 13,804 related backend tests.

Manual verification

How it was verified, on Linux (Ubuntu 24.04, kernel 7.0, Python 3.12): the trigger is a model calling reset_conversation, or a person sending /clear, while a sub-agent completion waits in the tab's queue, which cannot be timed deterministically by hand, so the reproduction drives the real end-of-turn consume, /clear answer and hand-off on a dashboard slot. Before the fix it recorded:

AssertionError: assert ['discard', '...nished:fresh'] == ['turn:[Subag...finished:old']

and, for a /clear behind a queued completion whose turn sends the old plan again, the plan still set after the discard landed:

plan after the discard landed: {'description': 'the old plan', ... 'completed': 1, 'total': 2, ...}
todo_recovery_prompt(): '[Task checklist — automatic recovery] ...'
todo_update broadcasts: []

After the fix (smoke):

outcome: queued armed key: dashboard:s1
events after hand-off: ['turn:[Subagent completion event] run r1 finished:old']
events after completion turn end: ['turn:[Subagent completion event] run r1 finished:old', 'discard']
plan after the discard landed: None
todo_recovery_prompt(): ''
todo_update broadcasts: [{'slot': 's1', 'todo': None}]
happy outcome: discarded events: ['discard'] armed key: None

The completion runs while the discard is still armed (the old conversation), the reset lands at that turn's end, and the fresh conversation starts with no plan; with nothing queued, /clear lands at once. The nearby suites (test_queue_hold_gate.py, test_dashboard_chat.py, test_dashboard_chat_refusal.py, test_chat_runner_coverage_pending.py, test_slot_running_readers.py, test_mate_thread_wakes.py, test_chat_runner_composition_contract.py, test_chat_runner_base_surface.py, test_slash_command_redaction_records.py, test_slash_command_no_channel.py, test_state_parts_facade.py, test_todo_pill_resync.py, test_todo_list_surface.py) pass file by file.

Related Issues

Closes #35237

Sibling sweep

Swept: git grep -n "_consume_pending_reset(" -- src
Sibling: src/kiro_crew/dashboard/chat_turn/session_reset.py -- changed here
Sibling: src/kiro_crew/dashboard/chat_turn/slash_commands.py -- changed here
Sibling: src/kiro_crew/dashboard/chat_turn/queue_cycle.py:773 -- not affected -- the end-of-turn consume passes own_turn, so the new wait applies to it as it stands
Sibling: src/kiro_crew/dashboard/chat_turn/eager_spawn.py:655 -- not affected -- it never consumes a discard (no allow_discard)
Sibling: src/kiro_crew/dashboard/chat_turn/turn_admission.py:932 -- not affected -- it never consumes a discard (no allow_discard)
Sibling: src/kiro_crew/dashboard/chat_api/slot_repair.py -- not affected -- the immediate reset route keeps its 409 on attached children only, by decision
Swept: git grep -n "set_todo(None)" -- src
Sibling: src/kiro_crew/dashboard/chat_turn/session_events.py:241 -- not affected -- kiro's native /clear drops the plan on its own clear status and queues no discard
Swept: git grep -n "_pending_discard_conversation_key = " -- src
Sibling: src/kiro_crew/dashboard/state_parts/slot_session.py:384 -- changed here
Sibling: src/kiro_crew/dashboard/session_directive_apply_slot.py:225 -- not affected -- it arms a discard; only the dashboard-answered /clear sets the flag
Sibling: src/kiro_crew/dashboard/state_parts/chat_slot.py -- changed here

Pattern harvest

Not generalizable: the wait is specific to a deferred discard racing the tab's own queue; its kind test mirrors the one the drain's user hold already makes.

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

Contribution License Agreement

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 87190faaa63012079835bb7767e06a4c1bf2aa7f 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 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 87190faaa63012079835bb7767e06a4c1bf2aa7f — 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

Nothing blocks. The wait, the notice settle and the /clear plan drop each target a defect in the same reset path, and the PR adds a test for each.

What this change ships

Inventory (6 items) — 5 justified

Intent: when the agent or a person resets a conversation mid-turn, a sub-agent result already queued for the old conversation should not become the fresh conversation's first turn, and the old conversation's failure notices should not leak into it. FIX.

  1. A queued reset now waits until a sub-agent completion already in the tab's queue has run in the old conversation, then lands — justified
  2. When the reset lands, pending failure notices for the old conversation are settled instead of being prepended to the fresh conversation's next prompt — justified
  3. A /clear that waits only on a queued completion now drops the checklist when the reset lands (new slot flag _pending_discard_drops_plan) — justified
  4. A tab whose queue is held (sign-in, memory preparation, Pause all) still gets its reset from the retry a few seconds after the turn ends; the retry does not wait on the completion — justified
  5. Giving up the queue hold also clears the plan-drop flag — justified
  6. Spec wording for Parent-end teardown: a spawn admitted late may start and a report late may deliver — no conversation-incarnation counter exists #12069 changes from "tracked" to "declined the counter" in session.md and subagent.md — rides along

[FIRST-PRINCIPLES-REVIEWED] 87190fa

Description read

[DESCRIPTION-READ] 83803288dee05b6730843b2b629a24a92229a2fddadb6febebaf0d14f108a930

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 Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Nothing blocks: the fix is a narrow change to _consume_pending_reset's existing discard branch, it adds one state flag on the slot, and it removes nothing.

Notes

  • If completions keep arriving, each completion turn re-arms the wait, so a /clear can be held off for as long as new completions keep coming. That is the same open-ended wait the attached-children deferral already accepts, but session.md should say so.

[DESIGN-REVIEWED] 87190fa

Description read

[DESCRIPTION-READ] c3061aabd221a72de523f9eec5c7dd6b887bb32fb3579cce8cd9c61cf0ab8471

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.

@bolichen97
bolichen97 enabled auto-merge (squash) November 13, 2026 12:21
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 87190faaa63012079835bb7767e06a4c1bf2aa7f and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 87190fa

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 87190faaa63012079835bb7767e06a4c1bf2aa7f false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 87190faaa63012079835bb7767e06a4c1bf2aa7f — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 87190fa

Verdict parsed from the review's SHA-scoped output markers for commit 87190faaa63012079835bb7767e06a4c1bf2aa7f.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 87190faaa63012079835bb7767e06a4c1bf2aa7f false-positive: <reason, 20 to 500 characters>

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 13, 2026
buluoray
buluoray previously approved these changes Nov 13, 2026

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

Approve on e850cae. This change makes a conversation reset that was queued during a turn wait until a sub-agent completion already in the tab's queue has run in the conversation it was meant for. The reset then lands at the end of that completion's turn. Only the turn-end consumers wait. The background retry does not, so a held queue still gets its reset about five seconds after the turn ends. A landed reset now settles the failure notices meant for the dropped conversation instead of passing them to the fresh one. The user still sees those notices, because each one is already shown as a card in the tab. Every new guard has a test that fails without it. Waiting: one backend test shard lost its runner (an infrastructure failure, not a test failure), and the coverage gate failed closed because of that shard. Both need a rerun on this head. Decisive lines: src/kiro_crew/dashboard/chat_turn/session_reset.py:443, src/kiro_crew/dashboard/chat_turn/session_reset.py:516-519, src/kiro_crew/dashboard/chat_turn/queue_drain.py:743-829

@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] CI is red here for an infrastructure reason, not a test failure.

Backend Tests (3.12, 7) lost its runner mid-run: the Run tests (shard 7/8) step never completed, no log was uploaded, and the check annotation reads "The self-hosted runner lost communication with the server ... Anything in your workflow that terminates the runner process, starves it for CPU/Memory, or blocks its network access can cause this error." Coverage Gate then failed closed on backend-test=failure, and PR Readiness folds that one item. Nothing in this head's diff is implicated: both AI review lanes, Design, First Principles, UX, Security Scope and the other seven Linux shards are green on e850cae.

The same shard fails the same way on main - https://github.com/kirodotdev/KiroCrew/actions/runs/43458639790 left the same step in_progress - and #36654 records the cause: shard 7 peaks at about 15.0 of 15.75 GiB and loses its runner. #36731 merged at 17:46Z and gives a large part of that memory back, which is why main's later runs pass the shard.

I re-ran the two failed jobs once on this head instead of rebasing, so the approval pinned to e850cae stays valid. If the shard loses its runner again, the next pass rebases onto main so the branch picks up #36731.

Sensitive Change Review (approval) failed separately on API rate limit exceeded for installation (HTTP 403); the Sensitive Change Review check itself is green on this head. Re-ran once as well.

@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] Holding this head; a new commit is coming, so please do not re-run its failed jobs.

  • The Backend Tests (3.12, 7) red on the re-run (attempt 2 of run 43423880173) is the shard-7 memory ceiling tracked in Flaky: test_ssrf_guard_fail_closed node subprocess tests time out on Linux shard 7 #36261 (peak 15041 of 15754 MiB; three test_ssrf_guard_fail_closed.py node-subprocess tests timed out). That run tests the PR on its old base, which does not have test: release each parsed tree in the lenient-read ratchet scan #36731. Main's shard 7 has peaked at 11862 MiB since test: release each parsed tree in the lenient-read ratchet scan #36731 landed, so the next push rebases onto main instead of re-running.
  • A local review of the rebased head found one defect in this PR's own change. A /clear that the dashboard answers (KAS and the other local-clear harnesses), drained ahead of a sub-agent completion queued behind it, now waits for that completion, which is the intended part. But it skips the plan drop, and nothing drops the plan when the deferred discard lands, so the old checklist is rebuilt into the cleared conversation. On main that input dropped the plan. The fix drops the plan at that /clear, as main did, and leaves every other deferral as it is. It is being reproduced and tested now and will be pushed with the rebase.

@bolichen97

bolichen97 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor Author
  • Superseding decisions require the maintainer override gate span=69ae0142cf9c

Rebutted: this PR adds and changes nothing under docs/decisions/. git diff c22557cd e850cae2 touches only session.md, subagent.md, session_reset.py and test_queued_reset_waits_for_queued_completion.py; the next head adds slash_commands.py, chat_slot.py, slot_session.py and test_state_parts_facade.py, none of them a decision record.
docs/decisions/2026-11-13-conductor-mode-keeps-no-ultra-names.md reached main in 36a018f (#37095), after this head's base c22557c, so the finding compared the head against a base it had not been rebased onto; the CI adjudicator read the merge diff the same way.

[operator: bolichen97]

A conversation reset queued during a turn (the reset_conversation tool,
or a /clear the dashboard answers itself) landed at the turn's end even
when a sub-agent completion was already waiting in the tab's queue, so
the hand-off then started the fresh conversation with the old one's
result. Failure notices pending for the old conversation reached the
fresh one's next prompt the same way.

The end-of-turn and /clear consumes (own_turn) now leave the discard
armed while the queue holds a completion, or a verbatim requeue of one;
the hand-off drains it into the conversation it was queued for and the
consume at that turn's end lands the reset. The armed-reset retry does
not wait on it, so a held queue still gets its reset a few seconds
later. A landed discard settles the tab's pending failure notices as a
drain does. A /clear whose discard waits only on a queued completion
marks it, and the plan is dropped where the discard lands, as a landed
/clear drops it: the completion turn runs in the old conversation and
can re-send that conversation's plan.

The specs record the wait, the settle and the plan drop, and the #12069
pointers say the conversation-incarnation counter was declined there.

Closes #35237

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in docs/system-specs/modules/session.md, docs/system-specs/modules/subagent.md, src/kiro_crew/dashboard/chat_turn/session_reset.py, src/kiro_crew/dashboard/chat_turn/slash_commands.py, src/kiro_crew/dashboard/state_parts/chat_slot.py, src/kiro_crew/dashboard/state_parts/slot_session.py, test/test_state_parts_facade.py since this head went green (c22557c -> 88ce21a); CI re-running.

The Backend Tests (3.12, 7) red on the old head is the shard-7 test_ssrf_guard_fail_closed timeout tracked in #36261, fixed on main by #37716 since c22557c. The new head carries the fix for the deferred /clear checklist finding.

[operator: bolichen97]

@bolichen97
bolichen97 force-pushed the fix/35237-reset-waits-queued-completion branch from e850cae to 87190fa Compare November 18, 2026 01:31
@bolichen97

Copy link
Copy Markdown
Contributor Author

self-added: no
mechanism: one slot flag, set by a /clear whose discard waits only on a queued completion, consumed where the discard lands

  • Deferred /clear leaves the old checklist behind span=1f15f9b0e49e

fixed in 87190fa: a dashboard-answered /clear whose discard waits only on a queued completion (no children attached) sets _pending_discard_drops_plan; _consume_pending_reset drops the plan (slot.set_todo(None) and its todo_update) where that discard lands, and the hold's give-up clears the flag.
The plan cannot be dropped at the /clear itself: the completion turn runs in the old conversation, whose todo_list can send the whole plan again.
Pinned by test_a_clear_waiting_on_a_queued_completion_drops_the_plan_where_it_lands, where the completion turn re-sends the plan before the discard lands; a /clear deferred for attached children and a reset_conversation discard keep the plan as before.

[operator: bolichen97]

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 18, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] CI is red here for an infrastructure reason, not a test failure.

New-test stability (windows-latest) failed in its Install dependencies step, before any test ran: uv pip install timed out reaching PyPI (Request failed after 3 retries in 128.2s, Failed to fetch: https://pypi.org/simple/pywhispercpp/, operation timed out). Job: https://github.com/kirodotdev/KiroCrew/actions/runs/44216436791/job/134510718255

Every other check on 87190faaa630 is green, including New-test stability (ubuntu-latest) and all eight Backend Tests (Windows) shards. That one job gets a single re-run once CI capacity frees up; no new push.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

readiness: action required A blocking check or review needs attention

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A conversation reset queued during a turn hands a sub-agent completion already in the tab's queue to the new conversation

2 participants