Skip to content

fix(cli): respect existing TERMINAL_CWD from MESSAGING_CWD in load_cli_config#10226

Closed
LLQWQ wants to merge 4 commits into
NousResearch:mainfrom
LLQWQ:fix/messaging-cwd-respect-existing-terminal-cwd
Closed

fix(cli): respect existing TERMINAL_CWD from MESSAGING_CWD in load_cli_config#10226
LLQWQ wants to merge 4 commits into
NousResearch:mainfrom
LLQWQ:fix/messaging-cwd-respect-existing-terminal-cwd

Conversation

@LLQWQ

@LLQWQ LLQWQ commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #10225

Fixes a bug where load_cli_config() in cli.py overwrites the TERMINAL_CWD environment variable that was correctly initialized by gateway/run.py from MESSAGING_CWD.

Root Cause

When running in messaging gateway mode:

  1. gateway/run.py sets TERMINAL_CWD = os.getenv("MESSAGING_CWD") at startup.
  2. Later, tools like execute_code and delegate_task lazily import cli.CLI_CONFIG.
  3. This triggers load_cli_config(), which sees terminal.cwd: "." and unconditionally sets TERMINAL_CWD = os.getcwd().
  4. All subsequent terminal commands now run in the wrong directory.

Changes

  • cli.py: Before resolving . / auto to os.getcwd(), check if TERMINAL_CWD is already a valid path and reuse it.
  • gateway/run.py: Removed temporary debug print statements.
  • tools/environments/base.py: Ensure shell snapshot captures the correct starting directory (cd $cwd before export).
  • tests/cli/test_cli_init.py: Added regression tests to verify existing TERMINAL_CWD is not overwritten.

Testing

  • tests/cli/test_cli_init.py — 29 passed (including 3 new regression tests)
  • tests/gateway/test_config_cwd_bridge.py — passed
  • tests/tools/test_ssh_environment.py — passed

Ubuntu and others added 4 commits April 15, 2026 18:04
…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).
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/cli CLI entry point, hermes_cli/, setup wizard comp/gateway Gateway runner, session dispatch, delivery area/config Config system, migrations, profiles labels Apr 26, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the careful diagnosis and the clean fix! The root cause you identified (lazy load_cli_config() import clobbering a gateway-resolved TERMINAL_CWD) was independently reproduced and fixed in PR #11029, which merged on 2026-04-16 as part of a broader CWD-source consolidation.

This is an automated hermes-sweeper review.

Evidence the fix is already on main:

The one addendum in this PR not covered by that commit is the cd $cwd shell-snapshot change in tools/environments/base.py — if that still applies, feel free to open a focused follow-up PR for just that piece.

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

Labels

area/config Config system, migrations, profiles comp/cli CLI entry point, hermes_cli/, setup wizard comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(cli): load_cli_config() overwrites gateway's TERMINAL_CWD from MESSAGING_CWD

3 participants