Skip to content

fix(chat): let a resolved Stop veto the lost-session reconnect replay - #16548

Merged
bolichen97 merged 1 commit into
mainfrom
fix/session-not-found-stop-pressed
Oct 3, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/session-not-found-stop-pressed

Conversation

@bolichen97

@bolichen97 bolichen97 commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Pressing Stop on a chat whose backend lost its session never lets the stopped prompt run again.

The lost-session reconnect added in #16221 queues one replay of the turn's prompt unless _should_suppress_requeue(slot) is true. That check only sees a Stop that is still in flight. A Stop that the user pressed and that already resolved back to idle (a backend holding no session answers Stop as idle) leaves _stopping false and only moves the Stop counters. The replay is queued, its Stop snapshots are taken after that Stop, so the drain-side veto also reads "not stopped", and the prompt the user cancelled runs again.

Why it matters

The replayed prompt is one the user explicitly stopped. If it was destructive ("delete the old branches"), Stop did not prevent it.

Not a goal

The other turn surfaces (#16225 / #16428) and the other recovery arms are untouched here.

What changed (motivation → approach → change)

  • src/kiro_crew/dashboard/chat_runner.py, session-not-found arm of _run_chat: the requeue gate is now _should_suppress_requeue(slot) or _stop_pressed(), the same pairing every sibling requeue gate in _run_chat already uses. _stop_pressed() reads the slot's and the session's Stop generations live, so a resolved Stop is visible.

Backwards compatibility

Compatible: a turn with no Stop behaves exactly as before (one reconnect replay). A turn whose Stop was pressed now ends without the replay, as it already did when the Stop was still in flight.

Removes nothing.

Tests

  • New test_stop_resolved_before_the_error_never_queues_a_replay in test/test_chat_session_not_found_recovery.py: Stop moves the slot's Stop generation and resolves to idle mid-turn, then the backend answers "Session not found". Asserts one provider call, empty queue, no reconnect notice, one-shot not spent.
  • Regression proof: without the fix the new test fails (the cancelled prompt is sent twice); with it the file passes 9/9.
  • test/test_chat_runner_composition_contract.py: 210 pass; the same 2 tests fail identically on untouched main locally (subprocess import environment), not touched by this change.
  • black (baselined gate), isort, flake8, mypy on chat_runner.py, comment-history (base origin/main), agent-sdk boundary: all pass.

Manual verification

Covered by the unit test; the race is a Stop that resolves before the error is classified.

Related Issues

Fixes #16547. Follow-up to #16221; the release backport #16412 carries the same line.

Pattern harvest

Rule candidate: review-prompt
Pattern: every requeue/replay gate pairs _should_suppress_requeue with _stop_pressed; a gate that checks only the in-flight Stop state misses a Stop that already resolved to idle.

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

The session-not-found arm queued its one reconnect replay unless
_should_suppress_requeue(slot) was true, which only sees a Stop still in
flight. A Stop that already resolved back to idle moved only the Stop
counters, and the replay snapshots are taken after it, so the drain-side
veto read 'not stopped' and the cancelled prompt ran again. Pair the
gate with _stop_pressed(), as every sibling requeue gate does.

Fixes #16547
@bolichen97
bolichen97 requested a review from a team as a code owner October 3, 2026 16:19
@bolichen97
bolichen97 requested a review from iamwhatever October 3, 2026 16:19
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 3, 2026
@github-actions

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — 🟡 CONCERNS

Design-level review of c692a078129443d7c688adfa5d5b6fae88e6660f — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: CONCERNS

Three sibling recovery arms in _run_chat keep the same gate, which can't see a resolved Stop, so a prompt the user stopped can still be replayed through them.

Watch

  • The fix is applied to one arm only. The description says the new gate is "the same pairing every sibling requeue gate in _run_chat already uses." Three gates in the tree contradict that:

    • chat_runner.py:16227 (the runtime-death requeue)
    • chat_runner.py:16363 (the busy / connection-lost retry)
    • chat_runner.py:16584 (the no-tokens requeue)

    Each still reads if _should_suppress_requeue(slot): pass. The chain is the one this PR describes: a Stop resolves to idle, _stopping reads False, the arm requeues, and the drain veto's snapshots are taken after the Stop. So "delete the old branches" can still run again after a Stop, just through a different error. The "Not a goal" section excuses the other arms, but the root cause is a check that callers have to remember to make themselves, not this one arm.

    Clears when: those three gates also check _stop_pressed(), or the description drops the "every sibling" claim and links a follow-up issue naming those three lines.

Suggestions

  • Give the requeue gates one local predicate, e.g. _requeue_vetoed() = _should_suppress_requeue(slot) or _stop_pressed(). A new arm then can't pick up only the half that misses a resolved Stop, which is exactly how this bug got in.

[DESIGN-REVIEWED] c692a07

Description read

[DESCRIPTION-READ] 44958ebc07413ddcee5f08d9d0d33c61acc63ca512be74c17b83ef8d963c6097

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

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — 🟡 CONCERNS

Premise-level review of c692a078129443d7c688adfa5d5b6fae88e6660f — 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: CONCERNS

The fix covers one of four replay arms. The description says "every sibling requeue gate" already pairs _stop_pressed(), but three arms still don't.

Not justified as shipped

  • Item 1 — symptom-level: the description says the gate copies "the same pairing every sibling requeue gate in _run_chat already uses." Grepping if _should_suppress_requeue(slot): in chat_runner.py finds 3 replay arms in this same except chain that still use the bare check. They are the shared-runtime death requeue at :16227, the session-busy retry at :16363 and the transient-backoff requeue at :16584. The cause is that _should_suppress_requeue reads only the Stop that is still in flight. Patching one arm leaves 3 open to the same resolved-Stop replay.
    Clears when: someone shows those 3 arms are already vetoed elsewhere after a resolved Stop, or the description stops claiming every sibling already pairs the check.

What this change ships

Inventory (2 items) — 1 justified

Intent: a prompt the user stopped must not run again when the lost-session reconnect fires. FIX.

  1. A Stop that already went back to idle now blocks the one automatic reconnect replay — symptom-level: the same gap remains in 3 sibling arms
  2. A regression test where Stop resolves mid-turn and then "Session not found" arrives — justified

[FIRST-PRINCIPLES-REVIEWED] c692a07

Description read

[DESCRIPTION-READ] 2851067f50aae59939557f186c714454eb884637a031738cd5400b9b90c5a5cb

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 Oct 3, 2026

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] c692a07

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

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

