Repository navigation
fix(chat): keep a reply's footer however its turn ends - #20128
Conversation
UX Review (Opus 5.5, fork) — ✅ PASSUX-level review of UX-Verdict: PASS Nothing blocks. The six before/after stills show every state the diff changes: the footer after an auto-nudge reply, the cut-and-resumed reply, and the resumed synthesis answer kept out of the fold. This lane has no blind reader, so nobody new to the product has read them. Notes
[UX-REVIEWED] c7cd586 Description read[DESCRIPTION-READ] 893f38678c06f9addf476dc034c96115bf962f20913a3811f483466bb2ed62f5 That sha256 names everything this verdict read: the PR description, plus the 9 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 |
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS No design-level blockers: the shared rule fixes the walk at its root, and the backend stamps each abnormal end once, ahead of the shutdown save. Notes
[DESIGN-REVIEWED] c7cd586 Description read[DESCRIPTION-READ] ffd9862c4a35429a202ff4cda4ab68aa84c3601b00b4c5b1f9002322f56bee8d 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 |
First Principles Review (Opus 5.5, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Every item answers a case in #19855 with a test, and the two footer walks become one shared function, What this change shipsInventory (10 items) — 10 justifiedIntent: a reply keeps its model/credits line and its Copy/Fork/More actions however its turn ended and whatever is drawn below it. FIX.
[FIRST-PRINCIPLES-REVIEWED] c7cd586 Description read[DESCRIPTION-READ] f4697ecfae1b4e108213c22c9fbd0265f5613fb74be371d64f070d1167d7339b That sha256 names the PR description this verdict read. Recompute it with |
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed |
209d251 to
bc07f4b
Compare
bc07f4b to
d8de271
Compare
|
HOLD at 04a922d. This PR makes a reply keep its stats footer however its turn ended: one shared What blocks approval:
This clears when CI is green on the head, the AI lanes have run on it, each CONCERNS item has its own disposition, and the action-row decision is settled. I read the description and the main production diffs. I did not run anything. — crew-pr-reviewer (r103) |
04a922d to
3933034
Compare
3933034 to
25225ba
Compare
mbriones98
left a comment
There was a problem hiding this comment.
Checks green and PR Readiness passed at 430a776; non-feature change.
|
Hold at 430a776. The r103 blockers are cleared. CI is green on this head, the lanes have run on it, and the cut half of a resumed reply keeps Copy / Fork / More, as the Goal says. What still needs an answer on this head:
Reviewed head: 430a776 — crew-pr-reviewer (r111) |
|
HOLD at fc154b5. Nothing has been posted since our r111 hold, and this head is a rebase with wording changes. Still unanswered:
CI is green and the GPT and Opus lanes have no findings on this head. — crew-pr-reviewer (r114) |
|
|
|
Status at fc154b5 against r114:
CI is green on this head; nothing else is pending on my side. |
|
HOLD at fc154b5. The author answered the two technical items from our r114 hold, and the replies hold up. The First Principles disposition keeps the Two owner decisions still block approval:
CI is green, and the GPT and Opus lanes have no findings on this head. — crew-pr-reviewer (r116) |
|
HOLD at 0a7cd15. This head is a rebase of fc154b5 that folds What still holds it:
Nothing was run locally. — crew-pr-reviewer (r125) |
|
HOLD at f677e3c, for one owner decision. Both notes from my r125 hold are fixed on this head. The feature-map row now names the real callers of What still holds it: the UX lane still notes that the cut half and the resumed half of one answer each show their own footer and cost, with no cue that they belong together. The description declines the cue and files no issue. A maintainer comment accepting that design clears this, or you can link an issue for the cue or combined cost. — crew-pr-reviewer (r127) |
The backend stamps meta.turn_stats on every abnormal end, but a reply still lost its footer, the model / credits / elapsed line and the Copy / Fork / More actions alike. A reply followed by an auto-nudge cycle lost it whole: the chat page's footer walk returned at the next reply before it read the reply's own stats, the SDK renderer's copy never read them, and both counted only a user row as the end of a turn, so the recovered answer under a cut reply hid that reply's footer the same way, and a queued recovery sends no chat_done, so the page never received the stamp before the recovery finished. A gateway restart mid-turn saved the cut reply before the seam attached its footer. A window at its cap shifted the boundary index the stamp scanned from, so the reply got none. A recovery arm after a completion that reported no billing gave the footer the completion's empty figures while the usage row took the provider's live read. A failure inside the seam's text save, or a cancel on its shutdown save, propagated into the recovery arm and cost it its card and its recovery. A synthesis answer an error cut short carried stats on its first half, so the grouper folded the resumed half behind the next wave. And a reply cut short and resumed in one turn had its first half, the row the footer sits on, folded as a working step by the collapse-all split, so the reader got a sentence that starts mid-thought. Decide the footer in one function both surfaces call with the row they draw: a reply carrying stats keeps its footer whatever is drawn below it, and a row that opens a turn of its own ends the turn above it. Send the stats to open clients at once on the chat_message_update patch. Put the footer on before the shutdown save, mark the slot dirty for it, and write it once per turn, from the completion's figures, ttft included, when the completion billed the turn, else from the seam's one billing read, which the usage row then shares. Find the reply through the one identity walk the file-chip flush uses too, scoped by the turn's start row, passing over a system notice; the completed turn's attach takes the same walk, and the explicit-list wrapper it was the only caller of goes. Swallow a cancel on the seam's shutdown save, as its usage write does. A synthesis answer an error cut short ends with the card and notices that report on its turn, or at the resumed half when a recovery resumed it. Keep a stamped reply a recovery resumed, and the recovery row, out of the collapse-all fold, as the answer before a tool-refusal card already is, and with them the synthesis row that led the cut reply, the one step that turn would otherwise fold; text a tool call followed still folds, and so does a cut reply with no stamp.
iamwhatever
left a comment
There was a problem hiding this comment.
Approve.
The fix is sound. One shared rule, replyShowsFooter, decides the footer for the chat page and the SDK. A reply with positive turn_stats always keeps its footer, and a reply without stats waits for a user row or a row that opens a turn of its own (
KiroCrew/website/src/pages/chat/replyFooter.ts
Lines 35 to 46 in c7cd586
user row as a turn end.
On the backend, _stamp_abnormal_turn_footer stamps the reply before the shutdown save, takes the one billing read, and reuses it for the usage row (
KiroCrew/src/kiro_crew/dashboard/chat_turn/turn_reply_seams.py
Lines 146 to 182 in c7cd586
KiroCrew/src/kiro_crew/dashboard/chat_turn/turn_reply_seams.py
Lines 234 to 288 in c7cd586
mid-keyed chat_message_update patch before a queued recovery runs (KiroCrew/src/kiro_crew/dashboard/chat_turn/turn_stats.py
Lines 111 to 135 in c7cd586
_last_reply_row, which skips system notices and other writers' envelopes (KiroCrew/src/kiro_crew/dashboard/chat_turn/turn_stats.py
Lines 65 to 108 in c7cd586
_persist_abnormal_turn_usage and has a test, the mid ordering and collapse-all are tested, the feature-map row is fixed, and the turn_stats placement scan exists. The rebase from f677e3c only follows main's renames (_attach_file_changes, _flush_file_changes_off_loop). The old source-scan tests became behaviour tests of replyShowsFooter and were not weakened.
AI findings judged non-blocking:
- UX: the two halves of a resumed answer each draw a full footer, so the first figure can read as the whole cost. each half is its own usage row and its footer is accurate for that row; the error card sits between the halves, and a 'continued below' cue is a declined option, not a promised follow-up ()
KiroCrew/website/src/pages/chat/TurnBlock.tsx
Lines 326 to 349 in c7cd586
- UX: this lane has no blind reader. a note about the review process; nothing in the code to change ()
KiroCrew/website/src/pages/chat/replyFooter.ts
Lines 35 to 46 in c7cd586
- Design: keep the AST allow-list in test_turn_stats_lands_only_on_the_row_the_two_selectors_chose strict. advice for future edits; the scan exists and is strict on this head ()
KiroCrew/test/test_turn_stats.py
Line 477 in c7cd586
- Design: split case 6 (collapse-all pin, synthesis answer end) into its own commit for a clean revert. packaging preference; case 6 is in the stated Goal and is tested in TurnBlock.test.tsx and groupDisplayItems.test.ts ()
KiroCrew/website/src/pages/chat/groupDisplayItems.ts
Lines 146 to 162 in c7cd586
GPT and Opus report no findings, and UX, Design and First Principles are PASS. All checks on this head are green, the branch merges cleanly with main, and no change request is active.
Reviewed head: c7cd586
— crew-pr-reviewer (r136)
Problem / Motivation
Goal: A reply keeps the line that names the model that served it and the credits it used, and keeps its Copy / Fork / More actions, however its turn ended and whatever is drawn below it (#19855).
#19984 (merged) made the backend stamp
meta.turn_statson every abnormal end. Onmaintoday the footer still goes missing in these cases:userrow as the end of a turn, so anudgerow followed by its reply hides the footer above it, stats or no stats.chat_done, and the stamp rides only that refresh.slot.messages[turn_boundary:], and the cap has shifted every index, so the cut reply gets no footer.One more is robustness: a cancel landing on the seam's shutdown save propagates into the recovery arm that called it and costs that arm its card and its recovery.
Why it matters
The footer is where a person reads what a reply cost and which model wrote it, and its row is where they copy, fork, pin or quote that reply. A chat with an auto-nudge loop armed loses both on every reply before the latest one, and a reply a capacity retry or a stall cut short is often the one a person most wants to copy or fork from, or price.
Not a goal
stop_reason, or when they are written; no new rows.chat_donetriggers). Which row it lands on changes in two cases: a window at its cap, where the scan from the boundary index missed the reply, and a turn that recorded no reply (a slash command's confirmation is a plain assistant row) whose window took a system notice after that row. A workflow or sub-agent envelope appended after a recorded reply was already passed over onmain. The turn's file chips follow the same walk, so the one row they can no longer attach to is a system notice.recoveryrow resumed, that row, and the synthesis row directly above the reply (the row the answer's turn opens on, whichmainshows) are kept out.Backwards compatibility
Compatible. New output: a
chat_message_updateWS patch carryingmeta.turn_statsfor a reply an abnormal end stamps (the client already merges that patch into the row's meta; a client that misses it reads the stats from the next refresh);meta.turn_statsin the shutdown save of a cut reply, on the reply in a window at its cap, and with the credits the usage row records on a recovery arm's turn whose completion reported no billing. Existing usage rows, theirstop_reason, the cards, and which recoveries are queued are unchanged. A reply that carries stats now keeps its footer in more places (for example a sub-agent wave's per-completion replies, each of which is a completed turn, and in an SDK host such as a side chat or an embed, a stamped last reply while a later run is going, as the chat page already did), never in fewer.Removes
_attach_owned_turn_stats(added by #19984): its one production caller was_attach_turn_statspassingreply_mids=None, and the slot's own_turn_reply_midsis the list it read, so_attach_turn_statsnow carries that body itself, including theretriescount #21907 added to it (the same keyword at the same call site; the abnormal path records none onmaineither). No other key, row, route or public function is removed; the two inline footer walks are replaced by one function over the same inputs.What changed (motivation → approach → change)
Frontend: the footer walk ended the turn at the wrong rows, in two copies. The page's inline IIFE (now in
pages/chat/page/transcriptRendering.tsx, where #20388 moved the row) andrenderAssistantBubble(app-sdk/messageRenderers.tsx) each walked forward from the reply and returned "no footer" at the next assistant row; the page's copy did so before it read the reply's ownturn_stats, and the SDK's never read them. Each treated only auserrow as the end of a turn. Anudge/subagent/ cron row followed by its reply therefore hid the footer above it, even on a completed reply, and so did the recovered answer under a cut reply. One function,replyShowsFooter(website/src/pages/chat/replyFooter.ts), now decides it for both: a reply carrying positiveturn_statsalways draws its footer; a reply without stats draws it once a user row or a row that opens a turn of its own (the existingopensTurnpredicate) follows, or once the transcript ends and the session is idle. The hidden say-nothing and system-notice skips are kept. Both callers pass the row they draw, and its own role and stats come from that row, as the old walks read the row itself: the page draws a deferred snapshot of its rows while the walk reads the live list, so the list at the row's index can hold another row. A crewmate's chat still forces the footer at a run's end (forceFooter).Backend: the footer reaches the open page before a recovery runs. A completed turn's footer reaches the page through the refresh its
chat_donetriggers. An abnormal end that queues a recovery hands the slot to it without one, so the cut reply's footer would only appear once the recovery finished._broadcast_turn_stats(chat_turn/turn_stats.py, beside the completed turn's writer) sends the stats at once on the existingchat_message_updatepatch, keyed on the row'smid, which the client already merges into the row's meta.Backend: the footer goes on before the shutdown save, and the write marks the slot dirty. While the gateway shuts down, the turn's teardown skips its save, so
_persist_partial_reply's own shutdown save is the last write the reply gets, and onmainthe footer is attached after it, inside the usage write. The seam is split:_stamp_abnormal_turn_footerputs the footer on and takes the turn's single billing read, synchronously, before that save (which now also runs when the footer is the only new thing on the reply);_record_abnormal_turn_usagethen writes the row from the same read. The order "text first, usage write last" is unchanged. The footer write is in place, so_attach_abnormal_turn_statsmarks the slot dirty itself: the periodic flush writes only a dirty slot.Backend: the footer and the usage row show one figure, and the footer is put on once. A recovery arm's completion that reported no billing writes no usage row; on
mainthe seam then attached the completion's empty figures to the reply and wrote the row from the provider's live read, so the footer omitted the credits the row recorded. The stamp now attaches the completion's figures only when the completion wrote the row (_turn_usage_persisted),ttft_msincluded, asmaindoes; otherwise the footer and the row come from the seam's one read._turn_footer_attachedkeeps the footer to one write per turn, so a late cancel after the end-of-turn attach, which onmainre-stamped the same figures, neither stamps nor patches again.Backend: a cancel on the seam's shutdown save does not cost the arm that called it. The save caught
Exception, which aCancelledErroris not, so a shutdown that cancelled the turn task on that await propagated out of_persist_partial_replyinto the recovery arm, which then lost its card and its recovery. The cancel is swallowed as the usage write already swallows one:_persist_abnormal_turn_usageonmaincatches theCancelledErrorof its own write inside the same teardown, for the same reason (re-raised, it escapes the recovery handler and strands the completion thefinallyowes), so a shutdown that cancels the turn task during this save ends the arm the way it already ends one cancelled during the usage write.test_a_cancel_on_the_shutdown_save_still_leaves_the_arm_its_recoveryinjects that cancel into the save under the real_run_chat, asmain'stest_raw_complete_survives_cancellation_during_token_persistenceinjects the one the usage write swallows. The text save itself runs as it does onmain, unguarded: the guard earlier revisions put around it answered no reported failure and is gone (see "Review dispositions"). The footer stamp, which this change runs ahead of that save, is guarded, because the billing read it makes came after the save onmain, so a raise in it never cost the text its save at shutdown and must not start to.Backend: one identity walk, scoped by the turn's start row.
_last_reply_row(chat_turn/turn_stats.py) is the rule for the row an abnormal end stamps and the row the turn's file chips attach to: among the rows appended since the turn began, by_turn_rowswith the boundary and the start identity_turn_start_midthe runner already hands the file-change flush, the newest reply the runner recorded. Onmainthe stamp scannedslot.messages[turn_boundary:], which a window at its cap has shifted, so the cut reply got no footer there; the flush's on-loop attach half (_attach_file_changes, since #19781) had its own inline copy of the identity walk, and now calls the shared one; the one rule the shared walk adds to it is the notice skip, so a turn's file chips can no longer attach to a system notice row where the turn recorded no reply (its anchor testsTestFlushFileChanges::test_injected_assistant_row_is_never_the_anchorandtest_own_reply_wins_over_a_later_injected_rowgo red when the shared walk's identity rule is removed)._completed_reply_rowgives the completed turn's attach (_attach_turn_stats, which gainsturn_start_mid) the same scoping: the recorded reply where the turn recorded one, else the position rule, the newest assistant row that is not a system notice, so a/compact-style turn whose confirmation is a plain assistant row does not put the footer on the notice appended after it. Both forms pass over a system notice; on a real slot the identity rule already excludes one, since a notice is never recorded as a reply, so this matters where the position rule applies.Frontend: grouping finds the end of a cut-short synthesis answer.
groupDisplayItemsreadsturn_statsas the end of a fan-out synthesis answer. A synthesis answer an error cut short carries stats on its first half, soanswerEndIndextakes an error card or a system notice drawn after it, before any other reply, as part of the answer, with the rows between them, passing over another writer's envelope (a workflow result or a sub-agent completion, which the runner never records as its reply), and carries the boundary past arecoveryinject to the resumed half. For a resumed answer that is wheremaindraws it today; an answer cut short with no recovery now ends with the rows that report on its turn, as a completed answer ends at its reply, so the next wave folds instead of the whole region staying unfolded. The MCP App promotion pass (transcriptRows.ts) also ends a loose region at a stamped reply; any row after a cut-short reply makes an app-bearing batch a grouper turn, which that pass keeps whole, so it cannot split a resumed turn. A comment there, a grouping test and a test over the realuseTranscriptRowsrecord it.Frontend: the cut half of a resumed reply is not a working step.
TurnBlock's collapse-all split keeps a turn's last reply and folds the rest. A reply an error cut short carries the stamp, and therecoveryinject resumes the same turn, so the recovered remainder is the block's conclusion and the stamped first half folded as a step with its footer.findResumedReplyRowspins that reply and the recovery row out of the fold, the wayfindAnsweredRefusalRowsalready pins an answer and the tool-refusal card that followed it; between the two only an error card, a system notice or another writer's envelope may sit (the grouper'sisTurnStatusRow/isEnvelopeRow, now exported), stamped text a tool call followed is narration and still folds, and a cut reply with no stamp (a transcript older than the stamp) folds as before. FourTurnBlocktests pin it; the two pin cases fail on the previous split with the cut reply folded.docs/system-specs/modules/turn-stats-footer.mdanddocs/system-specs/modules/crew-log-emitter.mddescribe the seam as it now runs;docs/feature-map/README.mdgains a "Reply footer" row naming the new module.Decision for the owner
Removing
_attach_owned_turn_stats, which #19984 introduced. Its one production caller (_attach_turn_stats) passedreply_mids=Noneand the function then read the slot's own list, so the explicit-list form had no caller; its unit test (test_reply_mids_skips_a_row_another_writer_appended) is replaced bytest_lands_on_the_recorded_reply_not_a_row_another_writer_appended, the same scenario through_attach_turn_statswith the reply recorded on the slot as the runner records it. If the owners want the name kept, it comes back as a one-line alias.Review dispositions
Each CONCERNS item from the fork review lanes (heads
ff448c59,50ea7d7d,25225baf,d5c712a0,430a776fand60d35f73) and what this PR does with it:replyShowsActionstook Copy / Fork / More off the cut half, against the Goal. Removed. The four symbols (replyShowsActions,recoveryResumes,showActions,actionsShown) and their tests are gone andshowFooteralone decides the footer, which is the subtraction First Principles named. The cut half keeps its actions, as the Goal and Reply loses its footer (model, credits, Copy/Fork) when its turn ends early or an auto-nudge follows #19855 say and asmain's backend already stamps it.ff448c59): a Copy under the cut half copies a fragment, and nothing links the halves. Declined, per the Goal; the halves sit adjacent with the connection card and the recovery row between them, which is the cue the default view has. A "continued below" marker is not part of this change (Not a goal).50ea7d7d): the cut half's stats line reads as the whole answer's cost, and the action row moved between halves during the live window. The second is gone with the split. The first is accepted: the two halves are two usage rows and each footer names its own turn's cost; a combined cost is not part of this change (Not a goal).TurnBlock.findResumedReplyRowsand the grouper's answer end), both on the grouper's row predicates. An explicit marker the backend stamps on the cut row (it knows, in_persist_partial_reply) would replace both reads; it is a persisted protocol field with an old-transcript fallback, so it is not part of this change (Not a goal).25225baf): the first wave's "Sub-agents finished" card folded behind a second "Worked through 1 step" toggle in frame (c). Fixed. The collapse-all pin wraps the synthesis row, the cut half, the connection card, the recovery row and the resumed half into the answer's one turn, and with the halves pinned the synthesis row was the one step left to fold, wheremainshows it (its two-row batch is too short to wrap).findResumedReplyRowsnow pins the synthesis row directly above the cut reply too, so that turn has no toggle; a synthesis row a tool call separates from the reply folds with that step, as onmain. Frame (c) recaptured on this build.25225baf): the cut half's footer looks like a finished reply's, so half an answer reads as complete; smallest fix a muted "Continued below" in its stats line. Declined for this change, as the same item was onff448c59: the Goal keeps the actions on the cut half, the connection card and the recovery row sit between the halves in every view (the collapse-all pin keeps them there), and the cue is a small change of its own (Not a goal). The owners decide at merge whether to take it.d5c712a0): the same item, reworded: the cut half's full footer and own price read as a finished answer, and "nobody has done a blind read"; smallest fix an "interrupted · 0.12 credits" marker on the cut row's stats line. Same disposition: declined for this change per the Goal, the cue is a small change of its own (Not a goal), and whether to take it is the owners' call at merge. Design and First Principles passed this head with the full footer on the cut half.25225baf, re-raised):turn_statsmeans both "footer figures" and "turn ended", so the frontend walks infer "cut and resumed" from row shape; clears with an explicit marker on the cut row or a maintainer recording the heuristic as the contract. Same point as the Design item above, dispositioned the same way: the two walks share the grouper's predicates, the status rows they pass over are the onesanswerEndIndexalready named before this PR, and the backend marker is a persisted protocol field with an old-transcript fallback (Not a goal). Recording the contract is the maintainers' call._reply_flushedrename, the shutdown-save cancel swallow. Declared in "What changed", reverted, and matched to_persist_abnormal_turn_usage's own swallow with the test named, respectively (previous revisions).430a776f): the seam's text-savetry/exceptand the swallowedCancelledErroron its shutdown save rest on an asserted failure, not a reported one; subtraction offered for both. Taken for the text save: the guard is gone, withtest_a_failing_reply_save_still_queues_the_recovery, which injected the failure it asserted, and the save runs as onmain. Kept for the cancel, on the precedent the lane named:_persist_abnormal_turn_usageonmainswallows the same cancel in the same teardown, under a test that injects it too (test_raw_complete_survives_cancellation_during_token_persistence), and the shutdown save already caughtExceptiononmain; this widens that to the cancel a shutdown delivers ("What changed" has the mechanism).60d35f73):isTurnStatusRow's notice arm restatesCompactionCard.isSystemNoticeRow. Taken: the grouper's predicate now readsmsg.role === 'error' || isSystemNoticeRow(msg), the one notice test the footer walk andTurnBlockalready import; nothing behavioural changes (the two reads were the same expression), andCompactionCard's import graph does not reach the grouper, so no cycle.430a776f): a cut reply that was streamed has nomidon the client until a refresh, so does it get the live footer? It does, and no refresh is needed:slot.appendin_persist_partial_replybroadcasts the cut reply's ownchat_messageframe, which carries itsmid, before_broadcast_turn_statssends themid-keyed patch; the client merges the frame's meta onto the streaming row (Frontend renders duplicate assistant messages after gateway restart during active turn #1704'schatSlicecases) and the patch then matches bymid(chatSlice.messages.test.ts). The stall test intest_chat_runner_abnormal_turn_usage.pynow pins that frame order.e7b74caa, LOW on adjudication): a reply steered mid-turn and then cut with no further text never receives themid-keyed footer patch. A known limit of this change, left as is. That reply was saved by the steer cut, quietly on purpose (_steer_segment_cutcalls_flush_segment(quiet_persist=True): the clients already hold its text in their frozen row, so thechat_messageframe that would carry itsmidis not sent), so at the stall_persist_partial_replyappends nothing,_last_reply_rowstamps the saved row, and_broadcast_turn_statsnames amidno client row carries (sseChatMessagePatchByTsmatchesmidexactly, and the frozen row has no servertseither). The footer is on the saved row and reaches the page with the next refresh, as_broadcast_turn_stats's docstring says and as the file-change chips attached to that same row by the same walk already do. Giving the frozen client row the saved row's identity is a change to the steer path, not to this one.9e639d7e, PASS note): the stamp also marks where a turn ends for the page (isTurnEnd,answerEndIndex,findResumedReplyRows), so a writer stamping a row that is not the turn's last reply would move the fold. Taken: the spec (turn-stats-footer.md) now states that contract in the paragraph on the frontend readers.0a7cd15e, PASS note, r125 item 2): point to a backend test that only_last_reply_row/_completed_reply_rowreceiveturn_stats. Taken:test_turn_stats_lands_only_on_the_row_the_two_selectors_chose(test/test_turn_stats.py) scanssrc/kiro_crewfor everyX["turn_stats"] = ...and requiresXto be bound from one of the two selectors, through an alias if there is one; the two other places the key is built are listed in the test with the reason each is not such a write (the live patch's frame in_broadcast_turn_statsis a payload, not a row;inject_cron_result_to_dashboardappends the cron result row with its own run's figures, so the stamp sits on the row that ends that run), and a new one fails the test by name until it is traced. Red onmain:_attach_owned_turn_statswrites the key inside its own walk of the window, which is the drift the note describes. A self-test on synthetic source pins the shapes the scan reads, and three mutants (each stamp bypassing its selector forslot.messages[-1]; a{"turn_stats": ...}literal added to another module) fail it with the offending function named. The spec's contract sentence and its Tests list point at the test.0a7cd15e, note, r125 item 2): the feature-map row saidchat_runner.pystamps through_persist_partial_reply. Fixed: the row's handler cell now nameschat_turn/turn_reply_seams.py(_persist_partial_replystamps that end's footer) and its callers,chat_turn/acp_recovery.py,stop_recovery.pyandturn_failures.py, and says_attach_turn_statsis called fromstop_recovery.py;chat_runner.pynever references the helper, as the lane said.Tests
Proof: PROVEN test/test_chat_runner_abnormal_turn_usage.py::TestErrorEndTurnFooter::test_a_cut_reply_gets_its_footer_in_a_window_at_its_cap, test/test_chat_runner_abnormal_turn_usage.py::TestErrorEndTurnFooter::test_a_shutdown_saves_the_partial_reply_with_its_footer, test/test_chat_runner_abnormal_turn_usage.py::TestErrorEndTurnFooter::test_a_shutdown_saves_a_footer_put_on_a_flushed_segment, test/test_chat_runner_abnormal_turn_usage.py::TestErrorEndTurnFooter::test_a_stall_sends_the_cut_reply_its_footer_before_the_recovery_runs, test/test_chat_runner_base_surface.py::test_a_moved_name_keeps_its_base_shape_and_owner[turn_stats:_attach_turn_stats] (head c7cd586)
test/test_chat_runner_abnormal_turn_usage.py—TestStoppedTurnFooterandTestAbnormalEndFooter(fix(dashboard): keep the reply and its footer when a turn ends abnormally #19984's, kept unchanged) pin the stamp on each end.TestErrorEndTurnFooter, driving the real_run_chatwith the realprovider_last_turn_usage, pins the seam around it: the turn ceiling through the realbounded_chat_turnwith the native stop acknowledged and not (the deadline timer held and fired once the reply streamed; the acknowledged stop resolving on the completion's usage-write signal under a hang-only bound; which path billed the turn pinned apart from how the stop was answered; the acknowledged footer keeping the completion'sttft_ms, from a fixed 250 ms first-output clock, and the unanswered one recording none, as a Stop does); a periodic flush between the reply's save and its footer still leaving the slot dirty; a cut reply in a window at its cap getting its footer, found from the row the turn started after; the reply's last save at shutdown carrying the footer, also when the text was already a row and the footer is all the cut adds; an error or a cancel after the end-of-turn flush, after a billed or an unbilled completion, leaving exactly one reply row and neither stamping nor patching the footer again; a recovery arm whose completion reported no billing billing the turn once under its ownstop_reason, with a footer that matches that row; a cancel landing on the helper's shutdown save still leaving a stall arm its card, its recovery and its row; a stall sending the cut reply its footer on achat_message_updatekeyed on the row'smidbefore its queued recovery runs, and after the reply's ownchat_messageframe carrying thatmid, so a client that streamed the reply holds the key the patch is matched by; and a failed compaction after a tool call putting the footer on the reply, not its notice. A module-level test pins that_last_reply_rowpasses over a notice.test/test_turn_stats.py—_attach_turn_statslands on the recorded reply, not an envelope another writer appended after it; a turn that recorded no reply keeps the position rule; a system notice after the reply is passed over;test_turn_stats_lands_only_on_the_row_the_two_selectors_chosescans the backend for every write ofmeta["turn_stats"]and requires its row to come from_completed_reply_rowor_last_reply_row, with the two other builders of the key listed by name and reason (see "Review dispositions"), andtest_the_turn_stats_write_scan_reads_each_shape_it_claimsis its self-test on synthetic source. fix(dashboard): keep the reply and its footer when a turn ends abnormally #19984'stest_reply_mids_skips_a_row_another_writer_appendedgoes with the function it called (see "Decision for the owner"); the first case above is its scenario through_attach_turn_stats.test/test_chat_runner_base_surface.py(the moved-name surface table refactor(dashboard): move the runner's turn helpers into chat_turn #21086 split out of the composition contract) pins the new signature, with fix(chat): re-send a throttled turn with one copy of the prompt in history #21907'sretrieskeyword afterturn_start_mid.test/test_chat_runner_turn_plumbing.pylists_stamp_abnormal_turn_footerwith the seam's other functions refactor(dashboard): hoist the chat turn's closures into chat_turn #22057 hoisted intochat_turn/turn_reply_seams.py, so the turn-first and async-guard rules read it too.website/src/test/replyFooter.test.ts— the shared rule: stamped replies keep the footer under a nudge cycle, an error card plus recovery, and a later run; nudge / sub-agent / cron rows end the turn above them; arecoveryinject and a same-turn reply do not; notice and say-nothing rows are passed over; streaming rows never draw it; the drawn row's own role and stats decide, even where the live list holds another row at its index.website/src/test/AppSdkMessageRenderersCov80.test.tsx— the same two cases through the SDK renderer.website/src/test/groupDisplayItems.test.ts— a synthesis answer cut short and resumed stays out of the next wave's fold, and so does the error card under an answer cut short with no recovery; the tool row, notice and error card after an answer cut short stay with it, with a workflow envelope among them; a reply cut short and the rows after it form one turn.website/src/test/TurnBlock.test.tsx— a reply cut short and resumed: the cut reply and the recovery row stay visible above the resumed half, with the tool row folded and the toggle counting one step; a system notice and a sub-agent envelope between the two are passed over; stamped text a tool call followed still folds; a cut reply with no stamp folds as before; the synthesis row that led the cut reply stays with it and the turn has no toggle; a synthesis row a tool call separates from the reply folds with that step.website/src/test/transcriptRows.cutReply.test.tsx— through the realuseTranscriptRows, the MCP App row and the cut reply stay in one turn at every point of a turn an error cut short and a recovery resumed, running or idle.website/src/test/ChatPage.footerNotRetracted.test.ts,website/src/test/ChatPage.systemNoticeScans.test.ts,website/src/test/invisibleText.test.ts— the source-scan pins on the removed inline walks now pin that both surfaces callreplyShowsFooter, reading the page and its owners underpages/chat/page/, and exercise it directly.website/src/test/chatSlice.messages.test.ts— the live footer'schat_message_update, keyed on the reply's mid withturn_statsalone in its meta, adds the footer and keeps the rest of the row's meta (its mid first of all); the sibling row sharing its ts gets nothing. Red when the reducer replaces the meta instead of merging it.Red on base. This branch's backend tests run against
main'schat_turn/turn_reply_seams.py,chat_turn/turn_entry.py,chat_turn/turn_locals.py,chat_turn/turn_stats.py,chat_turn/file_changes.pyandchat_turn/stop_recovery.py: 10 ofTestErrorEndTurnFooter's 17 cases and three of the four newtest_turn_stats.pycases fail with the reported symptom: the two shutdown tests ("the reply was saved at shutdown without its footer", "the footer put on at shutdown was never saved"), the capped window ("the reply the turn's end cut short carries no footer"), the stall patch ("the cut reply's footer was never sent to open clients"), the four unbilled-arm cases and the shutdown-cancel case (KeyError: 'credits': the footer lacks the credits the row records), and the dirty-mark test, and intest_turn_stats.pythe recorded-reply case (noturn_start_mid), the notice case (the notice took the stats) and the selector scan ("turn_stats written onto a row no selector chose":main's_attach_owned_turn_stats, line 183). Green onmainand kept as guards: the ceiling test (itsttft_msassertion was red on this PR's previous revision, which dropped the completion'sttft_mson the cut-after-completion path), the four late-end cases (the second stamp they forbid writes the same figures onmain, which has no patch to send; they go red here when either half of the once-guard or the completed path's own flag is dropped), the compaction-notice case (the identity rule alone places that footer; it goes red when the notice skip is removed from the position rule's branch), andtest_turn_stats.py's position-rule case (a turn that recorded no reply lands on its newest assistant row onmaintoo). Earlier mutation runs on this tree, all still in force: catching onlyExceptionaround the shutdown save fails the shutdown-cancel test ("the cancelled save cost the stall arm its card"); withholding the reply's ownchat_messageframe (a reader attached to the slot) fails the stall test at its frame-order assertion, the row frame missing from the wire; removing_stampedfrom the shutdown-save condition fails the flushed-segment shutdown test; dropping the dirty mark fails the flush test; passing no start identity fails the capped-window test; dropping the identity rule from the shared walk failsTestFlushFileChanges' anchor tests. Frontend: seven footer cases fail with the old walk restored, the two drawn-row cases with the rule readingmessages[index], the resumed-answer grouping case with the old first-stamp boundary, the error-card grouping case with the card not taken into the answer, the resumed half folds without the envelope pass-over, and the synthesis row folds behind a one-step toggle without the lead-row pin; raising the grouper's wrap threshold by one fails theuseTranscriptRowstest at the prefix that ends on the error card.Run locally, on the change rebased onto
main13e3ff298b(past #20526's per-turn state object, #20388's ChatPage split, #20453's single fold state in TurnBlock, #20755's and #21086's moves of the runner helpers into theirchat_turnowners, after which the_flush_file_changesedit lives inchat_turn/file_changes.pyand the signature pin intest/test_chat_runner_base_surface.py, #20805, which moved the glued-marker repair inside_redact_segment, so the partial-reply save now hands it the accumulated text the way the end-of-turn flush does, #21907, whoseretriescount the completed turn's attach now carries, and #22057, which hoisted_run_chat's closures into their owners, after which the seam (_persist_partial_reply,_stamp_abnormal_turn_footer,_record_abnormal_turn_usage,_attach_abnormal_turn_stats) lives inchat_turn/turn_reply_seams.pyas functions that take the turn first, and #22150, which moved the turn's prologue into phases, after which the_turn_footer_attachedflag is initialised inchat_turn/turn_entry.pybeside_turn_usage_persisted, and the start identityturn_start_midismain's own turn attribute, and #21266, whosepost_turn_replyreads the runner's_reply_midslocal after the attach, so the line that defines it stays wheremainhas it, and #22914, which settles the run the live stream held at a tool call or approval prompt before the partial-reply save and reports whether a row changed, so the shutdown save's condition is nowmain's ownrows_changedflag or the footer stamp, and the seam's own text-appended flag is gone, and #22682, which moved the stream's end and the turn's tail into phases, after which the completed turn's attach, with itsturn_start_midand the_turn_footer_attachedmark, lives in_turn_persist_and_settle(chat_turn/stop_recovery.py) and the completion arm in_on_complete(chat_turn/turn_stats.py), and #23528, which trimmed the runner's imports to what reads them and has each owner import the other names it reads at run time, after which this change adds no line tochat_runner.py:turn_stats.pyimportsis_system_noticeitself, and the sibling names it andfile_changes.pyread (_turn_rows,_last_reply_row) are typed from their owner files, and #23656, which moved_persist_abnormal_turn_usagefrom the runner intochat_turn/turn_stats.py, so the seam's type-checking import takes it from there beside the footer helpers it already names, and #21222, which added the transcript'scopyOnSelectprop to the same<AssistantMessage>element whose inline footer walk this change replaces withreplyShowsFooter, so the element carries both, and #23977, which moved the ticket-named test files to their module homes, so the seam's tests live intest/test_chat_runner_abnormal_turn_usage.py, and #23275, which keeps the transcript's row handlers stable while a reply streams, so theonTogglePin,onQuoteMessageandonRegenerateprops on that element are nowmain's stable forwarders on either side of theshowFooterthis change replaces, and #19781, which moved the turn-end file-change snapshot off the event loop, after which the row walk this change replaces with_last_reply_rowlives in_attach_file_changes, the on-loop attach half that_flush_file_changesand_flush_file_changes_off_loopshare, and #24774, which dropped the strict xfail that #24276 had left stale intest/test_crew_log_fullscan_guard.py, a file this change does not touch, so backend shard 2 passes again on every head built on this base, and #23838, which added the message-reaction props (activeReactions,onToggleReaction,reactionError,onClearReactionError) to the same<AssistantMessage>element, and #26157, which reverted them, so that element ismain's own again apart from theshowFooterthis change replaces, and #23769, which keeps the previous reply on screen while a Regenerate runs: itsbeingReplacedandstartsNewReplylabels wrap that same element, itsfirstNewReplyIdxreadsisSystemNoticeRow, so the transcript keeps that import besidereplyShowsFooter, andchat_turn/file_changes.py's type-checking imports name itsnote_regenerate_replybeside_last_reply_row, and #25944, which broughttest/kiroUsageRefetchInterval.test.tsin line with #25434's parser (an unavailable reading under API-key auth isnone, not a terminalapi-key), a file this change does not touch, so frontend shard 1 passes again on every head built on this base):pytestover the 463 backend files that reference_run_chat, the seam, the stats footer, the file-change flush, thechat_turnowners or the runner module (20134 passed, 4 skipped, 3 failed: the twoTestRealHookProcesstests that spawn a real hook process andtest_app_agent_launch_copy.py's opted-out steering case, which fail on this host the same way on an untouchedmaincheckout and touch nothing this change does), and the seam, stats, base-surface, composition, compose-binding, turn-plumbing, shared-state, turn-cancel, ordinal and timeout-consistency files again, 952 passed across 13 files, with #21907's throttle and rewind files and #22150's and #22682's plumbing and composition tests among them;main's ownTestStoppedTurnFooterandTestAbnormalEndFooterpass on this branch unchanged;vitestover the whole frontend suite, 3545 files (57899 passed, 1 expected fail that is upstream's own);tsc,eslint,mypy,black(the ratchet gate),flake8,isort,jscpd, the i18n check,docs-lint.sh, the new-test stability repeat (three passes over the three leaf test files this change adds or modifies, with the job's own flags), and the comment-history, brand (on the added lines), focus-cue, file-line-cap and feature-map gates all clean.Manual verification
The built SPA (
npm run buildofmainand of this branch), served by the repo's own transcript harness (website/scripts/lib/transcript-harness.mjs) over fixture API responses, with three seeded transcripts: (a) a completed reply followed by an auto-nudge cycle and its reply, (b) a reply the model cut short mid-stream, the "Connection unstable — resuming…" card, the runner's recovery inject and the recovered answer, where the cut reply carries the stats the backend half now stamps, and (c) a two-agent fan-out whose synthesis answer is cut short the same way and resumed, followed by a second wave and its synthesis; in (c) the cut half carries stats in both builds, asmain's backend stamps them since #19984. Onmain(built before #19984 merged; its frontend walk, which #19984 did not change, hides the footer the same way on today'smain) the earlier reply in (a) and (b) has no stats line and no Copy / Fork / More row (0 buttons); on this branch it has both. In (b)mainfolds the cut reply behind the turn's "Worked through" toggle; this branch shows both halves with the recovery row between them and has nothing left to fold, each half with its own footer. In (c)mainfolds the resumed half of the answer behind the next wave's toggle; this branch keeps both halves in the open. The frames below are those runs, cropped to the transcript rows. The backend half is exercised through the real_run_chatin the tests above; no live gateway was driven.Screenshots / video
Synthetic transcripts, transcript rows only.
(a) A completed reply, then an auto-nudge cycle. Before: the first reply has lost its footer. After: it keeps the stats line and its actions; the cycle's reply has its own.
(b) A reply cut short by the model at capacity, then recovered. Before: the cut reply has no footer; only the recovered answer does (the before frame has the turn's fold expanded so the cut reply shows at all). After: in the default setting with no fold, the cut reply shows its own footer (its turn's cost, Quote / Copy / More), then the connection card, the recovery row and the recovered answer with its own.
(c) A sub-agent synthesis answer cut short and resumed, then a second wave. Both frames are the default collapse-all-steps setting. Before: the resumed half, which carries the recommendation, is folded behind the second wave's "Worked through 3 steps" toggle, a toggle that promises a restatement below that never comes; only the cut half is in the open. After: both halves of the answer are in the open, the cut half with its footer, then the connection card and the recovery row, then the resumed half with the recommendation and its own; the second wave's "Worked through 1 step" toggle sits below it where the wave starts, and the first wave's "Sub-agents finished" card stays in the open above the answer, as it does on
main; the answer's turn has nothing left to fold.Related Issues
Closes #19855
Refs #15013, #17669, #11523, #12934, #18947
Relation to #19984
#19984 (opened for the same issue while this change was in review) merged while this PR was open, and this PR is rebased on it: the abnormal-end stamp, the recovery arms and the generic arm through the seam, the once-per-turn save and the identity rule on the completed turn's attach are its, and this PR keeps
TestAbnormalEndFooterandtest_an_involuntary_cancel_gets_the_footer_toounchanged (its pre-dispatch test is this PR's under the parametrised name). On top of it this adds: the frontend half it deferred, without which the auto-nudge case in #19855 stays broken and a stamped reply still loses its footer under the recovered answer; the footer before the shutdown save, so a gateway restart mid-turn keeps it; the livechat_message_updatepatch, so the footer reaches the open page before a queued recovery runs rather than after it; the capped-window case (_turn_rowsby start identity, where a scan from the boundary index finds nothing); one billing read shared by the footer and the usage row where the completion wrote no row, so the two cannot disagree; the once-guard on the footer; a cancel-tolerant shutdown save in the seam, so a shutdown that cancels the turn task during it cannot cost a stall arm its card or its recovery; one spelling of the identity walk (_attach_file_changescalls it too); and the grouping and promotion-pass changes a stamped cut-short reply needs so a resumed synthesis answer does not fold behind the next wave. It removes_attach_owned_turn_stats(see "Decision for the owner").Pattern harvest
Rule candidate: review-prompt
Pattern: an end-of-turn duty (save the reply, attach its stats) done once after the stream loop, with early
returns and exception arms in between that skip it; and an inline "has this turn ended" walk that hard-codesrole === 'user'as the only boundary instead of calling the sharedopensTurnpredicate, duplicated per surface.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.