hermes - ✅(Solved) Fix [Bug]: ACP session cwd is used for tool execution but not for project context file discovery [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
NousResearch/hermes-agent#11515Fetched 2026-04-18 06:00:36
View on GitHub
Comments
0
Participants
1
Timeline
1
Reactions
0
Author
Participants
Timeline (top)
cross-referenced ×1

Error Message

Additional Logs / Traceback (optional)

Root Cause

Root Cause Analysis (optional)

Fix Action

Fixed

PR fix notes

PR #11570: fix(acp): use session cwd for project context discovery

Description (problem / solution / changelog)

Summary

  • pass the ACP session cwd into AIAgent so project context discovery uses the same workspace as ACP tool execution
  • invalidate the cached system prompt when an ACP session changes cwd so context files are rebuilt from the new workspace
  • initialize ACP subdirectory hint tracking from the explicit session cwd and add regression coverage for both the agent and session manager paths

Closes #11515

Testing

  • source venv/bin/activate && python -m pytest tests/run_agent/test_run_agent.py -q -k 'TestBuildSystemPrompt'
  • source venv/bin/activate && python -m pytest tests/acp/test_session.py -q
  • source venv/bin/activate && python -m pytest tests/ -q

Full suite note

The full suite still fails in this environment on existing unrelated tests and missing optional deps (acp, fastapi), plus current gateway/Discord/transcription failures. The ACP and run_agent coverage for this change passed locally.

Changed files

  • acp_adapter/session.py (modified, +5/-0)
  • run_agent.py (modified, +9/-6)
  • scripts/release.py (modified, +1/-0)
  • tests/acp/test_session.py (modified, +11/-0)
  • tests/run_agent/test_run_agent.py (modified, +36/-0)
RAW_BUFFERClick to expand / collapse

Bug Description

In ACP mode, the session/workspace cwd appears to be used for tool execution, but not for system-prompt project context discovery.

This creates an inconsistency:

  • ACP tools run against the editor session's workspace cwd
  • but auto-loaded project context files such as .hermes.md, AGENTS.md, CLAUDE.md, and .cursorrules do not appear to be resolved from that same ACP session cwd

As a result, Hermes in ACP mode may execute tools in the correct editor workspace while following project instructions loaded from a different directory, or from the process cwd / global TERMINAL_CWD.

Steps to Reproduce

  1. Start Hermes in ACP mode from a directory that is different from the editor workspace.
  2. Open a project in Zed / VS Code / JetBrains with a workspace-local AGENTS.md or .hermes.md.
  3. Start a new ACP session for that workspace.
  4. Ask Hermes to inspect files or run tools in the workspace.
  5. Observe that tool behavior follows the ACP session cwd, but project-context auto-loading does not appear to be explicitly tied to the ACP session cwd.

Expected Behavior

ACP sessions should use the same workspace cwd for both:

  • tool execution
  • project context file discovery during system prompt construction

If the ACP session cwd is the editor workspace, Hermes should auto-discover project context files from that same directory tree.

Actual Behavior

ACP session cwd is registered as a task-level tool override, so tools are session-aware.

However, system prompt construction in run_agent.py uses:

  • os.getenv("TERMINAL_CWD"), or
  • falls back to os.getcwd()

I could not find ACP code that explicitly passes the session cwd into build_context_files_prompt(...) or synchronizes ACP session cwd into TERMINAL_CWD before system prompt construction.

This suggests ACP can run tools in one workspace while loading project context from another directory.

Affected Component

  • Agent Core (conversation loop, context compression, memory)
  • Tools (terminal, file ops, web, code execution, etc.)
  • Other

Messaging Platform (if gateway-related)

  • N/A (CLI only)

Debug Report

Not attached. This report is based on source analysis rather than a runtime crash.

Operating System

Windows 11

Python Version

Unknown

Hermes Version

Local repo checkout on main, currently behind origin/main by 7 commits at time of inspection.

Additional Logs / Traceback (optional)

None.

Root Cause Analysis (optional)

Relevant code paths:

  1. ACP session cwd is registered for tools:
  • acp_adapter/session.py
    • _register_task_cwd(task_id, cwd) calls tools.terminal_tool.register_task_env_overrides(task_id, {"cwd": cwd})
  • tools/terminal_tool.py
    • terminal_tool(...) resolves cwd via overrides.get("cwd") or config["cwd"]
  1. Project context discovery during system prompt build:
  • run_agent.py
    • _build_system_prompt()
    • uses os.getenv("TERMINAL_CWD") or None
    • then calls build_context_files_prompt(cwd=_context_cwd, skip_soul=_soul_loaded)
  1. Context file loader fallback:
  • agent/prompt_builder.py
    • build_context_files_prompt(cwd=None, ...)
    • if cwd is None, it falls back to os.getcwd()

I could not find code in ACP session creation / prompt handling that:

  • passes state.cwd directly into project context loading, or
  • temporarily binds ACP session cwd into TERMINAL_CWD before prompt construction

So ACP has two cwd paths:

  • session-aware cwd for tools
  • global/process cwd for prompt context discovery

extent analysis

TL;DR

To fix the inconsistency, pass the ACP session's cwd to the project context file discovery during system prompt construction.

Guidance

  • Review the run_agent.py file and modify the _build_system_prompt() function to use the ACP session's cwd instead of relying on os.getenv("TERMINAL_CWD") or os.getcwd().
  • Update the build_context_files_prompt() function in agent/prompt_builder.py to accept the ACP session's cwd as an argument and use it for context file discovery.
  • Ensure that the ACP session's cwd is properly registered and passed to the relevant functions during prompt construction.
  • Verify that the fix works by testing the ACP mode with different workspace directories and checking that project context files are loaded correctly.

Example

# In run_agent.py
def _build_system_prompt():
    # ...
    context_cwd = state.cwd  # Use the ACP session's cwd
    build_context_files_prompt(cwd=context_cwd, skip_soul=_soul_loaded)
    # ...

# In agent/prompt_builder.py
def build_context_files_prompt(cwd, skip_soul):
    # Use the provided cwd for context file discovery
    if cwd is not None:
        # Load context files from the provided cwd
        # ...
    else:
        # Fallback to os.getcwd() if cwd is not provided
        # ...

Notes

The fix assumes that the ACP session's cwd is properly registered and available during prompt construction. Additional debugging may be necessary to ensure that the cwd is correctly passed to the relevant functions.

Recommendation

Apply the workaround by modifying the run_agent.py and agent/prompt_builder.py files to use the ACP session's cwd for project context file discovery. This should resolve the inconsistency between tool execution and project context loading.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

hermes - ✅(Solved) Fix [Bug]: ACP session cwd is used for tool execution but not for project context file discovery [1 pull requests, 1 participants]