Skip to content

fix(terminal): honor configured cwd at session init#7802

Closed
luoxiao6645 wants to merge 1 commit into
NousResearch:mainfrom
luoxiao6645:fix/gateway-profile-cwd
Closed

fix(terminal): honor configured cwd at session init#7802
luoxiao6645 wants to merge 1 commit into
NousResearch:mainfrom
luoxiao6645:fix/gateway-profile-cwd

Conversation

@luoxiao6645

Copy link
Copy Markdown

Summary

Fixes a gateway / messaging working-directory bug where Telegram sessions ignored the configured profile cwd and kept starting in the gateway process launch directory
instead.

In affected setups, env/config values such as terminal.cwd, TERMINAL_CWD, and MESSAGING_CWD were present and correct, but commands like pwd still resolved to
~/.hermes/hermes-agent.

Fixes #7663

Root Cause

The config/env bridge in gateway/run.py was working correctly and did set TERMINAL_CWD.

The actual problem was lower in the terminal environment lifecycle:

  • BaseEnvironment.init_session() creates the shell snapshot used by later terminal commands
  • during that initialization, it captured the shell state and current directory
  • but it did not first cd into the configured working directory
  • so the snapshot locked in the gateway process startup directory instead of the configured terminal cwd

That made later commands inherit the wrong default directory even though the env vars were correct.

What Changed

  • update BaseEnvironment.init_session() to cd into the configured cwd before capturing the shell snapshot
  • reuse the same cwd quoting logic for both init-time and normal command execution
  • add a regression test to verify init-session bootstrap honors configured cwd

Behavior Before

Configured profile/gateway cwd could be visible in env vars, but new messaging terminal sessions still started in the gateway launch directory:

  • MESSAGING_CWD correct
  • TERMINAL_CWD correct
  • pwd wrong

Behavior After

When a terminal environment is initialized for messaging/gateway use, its initial shell snapshot now starts in the configured cwd, so subsequent commands like pwd reflect the
configured profile working directory.

Testing

Ran:

  • .\venv\Scripts\python -m pytest tests\tools\test_base_environment.py tests\gateway\test_config_cwd_bridge.py -q

zwcf5200 added a commit to zwcf5200/hermes-agent that referenced this pull request Apr 24, 2026
Apply upstream PR NousResearch#7802 behavior so BaseEnvironment captures its initial snapshot after cd'ing into the configured cwd. This preserves SSH terminal.cwd instead of letting the remote login shell home directory overwrite it.

Upstream-PR: NousResearch#7802

Upstream-Commit: 12e3ef9
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists tool/terminal Terminal execution and process management comp/gateway Gateway runner, session dispatch, delivery platform/telegram Telegram bot adapter labels Apr 29, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #14831 — same fix for init_session() not cd-ing into configured cwd before snapshot capture. Also references #7663.

@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the contribution @luoxiao6645! Closing — the init_session cwd fix landed in #17205 (commit ac855bb) via @Tranquil-Flow's #14796, which uses the same approach (inject cd $cwd into the bootstrap before pwd -P). Both reports also overlap with the v0.11.0 fix 4c13628 (Popen cwd= argument). Issue #14044 is now resolved.

@teknium1 teknium1 closed this Apr 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists platform/telegram Telegram bot adapter 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.

[Bug]: Telegram/gateway ignores profile working directory (pwd returns ~/.hermes/hermes-agent)

3 participants