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`. 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,