Skip to content

fix(grading): detect stdout spoofing via test exit code (model can forge PASSED lines) - #620

Merged
john-b-yang merged 4 commits into
SWE-bench:mainfrom
AUTHENSOR:fix/grading-spoof-exit-code
Aug 14, 2026
Merged

john-b-yang merged 4 commits into
SWE-bench:mainfrom
AUTHENSOR:fix/grading-spoof-exit-code

Conversation

@AUTHENSOR

Copy link
Copy Markdown
Contributor

Summary

The grading harness parses captured pytest stdout line-by-line (log_parsers/python.py:7-26) and never checks the test command's exit code or junit XML. A model patch that writes a conftest.py printing forged PASSED <testname> lines is scored RESOLVED_FULL with no genuine fix.

This is a novel class — "test-runner capture" / grading spoofing — distinct from verdict-injection (which poisons an LLM judge) and unscoreable-as-pass (which drops samples from the denominator). Here the model forges the test results themselves.

The chain (confirmed line-by-line)

Step File:line Behavior
Run tests run_evaluation.py:206 exec_run_with_timeout captures combined stdout; exit code discarded (only timed_out retained)
Write log run_evaluation.py:211 stdout written to test_output.txt verbatim
Parse grading.py:58-91 get_logs_eval reads test_output.txt as text, slices between markers, passes to log_parser. No exit-code check. No junit.
Match log_parsers/python.py:7-26 parse_log_pytest any line startswith("PASSED") → next token = test name → recorded as pass

There is no exit-code check and no junit XML parsing anywhere in the Python grading path. A model patch (applied unrestricted as root at /testbed, run_evaluation.py:168-173) that drops a conftest.py with a pytest_terminal_summary hook printing PASSED <gold_test_name> for every fail_to_pass / pass_to_pass entry is scored RESOLVED_FULL.

Reproduced

A forged stdout containing only PASSED <testname> lines (no genuine fix) is parsed by parse_log_pytest into an all-pass status map, yielding fail_to_pass=1.0, pass_to_pass=1.0 → RESOLVED_FULL. The PoC reproduces the parser + resolution logic verbatim.

Fix

Three additive changes (44 lines, no change to existing parse/resolution semantics):

  1. docker_utils.py exec_run_with_timeout — capture and return the test command's exit code via exec_inspect, as a 4th return value. (The API was already called for the PID on timeout; we now also call it on completion.)

  2. run_evaluation.py — append a >>>>> Test Exit Code: N marker to test_output.txt so the grader can see the process-level result.

  3. grading.py get_logs_eval — spoofing defense: if the exit code is non-zero (tests genuinely failed at the process level) BUT the parsed status map shows no FAILED/ERROR entries (stdout says all-pass), refuse to grade — return ({}, False) → unresolved. This is the signature of forged stdout.

Verified (no regression)

Scenario Exit code Stdout Before fix After fix
Spoofed (forged PASSED, no fix) 1 all PASSED RESOLVED_FULL ❌ UNRESOLVED ✅
Genuine pass 0 all PASSED RESOLVED_FULL RESOLVED_FULL (no change)
Genuine fail 1 real FAILED not resolved not resolved (no change)

The check only fires when exit≠0 AND no FAILED lines — the spoofing signature. Genuine runs are unaffected.

Why this matters

SWE-bench is a headline agent-capability benchmark (Princeton + OpenAI Preparedness; SWE-bench Verified is used to rank frontier models). A model that can write a conftest.py to forge its own test results can claim a perfect score with zero genuine fixes. The fix is cheap (capture an exit code that was already available), but only if you know to look.

Notes

  • The deeper defense is to run pytest with --junitxml and parse structured XML instead of stdout. This PR is the minimal, immediately-mergeable defense; a follow-up could migrate to junit.
  • Also noted but out of scope: compute_fail_to_pass / compute_pass_to_pass return 1 when total==0 (the unscoreable-as-pass / denominator-drop class, with a # TODO at grading.py:210 admitting it). Worth a separate discussion.
  • The conftest.py delivery vector is enabled by unrestricted patch application as root (GIT_APPLY_CMDS includes patch --fuzz=5 -p1); a follow-up could confine patches to /testbed.

Checklist

  • Code follows project style
  • 0 new ruff errors (verified per-file against base)
  • Fix verified: spoofed→blocked, genuine-pass→resolved, genuine-fail→graded
  • Additive only — existing parse/resolution semantics unchanged

The grader parses pytest stdout line-by-line (log_parsers/python.py) and
never checks the test command's exit code or junit XML. A model patch that
writes a conftest.py printing forged 'PASSED <testname>' lines is scored
RESOLVED_FULL with no genuine fix.

Capture the test command's exit code in exec_run_with_timeout, record it as
a TEST_EXIT_CODE marker in the test output, and have get_logs_eval refuse to
grade a run whose exit code is non-zero but whose parsed status map shows no
failures (the spoofing signature). Genuine all-pass runs (exit 0) and genuine
fail runs (exit !=0 with real FAILED lines) are unaffected.
@john-b-yang

Copy link
Copy Markdown
Member

Good catch on the underlying problem. I updated this branch so it merges cleanly, and changed which exit code we read.

The original version read the exit code of the whole eval script. That script ends with a git checkout that resets the test files, and it does not stop on errors. So the exit code came from the reset, not from the tests. Two effects:

  • The spoof was not caught. The reset normally succeeds, so the script exits 0 even when the tests failed.
  • Passing runs were wrongly rejected. When a test patch adds a brand new test file, the reset fails because that file does not exist yet. In a real run of the Verified split, 18 solved instances would have flipped to unsolved.

Now the eval script saves the test command's exit code right after the tests run, before the reset. Grading reads that value.

I checked this by running the real script shape:

  • Tests fail, reset succeeds → script says 0, saved value says 1. Spoof caught.
  • Tests pass, reset fails → script says 1, saved value says 0. Run still graded, no false rejection.

The saved value is written after the end marker, so log parsers never see it. I checked all 57 parsers. Logs from older runs have no saved value, and those are graded exactly as before.

@john-b-yang

Copy link
Copy Markdown
Member

Tysm for this fix! This is a really interesting potential hack I hadn't thought about, maybe somewhere down the line models will try doing this and get blocked 😆

@john-b-yang
john-b-yang merged commit 62ad43a into SWE-bench:main Aug 14, 2026
@AUTHENSOR

AUTHENSOR commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for the rework! You caught an important issue in my initial implementation: I was reading the overall script's exit status rather than the test command's. Capturing it before cleanup addresses both the spoofing case and the false rejections you identified.

Appreciate the additional checks to make sure every parser can record a failure. That's a useful guardrail for future changes.

Glad this landed. I keep finding this same pattern, where the evaluator trusts something the model controls, across the major harnesses. If you'd ever like to compare notes or want another pass over the grading side, I'd be happy to help.

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