Repository navigation
fix(dashboard): preserve previous reply when regenerate ends empty - #23769
Conversation
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing to check. What this change shipsInventory (10 items) — 10 justifiedIntent: a user who presses Regenerate and gets no new reply keeps the reply they already had. This is a FIX (#14632, #24039).
[FIRST-PRINCIPLES-REVIEWED] 71fe3ff Description read[DESCRIPTION-READ] 4c71dcd2021df47e5d0268781b57ad2b0f4769103cca918d198d20d497954f4a That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the fix removes the cause, an irreversible delete made before the new reply existed. Rendered evidence for this revision is committed (8 images, 1 recording). Notes
[DESIGN-REVIEWED] 71fe3ff Description read[DESCRIPTION-READ] fbf55937dc532d1cb1fad7c9a68170a6b015e7f231df2fc0941f838b68c617e1 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 |
UX Review (Opus 5.5) — ✅ PASSUX-level review of UX-Verdict: PASS Nothing blocks. The blind reader read both notes and the "New version" divider correctly, and said they would dare to press Stop. The swap at turn end is explained in the PR and shown in Notes
[UX-REVIEWED] 71fe3ff Description read[DESCRIPTION-READ] b8160a3133a1684a82decaea903048b36a8e3168e5f84c42ffa6f42dce0d90e2 That sha256 names everything this verdict read: the PR description, plus the 11 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 — ✅ no blocking findingsReviewed Review detailsNo findings. None of the five candidates holds up against the code at this commit. [OPUS-REVIEWED] 71fe3ff Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
40d3a79 to
fbbb5db
Compare
9907e40 to
fc5fbe0
Compare
fc5fbe0 to
2eadca7
Compare
9624460 to
dc68556
Compare
266a378 to
b386733
Compare
b386733 to
8391d64
Compare
|
|
|
|
|
|
|
|
Holding for human review. This PR changes what the regenerate path deletes from persisted chat history. The up-front delete is removed, and a deferred rewrite removes Also open on this head:
To clear: a maintainer review of the persistence change and the UX ruling, replies to the UX notes, and an issue for edit-resend. Reviewed head: — crew-pr-reviewer (r131) |
|
|
|
|
Re r131 (crew-pr-reviewer) on edit-resend,
|
|
resolution: removed
|
|
|
HOLD at
The r131 items are answered. The edit-resend reply (the edit replaces the prompt, so the dropped reply answers a question nobody is asking) is reasonable and needs no issue. The UX notes and the screenshot gap were handled in 858ef11 and fd5b9d4. All AI lanes pass and CI is green. A rebased head needs a fresh review. — crew-pr-reviewer (r133) |
|
Frontend Lint & Type Check (and the Coverage Gate that waits on it) is red on main, not this PR: |
|
Regenerate used to remove the previous assistant reply before the new turn ran, both on the server (history rewrite) and in the browser (optimistic truncation). A re-run that produced no reply left the turn with no answer at all, and the old one was gone. The previous reply now stays in place until the turn ends. At the end, settle_regenerate (chat_turn/regenerate_swap.py) removes it and keeps it as a variant only when the turn produced a reply, through one write pinned to the transcript and slot the Regenerate was authorized against. An empty turn leaves it untouched. The replace write names the rows it retires (retired_rows). The rewrite keeps its foreign-append scan, so a row another writer persisted after the snapshot, such as a workflow result landing during the write's await, survives the swap instead of being rewritten away. A committed swap also bumps a slot epoch inside the transcript lock (write_guards.publish_swap). A save whose window copy predates the commit, or was taken before memory applied it, re-takes the copy under the lock with the swap applied, variants included; a caller's own snapshot is refused. So an in-flight flush or a tag save cannot write the old reply back, however many rows the swap retired. The guard applies the swap record it read before re-copying the window, since the event loop may apply the swap and clear the record meanwhile. A swap whose previous reply was partly trimmed off the window into the frozen prefix is refused: a rewrite cannot retire those rows, so both replies stay. While a swap is in flight the window's front trim waits, so an append at the window cap cannot credit a retired row to the frozen prefix after the write removed it from disk; the next append trims the excess. A recovery the Regenerate turn queues before it has a reply (a session-not-found replay, a refusal fallback, a continuation) is the same Regenerate's next attempt: _queue_recovery hands it the target and the drain re-arms it on the replay turn, so the replay's reply replaces the previous one instead of landing after it. Command replies the slash gate writes directly (an empty /prompts, a blocked command, unsupported compaction) are recorded on the target like every other reply, and the settle step runs in whichever frame runs the turn's tail, so a /prompts get re-entry (depth 1) settles too. test/test_regenerate_invariants.py checks the swap contract (the window cap, a Regenerate during a swap, and one that ends with no reply) over boundary inputs. The streaming reply is labelled "New version". The previous one reads "Previous version. Kept if no new reply arrives. Stopping now keeps it." until new text starts, then "Previous version. New reply started: this one moves to the version arrows. Stopping keeps both.", using the word the version switcher already uses. While the turn runs, the browser draws the previous reply dimmed under a "Previous version" label, so the collapse into one reply with a variant switcher at turn end reads as expected rather than as a lost answer. A turn that ends without streaming also clears the pending press, so the label leaves the kept reply as soon as the empty turn ends instead of at the 30 s pending-press safety timeout. The committed swap's chat_variant_switch frame names the rows it retired (mids and approval ids), and the client drops them (retireSwappedRows) before the refetch: that refetch re-seats decided rows (permissions, elicitations) from the client's own copies, so a decided card of the replaced turn would otherwise come back beside the new reply. An empty or failed swap sends no frame, so its rows stay. A row made of nothing but backend control notices (the Claude adapter's "Compacting...") is not a reply: the target records each notice chunk, and such a row is neither recorded as the reply nor given the stashed variants. A notice-only turn that dies keeps the previous reply; one that ends normally hands the target to the compaction continuation it queues, whose real reply replaces the previous one. The crew-log turn ordinal skips the kept reply (rows_before_regenerate_target) so the re-run still draws the ordinal of the turn it repeats and the emitter's attempt increments. Fixes #14632 Fixes #24039
Fixes #14632
Fixes #24039
Problem / Motivation
Goal: A Regenerate that produces no new reply leaves the previous reply in place instead of destroying it.
Bug fix: pressing Regenerate and then having the new turn end before it produces any content permanently deletes the previous assistant reply. The old reply the user was trying to improve on is gone from the transcript and from disk, with no way to recover it. One concrete trigger is a Regenerate pressed while gateway memory preparation is still running (the turn is refused before it produces a reply), but any early exit from the turn before its first message hits the same path.
Why it matters
This is silent, user-visible data loss on a common action. A user reaches for Regenerate because they value the current answer and want a variation; the failure mode throws that answer away exactly when the retry fails to replace it. There is no undo and no copy left anywhere, so the content cannot be recovered.
Not a goal
What changed (motivation → approach → change)
Replaces #15417.
Symptom. A Regenerate turn ending with no reply (refused, stopped, failed) lost the old reply from screen and disk.
Cause. The endpoint deleted the old reply before the new turn ran.
Change. Nothing is deleted before a new reply exists.
chat_turn/regenerate_swap.py(new owner):RegenerateTarget,settle_regenerate,note_regenerate_reply,rows_before_regenerate_target.chat_runnerre-exportsRegenerateTargetforchat_regenerate.py.chat_regenerate.py: the up-frontdel, truncating save and 409 are gone; the endpoint arms the target and passes the request row (_current_message).release_regenerate_on_donedrops a target no turn end settled.queue_cycle._end_turn_tail: callssettle_regeneratebefore_hand_off_queuein whichever frame runs the tail (/prompts getre-entry included), so a queued successor never sees the target.file_changes._note_reply_row(model segments, partial replies)segment_flush._append_command_replyand the slash gate's direct answers (slash_commands) record the reply on the target.save_transaction(forwardsexpected_disk_older_count) /slot_persistence/transcript_merge.py:retired_rowsnames the rows a rewrite removes; any other window-region line the snapshot lacks is kept, and the cached fast path drops a kept line once the window carries it (_drop_carried_foreign).slot_persistence/write_guards.py,save_transaction: a swap-won guard. The committed swap bumps a slot epoch inside the transcript lock (publish_swap). A save whose window copy predates it, or falls before memory applies it, re-takes it under the lock with the pre-copy swap record applied; a caller's own snapshot is refused.turn_admission._turn_admit: the crew-log ordinal countsrows_before_regenerate_target, so a regenerate stays a retry (turn_dispatch_gates.py).state_parts/chat_slot.py,slot_turns.py,slot_transcript.py: the slot carries_regenerate_target; the front trim waits during a swap (_swap_in_flight).stream_chunks,segment_flush,turn_reply_seams: a notice-only row (Compacting...) gets no variants, the continuation takes the target (Regenerate replaces the previous answer when its only output is a control notice #24039), and both save seams tag it a notice so the next Regenerate skips it.turn_ledgers._queue_recovery,queue_drain: a recovery queued before any reply takes the target; the replay turn re-arms it.prompt_assembly,context.py,context_assembly/replay.py: a cold-start replay and the interrupted-turn preamble leave out the reply being replaced (regenerate_replaced_rows).docs/system-specs/modules/history.md,learn-cron-dashboard.md: document all of the above.turnActions.ts/ChatPage.tsx: the optimistictruncateAfterIndexand its rollback are removed, and with them the hook'sdispatchoption. The settle step'schat_variant_switchnames the retired rows;useWebSocket.tsdrops them (retireSwappedRows) before refetching, so the refresh cannot re-seat a retired permission or elicitation card.turnActions.ts/transcriptRendering.tsx: on press, the hook records the ids of the rows after the regenerated user row (replacingMids), as the server arms them. They render dimmed under "Previous version. Kept if no new reply arrives. Stopping now keeps it."; once the "New version" starts below, it reads "Previous version. New reply started: this one moves to the version arrows. Stopping keeps both." Strings: every catalog inwebsite/src/i18n/locales/.The replace write is pinned (
expected_history_key,expected_slot_name,_disk_older_count,best_effort=False). A rebind, a recreate, or a previous reply partly trimmed into the frozen prefix refuses it, and both replies stay.Tests from #23388 change. They expected Regenerate to remove the old reply on press. It now stays until the new one lands, so five assert that and the rows marked for replacement: three in
test/test_regenerate_taken_back_steer.py, two inwebsite/src/test/transcriptRowCallbacksStable.test.tsx.Invariants
The swap contract, checked over boundary inputs: the window cap +/-1, a concurrent and a cancelled Regenerate, and a reload mid-swap. They are in
test/test_regenerate_invariants.py.test_i1_no_retired_row_is_credited_at_the_window_cap(9 cases)test_i2_a_regenerate_during_the_swap_is_refused_and_after_it_worksCompacting...-only turn that ends normally, dies or is stopped, then regenerated againtest_i3_a_cancelled_regenerate_leaves_the_reply_and_its_versions,test_i3_reload_mid_swap_reads_one_whole_transcript,test_a_regenerate_after_a_notice_only_one_re_runs_the_kept_replyThe version cap and dedupe stay as on main (
_cap_keeping_shown, content-only dedupe).Why a plain swap
At turn end the dimmed previous version and the new reply collapse into one reply carrying the version switcher, with no exit animation or closing notice. That reads as a move, not a loss:
2/2, with the previous version one step back (the settled screenshot below).A closing notice or an animation into the switcher would be new version-management UI, which the Goal rules out: "Not adding a new recovery UI, undo affordance, or variant-management surface." An earlier head added a "kept as version N of M" notice, and First Principles blocked it on that line, so it was removed.
Backwards compatibility
Compatible: a Regenerate that produces a reply ends with the same window and variants as before; an empty turn keeps the reply.
Visible during a Regenerate: the previous reply stays on screen, dimmed under "Previous version. Kept if no new reply arrives. Stopping now keeps it.", which turns into "Previous version. New reply started: this one moves to the version arrows. Stopping keeps both." once the new reply appears below it under "New version" until the turn ends. Then the two collapse into one reply with the version switcher, the previous version one step back in it (see "Why a plain swap"). A refused press drops the label at once, and a turn that ends empty drops it when the turn ends; the old reply is then the answer again, unmarked.
Accepted outcome: if the gateway stops mid-turn after the turn's own save, the transcript keeps
user, old, newwith no variant link. Nothing is lost, and both rows render as ordinary assistant rows.Reader:
website/src/pages/chat/page/turnActions.ts:handleRegenerate-- chat -- the 409regenerate_save_refusedcode had no reader (git grepon origin/main finds only the endpoint and its test); other refusals still reachshowRefusedPress.Reader:
src/kiro_crew/dashboard/chat_turn/segment_flush.py:_flush_segment-- chat -- outside a Regenerate turn it still adopts_pending_variantson the first segment (test_pending_variants_are_attached_and_broadcast); during one it leaves them for the committed swap (test_a_declined_write_after_a_real_flush_saves_no_variants,test_a_reply_trimmed_into_the_prefix_after_a_real_flush_saves_no_variants).Tests
Proof: PROVEN test_regenerate_swap.py::test_a_refused_regenerate_turn_keeps_the_previous_reply, test_regenerate_swap.py::test_a_stale_window_save_after_the_swap_does_not_restore_the_old_reply, test_regenerate_swap.py::test_a_window_copied_before_a_long_swap_is_retaken_under_the_lock, test_regenerate_swap.py::test_a_callers_snapshot_from_before_a_swap_is_refused, test_regenerate_swap.py::test_a_swap_that_finishes_during_the_retake_still_corrects_it, test_regenerate_swap.py::test_a_previous_reply_partly_trimmed_into_the_prefix_is_kept, test_regenerate_swap.py::test_appends_at_the_cap_during_the_swap_do_not_credit_retired_rows, test_regenerate_swap.py::test_the_swap_frame_names_the_rows_it_retired, test_regenerate_swap.py::test_a_notice_only_regenerate_through_the_runner_waits_for_the_continuation, test_regenerate_swap.py::test_a_notice_only_reply_that_dies_keeps_the_previous_reply, test_regenerate_swap.py::test_a_notice_only_regenerate_stopped_mid_compaction_saves_a_notice_row, test_dashboard_chat_regenerate.py::TestRegenerateAndVariants::test_a_regenerate_after_a_notice_only_one_re_runs_the_kept_reply, test_regenerate_swap.py::test_a_cold_start_regenerate_replays_history_without_the_reply_it_replaces, test_regenerate_swap.py::test_a_row_kept_as_foreign_is_written_once_when_the_window_carries_it, test_regenerate_swap.py::test_a_recovery_replay_of_the_regenerate_settles_the_previous_reply, test_regenerate_swap.py::test_regenerating_a_command_answered_directly_replaces_its_reply, test_regenerate_swap.py::test_regenerating_a_prompt_get_settles_in_its_nested_turn, test_dashboard_chat_regenerate.py::TestRegenerateAndVariants::test_regenerate_empty_turn_keeps_the_previous_reply, test_dashboard_chat_regenerate.py::TestRegenerateAndVariants::test_regenerate_replaces_the_reply_once_a_new_one_exists (head 0510fc5)
prove.py over all hunks was inconclusive (reverting every hunk deletes
regenerate_swap.py, so the new test file fails at collection). The line above is from reverting onlychat_regenerate.pytoorigin/mainand re-running those tests: all three fail ([] == ['old'],['hi'] == ['hi', 'old'],KeyError: 'variants').test/test_regenerate_swap.py(new)test/test_regenerate_invariants.py(new)test/test_dashboard_chat_regenerate.pytest/test_chat_regenerate_cov80.py,test/test_regenerate_taken_back_steer.pywebsite/src/test/ChatPageMoreCoverage.test.tsx,transcriptRowCallbacksStable.test.tsx,chatSlice.retireSwappedRows.test.tsThe rest follow the new owner:
test_slot_ownership_checkpoint_post_await.py,test_no_config_dir_in_async.py,test_state_parts_facade.py,test_redaction_blocked_links.py,test_chat_runner_base_surface.py, the two composition-contract tests,chatSlice.publicSurface.test.ts,ChatPage.transcriptRendering.test.tsx.On this head: the regenerate, slot, redaction and composition suites, 1366 passed; flake-pattern ratchet 64 passed; Vitest over the related frontend set, 12087 passed; tsc, eslint,
i18n:check,i18n:render, mypy, flake8, isort, black, docs-lint, semgrep clean. Determinism: the regenerate test files passed 3 repeats; the label Vitest suites passed 3 shuffled runs. The capture harness asserts every state before each screenshot.Manual verification
Rendered the real
ChatPagein a browser through the capture entrywebsite/capture/regenerate-preserve-reply.html, driven bywebsite/scripts/capture-14632-regenerate-preserve-reply.mjs(scripted Playwright, its own loopback vite server). The script presses the real Regenerate button, then plays the server's side through the store paths the live socket uses:chunkframes for the new reply,setSlotRunningfor the turn's start and end, and therefreshSlotrefetch thatchat_variant_switchtriggers. Before each frame it asserts the state: in flight, the old reply is marked and the new one streams below it; at turn end the mark is gone, the old reply is folded into the variants and the switcher is visible; after an empty turn the old reply is kept, unmarked, with no switcher. All 33 checks pass on this head, including both previous-version labels and the "New version" label in flight. The empty-turn checks are what found the 30 s label linger fixed here.Screenshots / video
Just pressed, nothing new yet: the old reply is dimmed under "Previous version. Kept if no new reply arrives. Stopping now keeps it."
In flight: the previous version stays on screen, dimmed under "Previous version. New reply started: this one moves to the version arrows. Stopping keeps both.", and the new reply streams in below it under "New version".
Turn end: the two collapse into one reply. The previous reply is one step back in the switcher (
2/2).Empty turn: the new turn produced nothing, so the old reply is kept as the answer, unmarked and with no switcher. This is the #14632 outcome; before this fix the reply was gone.
A full Regenerate, from the press to the turn-end collapse (recording, WebM):
regenerate.webm
Light theme
Fixes #14632
Fixes #24039
Supersedes #15417.
Sibling sweep
Swept: git grep -nE "del slot.messages[" -- src/ and git grep -n "truncateAfterIndex" -- website/src
Sibling: website/src/pages/chat/page/messageActions.ts:109 -- not affected -- edit-resend replaces the user's own prompt, so the reply it drops answers a prompt the user rewrote
Sibling: src/kiro_crew/dashboard/chat_turn/regenerate_swap.py:162 -- changed here
Pattern harvest
Rule candidate: review-prompt
Pattern: a replace operation deletes or truncates live state before its replacement exists.
Checklist
Contribution License Agreement
Contributions are accepted under the project's Apache-2.0 license.