Repository navigation
fix(chat): continue replies interrupted by compaction - #20867
Conversation
UX Review (Opus 5.5, fork) — ⏭️ skippedRevision |
First Principles Review (Opus 5.5, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Before merging, a human should accept the declared trade-off: a reply that was already complete before a turn-end auto-compaction now gets one extra continuation turn. What this change shipsInventory (4 items) — 4 justifiedIntent: when an inline compaction cuts a dashboard reply short, the reply finishes on its own and the user doesn't have to ask the agent to continue. This is a FIX (#20863).
[FIRST-PRINCIPLES-REVIEWED] 264f594 Description read[DESCRIPTION-READ] ccf57df2601ad5d4689f210ba5f045b49a71a06c27e0ce8e3f5a036123ba0ab1 That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5, fork) — 🟡 CONCERNSDesign-level review of Design-Verdict: CONCERNS A reply that finished before a turn-end auto-compaction now gets a continuation it does not need. That costs an extra billed turn and shows a card falsely saying the reply stopped. Watch
Suggestions
[DESIGN-REVIEWED] 264f594 Description read[DESCRIPTION-READ] 1900d6975bdd21c87bb58f5bd7e1f4123aef249a4d2badced8e1e30a21dc57d3 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 (fork) — ✅ no blocking findingsReviewed |
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
f7ce7dc to
ca57e04
Compare
|
self-added: yes
|
|
|
bolichen97
left a comment
There was a problem hiding this comment.
Not ready yet, but close. The offset approach fixes the segment-cut problem from the previous head: a turn that compacts, narrates, calls a tool and then goes quiet is now continued, and test_a_segment_cut_after_compaction_is_judged_on_its_own_text pins both directions.
Head reviewed: ca57e04. Bots read: Design CONCERNS, First Principles PASS, UX skipped, Opus no blocking, GPT no blocking, readiness action required (backend shards and E2E were still running when I read it).
What I verified:
- Every site that empties
turn.assistant_textsets it to"", so a stale_compaction_text_offsetcan only slice an empty string. The first chunk of a new segment zeroes the offset. No site truncates the accumulator to a non-empty value. - A turn with no compaction keeps offset 0, so
_continuation_answer_text == _answer_textand nothing changes outside compaction turns. - This head merges cleanly with current main. On the merged tree,
test/test_post_compaction_continuation.pypasses (58 tests). - Main has no other fix for #20863.
🟡 1 should-fix: a refusal explanation that streamed before the compaction now repeats in the refusal card. Reproduced with a scratch runner test, details inline. This is the second Design Review watch item; the disposition replies answer only the first one.
The answered point about a finished pre-compaction answer getting one bounded continuation is a reasonable trade, and I do not raise it again.
| ) | ||
|
|
||
| if _answer_text: | ||
| if _continuation_answer_text: |
There was a problem hiding this comment.
🟡 A refusal explanation streamed before compaction now prints twice
The answer branch now keys on post-compaction text only. A refusal whose explanation streamed before the compaction started has no post-compaction text, so it skips this branch and reaches the text-less elif _stop_reason == STOP_REASON_REFUSAL: branch. That branch builds the card without streamed_text, so refusal_card_text adds the explanation again.
if _continuation_answer_text:
_flush_text_stream()
_flush_segment(state, slot, turn.assistant_text, broadcast=False)
turn._reply_flushed = True
if _stop_reason == STOP_REASON_REFUSAL:I reproduced it with the _drive_compaction_turn helper from this PR: events are an explanation chunk, started, the Compacting... notice, a synthesized completed, then EVENT_COMPLETE with stop_reason=refusal and RefusalInfo(category="CYBER", explanation=<same text>). On main the card reads "Response declined by the model. Content filter: cyber. Try rephrasing...". On this head the card also contains the explanation, so the user reads it twice. No continuation is queued in either case.
Why it matters: small and rare, but it is a behaviour change the description does not list, and the refusal path is outside the stated goal.
Suggestion: judge a refusal on the whole turn. For example, compute the gate text once and use it at both the flush block above and this branch:
_gate_text = _answer_text if _stop_reason == STOP_REASON_REFUSAL else _continuation_answer_textA parametrized case of the probe above pins it. If you prefer to keep the change and list it in the description, I will withdraw this.
Rule: PR goal is frozen (AGENTS.md); description and diff fidelity.
ca57e04 to
1128be3
Compare
|
This round's push is
The fork runs on |
|
|
bolichen97
left a comment
There was a problem hiding this comment.
Thanks, this addresses my earlier comment. The new head is a rebase onto current main plus one change: the branch gate now uses the whole turn's answer text for a refusal and the post-compaction text otherwise (_branch_answer_text), at both the flush block and the answer branch. A refusal whose explanation streamed before the compaction now takes the streamed-explanation refusal path, so the card no longer repeats it.
Head reviewed: 1128be3.
What I verified:
- The incremental diff against the previous head (ca57e04) is only that gate change, the matching source-order test update, and the new test
test_a_refusal_explained_before_compaction_takes_the_streamed_refusal_path. test/test_post_compaction_continuation.pypasses on this head (59 tests).- With the gate reverted to
_continuation_answer_text, the new test fails, so it pins the fix. - Non-refusal turns are unchanged from the previous head, which I already reviewed.
Looks good to me. The remaining maintainer step is CI: the workflow runs on this head are waiting for approval, so readiness is not passed yet. I will approve once the checks are green.
1128be3 to
57d1e36
Compare
bolichen97
left a comment
There was a problem hiding this comment.
Re-checked at 57d1e36. This head is a clean rebase of 1128be3 onto current main: the PR's own changes to chat_runner.py and test/test_post_compaction_continuation.py are line-for-line identical, and the PR reports mergeable with base main. The refusal double-print fix and its pinning test still hold, so nothing new to raise.
Good to ship. Approval still waits on fork CI: the readiness label is readiness: action required because the required runs on this head are held for maintainer approval. Once those run and readiness turns passed, this can be approved and queued for merge.
57d1e36 to
196eb4d
Compare
|
Round push: Merge conflict with main, resolved. Main's #22150 moved the chat turn's prologue into phases. That move conflicted with this change in Validation. The focused module passes ten serial runs. The 38 chat-runner, The two PASS punchlines:
|
bolichen97
left a comment
There was a problem hiding this comment.
Re-reviewed at 196eb4d, incremental since 57d1e36.
This is a rebase onto main, where _run_chat now reads its turn state from the turn object. git range-diff shows every added and removed line of this PR unchanged; only surrounding context moved. The new _compaction_text_offset local is declared, reset, set and read inside _run_chat itself with no nested function in between, so it needs no mirroring onto turn.
Verified locally on this head: test/test_post_compaction_continuation.py (59 passed) and every test matching compaction across the suite (1076 passed, 4 skipped).
Looks good to ship. Not approving yet: the readiness signal is still checking and backend tests, lint, E2E and desktop builds are still running on this head. I will approve once readiness reports passed.
|
The only red check on this head is Could you rebase onto current main and push? Once CI is green on the new head I can re-check and merge it. Nothing else in the change needs to move. |
196eb4d to
264f594
Compare
|
@bolichen97 Done. This is rebased onto Verified on
The fork's runs on the new head wait for a maintainer to approve them before they start. |
|
|
bolichen97
left a comment
There was a problem hiding this comment.
Approving on head 264f594. Gates checked on this head: readiness label is passed, required PR Readiness is green, no failing or pending checks, the AI review lanes report no BLOCK, the branch merges cleanly into main, and the linked issue is tier T1. The rebase onto main left the patch unchanged from the version reviewed earlier. Enabling squash auto-merge.
Problem / Motivation
Goal: Finish dashboard replies automatically when an inline compaction interrupts them.
The Claude ACP adapter can emit a partial answer, compact its context, and end the turn without producing more answer text. The dashboard persists the partial text as a completed assistant bubble and leaves the request unfinished.
Why it matters
A user sees a sentence stop midstream after
Compacting...and receives no answer unless they manually ask the agent to continue.Not a goal
/compactbehavior.What changed (motivation → approach → change)
A synthesized compaction terminal arrives at turn end, so the accumulated answer still contains text emitted before compaction. That old fragment made the dashboard classify the turn as answered and skip its existing continuation branch.
src/kiro_crew/dashboard/chat_runner.pyrecords where the most recent compaction started in the current segment's text, and the continuation gate judges only the text after that point. Every pre-compaction chunk still streams, flushes and persists. A segment cut after the compaction starts (a tool call, an approval card, a steer) begins a segment that is wholly post-compaction, so the gate judges that segment whole: a turn that goes quiet after its last tool is continued, and any answer after the tool suppresses the continuation.A refusal is the one stop reason judged on the whole turn's text: its explanation answers the turn wherever it streamed, so a refusal explained before a compaction still takes the streamed-explanation refusal path, whose card quotes it, rather than the no-text refusal branch. The tool-refusal recovery's
answeredflag also stays on the whole turn's text, deliberately: it picks the body that forbids restating what the user already saw, and a pre-compaction fragment is on screen.Trade-off: a turn that finished its answer before a turn-end auto-compaction, and produced nothing after it, now gets the one continuation as well. The continuation tells the model the summary records the completed work, so the cost is one extra turn that may restate or close the answer. Judging the pre-compaction text instead is the stopped reply this PR fixes, and no text test can tell a finished sentence from an interrupted one that happens to end at a full stop.
This keeps compaction inside the provider and leaves the durable Kiro Crew transcript intact, as required by
docs/request-for-change/rfc-append-only-session-transcript.md§2.Backwards compatibility
Compatible: completed replies, compaction notices, and manual
/compactturns keep their existing behavior.Removes nothing: the change only classifies which already-preserved answer text belongs after the compaction boundary.
Tests
test/test_post_compaction_continuation.pydrives the real dashboard runner through aCompacting...control notice, a synthesized completed terminal and turn end:test_runner_continues_a_pre_compaction_fragmenttest_a_segment_cut_after_compaction_is_judged_on_its_own_texttest_a_refusal_explained_before_compaction_takes_the_streamed_refusal_pathEach case fails alone when its mechanism is removed: without the production change,
test_runner_continues_a_pre_compaction_fragment[-True]fails; with a post-compaction buffer that outlives a segment cut,test_a_segment_cut_after_compaction_is_judged_on_its_own_text[-True]fails; with an offset a new segment does not reset, its[Done.-False]case fails; routing a refusal by its post-compaction text again failstest_a_refusal_explained_before_compaction_takes_the_streamed_refusal_path.On
264f59464d(one commit directly on5c1746933c, a clean rebase of196eb4d095with every per-file patch ID unchanged; main now carries #22320's longer timeout for the tree-scan facade-mirror test that failed shard 2 on the previous head): the chat runner,chat_turn, control-notice and compaction modules passed (46 modules, 1,768 tests), the refusal, empty-response and segment modules passed (30 modules, 699 tests), and so did the repository-wide facade-mirror, link-screen and dashboard-files composition guards (139 tests). Main moved the turn's prologue into phases (#22150), and this change's offset declaration sat in the moved prologue:_compaction_text_offsetis now declared in_run_chatright after it reads the turn's locals, and the compaction-start site keeps main'sturn._compaction_startedcopy beside the offset store. Main hoisted the turn's closures intodashboard/chat_turn/(#22057), so the two flush blocks call_flush_text_stream(turn)as main's do; every other hunk replays line for line. Black, isort, flake8, mypy, Comment History, Brand Name, Harness Parity, the file-line cap, the flake-pattern and wait-discipline ratchets and the single-commit push guard passed.Determinism proof on the previous head: 20 serial repetitions and 10
-n 4 --dist loadgroupruns besidetest_dashboard_chat_empty_response.pyandtest_dashboard_chat_segments.pypassed, and the module passed in a shuffled order (seed 27183).Manual verification
N/A — the unit test drives the production runner event loop and asserts both the persisted transcript and queued recovery request.
Screenshots / video
N/A — no frontend code or rendered string changes.
Related Issues
Closes #20863
Pattern harvest
Rule candidate: review-prompt
Pattern: a terminal synthesized at turn end cannot identify which accumulated output was produced after an earlier stream boundary.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.