Skip to content

fix(tools): preserve live session cwd in terminal_tool, keep ACP update_cwd authoritative - #36010

Merged
kshitijk4poor merged 1 commit into
NousResearch:mainfrom
kshitijk4poor:fix/terminal-cwd-acp-aware
May 31, 2026
Merged

fix(tools): preserve live session cwd in terminal_tool, keep ACP update_cwd authoritative#36010
kshitijk4poor merged 1 commit into
NousResearch:mainfrom
kshitijk4poor:fix/terminal-cwd-acp-aware

Conversation

@kshitijk4poor

Copy link
Copy Markdown
Collaborator

Summary

Salvage of #35510 by @Dusk1e — fixes a terminal_tool cwd regression for existing sessions, with one additional fix so the ACP update_cwd path 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

  • Added a small cwd resolver in tools/terminal_tool.py with this precedence:
    1. explicit workdir
    2. live session env.cwd
    3. fallback config/init cwd
  • Applied that resolver to:
    • foreground env.execute(...)
    • background process_registry.spawn_local(...)
    • background process_registry.spawn_via_env(...)
  • Preserved existing explicit workdir behavior.

Additional fix vs #35510

Preferring live env.cwd (so a session-local cd survives) means a freshly registered cwd override would otherwise sit below the already-set env.cwd. The ACP adapter sets the editor's working directory exclusively through that override — acp_adapter/session.py::_register_task_cwdregister_task_env_overrides(task_id, {"cwd": ...}), called on session/load and session/resume (acp_adapter/server.py). With the override demoted below env.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_overrides now syncs a newly registered cwd onto the live cached env, so:

  • an explicit ACP update_cwd wins (the editor's project root takes effect), and
  • ordinary in-session cd tracking is still preserved (no override re-registration → env.cwd is left to the cd machinery).

Testing

tests/tools/test_terminal_task_cwd.py
7 passed

Regression coverage:

  • existing task cwd override behavior
  • explicit workdir override behavior
  • foreground commands following live env.cwd
  • background commands following live env.cwd
  • registering a cwd override updates the live env cwd (ACP authority)
  • no-op when no live env exists yet
  • non-cwd overrides (e.g. per-task Modal image) leave env.cwd untouched

ruff check clean; no new ty diagnostics in the changed region.

Based on #35510 by @Dusk1e.

…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>
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/tools Tool registry, model_tools, toolsets tool/terminal Terminal execution and process management comp/acp Agent Communication Protocol adapter labels May 31, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Salvage of #35510 by @Dusk1e. Adds ACP update_cwd authoritativeness fix on top of the original CWD precedence fix.

@kshitijk4poor
kshitijk4poor merged commit 01dda3f into NousResearch:main May 31, 2026
23 checks passed
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
@kshitijk4poor
kshitijk4poor deleted the fix/terminal-cwd-acp-aware branch August 5, 2026 07:08
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/acp Agent Communication Protocol adapter comp/tools Tool registry, model_tools, toolsets P2 Medium — degraded but workaround exists tool/terminal Terminal execution and process management type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants