Skip to content

Edit and resubmit any past user message (#254) - #387

Merged
currentbits merged 12 commits into
mainfrom
coder/edit-and-resubmit-any-past-message-00986e
Aug 17, 2026
Merged

currentbits merged 12 commits into
mainfrom
coder/edit-and-resubmit-any-past-message-00986e

Conversation

@currentbits

Copy link
Copy Markdown
Owner

Closes #254. Inspired by Zed's editable message history: edit any past user message and re-run from that point, instead of doing checkpoint archaeology to undo a wrong turn.

What changed

threads.rewind (new IPC). Truncates the transcript at a chosen past user message — that message and everything after it — plus the work-log items belonging to the dropped runs. It clears sessionId and sets a one-shot replayContext: a provider CLI session cannot be rewound, so the next turn starts a fresh session and the runner seeds its prompt with a digest of the retained tail. That reuses the existing hand-off prefix builder with the thread itself as source; it deliberately does not set handoffFrom to the thread's own id, because that field drives orchestrator crew sweeps and the OTel ancestor walk, where a self-reference risks a cycle.

Rewind starts no run. The renderer follows with the ordinary runs.start, which appends the edited text as a new user message — so there is one run-start path, not two. Usage and spend history are never rewritten: that money was really spent.

Optional file rewind. With restoreFiles, the worktree is hard-reset to the newest checkpoint at or before the edited message, through the existing guarded restoreCheckpoint path. No worktree or no matching checkpoint is not an error — the transcript still rewinds and restoredSha comes back null.

UI. User bubbles gain an Edit affordance that opens an inline editor prefilled with the original text (focus on open, Escape cancels, Cmd/Ctrl+Enter submits). Because resubmitting destroys later transcript, a confirm dialog names how many messages will be dropped; it reuses the existing confirm overlay and useEscapeClose rather than introducing a modal system. The "also restore files" option appears only when the thread has a worktree and is off by default, keeping transcript-only rewind the one-click path. Attachments on the edited message are carried through, as Retry turn already does.

Checkpoint hazards found and fixed

A read-only scan of the live store surfaced two problems the test suite could not have shown, both of which made the automatic file reset land on the wrong tree:

  • Turn numbers are not turns. maybeCreateCheckpoint numbers a checkpoint by counting existing checkpoint commits, and returns early when the worktree is clean — so a turn that changes nothing skips a number. Mapping retained user messages onto turn N therefore restored the wrong state; 2 of 6 sampled live threads had the mismatch. Selection is now by commit time.
  • Merged branches inject foreign checkpoints. listCheckpoints walked all reachable history, so a thread that merged a worker branch saw that worker's checkpoints, with repeating turn numbers — one live thread has 8 checkpoint commits against a max turn of 3. Restoring one would hard-reset onto the fork's tree and discard the merge. Fixed with --first-parent at the shared function, so the pre-existing checkpoint-restore UI is covered too; that is what the restoreCheckpoint guard already claimed to do.

Two smaller correctness fixes: rewind persists with saveNow() (the debounced save() left a window where a crash would resurrect the dropped transcript against already-reset files), and the renderer refetches the detail right after a rewind (otherwise a follow-up run that fails to start leaves the dropped messages on screen, looking as though nothing happened).

Tests

electron/test/rewind.test.js drives real git repos, including a turn that leaves the worktree clean and a foreign checkpoint merged in with a commit time that would fool a naive newest-at-or-before pick. test/editResubmit.test.ts covers the pure decisions; test/editResubmitWiring.test.tsx asserts the call order and arguments (rewind before start, neither on cancel, attachments preserved). Both regression tests were confirmed to fail without their fixes.

Core 38/38, renderer 865/865, electron 1046/1047 — the single failure is the wireClient × webBridge reconnect suite, which fails identically on main. An occasional memory-server trust-ranking failure is a pre-existing flake, reproduced on an untouched main checkout; this branch does not touch memory-server.

🤖 Generated with Claude Code

  • PR created by the Claude Code agent

Willem and others added 12 commits August 17, 2026 20:53
Shared IPC contract only: RewindResult, ThreadInfo.replayContext,
threads.rewind doc, wireClient proxy, devCoder fixture twin.

Co-Authored-By: Claude Opus 5 <[email protected]>
…oder/fork-edit-and-resubmit-any-past-message-e4dd81
…oder/fork-edit-and-resubmit-any-past-message-310cdb
Truncate the transcript and work-log at a user message, clear the CLI
session, and arm a one-shot replay of the retained tail. Optional
restoreFiles hard-resets the worktree via the existing checkpoint path.
Inline editor on user bubbles, confirm, then threads.rewind followed by
the existing startRun path. Transcript-only rewind is the default;
restoreFiles is an opt-in when the thread has a worktree.
Clean turns skip a checkpoint number, so mapping retained user
messages onto coder-checkpoint turn N restored the wrong tree.
Select the newest checkpoint whose commit time is at or before
the edited message. Persist with saveNow so a crash cannot
resurrect the dropped transcript against already-reset files.
…nto coder/edit-and-resubmit-any-past-message-00986e
Editing the words of a message must not silently drop the images it
came with; Retry turn already re-sends them.

Co-Authored-By: Claude Opus 5 <[email protected]>
Merged worker branches make their coder-checkpoint commits reachable.
Walking them lets rewind (and the restore UI) hard-reset onto the
fork's tree. --first-parent keeps the shared list on this thread's
own line, which is what restoreCheckpoint already claimed to do.
…nto coder/edit-and-resubmit-any-past-message-00986e
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@currentbits
currentbits merged commit 94b1ad4 into main Aug 17, 2026
1 check failed
@currentbits
currentbits deleted the coder/edit-and-resubmit-any-past-message-00986e branch October 3, 2026 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Edit and resubmit any past message

1 participant