Repository navigation
fix(tier3): keep Codex apply_patch contents in FILE CHANGES evidence - #551
Merged
Merged
Conversation
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
requested review from
chrisknvidia,
mosheabr and
rmalani-nv
as code owners
November 14, 2026 07:03
This was referenced Nov 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_patchdecode toaction_input = {"input": "<patch text>"}. But inatif_helpers.py,_tool_file_pathreads onlyfile_path/path/filename/target_file, and_tool_write_bodyreads onlycontent/new_string/patch/code. Neither readsinput.So every Codex patch contributed zero entries to the judge's FILE CHANGES evidence:
That last line is the tell: the code already classifies
apply_patchas 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
mainloses the patch text entirely atmax_chars8000, 6000 and 4000; this branch keeps it at all three.After
src/app.pysrc/app.py, src/new_mod.py, docs/readme.mdsrc/dead.py*** Begin Patch, no file header''— body kept, no fabricated path''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 anexeccommand — treating that as a file change would introduce a new false positive. A value that carries*** Begin Patchbut no file header keeps its body with noPath:line: the write genuinely happened, so dropping it loses evidence, but there is no path to honestly name.Multi-file patches
_tool_file_pathreturns 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.pywith 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-stringinput, 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_EVIDENCEis 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.py46 → 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:origin/main: 31 failed, 16229 passed, 7 errorsComparing 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
harborlacksharbor.agents.agent_auth_resolution, plus installed-source kwarg-contract drift.ruff checkclean. CHANGELOG under## Unreleasedonly; all 13##headings verified against main's, with only## Unreleaseddiffering.Notes
templates/eval.pyalready re-exports_tool_file_pathand_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 importingchecks._APPLY_PATCH_HEADER_RE, which would pull a 7K-line module and its dependencies intoatif_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_refnow yieldslabel: "apply_patch: src/app.py"with apath, where it previously had a bare label and no path. The excerpt narrows from args-JSON to the path, butjson_pointerstill addresses the full call and FILE CHANGES now carries the patch text.Scope
This does not close #236. The native
event_msg.item_completedpreservation architecture that issue recommends is untouched, and the truncated-outer-response case remains open.🤖 Generated with Claude Code