Skip to content

fix(gateway): honor configured cwd in gateway sessions#29365

Open
qdaszx wants to merge 1 commit into
NousResearch:mainfrom
qdaszx:fix/29265-gateway-cwd-contract
Open

fix(gateway): honor configured cwd in gateway sessions#29365
qdaszx wants to merge 1 commit into
NousResearch:mainfrom
qdaszx:fix/29265-gateway-cwd-contract

Conversation

@qdaszx

@qdaszx qdaszx commented May 20, 2026

Copy link
Copy Markdown

What does this PR do?

Fixes gateway workspace drift for configured terminal.cwd: gateway sessions should show and use the user's configured workspace, not the long-lived Hermes daemon/source checkout.

This is based on the same root cause identified in #27488, but expands the regression coverage around the shared gateway/tool cwd contract instead of only testing the prompt-builder surface.

Related Issue

Fixes #29265

Related PRs / context:

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

  • agent/prompt_builder.py
    • Prefer TERMINAL_CWD when rendering the system prompt's Current working directory hint.
    • Preserve the previous os.getcwd() fallback when TERMINAL_CWD is unset.
  • gateway/run.py
    • Re-bridge explicit terminal.cwd values from config.yaml into TERMINAL_CWD during runtime env reloads, so long-lived gateway sessions can pick up cwd config changes without restart.
    • Avoid clobbering an already-resolved cwd with placeholders such as ., auto, or cwd.
  • tests/gateway/test_gateway_cwd_contract.py
    • Adds platform-neutral gateway cwd contract coverage for prompt hints and reload behavior.
  • tests/tools/test_gateway_cwd_contract.py
    • Adds tool-surface contract coverage for terminal, file/search/patch path resolution, and execute_code project mode.
  • tests/gateway/test_issue_29265_qqbot_weixin_cwd.py

How to Test

  1. Configure a messaging gateway with an explicit workspace, for example:
    terminal:
      cwd: /path/to/workspace
  2. Start or keep a gateway running, then use /new or /reset after changing terminal.cwd.
  3. Ask the gateway for its working directory or use relative file/tool operations.
  4. Confirm the prompt/tool surfaces are anchored to the configured workspace instead of the Hermes source checkout.

Automated validation run locally:

scripts/run_tests.sh \
  tests/gateway/test_gateway_cwd_contract.py \
  tests/tools/test_gateway_cwd_contract.py \
  tests/gateway/test_issue_29265_qqbot_weixin_cwd.py \
  tests/agent/test_prompt_builder.py \
  tests/gateway/test_config_cwd_bridge.py \
  tests/tools/test_resolve_path.py \
  tests/tools/test_parse_env_var.py \
  -q

Result:

176 passed in 8.08s

Additional checks:

git diff --cached --check: passed
scripts/check-windows-footguns.py: passed, 5 files scanned
static secret / shell-injection / eval / pickle / SQL-pattern scan: no findings
independent review agent: passed; no blocking security concerns or logic errors

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: Ubuntu/Linux

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

Screenshots / Logs

Not applicable; this is a gateway runtime/env contract fix with automated regression coverage.

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery comp/agent Core agent loop, run_agent.py, prompt builder labels May 20, 2026
@qdaszx qdaszx force-pushed the fix/29265-gateway-cwd-contract branch from d2a33b6 to 4a99677 Compare May 20, 2026 15:43
@pinguarmy

Copy link
Copy Markdown

Thanks for building this out — this looks like a more complete/generalized version of the root cause I was seeing in #27488.

I especially like the gateway/tool cwd contract coverage and regression tests.

My PR (#27488) was focused on the immediate production fix direction, but this seems like the broader/systemic approach. Happy to close or mark #27488 as superseded if maintainers prefer consolidating on this direction.

If useful, I'm also happy to help test edge cases from the original repro.

@qdaszx

qdaszx commented May 20, 2026

Copy link
Copy Markdown
Author

@pinguarmy Thanks — really appreciate the context, and especially the original production-fix direction in #27488.

I tried to preserve that root-cause fix while adding a bit more contract coverage around the shared gateway/tool cwd behavior, so the #29265 QQBot/Weixin report does not end up as a platform-only regression test.

I’ll defer to you and the maintainers on whether #27488 should stay open or be marked superseded. If you still have edge cases from the original repro, I’d be happy to check whether they’re covered here and add coverage if there’s a gap.

banditburai added a commit to banditburai/hermes-agent that referenced this pull request May 30, 2026
…earch#29265)

Port PR NousResearch#29365's tool-surface contract test: terminal/file/execute_code
already honor TERMINAL_CWD (out of scope for the resolver cluster). Pinning
the behavior makes the supersession of NousResearch#29365 airtight and guards against a
future refactor silently regressing the workspace contract.
teknium1 pushed a commit that referenced this pull request Jun 1, 2026
Port PR #29365's tool-surface contract test: terminal/file/execute_code
already honor TERMINAL_CWD (out of scope for the resolver cluster). Pinning
the behavior makes the supersession of #29365 airtight and guards against a
future refactor silently regressing the workspace contract.
changman pushed a commit to changman/hermes-agent that referenced this pull request Jun 10, 2026
…earch#29265)

Port PR NousResearch#29365's tool-surface contract test: terminal/file/execute_code
already honor TERMINAL_CWD (out of scope for the resolver cluster). Pinning
the behavior makes the supersession of NousResearch#29365 airtight and guards against a
future refactor silently regressing the workspace contract.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder 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.

[Feature]: Configurable default working directory for QQBot and Weixin gateway sessions

3 participants