fix(checkpoints): snapshot the task/session cwd before destructive terminal commands - #70230
Open
KikeTorillo wants to merge 1 commit into
Open
fix(checkpoints): snapshot the task/session cwd before destructive terminal commands#70230KikeTorillo wants to merge 1 commit into
KikeTorillo wants to merge 1 commit into
Conversation
…rminal commands The pre-destructive-command checkpoint resolved TERMINAL_CWD/os.getcwd() directly, while the terminal tool itself executes in the task/session cwd (explicit workdir -> per-task override -> live session cwd -> TERMINAL_CWD). For sessions created with an explicit cwd (session.create(cwd=...)) or re-anchored via session.cwd.set, the checkpoint snapshotted the WRONG tree and the later rollback silently restored nothing. _ensure_file_checkpoint was already fixed to honor the task cwd (NousResearch#68195); this routes the terminal twin through the same file-tools path pipeline (_resolve_path_for_task) via a shared helper, covering both the batch and sequential call-sites. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017PkWV7rR2oeg8BBttcNoyE
Contributor
|
Thanks for identifying the terminal/file checkpoint divergence. The underlying issue is still present on current main: Problems
Suggested changes
Automated hermes-sweeper review. |
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
The checkpoint taken before a destructive terminal command resolves its directory as:
But the terminal tool itself executes the command in the task/session cwd (explicit
workdir→ per-task override → live session cwd →TERMINAL_CWD/process cwd — seeterminal_tool's resolution). Any session created with an explicit cwd (session.create(cwd=...)) or re-anchored viasession.cwd.setruns its commands in a directory that can differ from the Hermes process cwd.Consequence: for those sessions, the pre-destructive-command checkpoint snapshots the wrong tree (the process cwd), and a later rollback silently restores nothing of what the
rm/git reset/etc. actually touched._ensure_file_checkpointwas already fixed to honor the task cwd in #68195 — this is the terminal twin of that fix.Fix
New
_terminal_checkpoint_cwd(function_args, effective_task_id)helper that mirrors the file-tools resolution (_resolve_path_for_task(".", task_id)— same base-dir pipeline), used by both the batch and sequential call-sites. Explicitworkdirstill wins; without a session override, behavior is unchanged (TERMINAL_CWD→ process cwd).Tests
tests/agent/test_terminal_checkpoint_cwd.py:workdirwins,TERMINAL_CWD(the regression),TERMINAL_CWDfallback is preserved.Found while integrating a downstream client that re-anchors sessions per workspace via
session.cwd.set— file-tool checkpoints landed in the right tree, terminal ones didn't.🤖 Generated with Claude Code
https://claude.ai/code/session_017PkWV7rR2oeg8BBttcNoyE