@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] c692a07

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

@bolichen97
bolichen97 merged commit 105630f into main Oct 3, 2026
103 of 107 checks passed
@bolichen97
bolichen97 deleted the fix/session-not-found-stop-pressed branch October 3, 2026 16:58
@github-actions github-actions Bot removed the readiness: checking Automated validation is still running label Oct 3, 2026
leonlaiyc added a commit to leonlaiyc/KiroCrew that referenced this pull request Oct 4, 2026
kirodotdev#16548 paired _stop_pressed() with _should_suppress_requeue() on _run_chat's
lost-session arm. Two sibling arms of the same except chain still gated
their replay on the suppress check alone, which sees only a Stop still in
flight: the AcpProcessDied requeue and the busy / pipe-death AcpError
requeue. A Stop that pressed and resolved back to idle before the error
reached the handler moved only the Stop counters, so the stopped prompt
was queued for verbatim replay on a fresh runtime. _queue_recovery takes
no Stop snapshot of its own, so the gate is the only place that can see
it.

The transient-5xx arm, named alongside these by the kirodotdev#16548 reviews, already
re-reads _stop_pressed() after its backoff and drops the replay, so it is
left as is.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
leonlaiyc added a commit to leonlaiyc/KiroCrew that referenced this pull request Oct 6, 2026
kirodotdev#16548 paired _stop_pressed() with _should_suppress_requeue() on _run_chat's
lost-session arm. Two sibling arms of the same except chain still gated
their replay on the suppress check alone, which sees only a Stop still in
flight: the AcpProcessDied requeue and the busy / pipe-death AcpError
requeue. A Stop that pressed and resolved back to idle before the error
reached the handler moved only the Stop counters, so the stopped prompt
was queued for verbatim replay on a fresh runtime. _queue_recovery takes
no Stop snapshot of its own, so the gate is the only place that can see
it.

The transient-5xx arm, named alongside these by the kirodotdev#16548 reviews, already
re-reads _stop_pressed() after its backoff and drops the replay, so it is
left as is.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
leonlaiyc added a commit to leonlaiyc/KiroCrew that referenced this pull request Oct 6, 2026
kirodotdev#16548 paired _stop_pressed() with _should_suppress_requeue() on _run_chat's
lost-session arm. Two sibling arms of the same except chain still gated
their replay on the suppress check alone, which sees only a Stop still in
flight: the AcpProcessDied requeue and the busy / pipe-death AcpError
requeue. A Stop that pressed and resolved back to idle before the error
reached the handler moved only the Stop counters, so the stopped prompt
was queued for verbatim replay on a fresh runtime. _queue_recovery takes
no Stop snapshot of its own, so the gate is the only place that can see
it.

The transient-5xx arm, named alongside these by the kirodotdev#16548 reviews, already
re-reads _stop_pressed() after its backoff and drops the replay, so it is
left as is.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
iamwhatever pushed a commit that referenced this pull request Oct 10, 2026
…e arms

Follow-up to merged #16548, which gave only the lost-session arm the
`_stop_pressed()` read. The runtime-death arm, the prompt-busy / pipe-death
arm, and the post-busy-exhaustion requeue helper still gate on
`_should_suppress_requeue(slot)` alone, so a Stop that pressed and resolved
back to idle before the error reached the handler (invisible to the suppress
check, and `_queue_recovery` takes no Stop snapshot of its own) still queues
the stopped prompt for replay on a fresh runtime.

