Repository navigation
fix(dashboard): record a turn a chat close cut off as interrupted - #18990
Conversation
UX Review (Opus 5.5, fork) — ⏭️ skippedRevision |
First Principles Review (Opus 5.5, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS The new helper repeats What this change shipsInventory (3 items) — 3 justifiedIntent: a chat that was closed mid-turn should reopen showing the turn as interrupted, with a Resume control, instead of showing half an answer as finished. This is a FIX.
[FIRST-PRINCIPLES-REVIEWED] d63737e Description read[DESCRIPTION-READ] 95825df04134247461d7888d556c4a41616a3d062629a0624fb38b216df6b5f0 That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Check whether [DESIGN-REVIEWED] d63737e Description read[DESCRIPTION-READ] c330405804001a55444955e803013cf6f0d33911878bb3cb70ab7a258301ab33 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 |
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed |
Closing a tab while its turn runs cancels the turn, and the runner's cancel branch keeps the streamed part of the reply as an ordinary assistant row. Nothing followed it, so the chat reopened from history read the cut-off reply as a finished answer, with no notice and no Resume control. When a close cancels the turn (the slot is fenced by begin_close: one tab, the bulk archive, and close_target through close_slot), the cancel branch now lands the same error row a restart lands, through turn_marker.record_close_interruption, with its own wording and kind. A Stop press, a turn that already reads as interrupted, and a finished turn get no row.
a57d28c to
d63737e
Compare
iamwhatever
left a comment
There was a problem hiding this comment.
When a chat is closed mid-turn, the reopened chat currently shows the streamed partial reply as a finished answer, with no notice and no Resume. This PR lands a chat_close_interruption error row after the partial reply so is_turn_interrupted reads True, the same mechanism the restart reconcile already uses. That fixes the root cause without adding any UI. The new branch in _run_chat's CancelledError path fires only when _cancel_reason is not the Stop press (Stop yields STOP_REASON_CANCELLED, while an involuntary cancel yields "error: cancelled") and slot.is_closing is set. Every close path calls begin_close before it cancels: the single-tab close, both bulk-archive sites and close_target. I tried a Stop followed by a close, an unanswered opener, and a trailing error. record_close_interruption returns early on is_turn_interrupted or _latest_turn_was_deliberately_stopped, so none of them gets a duplicate row. The kind is only metadata, and no consumer special-cases the restart kind's value, so Resume works the same. The test drives the real _run_chat and the real DELETE route and reads the transcript back from a fresh ConversationLog. It fails on main. Optional: name the new kind next to gateway_restart_interruption in docs/system-specs/modules/history.md, as the Design lane suggested. — crew-pr-reviewer (deep re-check)
Problem / Motivation
Closing a tab while its turn is running cancels the turn. The runner's cancel branch (
_run_chatinsrc/kiro_crew/dashboard/chat_runner.py, through_persist_partial_reply) keeps the streamed part of the reply as an ordinary assistant row, and nothing follows it. The chat reopened from history therefore shows the cut-off reply as a finished answer: no notice and no Resume control (state.is_turn_interruptedreturns False for that tail). Reproduced with the real_run_chat, the realDELETE /api/chat/slots/{slot}route and a freshConversationLog: the archived tail is[user, assistant "Part one of the plan is to "].Goal: a turn that closing its chat cut off reads as interrupted when the chat is reopened, with the same notice and Resume control a restart gives.
Why it matters
The reopened chat presents half an answer as the whole answer, and the person has no prompt to resume it. #15461 asked for a notice when a chat with a running turn is archived; #18009 added only the confirmation before the close.
Not a goal
What changed
turn_marker.record_close_interruption(new,src/kiro_crew/dashboard/slot_persistence/turn_marker.py) lands oneerrorrow,msg msg-errwithmeta.kind = "chat_close_interruption"and the text "This turn was interrupted when its chat was closed. Review the partial output above, then resume to continue." It is the row the restart reconcile (_reconcile_local_turn_marker) lands, with its own wording, and it lands nothing when the transcript already reads as interrupted or the newest turn ends in the user's Stop card._run_chat'sCancelledErrorbranch, after the partial reply is saved: when the cancel was not a Stop press and the slot is closing (slot.is_closing), the row is landed. Every close that cancels a running turn fences the slot withbegin_closebefore it cancels: the single-tab close (_close_slot), the bulk archive of inactive tabs (api_chat_slots_cleanup, both cancel sites), andsession_control.close_target, which reusesclose_slot. So all three are covered by the one check.Backwards compatibility
Compatible: a finished turn, a Stop press and a reset are unchanged. A chat closed mid-turn now ends with one more row, the interruption notice.
Removes nothing.
Tests
test/test_chat_close_interrupts_turn.py(new), adapted from an earlier graceful-shutdown reproducer. Its fake background session is now awaitable (get_bg_sessionis anAsyncMock), which removes theTypeError: object MagicMock can't be used in 'await' expressionthat auto-title logged.test_a_turn_cut_by_closing_its_tab_reads_as_interrupted: the real turn, the real close route; the archived chat reads as interrupted, with exactly onechat_close_interruptionrow.test_closing_a_tab_after_a_finished_turn_archives_it_unchanged: the control; no error row.test_a_restart_interrupted_turn_is_recorded_as_before: the control; the restart reconcile still lands its own row.test_no_close_row_when_the_turn_already_reads_as_interrupted_or_stopped: an unanswered opener and a Stop card get no row.The busy-slot reset refusal (409) is covered by the existing
test/test_chat_slot_reset_conversation.py, which passes unchanged.Red: only the new test file copied onto main 843abe3, three runs, the same result each time:
The first failure is the defect: the archived tail ends in a plain assistant row. The second is structural, since the helper does not exist on main; what it pins (no row after an unanswered opener or a Stop card) is checked on this branch. The two that pass on main are the finished-turn and restart controls.
Green: the new file, 4 passed, three runs; the 46 test files that name the close routes (
api_chat_slot_delete,api_chat_slots_cleanup,close_slot),close_target, the turn marker,is_turn_interruptedor_persist_partial_reply, less two that resolve paths under the home directory: 3465 passed. mypy, flake8, isort, black,scripts/check_black_formatting.py,scripts/docs-lint.shandscripts/check_comment_history.py(baseorigin/main) all pass.Manual verification
None beyond the tests.
Related Issues
#15461 (asked for an archive notice), #18009 (added the close confirmation only).
Pattern harvest
Rule candidate: every path that cancels a running turn records why it ended, in the same row shape the transcript classifier already reads; a cancel that leaves only the partial text is indistinguishable from a finished turn.
Checklist