Repository navigation
fix(workspace): back up before writing; make edit_file/write_file replay-safe - #665
Merged
Merged
Conversation
…lay-safe
WorkspaceCheckpoints.track() wrote the file first and recorded the backup
after, so a process killed in between lost the original: the re-run call on
resume backed up the agent's own content and rewind() put that back. The
backup is now stored before the write, a re-run keeps the turn's first
backup, and rewind treats a file still holding its backed-up content as
nothing to undo. track() also accepts a PreparedWorkspaceWrite ({ prepare,
write }), used by the built-in tools so a failed edit still records nothing.
edit_file re-run after its edit was applied (old_string gone, non-empty
new_string present) now succeeds as "already applied" without writing,
instead of telling the model an applied edit failed.
Docs: replay safety of the file tools, progress for resumed turns via
session.on()/onEvent, compaction for long coding turns, and approvals after a
restart resolve directly (no resume() first).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
LinuxDevil
force-pushed
the
fix/checkpoint-crash-replay
branch
from
October 16, 2026 20:55
221d491 to
b6b5876
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
WorkspaceCheckpoints.track()wrote the file first and recorded the backup after. A process killed between the two lost the backup; on resume the interruptedwrite_filere-ran and backed up the agent's own content as "before", sorewind()reportedrestored: [file]but put back the agent's version. Foredit_filethe re-run failed, so nothing was recorded and rewind silently did nothing.edit_filethen threwold_string was not foundbecause its edit was already in the file, so the model was told an applied edit failed and looped.sessions.mdsaid to callresume()/send()before resolving an approval after a restart, butagent.approvals.resolve()/streamResolve()already find the session from the pause record (covered by an existing test).Fix
track()stores the backup before the write. A path's first write in a turn records the backup; any later record in that turn, including a re-run of the interrupted call, keeps that first backup. Rewind treats a file that still holds its backed-up content as nothing to undo.track()also accepts aPreparedWorkspaceWrite({ prepare, write }). The built-in tools use it, so the backup'safterHashis known before the write, a failed edit still records nothing, and a change that leaves the file as it is records and writes nothing. The plain-function form still works: it stores the backup first, then adds a second record carrying the written content's hash.edit_file: whenold_stringis absent and a non-emptynew_stringis present (with or withoutreplace_all), it returns "the edit was already applied" and writes nothing.write_filewas already idempotent.session.on()/onEventfor progress during resume, approvals after a restart), durable-execution, workspace-tools, sessions (corrected the approval-after-restart text, documented thatresume()doesn't stream). CHANGELOG, API reports and llms-full.txt regenerated.Verification
appendthrows); a crash after the write forwrite_fileandedit_filefollowed by a re-run, after which rewind restores the original; the plain-functiontrack()crash path; already-appliededit_filewith and withoutreplace_all, plus the cases that must still fail;session.on()andonEventseeing a resumed turn's events.npx tsc --noEmit,npm run lint,npm run buildclean.vitest run src/tools src/session src/execution scripts src/createAgentApprovals.test.ts: all pass (2011 + 102 tests).🤖 Generated with Claude Code