Skip to content

fix(cron): use TERMINAL_CWD for system prompt working directory#24985

Closed
luyao618 wants to merge 1 commit into
NousResearch:mainfrom
luyao618:fix/cron-workdir-system-prompt
Closed

fix(cron): use TERMINAL_CWD for system prompt working directory#24985
luyao618 wants to merge 1 commit into
NousResearch:mainfrom
luyao618:fix/cron-workdir-system-prompt

Conversation

@luyao618

Copy link
Copy Markdown
Contributor

Summary

When a cron job is registered with --workdir <PATH>, the scheduler correctly sets TERMINAL_CWD so terminal/file tools run from the right directory. However, build_environment_hints() in agent/prompt_builder.py uses os.getcwd() unconditionally for the Current working directory line in the system prompt, which reports the scheduler's own cwd (typically ~/.hermes/hermes-agent) instead of the job's configured workdir.

Since the model trusts the system prompt over pwd, it often starts by cd-ing to the wrong directory, silently operating on the wrong filesystem location.

Root Cause

prompt_builder.py:775 calls os.getcwd() without checking the TERMINAL_CWD environment variable that the cron scheduler sets at scheduler.py:1265.

Fix

Check os.environ.get("TERMINAL_CWD") first, falling back to os.getcwd() — consistent with how the terminal tools already resolve working directory.

Testing

  • 121 prompt_builder/environment_hints tests pass (5 skipped)
  • Manual: TERMINAL_CWD=/tmp python -c "from agent.prompt_builder import build_environment_hints; print(build_environment_hints())" now shows /tmp

Closes #24969

@alt-glitch alt-glitch added type/bug Something isn't working comp/cron Cron scheduler and job management comp/agent Core agent loop, run_agent.py, prompt builder P2 Medium — degraded but workaround exists labels May 13, 2026
When a cron job is registered with --workdir, the scheduler sets
TERMINAL_CWD so tools run from the correct directory. However,
build_environment_hints() in prompt_builder.py unconditionally uses
os.getcwd(), which reports the scheduler's own cwd rather than the
job's configured workdir.

The model trusts the system prompt over `pwd`, so it often starts by
cd-ing to the wrong directory.

Fix: check TERMINAL_CWD env var first, falling back to os.getcwd().

Closes NousResearch#24969
@luyao618

Copy link
Copy Markdown
Contributor Author

Closing — open too long, no longer relevant.

@luyao618 luyao618 closed this May 31, 2026
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/cron Cron scheduler and job management 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.

Cron --workdir not reflected in agent system prompt 'Current working directory'

2 participants