Skip to content

fix(local): respect configured cwd in init_session()#12983

Closed
WuTianyi123 wants to merge 1 commit into
NousResearch:mainfrom
WuTianyi123:fix/local-env-init-session-cwd
Closed

fix(local): respect configured cwd in init_session()#12983
WuTianyi123 wants to merge 1 commit into
NousResearch:mainfrom
WuTianyi123:fix/local-env-init-session-cwd

Conversation

@WuTianyi123

Copy link
Copy Markdown
Contributor

What does this PR do?

LocalEnvironment._run_bash() spawns subprocess.Popen() without a cwd argument. This causes init_session() — which runs pwd -P to capture the initial working directory — to execute in the gateway process's startup directory instead of the user-configured terminal.cwd. The result is then written back to self.cwd, silently overwriting the correct path.

This PR adds cwd=self.cwd to the subprocess.Popen() call so the initial session snapshot correctly captures the working directory from config.yaml's terminal.cwd setting.

Related Issue

No existing issue filed, but this bug is reproducible by:

  1. Setting terminal.cwd: /some/absolute/path in config.yaml
  2. Starting Hermes (gateway starts from a different directory, e.g. ~/.hermes/hermes-agent)
  3. Running pwd via the terminal tool — it returns the gateway directory, not the configured one

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)

Changes Made

  • tools/environments/local.py: Add cwd=self.cwd to subprocess.Popen() in _run_bash() (line 268)

How to Test

Reproduce the bug (before this fix):

  1. In config.yaml, set:
    terminal:
      cwd: /tmp/test-workspace
  2. Start Hermes from a different directory (e.g. ~/.hermes/hermes-agent)
  3. Run pwd — observe it returns ~/.hermes/hermes-agent instead of /tmp/test-workspace

Verify the fix (after this PR):

  1. Apply the change
  2. Start Hermes from any directory
  3. Run pwd — it now correctly returns /tmp/test-workspace

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(local): ...)
  • I searched existing PRs — no duplicate found
  • My PR contains only changes related to this fix
  • I've run pytest tests/ -q and all tests pass (13,537 passed; 70 pre-existing failures unrelated to local env)
  • I've added tests for my changes (existing env test suite covers this; no new tests needed for a one-line cwd fix)
  • I've tested on my platform: Ubuntu 22.04

Documentation & Housekeeping

  • I've updated relevant documentation — or N/A (behavioral fix, no API change)
  • I've updated cli-config.yaml.example — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md — or N/A
  • I've considered cross-platform impact — Verified: cwd parameter is standard subprocess.Popen behavior, works on Windows/macOS/Linux
  • I've updated tool descriptions/schemas — or N/A

LocalEnvironment._run_bash() spawned subprocess.Popen without a cwd
argument, so init_session()'s pwd -P ran in the gateway process's
startup directory and overwrote self.cwd. Pass cwd=self.cwd so the
initial snapshot captures the user-configured working directory.

Tested:
- pytest tests/ -q (255 env-related tests passed)
- Full suite: 13,537 passed; 70 pre-existing failures unrelated to local env
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists backend/local Local shell execution tool/terminal Terminal execution and process management labels Apr 22, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #9798 — same root cause: local terminal init_session() ignores configured cwd.

1 similar comment
@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #9798 — same root cause: local terminal init_session() ignores configured cwd.

@teknium1

Copy link
Copy Markdown
Contributor

Thanks @WuTianyi123! Your fix was cherry-picked and merged via #14242. Your original commit email was an unlinked gmail, so we re-authored to your GitHub noreply email so the contribution attributes to your profile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend/local Local shell execution 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.

3 participants