Skip to content

fix(tier3): keep Codex apply_patch contents in FILE CHANGES evidence - #551

Merged
rng1995 merged 1 commit into
mainfrom
naren/codex-native-evidence
Nov 14, 2026
Merged

rng1995 merged 1 commit into
mainfrom
naren/codex-native-evidence

Conversation

@rng1995

@rng1995 rng1995 commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator

Addresses #236 requirement 7 ("retain patch contents"). Found while scoping the native-evidence redesign that issue asks for — this one is a plain defect on current main, independent of that architecture question.

The defect

PR #530 made a Codex apply_patch decode to action_input = {"input": "<patch text>"}. But in atif_helpers.py, _tool_file_path reads only file_path / path / filename / target_file, and _tool_write_body reads only content / new_string / patch / code. Neither reads input.

So every Codex patch contributed zero entries to the judge's FILE CHANGES evidence:

_tool_file_path({"input": patch})   -> ''
_tool_write_body({"input": patch})  -> ''
_collect_file_change_evidence(traj) -> 0 entries
"apply_patch" in _BEHAVIOR_WRITE_TOOLS -> True

That last line is the tell: the code already classifies apply_patch as a write tool. Only the plumbing that reads the argument was missing.

The consequence is worse than a missing section. The patch text survived only in COMPACT TOOL HISTORY, which is budgeted last, while FILE CHANGES is budgeted first — so the patch was the first evidence discarded under exactly the truncation pressure #236 is about. Demonstrated: on a long trajectory carrying a Codex patch, clean main loses the patch text entirely at max_chars 8000, 6000 and 4000; this branch keeps it at all three.

After

case before after path reported
single-file patch 0 1 src/app.py
multi-file patch (3 files) 0 1 src/app.py, src/new_mod.py, docs/readme.md
delete 0 1 src/dead.py
*** Begin Patch, no file header 0 1 '' — body kept, no fabricated path
no patch markers at all 0 0 ''
normal non-patch write 1 1 unchanged

The last two rows are the deliberate ones. A value with no patch markers is still rejected, because {"input": "<shell source>"} is also how Codex passes an exec command — treating that as a file change would introduce a new false positive. A value that carries *** Begin Patch but no file header keeps its body with no Path: line: the write genuinely happened, so dropping it loses evidence, but there is no path to honestly name.

Multi-file patches

_tool_file_path returns every path, comma-joined, capped at 10 with a (+N more) suffix.

Returning only the first would report a three-file write as a one-file write — a quieter lie than returning nothing, since the judge would read Path: src/app.py with no signal that two more files changed. Returning '' would be honest but discards the paths. Joining is accurate and strictly improves the two other consumers: _tool_call_ref's label/path fields, and _verified_facts, which uses this as a substring haystack — each path remains a substring, so more claims match and none fewer. The cap exists so a sprawling patch's path line cannot eat the FILE CHANGES budget this fix exists to protect.

Non-regression

All 11 existing argument shapes — file_path/path/filename/target_file, content/new_string/patch/code, edits, non-dict args, None/non-string input, and key precedence — return byte-identical path and body before and after. CRLF headers, paths with spaces, indented headers and duplicate headers were all checked; nothing raises.

This cannot change any verdict. _BEHAVIOR_REQUIRED_EVIDENCE is final-response only, so file-change completeness is diagnostic and never withholds a score. The change enriches evidence and diagnostics, nothing else.

Tests

tests/tier3/test_behavior_evidence.py 46 → 71, all passing.

Blast radius run — tests/tier3, tests/reporting, and 12 root files covering llm_judge, the Harbor collector and metrics, packaging, public runtime, verifier redaction and checks routing — 16,290 tests on both trees:

  • patched: 31 failed, 16254 passed, 7 errors
  • clean origin/main: 31 failed, 16229 passed, 7 errors

Comparing FAILED/ERROR sets rather than counts: 38 entries each side, zero new and zero vanished. The pre-existing failures are environmental — the shared venv's installed harbor lacks harbor.agents.agent_auth_resolution, plus installed-source kwarg-contract drift.

ruff check clean. CHANGELOG under ## Unreleased only; all 13 ## headings verified against main's, with only ## Unreleased differing.

Notes

  • The bundled templates/eval.py already re-exports _tool_file_path and _tool_write_body, so it inherits the fix — verified by loading the template and getting identical results. The three new helpers are internal and never referenced from it. The change adds no new imports: the header regex is defined locally rather than importing checks._APPLY_PATCH_HEADER_RE, which would pull a 7K-line module and its dependencies into atif_helpers' import graph for one regex.
  • *** Move to: is not parsed, so a rename reports its source path only; the destination remains visible in the retained patch body. Worth a follow-up if renames should be named precisely.
  • _tool_call_ref now yields label: "apply_patch: src/app.py" with a path, where it previously had a bare label and no path. The excerpt narrows from args-JSON to the path, but json_pointer still addresses the full call and FILE CHANGES now carries the patch text.

Scope

This does not close #236. The native event_msg.item_completed preservation architecture that issue recommends is untouched, and the truncated-outer-response case remains open.

🤖 Generated with Claude Code

Codex decodes its native file-edit tool to {"input": "<patch text>"}, but the
behavior-evidence helpers read only file_path-style and content-style keys.
Every Codex patch therefore contributed zero entries to the judge's FILE
CHANGES section, and the patch text survived only in the compact tool history
-- the section budgeted last, and so the first dropped under exactly the
truncation pressure issue #236 is about. Below roughly an 8K budget the patch
vanished from the bundle entirely.

_tool_file_path now takes the changed paths from the patch's Add File, Update
File and Delete File headers, naming every file a multi-file patch touches
rather than letting the first stand for the rest, and _tool_write_body keeps
the patch text as the write body. Only an input value carrying patch markers is
read, so a Codex shell source string is not reported as a file change, and a
headerless or malformed patch yields no fabricated path.

The bundled Harbor verifier template picks this up through its existing
_tool_file_path / _tool_write_body re-exports; no new re-export is needed.

Signed-off-by: Narendran Raghavan <nraghavan@nvidia.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@rng1995
rng1995 merged commit 707657e into main Nov 14, 2026
27 checks passed
@rng1995
rng1995 deleted the naren/codex-native-evidence branch November 14, 2026 17:43
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.

Preserve complete rubric references and native Codex tool evidence

1 participant