Pair each remaining arm's gate with `_stop_pressed()`, the same pairing #16548
used, and thread `_stop_pressed` into `_requeue_after_prompt_busy` so the
recovery helper can see it too. Adds a parametrised test covering all four
arms with a positive control (no Stop replays once) and the stopped case
(resolved Stop queues nothing).

Replaces #16767 by @leonlaiyc.

Co-authored-by: Leon <276034861+leonlaiyc@users.noreply.github.com>
iamwhatever pushed a commit that referenced this pull request Oct 10, 2026
…e arms

Follow-up to merged #16548, which gave only the lost-session arm the
`_stop_pressed()` read. The runtime-death arm, the prompt-busy / pipe-death
arm, and the post-busy-exhaustion requeue helper still gate on
`_should_suppress_requeue(slot)` alone, so a Stop that pressed and resolved
back to idle before the error reached the handler (invisible to the suppress
check, and `_queue_recovery` takes no Stop snapshot of its own) still queues
the stopped prompt for replay on a fresh runtime.

Pair each remaining arm's gate with `_stop_pressed()`, the same pairing #16548
used, and thread `_stop_pressed` into `_requeue_after_prompt_busy` so the
recovery helper can see it too. Adds a parametrised test covering all four
arms with a positive control (no Stop replays once) and the stopped case
(resolved Stop queues nothing).

Replaces #16767 by @leonlaiyc.

Co-authored-by: Leon <276034861+leonlaiyc@users.noreply.github.com>
iamwhatever pushed a commit that referenced this pull request Oct 11, 2026
…e arms

Follow-up to merged #16548, which gave only the lost-session arm the
`_stop_pressed()` read. The runtime-death arm, the prompt-busy / pipe-death
arm, and the post-busy-exhaustion requeue helper still gate on
`_should_suppress_requeue(slot)` alone, so a Stop that pressed and resolved
back to idle before the error reached the handler (invisible to the suppress
check, and `_queue_recovery` takes no Stop snapshot of its own) still queues
the stopped prompt for replay on a fresh runtime.

Pair each remaining arm's gate with `_stop_pressed()`, the same pairing #16548
used, and thread `_stop_pressed` into `_requeue_after_prompt_busy` so the
recovery helper can see it too. Adds a parametrised test covering all four
arms with a positive control (no Stop replays once) and the stopped case
(resolved Stop queues nothing).

Replaces #16767 by @leonlaiyc.

Co-authored-by: Leon <276034861+leonlaiyc@users.noreply.github.com>
chenmingwei23 pushed a commit that referenced this pull request Oct 11, 2026
…e arms (#18401)

* fix(chat): let a resolved Stop veto the runtime-death and busy requeue arms

Follow-up to merged #16548, which gave only the lost-session arm the
`_stop_pressed()` read. The runtime-death arm, the prompt-busy / pipe-death
arm, and the post-busy-exhaustion requeue helper still gate on
`_should_suppress_requeue(slot)` alone, so a Stop that pressed and resolved
back to idle before the error reached the handler (invisible to the suppress
check, and `_queue_recovery` takes no Stop snapshot of its own) still queues
the stopped prompt for replay on a fresh runtime.

Pair each remaining arm's gate with `_stop_pressed()`, the same pairing #16548
used, and thread `_stop_pressed` into `_requeue_after_prompt_busy` so the
recovery helper can see it too. Adds a parametrised test covering all four
arms with a positive control (no Stop replays once) and the stopped case
(resolved Stop queues nothing).

Replaces #16767 by @leonlaiyc.

Co-authored-by: Leon <276034861+leonlaiyc@users.noreply.github.com>

* fix(chat): let a resolved Stop veto the image-history and poisoned-reset replays

Self-review follow-up. The image-history recovery and the poisoned-conversation
reset arm still gated their replay on _should_suppress_requeue(slot) alone, and
each takes its Stop snapshot (_image_stop_gen, _stop_gen_before_canary) after a
resolved Stop already moved the counter, so the stopped prompt was replayed on
a fresh session. Pair both gates with _stop_pressed() (the image arm's
owed-completion half is unchanged). Also give the transient-5xx arm's first
gate its own resolved-Stop branch, so a resolved Stop no longer flashes a
"retrying" card the post-backoff re-read withdraws. That branch ends the turn
with no requeue, so it resets the same four per-turn budgets the post-backoff
drop arm resets (_transient_5xx_retries, _infra_retries,
_fallback_candidate_idx, _fallback_walked); otherwise the attempt it just
counted shortens the next turn's 5xx ladder.

Tests: image-history, transient-5xx and poisoned-reset cases in
test/test_chat_requeue_resolved_stop.py; each stopped case fails on base. A
budget case checks a resolved Stop on a transient 5xx leaves all four fields at
zero for the next turn. The file patches the runner's _recovery_delay seam
instead of a process-wide asyncio.sleep (Determinism contract / flake-pattern
ratchet).

---------

Co-authored-by: cixuuz <26782336+cixuuz@users.noreply.github.com>
Co-authored-by: Leon <276034861+leonlaiyc@users.noreply.github.com>
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.

Lost-session reconnect replays a prompt whose Stop already resolved

1 participant