fix(cron): scope workdir to subprocess instead of os.chdir() global process - #69813
fix(cron): scope workdir to subprocess instead of os.chdir() global process#69813JonthanaHanh wants to merge 1 commit into
Conversation
…rocess The no_agent cron job path used os.chdir() to apply the job's workdir, which changed the global process cwd for ALL threads. Any gateway session (Telegram/Signal/etc.) created while the cron job was running inherited the cron job's workdir, causing AGENTS.md from an unrelated project to be injected into the interactive session's system prompt. Fix: remove os.chdir() and pass the workdir to subprocess.run(cwd=) instead, which scopes the directory change to the child process only. The agent path already correctly uses TERMINAL_CWD env var. Fixes NousResearch#69396
|
Triage evidence (not a merge/close recommendation): at current head hermes-agent/cron/scheduler.py Lines 2262 to 2305 in b918fab no_agent scripts still run with _run_job_script's fallback cwd=str(path.parent), so the configured job workdir is not applied (although the process-global chdir leak is removed). Concrete next action: forward workdir=workdir at those three call sites and add a real-path regression in tests/cron/test_cron_workdir.py or test_cron_script.py that has the script print os.getcwd(), asserts it sees the configured workdir, and asserts the parent process cwd remains unchanged; covering both recurring and claimed one-shot paths would guard both wrapper branches.
|
|
suggesting changes The process-global I reproduced this against refreshed current main Please forward Security evidence:
Signed: GPT-5.6-sol-xhigh in Codex |
Summary
The
no_agentcron job path usedos.chdir()to apply the job'sworkdir, which changed the global process cwd for all threads. Any gateway session (Telegram/Signal/etc.) created while the cron job was running inherited the cron job'sworkdir, causingAGENTS.mdfrom an unrelated project to be injected into the interactive session's system prompt.Root Cause
In
_run_no_agent_job():Between the
chdirand the restore, any concurrent gateway session sees the wrong cwd.Fix
Remove
os.chdir()and pass the workdir tosubprocess.run(cwd=)instead, which scopes the directory change to the child process only. The agent path already correctly usesTERMINAL_CWDenv var — this fix aligns theno_agentpath.Changes
_run_job_script()— newworkdirkwarg, passed tosubprocess.run(cwd=)_run_job_script_with_claim_heartbeat()— newworkdirkwarg, forwarded_run_no_agent_job()— removedos.chdir()/restore block, passes workdir to runnerFixes
Fixes #69396