fix(tools): preserve live session cwd in terminal_tool, keep ACP update_cwd authoritative - #36010
Merged
kshitijk4poor merged 1 commit intoMay 31, 2026
Conversation
…update_cwd authoritative terminal_tool re-sent the init-time/config cwd on every command, clobbering session-local `cd` state: the environment tracked the new directory in `env.cwd`, but foreground/background calls forced the old cwd back. A small `_resolve_command_cwd` resolver now applies the precedence `workdir > live env.cwd > config/override cwd` to: - foreground `env.execute(...)` - background `process_registry.spawn_local(...)` - background `process_registry.spawn_via_env(...)` Additionally, syncing the cwd onto the live cached env when a `cwd` override is (re-)registered. Preferring live `env.cwd` would otherwise demote the ACP `update_cwd` override (registered via `register_task_env_overrides` on `session/load` / `session/resume`) below an already-set `env.cwd`, silently ignoring an editor's mid-session project-root change once any command had run. `register_task_env_overrides` now pushes a new cwd onto the cached env so an explicit ACP cwd change wins, while ordinary in-session `cd` tracking is preserved. Regression coverage: - foreground/background commands follow live `env.cwd` - explicit `workdir` still overrides everything - registering a cwd override updates the live env cwd (ACP authority) - no-op when no live env exists; non-cwd overrides leave env.cwd untouched Based on NousResearch#35510 by @Dusk1e. Co-authored-by: Dusk1e <yusufalweshdemir@gmail.com>
Collaborator
alt-glitch
pushed a commit
that referenced
this pull request
Jun 14, 2026
fix(tools): preserve live session cwd in terminal_tool, keep ACP update_cwd authoritative
T02200059
pushed a commit
to T02200059/hermes-agent
that referenced
this pull request
Jun 18, 2026
…-cwd-acp-aware fix(tools): preserve live session cwd in terminal_tool, keep ACP update_cwd authoritative
waefrebeorn
pushed a commit
to waefrebeorn/slermes
that referenced
this pull request
Jul 2, 2026
…-cwd-acp-aware fix(tools): preserve live session cwd in terminal_tool, keep ACP update_cwd authoritative
santhreal
pushed a commit
to santhreal/hermes-agent
that referenced
this pull request
Jul 13, 2026
…-cwd-acp-aware fix(tools): preserve live session cwd in terminal_tool, keep ACP update_cwd authoritative
Gravezzz
pushed a commit
to Gravezzz/hermes-agent
that referenced
this pull request
Jul 21, 2026
…-cwd-acp-aware fix(tools): preserve live session cwd in terminal_tool, keep ACP update_cwd authoritative
leewenjie
pushed a commit
to leewenjie/hermes-agent
that referenced
this pull request
Aug 7, 2026
…-cwd-acp-aware fix(tools): preserve live session cwd in terminal_tool, keep ACP update_cwd authoritative
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.
Summary
Salvage of #35510 by @Dusk1e — fixes a
terminal_toolcwd regression for existing sessions, with one additional fix so the ACPupdate_cwdpath stays authoritative.When a session had already changed directories,
terminal_tool()could still force later commands to run in the init-time/config cwd instead of the live session cwd. That caused both foreground commands and background launches to run in the wrong directory.Fix
tools/terminal_tool.pywith this precedence:workdirenv.cwdenv.execute(...)process_registry.spawn_local(...)process_registry.spawn_via_env(...)workdirbehavior.Additional fix vs #35510
Preferring live
env.cwd(so a session-localcdsurvives) means a freshly registeredcwdoverride would otherwise sit below the already-setenv.cwd. The ACP adapter sets the editor's working directory exclusively through that override —acp_adapter/session.py::_register_task_cwd→register_task_env_overrides(task_id, {"cwd": ...}), called onsession/loadandsession/resume(acp_adapter/server.py). With the override demoted belowenv.cwd, an editor's mid-session project-root change would be silently ignored once any command had run in a long-lived ACP server process.register_task_env_overridesnow syncs a newly registeredcwdonto the live cached env, so:update_cwdwins (the editor's project root takes effect), andcdtracking is still preserved (no override re-registration →env.cwdis left to thecdmachinery).Testing
Regression coverage:
workdiroverride behaviorenv.cwdenv.cwdenv.cwduntouchedruff checkclean; no newtydiagnostics in the changed region.Based on #35510 by @Dusk1e.