From ce1ece2850787ab29600ae2ca7476007edb13fca Mon Sep 17 00:00:00 2001 From: Drew Stone Date: Sun, 12 Jul 2026 23:43:08 -0600 Subject: [PATCH 1/2] fix(mcp): pin PWD to cwd when spawning a local harness MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit runLocalHarness spawns the coding CLI with `cwd` set to the worktree, but inherited the parent process's `PWD`. Harnesses that resolve their working directory from `$PWD` rather than getcwd() (opencode does) then edit the WRONG directory, so the worktree diff comes back empty and the delegation fails with a phantom "empty patch — no candidate passed validation". Merge `PWD: cwd` into the child env so the harness edits where it was placed. --- src/mcp/local-harness.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/mcp/local-harness.ts b/src/mcp/local-harness.ts index e9574ea3..fdcf3d26 100644 --- a/src/mcp/local-harness.ts +++ b/src/mcp/local-harness.ts @@ -409,7 +409,14 @@ export async function runLocalHarness( : buildHarnessArgs(harness, taskPrompt, options) if (options.codexReproducible) assertCodexReproducibleInvocation(requestedCommand, args) - const baseEnv = options.env ?? process.env + // We spawn the harness with `cwd`, but a harness that resolves its working + // directory from `$PWD` rather than `getcwd()` (opencode does; the others may) + // inherits the parent's stale `PWD` and edits the WRONG directory — its + // worktree diff then comes back empty and the delegation fails with a phantom + // "empty patch". Pin `PWD` to `cwd` so the harness edits where it was placed. + // `baseEnv` feeds both the codex-isolated and the plain spawn paths below, so + // pinning it here covers every runLocalHarness consumer. + const baseEnv: NodeJS.ProcessEnv = { ...(options.env ?? process.env), PWD: cwd } const isolated = options.codexReproducible ? await isolateCodexHome({ baseEnv, From ed7c6675bc6505f693d7aaf22ff6de42807d4ee9 Mon Sep 17 00:00:00 2001 From: Drew Stone Date: Mon, 13 Jul 2026 14:14:24 -0600 Subject: [PATCH 2/2] docs(api): regenerate mcp.md line ref for parseCodexTokenUsage --- docs/api/mcp.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api/mcp.md b/docs/api/mcp.md index d2b1ff4a..1592a8d5 100644 --- a/docs/api/mcp.md +++ b/docs/api/mcp.md @@ -7677,7 +7677,7 @@ Does NOT throw when: > **parseCodexTokenUsage**(`stdout`): [`CodexTokenUsage`](#codextokenusage) -Defined in: [mcp/local-harness.ts:1341](https://github.com/tangle-network/agent-runtime/blob/main/src/mcp/local-harness.ts#L1341) +Defined in: [mcp/local-harness.ts:1348](https://github.com/tangle-network/agent-runtime/blob/main/src/mcp/local-harness.ts#L1348) Parse and validate the one terminal usage event emitted by `codex exec --json`.