fix(cli): respect existing TERMINAL_CWD from MESSAGING_CWD in load_cli_config#10226
Closed
LLQWQ wants to merge 4 commits into
Closed
fix(cli): respect existing TERMINAL_CWD from MESSAGING_CWD in load_cli_config#10226LLQWQ wants to merge 4 commits into
LLQWQ wants to merge 4 commits into
Conversation
…i_config When running in messaging gateway mode, gateway/run.py correctly sets TERMINAL_CWD from MESSAGING_CWD at startup. However, tools like execute_code and delegate_task lazily import cli.CLI_CONFIG, which triggers load_cli_config(). If config.yaml has terminal.cwd set to '.' or 'auto', load_cli_config() unconditionally resolved it to os.getcwd() and overwrote the already-correct TERMINAL_CWD env var. This fix checks whether TERMINAL_CWD is already set to a valid path before overwriting it, preserving the gateway's MESSAGING_CWD value. Also cleans up temporary debug prints in gateway/run.py and adds regression tests. Fixes #<issue-number-to-be-filled>
… cron & send_message - gateway/platforms/weixin.py: - Split aiohttp.ClientSession into _poll_session and _send_session - Add _LIVE_ADAPTERS registry so send_weixin_direct() reuses the connected gateway adapter instead of creating a competing session - Fixes silent message loss when gateway is running (iLink token contention) - cron/scheduler.py: - Support comma-separated deliver values (e.g. 'feishu,weixin') for multi-target delivery - Delay pconfig/enabled check until standalone fallback so live adapters work even when platform is not in gateway config - tools/send_message_tool.py: - Synthesize PlatformConfig from WEIXIN_* env vars when gateway config lacks a weixin entry - Fall back to WEIXIN_HOME_CHANNEL env var for home channel resolution - tests/gateway/test_weixin.py: - Update mocks to include _send_session
…pter for cron & send_message" This reverts commit 8072467.
…e pre-expanded TERMINAL_CWD - gateway/run.py: record config.yaml raw terminal.cwd value before env expansion, force MESSAGING_CWD fallback even if TERMINAL_CWD was pre-expanded by systemd. - tests/gateway/test_config_cwd_bridge.py: add regression test for pre-expanded service CWD scenario. - cli.py: minor consistency fix (defaults["terminal"]["cwd"] = existing_terminal_cwd).
1 task
This was referenced Apr 22, 2026
Contributor
|
Thanks for the careful diagnosis and the clean fix! The root cause you identified (lazy This is an automated hermes-sweeper review. Evidence the fix is already on
The one addendum in this PR not covered by that commit is the |
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 #10225
Fixes a bug where
load_cli_config()incli.pyoverwrites theTERMINAL_CWDenvironment variable that was correctly initialized bygateway/run.pyfromMESSAGING_CWD.Root Cause
When running in messaging gateway mode:
gateway/run.pysetsTERMINAL_CWD = os.getenv("MESSAGING_CWD")at startup.execute_codeanddelegate_tasklazily importcli.CLI_CONFIG.load_cli_config(), which seesterminal.cwd: "."and unconditionally setsTERMINAL_CWD = os.getcwd().Changes
cli.py: Before resolving./autotoos.getcwd(), check ifTERMINAL_CWDis already a valid path and reuse it.gateway/run.py: Removed temporary debugprintstatements.tools/environments/base.py: Ensure shell snapshot captures the correct starting directory (cd $cwdbefore export).tests/cli/test_cli_init.py: Added regression tests to verify existingTERMINAL_CWDis not overwritten.Testing
tests/cli/test_cli_init.py— 29 passed (including 3 new regression tests)tests/gateway/test_config_cwd_bridge.py— passedtests/tools/test_ssh_environment.py— passed