Skip to content

fix(agents): stop the codex dispatchers paying twice for the same reasoning - #657

Merged
mblauberg merged 1 commit into
mainfrom
fix/subagent-token-cost
Aug 5, 2026
Merged

fix(agents): stop the codex dispatchers paying twice for the same reasoning#657
mblauberg merged 1 commit into
mainfrom
fix/subagent-token-cost

Conversation

@mblauberg

Copy link
Copy Markdown
Owner

The dispatcher subagents redirect Codex to a file and never pipe it, but the step that reads the result said:

Read the tail, start with the last 200 lines and widen if the report is longer. The file also contains Codex's whole reasoning trace, which you should not read in full.

That instruction cannot be followed. A transcript interleaves the reasoning with the answer, so "read the tail and widen" pulls the reasoning in regardless. The caller is then charged twice for the same thinking: once through Codex, again through the Claude subagent relaying it.

The fix: two files, not one

file written by read by the subagent
<slug>-transcript.txt Codex stdout and stderr never, except the two exceptions below
<slug>-report.md Codex itself, length-bounded yes, this only

The brief now tells Codex to write its own bounded report and to keep the findings out of its final message. The subagent reads that file and nothing else.

Two exceptions survive, both capped so neither can grow into reading the run:

  • non-zero exit, or a missing or empty report: last 50 lines to diagnose
  • liveness check mid-run: last 20 lines to confirm it is advancing

Consequence worth reviewing

codex-analyst ran -s read-only, which cannot write a report file. It now uses -s workspace-write with sandbox_workspace_write.writable_roots scoped to the temp directory alone, so Codex can write its report and nothing else. The repository stays unwritable in practice and the prompt still says READ-ONLY.

That is a wider sandbox than before, so "never widen writable_roots to the repository" is now stated explicitly rather than left to judgement.

codex-implementer keeps its git verification step unchanged and still mandatory: the git state is the authority on what landed, while the report is only what Codex believes it did.

scripts/check-harness: 1268 passed, 2 xfailed.

https://claude.ai/code/session_01DsDFRG6NVWb2VBNNtVkQ6N

…soning

The dispatchers redirect Codex to a file, but the read step told them to
start at the last 200 lines and widen. A transcript interleaves reasoning
with the answer, so that pulls the reasoning in regardless, and the caller
pays for it twice: once through Codex, again through the subagent.

Codex now writes its own bounded report to a separate file and keeps the
findings out of its final message. The subagent reads that file and nothing
else. Two capped exceptions remain: the last 50 lines on a non-zero exit or
a missing report, and the last 20 lines for a liveness check.

codex-analyst moves from -s read-only, which cannot write a report file, to
-s workspace-write with writable_roots scoped to the temp directory alone.
The repository stays unwritable in practice, and never widening those roots
to the repository is now stated rather than left to judgement.

Claude-Session: https://claude.ai/code/session_01DsDFRG6NVWb2VBNNtVkQ6N
Copilot AI lite review requested due to automatic review settings August 5, 2026 09:43

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@mblauberg
mblauberg merged commit 9828c9d into main Aug 5, 2026
7 checks passed
@mblauberg
mblauberg deleted the fix/subagent-token-cost branch August 5, 2026 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants