Repository navigation
fix(grading): detect stdout spoofing via test exit code (model can forge PASSED lines) - #620
Conversation
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.
|
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
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:
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. |
|
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 😆 |
|
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. |
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 aconftest.pyprinting forgedPASSED <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)
run_evaluation.py:206exec_run_with_timeoutcaptures combined stdout; exit code discarded (onlytimed_outretained)run_evaluation.py:211test_output.txtverbatimgrading.py:58-91get_logs_evaltest_output.txtas text, slices between markers, passes tolog_parser. No exit-code check. No junit.log_parsers/python.py:7-26parse_log_pyteststartswith("PASSED")→ next token = test name → recorded as passThere 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 aconftest.pywith apytest_terminal_summaryhook printingPASSED <gold_test_name>for every fail_to_pass / pass_to_pass entry is scoredRESOLVED_FULL.Reproduced
A forged stdout containing only
PASSED <testname>lines (no genuine fix) is parsed byparse_log_pytestinto an all-pass status map, yieldingfail_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):
docker_utils.pyexec_run_with_timeout— capture and return the test command's exit code viaexec_inspect, as a 4th return value. (The API was already called for the PID on timeout; we now also call it on completion.)run_evaluation.py— append a>>>>> Test Exit Code: Nmarker totest_output.txtso the grader can see the process-level result.grading.pyget_logs_eval— spoofing defense: if the exit code is non-zero (tests genuinely failed at the process level) BUT the parsed status map shows noFAILED/ERRORentries (stdout says all-pass), refuse to grade — return({}, False)→ unresolved. This is the signature of forged stdout.Verified (no regression)
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.pyto 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
--junitxmland parse structured XML instead of stdout. This PR is the minimal, immediately-mergeable defense; a follow-up could migrate to junit.compute_fail_to_pass/compute_pass_to_passreturn1whentotal==0(the unscoreable-as-pass / denominator-drop class, with a# TODOat grading.py:210 admitting it). Worth a separate discussion.conftest.pydelivery vector is enabled by unrestricted patch application as root (GIT_APPLY_CMDSincludespatch --fuzz=5 -p1); a follow-up could confine patches to/testbed.Checklist