fix(terminal): honor configured cwd at session init#7802
Closed
luoxiao6645 wants to merge 1 commit into
Closed
Conversation
This was referenced Apr 22, 2026
This was referenced Apr 24, 2026
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
2 tasks
Collaborator
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 |
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
Fixes a gateway / messaging working-directory bug where Telegram sessions ignored the configured profile
cwdand kept starting in the gateway process launch directoryinstead.
In affected setups, env/config values such as
terminal.cwd,TERMINAL_CWD, andMESSAGING_CWDwere present and correct, but commands likepwdstill resolved to~/.hermes/hermes-agent.Fixes #7663
Root Cause
The config/env bridge in
gateway/run.pywas working correctly and did setTERMINAL_CWD.The actual problem was lower in the terminal environment lifecycle:
BaseEnvironment.init_session()creates the shell snapshot used by later terminal commandscdinto the configured working directoryThat made later commands inherit the wrong default directory even though the env vars were correct.
What Changed
BaseEnvironment.init_session()tocdinto the configured cwd before capturing the shell snapshotBehavior Before
Configured profile/gateway cwd could be visible in env vars, but new messaging terminal sessions still started in the gateway launch directory:
MESSAGING_CWDcorrectTERMINAL_CWDcorrectpwdwrongBehavior 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
pwdreflect theconfigured profile working directory.
Testing
Ran:
.\venv\Scripts\python -m pytest tests\tools\test_base_environment.py tests\gateway\test_config_cwd_bridge.py -q