Skip to content

fix(agent): let a read-only cd sit anywhere in a read-only chain - #1327

Merged
huichen merged 1 commit into
mainfrom
pr/huichen
Oct 23, 2026
Merged

huichen merged 1 commit into
mainfrom
pr/huichen

Conversation

@huichen

@huichen huichen commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator

recovery_safety only exempted a cd from fencing when it was the last segment
of a chain (#1326), so the common cd <dir>; git status still fenced the whole
session after Stop. cd only moves the process: nothing observable can be
waiting on it and repeating it cannot apply anything twice, so it is harmless in
any position - as long as its arguments are literal paths. A $-expansion, a
substitution, or a script block can name another command, so cd $DIR, cd $(...) and anything with (, ), {, } or a backtick stay fenced, and the
argument list must not start with -.

Commits

  • fix(agent): let a read-only cd sit anywhere in a read-only chain

Verification

  • cargo fmt --all -- --check: clean
  • cargo clippy -p future-agent --all-targets -- -D warnings: clean
  • cargo test -p future-agent --lib recovery_safety: 12 passed; the read-only
    table now covers cd before, between and after other read-only segments, and
    the expansion cases above still fence.

Notes

The effective diff against main is agent/src/rpc/recovery_safety.rs only:
39 insertions, 9 deletions. This is the follow-up to #1326 and it reached
dev-huichen after that PR had been frozen, so it travels in its own PR.

The read-only classification required `cd` to be the last segment, so the
command that triggered tonight's third incident — `cd …; git worktree
list; git status --short` — still fenced the whole session even after
interrupted read-only shells stopped counting as unknown effects.

`cd` only moves the current process: nothing observable can be waiting on
it and repeating it cannot apply anything twice, so its position in the
chain no longer matters. Its arguments must still be literal paths: a
variable reference, a substitution, a script block or an option flag stays
fenced, because such a form can name whatever a hidden command produced.

The other segments of a chain are still judged one by one, and redirection,
writing pipes, interpreters, `rm`, `git commit` and `cargo` stay fenced.
@huichen
huichen enabled auto-merge (squash) October 23, 2026 15:33
@huichen
huichen merged commit 301d47f into main Oct 23, 2026
25 checks passed
@huichen
huichen deleted the pr/huichen branch October 23, 2026 15:50
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.

1 participant