Repository navigation
fix(chat): fork the native claude conversation when a message is edited - #19871
Conversation
Edit + Send on the claude backend discarded the native session and primed a fresh one with the text replay, which carries no tool calls or tool results and stops at 80k characters. The claude adapter can fork a stored session up to a given assistant message, so the rewind now arms that fork at the retained prefix's last assistant message and the next cold start restores the fork like any resume. Anything that keeps the fork from running falls back to the replay. Closes #18298
UX Review (Opus 5.5) — ⏭️ skippedRevision |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS This rebased head never ran against a live claude-agent-acp, so the What this change shipsInventory (8 items) — 8 justifiedIntent: when a user edits a message on the Claude backend, the model keeps its native history up to that point, tool results included. This is a FIX.
[FIRST-PRINCIPLES-REVIEWED] 5f7c446 Description read[DESCRIPTION-READ] 473328ef29eecc5f1baab7a21f5021e4cfca28f0edd6f3140e578c34f0431366 That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5) — 🟡 CONCERNSDesign-level review of Design-Verdict: CONCERNS Whether the fork is correct rests on claude-agent-acp's private Watch
[DESIGN-REVIEWED] 5f7c446 Description read[DESCRIPTION-READ] 6de1ec59f51513f4cddc2548ebba44636039bdc90e447b0d6579f7e7fa469336 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 — ✅ 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: |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
bolichen97
left a comment
There was a problem hiding this comment.
Reviewed the diff: the change matches its stated goal and tests cover it. Readiness passed at this head.
Posted by an AI assistant at bolichen97's request.
Replaces #18319 by @rinbn, rebased onto current
mainas a same-repo branch so CI runs with repository secrets. The commit keeps @rinbn as author.Problem / Motivation
Goal: Editing a message on the Claude backend keeps the conversation the model had up to that message, tool results included, instead of shrinking it to a text replay.
Edit + Send (
POST /api/chat/slots/{slot}/rewind) on a Claude-backed session throws the native Claude Code conversation away. The replacement turn starts a new native session whose only view of the retained history is the text session replay: user and assistant text, at most 80k characters, no tool calls and no tool results. After an edit the model no longer knows anything it had only seen in tool output, such as file contents and command results, and on a long session most of the context is gone. Nothing tells the user.Why it matters
Every dashboard user on the Claude backend who edits a message loses context silently, and the loss grows with the session: a session holding a few hundred thousand tokens comes back with at most 80k characters of text, even when the edit is to the latest message and that message was stopped before any reply. The answers that follow are then built on a model that has forgotten the tool output earlier turns relied on.
Not a goal
edit-resend. The dashboard no longer calls it; it keeps today's discard and replay.session/fork, but not the fork-point key this uses.What changed (motivation → approach → change)
After this change, editing a message on the Claude backend leaves the model with its native conversation up to that message, tool calls and results included, instead of a text replay of at most 80k characters.
The rewind discarded the native session because that is the only boundary kiro-cli offers. claude-agent-acp can do better: it implements
session/forkwith a fork point, which calls the Agent SDK'sforkSession(sessionId, { upToMessageId }). That copies the stored transcript up to and including one assistant message into a new session and leaves the source untouched. So on Claude the rewind now forks instead:messageIdasAcpEvent.message_id(acp/types.py), read on both the direct-client and shared-runtime paths (acp/client.py,acp/_dispatch.py) and copied throughproviders/acp.py. Each assistant segment row stores it asmeta.native_message_id(dashboard/chat_runner.py,dashboard/state.py).dashboard/chat_rewind.py) takes the retained prefix's last assistant row, skipping runtime notices and wire-only rows (thedoneevery finished turn leaves in the live window), and storesnative_fork = {sid, message_id}on the session-map entry (session_map.py). Any write or clear of the entry'ssiddrops it, so a reset issued before the next turn wins.session_allocation.py) treats a pending fork like a resume: it stays off the warm pool, keeps the stored cwd, and refuses to run on a speculative start. It hands the fork to the Claude client and drops it from the map. A temporary or incognito session, which never restores native history, drops it without forking. The client sendssession/fork, then runssession/loadon the fork, so the turn takes the ordinary resumed path with no replay._meta.jetbrains.air.forkkey, and a fork that ignored it would copy the edited-away suffix too. So the client forks only for a backend in the newACP_BACKENDS_FORK_AT_MESSAGEset (claude;agent_sdk/backends.py, re-exported byacp_backends.py, classified off-card inagent_sdk/backend_cards.pyand listed inharness-onboarding.md), at or aboveCLAUDE_ACP_FORK_POINT_MIN_VERSION(0.71.0), and only when the handshake advertisedsessionCapabilities.fork. 0.70.0 advertises fork and copies the whole session; 0.71.0 cuts at the point (both measured, see Manual verification). The floor is checked with the existing_adapter_version_at_least.session/newplus replay, as before. The adapter answers-32602for an unknown fork point.Recorded frames from every adapter already carry
messageId, so the frame-replay snapshots gainmessage_idlines and nothing else.Backwards compatibility
Compatible: every new field (
AcpEvent.message_id, rowmeta.native_message_id, session-mapnative_fork) is optional and empty by default, and a row or entry without one takes today's replay path.Removes nothing: the change adds fields and a path that falls back to the existing behavior; no field, key, endpoint or check is removed or tightened.
Tests
test/test_rewind_native_fork.py:parse_message_idreads a chunk's id and rejects missing, non-string and over-long ones.native_forkthrough disk, and drops it onset, onclear_sid(even with no sid), and onclear_native_fork.session/forkwith the fork point and thensession/loadon the fork. Each of these starts fresh instead: a missing capability, an adapter below 0.71.0, a failed fork, and a non-Claude backend (DeepSeek advertising fork)._native_fork_pointover compaction, recycle and session-reload notices, a wire-onlydonerow, a trailing tool row, a trailing user row, a row with no id, and an empty prefix.donerow, which is the live window a finished turn leaves. It does not arm when the edited message is the first one.Other test changes:
test/fixtures/acp_frames/**/*.expected.jsonwere regenerated withscripts/update_acp_frame_snapshots.py; the only change is the addedmessage_idlines.test_post_compaction_continuation.pynow pins the notice flag on the forwarded chunk with a regex, so the extra keyword argument on thatyieldno longer breaks it.Verification
On this replacement (main
ac8a96a24+ cherry-pick). One conflict insrc/kiro_crew/acp/client.py: main addedCLAUDE_ACP_STEERING_MIN_VERSIONand its own_adapter_version_at_least/steering_advertised. Kept main's helper and addedCLAUDE_ACP_FORK_POINT_MIN_VERSIONbeside it; no behaviour change from the fork's head.test/test_rewind_native_fork.pyon base: ImportError (parse_message_id). With this PR: 27 passed.test_rewind_native_fork.py+test_post_compaction_continuation.py+test_acp_frame_replay.py: 125 passed.mypy src/kiro_crew/: clean.session/newfallback was run against a live adapter for this replacement. The fork point rides the vendor_meta.jetbrains.air.forkfield. The live runs below are the original author's, on fix(chat): fork the native claude conversation when a message is edited #18319's head.Original author's manual verification
End to end on this build. A dev gateway from this branch (
KIROCREW_PROFILE=standalone, an emptyKIROCREW_HOMEwith onlyagent.acp_backend: claude, claude-agent-acp 0.87.0), driven through the dashboard API. Edit + Send went throughPOST /api/chat/slots/{slot}/rewindwith{ts, content}, the same call the UI makes.secret.txt… reply with exactly one word: done". The file saysZEBRA-4417. The reply wasdone, and the row carriedmeta.native_message_id.noted.at_message_index: 4, because the live window held turn 1'sdonerow.a=ZEBRA-4417; b=UNKNOWN. The text replay could not have produced (a): turn 1's only assistant text is "done".sidfrom0515ca67…to4c930cb0…, kept0515ca67…asdiscarded_sid, and droppednative_fork.tool_resultand no MAGENTA. The original transcript still holds turn 2, unchanged.[SESSION RESUMED …]header (9,147 chars), with no[SESSION CONTEXTreplay block. So the fork is not followed by a second, text copy of the history.The adapter, directly over ACP, outside Kiro Crew. Each probe used the same S1: turn 1 read
secret.txtwith the Read tool (contentZEBRA-9182, reply only "done"), turn 2 said "my favorite color is MAGENTA". S1 was then forked at turn 1'smessageIdand both sessions were asked without tools.forka=ZEBRA-9182; b=MAGENTAa=ZEBRA-9182; b=UNKNOWNa=ZEBRA-9182; b=UNKNOWNOn every version S1 itself answered
a=ZEBRA-9182; b=MAGENTA, and its transcript was unchanged by the fork. An unknown fork point on 0.87.0 returned-32602 Invalid params: Fork point message ... was not found. Grepping the published npm tarballs agrees with the table:_meta.jetbrains.air.forkfirst appears in 0.71.0 (dist/fork-session.js); 0.70.0 and earlier have only a whole-session fork. That is whereCLAUDE_ACP_FORK_POINT_MIN_VERSIONcomes from.Related Issues
Fixes #18298
Replaces #18319
Related: #14512, #8067, #5395.
Pattern harvest
Not generalizable: the loss came from one endpoint using the only boundary kiro-cli offers on every backend, not from a code shape that recurs elsewhere.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)