Commit cdfe707
authored
fix(cron): redirect file-edit tools to a job's workdir, not just git (#585)
A cron AGENT job's `workdir` only set `TERMINAL_CWD`, which the terminal/git
tools read live — so `git` honoured the workdir, but the file-edit tools did
not. `tools/file_tools._resolve_base_dir` resolves relative paths against the
task's *live* terminal-env cwd (priority #1), which in a long-lived
gateway/daemon is the shared "default" env still anchored at the runtime
checkout. That #1 cwd shadowed `TERMINAL_CWD` (#3): `write_file`/`patch` landed
in the runtime mirror while git committed in the workdir — a split-brain that
dirtied the runtime checkout the evolution pipeline mirrors.
Fix (cron/scheduler.py::_run_job_impl workdir setup + finally only):
- When a live "default" terminal env exists at job start, point THAT env's
`.cwd` at the workdir (under `_env_lock`), capturing the prior cwd. That one
object backs both `_resolve_base_dir` (#1) and the shell-backed
`ShellFileOperations`, so both file-tool paths follow the workdir. The prior
cwd (incl. `None`) is restored under the lock in `finally`, mirroring the
existing `TERMINAL_CWD` save/restore — no leak into a later job.
- Cold start (no live env yet): the file tools already fall through to
`$TERMINAL_CWD` (#3) = workdir, and a terminal command run during the job
lazily creates the shared env seeded from it. On cleanup that env's cwd is
cleared (non-destructively — no os.chdir / teardown) and the file-ops cache
dropped, so it cannot leak the workdir into a later workdir-less job (the
same leak `TERMINAL_CWD` already had for that env's git).
NOT touched: the `no_agent` script path (real per-job `os.chdir`), workdir-less
jobs (verified untouched), and the file/terminal tools themselves. Workdir jobs
are serialized by `tick()`, so mutating the shared in-process env cwd has the
same (already-accepted) blast radius as the existing process-global
`TERMINAL_CWD` mutation. The remaining shared-"default"-env concurrency between
a sequential workdir job and concurrent parallel workdir-less jobs is a
pre-existing architectural property (true isolation needs task-scoped env keys)
and is out of scope here.
TDD: new tests reproduce the split (file base dir resolves to the runtime
checkout while git follows the workdir) — failing pre-fix, green post-fix —
plus regressions that a workdir-less job is unaffected, that a workdir job does
not leak into a following workdir-less job, and that a lazily-created env is
neutralised on cleanup. Cross-reviewed by two non-Claude advisors (Gemini,
Kimi).1 parent ffff7e6 commit cdfe707
2 files changed
Lines changed: 415 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2176 | 2176 | | |
2177 | 2177 | | |
2178 | 2178 | | |
| 2179 | + | |
| 2180 | + | |
| 2181 | + | |
| 2182 | + | |
| 2183 | + | |
| 2184 | + | |
| 2185 | + | |
| 2186 | + | |
| 2187 | + | |
| 2188 | + | |
| 2189 | + | |
| 2190 | + | |
| 2191 | + | |
| 2192 | + | |
| 2193 | + | |
| 2194 | + | |
| 2195 | + | |
| 2196 | + | |
| 2197 | + | |
| 2198 | + | |
| 2199 | + | |
| 2200 | + | |
| 2201 | + | |
| 2202 | + | |
| 2203 | + | |
| 2204 | + | |
| 2205 | + | |
| 2206 | + | |
| 2207 | + | |
| 2208 | + | |
| 2209 | + | |
| 2210 | + | |
| 2211 | + | |
| 2212 | + | |
| 2213 | + | |
| 2214 | + | |
| 2215 | + | |
| 2216 | + | |
| 2217 | + | |
| 2218 | + | |
| 2219 | + | |
| 2220 | + | |
| 2221 | + | |
| 2222 | + | |
| 2223 | + | |
| 2224 | + | |
| 2225 | + | |
| 2226 | + | |
| 2227 | + | |
| 2228 | + | |
| 2229 | + | |
| 2230 | + | |
| 2231 | + | |
| 2232 | + | |
| 2233 | + | |
| 2234 | + | |
| 2235 | + | |
| 2236 | + | |
| 2237 | + | |
| 2238 | + | |
| 2239 | + | |
| 2240 | + | |
| 2241 | + | |
| 2242 | + | |
| 2243 | + | |
| 2244 | + | |
| 2245 | + | |
| 2246 | + | |
| 2247 | + | |
| 2248 | + | |
| 2249 | + | |
| 2250 | + | |
| 2251 | + | |
| 2252 | + | |
| 2253 | + | |
| 2254 | + | |
| 2255 | + | |
| 2256 | + | |
| 2257 | + | |
| 2258 | + | |
| 2259 | + | |
| 2260 | + | |
| 2261 | + | |
| 2262 | + | |
| 2263 | + | |
| 2264 | + | |
| 2265 | + | |
2179 | 2266 | | |
2180 | 2267 | | |
2181 | 2268 | | |
| |||
2458 | 2545 | | |
2459 | 2546 | | |
2460 | 2547 | | |
| 2548 | + | |
2461 | 2549 | | |
2462 | 2550 | | |
2463 | 2551 | | |
| 2552 | + | |
| 2553 | + | |
| 2554 | + | |
| 2555 | + | |
| 2556 | + | |
| 2557 | + | |
| 2558 | + | |
2464 | 2559 | | |
2465 | 2560 | | |
2466 | 2561 | | |
| |||
3037 | 3132 | | |
3038 | 3133 | | |
3039 | 3134 | | |
| 3135 | + | |
| 3136 | + | |
| 3137 | + | |
3040 | 3138 | | |
3041 | 3139 | | |
3042 | 3140 | | |
| |||
0 commit comments