Skip to content

fix(scicode): require sub-step programs to reach their tests before passing - #4946

Open
salma2vec wants to merge 7 commits into
NVIDIA-NeMo:mainfrom
salma2vec:fix/4901-scicode-require-tests-to-finish
Open

salma2vec wants to merge 7 commits into
NVIDIA-NeMo:mainfrom
salma2vec:fix/4901-scicode-require-tests-to-finish

Conversation

@salma2vec

@salma2vec salma2vec commented Oct 22, 2026 •

Copy link
Copy Markdown

Fixes #4901.

What and why

SciCode previously accepted any sub-step program that exited with status 0, even when model code exited before the assertions ran. This covers raise SystemExit(0), sys.exit(), exit(), os._exit(0), and an atexit hook calling os._exit(0) after a failing assertion. Accumulated solutions can carry the shortcut into subsequent sub-steps.

run_substep now appends a random per-run completion sentinel after the program and requires both that sentinel on stdout and exit code 0. The marker is written directly to fd 1, so a partial printed line or replacement of sys.stdout does not hide completion. An exit-0 run without the marker fails with the program exited before its tests finished. Result dictionary keys are unchanged.

The sentinel is removed before retaining the stdout tail, including when assertions finish but an exit hook hangs and the process times out. Regression tests cover that shutdown case, zero/short output retention, and nonzero shutdown after completion. The runner docstrings and resources-server README now describe the actual pass condition.

The sentinel is in the program text: deliberately self-inspecting code could forge it. This addresses generic early-exit grading shortcuts, not hostile-code isolation or all possible grading attacks.

Completed local validation

Final PR head: 215f0c0af71ffe91526166fd3ecb378f4d891aac. Python 3.13.16, macOS ARM64.

  • 132 tests passed: 86 SciCode resource tests and 46 SciCode agent tests, using:

    PYTHONPATH=.:resources_servers/scicode:responses_api_agents/scicode_agent \
      python -m pytest resources_servers/scicode/tests/test_app.py \
      responses_api_agents/scicode_agent/tests -q -o addopts=''

    The original five early-exit regressions remain covered. The new timeout-marker regression failed before the follow-up fix and passes afterward.

  • Real subprocess/HDF5 integration with a small synthetic fixture: exercised ScicodeResourcesServer.verify, interpreter preflight, program construction, HDF5 loading and reward aggregation. Two-step correct solutions retained reward 1.0; wrong solutions retained 0.0. Each of the five exit mechanisms changed from false reward 1.0 on the baseline runner to 0.0 here. This used NumPy 2.5.4, SciPy 1.18.1 and h5py 3.16.0; it is not the official SciCode dataset or fix(scicode): use a pinned scientific grading environment #4892's pinned scientific stack.

  • Example exploit replay, comparing the runner on main@9d6e0c2824894814359aa0739c29d141fa59b98b with this head:

    Injected solution Baseline This PR
    raise SystemExit(0) 15/15 sub-steps; reward 1.0 on 5/5 problems 0/15 sub-steps; reward 0.0 on 5/5
    import os; os._exit(0) 15/15 sub-steps; reward 1.0 on 5/5 problems 0/15 sub-steps; reward 0.0 on 5/5

    These programs exit before loading HDF5 targets. This demonstrates the exploit and its rejection; it does not validate ordinary solutions against test_data.h5.

  • pre-commit run --all-files passed in a full checkout. The private guardwords catalog was unavailable, so that hook reported a skipped scan; no private-catalog validation is claimed.

  • The repository's _validate_data_single(TestConfig(entrypoint="resources_servers/scicode", should_validate_data=True)) passed. This checks the committed example/metrics/rollout fixture structure, not a new rollout.

  • git diff --check passed; both contributed commits have DCO sign-offs.

Related changes

A separate local integration with main@9d6e0c2824894814359aa0739c29d141fa59b98b passed 144 resource/agent tests. This is separate from the 132 tests on the published head.

Combining the SciCode source/tests with #4892 at e80b5c324cb147aebab44ec8c5afe2ccb5d59a6c passed 91 component/setup tests. Source/test changes combine cleanly; both PRs edit the same README grading paragraph, which needs a small reconciliation when the second PR lands. #4892 is not incorporated into this PR. Its pinned grading environment was built from the lock and used for the real-data regrade below.

Real-data SciCode run

Run on the merged head 59b507587ce2550b0dbf317a8d86675d2d6d8778 with the official test_data.h5 (sha256 48b0272a…b890), using the resources server's own venv (Python 3.13.16, numpy 2.5.4, scipy 1.18.1, h5py 3.16.0; not #4892's pinned stack). Details are in the PR conversation.

  • Model smoke: the documented gym eval run --no-serve on example.jsonl, 1 repeat, temperature 0.0, with record_step_outputs and record_step_code on. The policy was a small local model (qwen2.5-coder:1.5b via Ollama), so the reward is not representative: 0.2 reward, 1/15 sub-steps. No step was rejected as an early exit, and no completion marker appeared in recorded stdout.
  • Regrade parity: the retained per-step code, regraded through verify with main's run_substep (5911d628c), gives identical per-step results.
  • Reference control: dev-split reference solutions (15 problems, 50 sub-steps) score 48/50 sub-steps and 13/15 problems under both runners, with zero per-step differences. The two failures (78.3, 70.8) also fail under fix(scicode): use a pinned scientific grading environment #4892's pinned stack. They come from the dataset, not this change: 78.3 picks its timestep from wall-clock timings, and 70.8's last case is sensitive to floating-point rounding.
  • Early exits, real HDF5: five exit mechanisms pass 50/50 dev sub-steps on main and 0/50 with this PR.
  • fix(scicode): use a pinned scientific grading environment #4892's pinned stack: the same regrades with Python 3.11.15, numpy 1.26.4, scipy 1.10.1 and h5py 3.12.1 as the grading interpreter give identical results on both runners: smoke 1/15, reference 15/15 and 48/50, early exits 50/50 on main and 0/50 here.
  • Tests: 145 SciCode resource, agent and benchmark tests pass on the merged head.

Not covered: a production-model run over the 65-problem test split. CI requires a qualified maintainer to authorize the current full head SHA.

Proposed labels: bug, area:environment.

@copy-pr-bot

copy-pr-bot Bot commented Oct 22, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@svcnvidia-nemo-ci svcnvidia-nemo-ci added area:environment Individual environments, benchmarks, verifiers, and environment-specific resources servers bug Something isn't working labels Oct 22, 2026
@nemo-automation-bot nemo-automation-bot Bot added the community-request Issue reported or requested by someone from the community label Oct 22, 2026
…assing

run_substep passed any program that exited with status 0. Model code runs
before the sub-step's assertions, so raise SystemExit(0), sys.exit(),
exit(), os._exit(0) or an atexit os._exit passed every sub-step, and the
solution carried into later steps passed those too.

Append a statement that writes a random per-run sentinel line to fd 1
after the assertions, and require it along with exit status 0. A program
that exits 0 early now fails with 'the program exited before its tests
finished'. The sentinel is removed from the recorded stdout tail.

Signed-off-by: Salma <[email protected]>
Remove the completion marker when a program reaches its assertions but hangs during interpreter shutdown. Cover timeout cleanup, zero or short output tails, and nonzero shutdown exits. Update the grading description to match the completion requirement.

Signed-off-by: Salma <[email protected]>
(cherry picked from commit 654210d)
@salma2vec

Copy link
Copy Markdown
Author

@marcromeyn @Kipok — following up on the request in #4901. I rechecked readiness and pushed 215f0c0af71ffe91526166fd3ecb378f4d891aac.

The follow-up fixes a reproduced timeout-path issue: assertions could finish, an exit hook could hang, and the internal completion marker would leak into the recorded stdout tail. The regression failed before the fix and passes now. It also adds zero/short-tail and nonzero-shutdown coverage and corrects the grading documentation.

Completed local evidence on the published head:

  • 132 tests passed: 86 resource + 46 agent tests, Python 3.13.16/macOS ARM64.
  • Real verify() execution with small synthetic HDF5 data preserves correct/wrong rewards and rejects all five early-exit mechanisms that falsely passed on the baseline.
  • Both example-file exploit replays reproduce 15/15 → 0/15 passing sub-steps. They exit before HDF5 loading and are not ordinary-solution benchmark validation.
  • Full-checkout pre-commit run --all-files, the native example-data structure validator, and diff whitespace checks passed. The private guardwords scan was skipped because its catalog was unavailable. Both contributed commits have DCO sign-offs.

A separate integration with current main@9d6e0c2824894814359aa0739c29d141fa59b98b passed 144 resource/agent tests. Combining the SciCode source/tests with #4892 at e80b5c324cb147aebab44ec8c5afe2ccb5d59a6c passed 91 component/setup tests; source changes combine cleanly, with a small README grading-paragraph conflict to reconcile when the second PR lands. That was not a fresh build of #4892's pinned grading environment.

Remaining request: could a qualified vetter authorize CI for the full head SHA above, and could you arrange a representative five-example SciCode smoke on authorized infrastructure with the official test_data.h5 and a model endpoint? Neither is available in this local validation environment. Ordinary component CI and the generic GPU E2E job do not establish this SciCode-specific result.

For the smoke, please retain record_step_outputs=true and record_step_code=true, the data checksum, model/configuration, and interpreter/package versions. Regrading the same retained generations before/after this fix under the same scientific environment would separate sentinel behavior from #4892's dependency-related score changes. Include a genuine passing control and inspect per-step failures; an all-fail run alone is insufficient. The documented command after server setup is:

gym eval run --no-serve \
  --agent scicode_benchmark_agent \
  --input resources_servers/scicode/data/example.jsonl \
  --output results/scicode-4946-smoke.jsonl \
  --num-repeats 1 --temperature 0.0

Complete saved generations plus real HDF5 targets can establish grading parity without new inference, but that remains replay evidence; the committed example rollouts do not retain all per-step code.

I have kept this draft because the contribution policy calls for a representative model rollout for behavior changes. If your intended sequence is ready-for-review first, then CI authorization and this smoke, please explicitly confirm that review can start with the smoke still outstanding. I will preserve that gap in the PR rather than treating local regressions as full benchmark validation.

@dhruvnathawani
dhruvnathawani self-requested a review October 29, 2026 18:34
@dhruvnathawani

Copy link
Copy Markdown
Contributor

The PR is still marked as draft. Could you please run SciCode on the PR branch with the real test data and share the results before marking it ready for review?

@salma2vec

Copy link
Copy Markdown
Author

@dhruvnathawani I ran SciCode on the PR branch with the official test_data.h5; results are below. I'm marking the PR ready for review.

Setup

  • Head: 59b507587ce2550b0dbf317a8d86675d2d6d8778 (your merge of main@5911d628c into the branch). Baseline grader: runner.py at 5911d628c; run_substep is the only code that changes.
  • test_data.h5 from the official SciCode Google Drive folder, sha256 48b0272a88b17dbd29777c217e1b4fb2b019b92e11cc2add847409db9541b890 (matches benchmarks/scicode/README.md).
  • Grading environment: the resources server's own venv from requirements.txt: Python 3.13.16, numpy 2.5.4, scipy 1.18.1, h5py 3.16.0, sympy 1.14.0, matplotlib 3.11.2, macOS arm64. This is not fix(scicode): use a pinned scientific grading environment #4892's pinned stack.

1. Model smoke (documented command)

gym env start --benchmark scicode --model-type openai_model \
  ++scicode_benchmark_resources_server.resources_servers.scicode.test_data_fpath=<path>/test_data.h5 \
  ++scicode_benchmark_resources_server.resources_servers.scicode.record_step_outputs=true \
  ++scicode_benchmark_resources_server.resources_servers.scicode.output_tail_chars=2000 \
  ++scicode_benchmark_resources_server.resources_servers.scicode.record_step_code=true

gym eval run --no-serve --agent scicode_benchmark_agent \
  --input resources_servers/scicode/data/example.jsonl \
  --output results/scicode-4946-smoke.jsonl \
  --num-repeats 1 --temperature 0.0

The policy was qwen2.5-coder:1.5b (Q4_K_M, d7372fd82851), served by Ollama 0.40.13's Responses API with num_ctx 16384. It was the only endpoint available to me, so the accuracy says nothing about a production model; the run exercises the full agent → verify path on real targets.

mean/reward 0.2 (problem 4 passes)
subtask_accuracy 1/15 = 0.067
generation_coverage 1.0
failing sub-steps 6 AssertionError, 4 SyntaxError (10.8–10.11), 1 NameError, 1 IndexError, 1 ValueError, 1 timeout (1.1, 30 s)
rejected as "exited before its tests finished" 0
completion marker in any recorded stdout tail 0

2. The same generations, regraded with main's runner

I rebuilt each verify request from the retained step_outputs[].code and ran the real ScicodeResourcesServer.verify twice, once with run_substep from 5911d628c. Both give 1/15 sub-steps and reward 0.2, with zero per-step differences, and both match the live run.

3. Passing control: reference solutions

The test split does not publish reference code, so I used the dev split (15 problems, 50 sub-steps; it includes the 5 smoke problems). I accumulated ground_truth_code the way the agent accumulates model code and graded it through verify against the real HDF5:

main runner this PR
smoke problems (5 problems, 15 sub-steps) 15/15, 5/5 15/15, 5/5
dev split (15 problems, 50 sub-steps) 48/50, 13/15 48/50, 13/15

There are zero per-step differences. The two reference failures are identical under both runners, so they come from the grading stack, not the sentinel:

  • 78.3: ValueError: operands could not be broadcast together with shapes (10001,2) (2,2) inside np.allclose.
  • 70.8: a numeric np.allclose assertion.

Both look like the dependency drift #4892 addresses.

4. Early exits with the real HDF5, through verify

On the dev split, each solution is the problem's imports plus the exit, with no implementation:

injected code main runner this PR
raise SystemExit(0) 50/50 sub-steps, 15/15 problems 0/50, 0/15
import sys; sys.exit() 50/50, 15/15 0/50, 0/15
exit() 50/50, 15/15 0/50, 0/15
import os; os._exit(0) 50/50, 15/15 0/50, 0/15
atexit hook calling os._exit(0), then assert False 50/50, 15/15 0/50, 0/15

All 250 PR-side failures report "the program exited before its tests finished", and no marker leaked into recorded stdout.

5. Tests on the merged head

145 passed across resources_servers/scicode/tests, responses_api_agents/scicode_agent/tests and benchmarks/scicode/tests.

Not covered: a production-model run over the 65-problem test split, and #4892's pinned environment. CI still needs a vetter to authorize 59b507587ce2550b0dbf317a8d86675d2d6d8778. I can share the rollout JSONL and regrade outputs if they would help.

@salma2vec
salma2vec marked this pull request as ready for review October 30, 2026 09:37
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the needs-review PR is ready for code review and waiting on a reviewer label Oct 30, 2026
@salma2vec

Copy link
Copy Markdown
Author

Follow-up: I reran the real-data regrades under #4892's pinned grading stack. They also correct one claim in my previous comment.

Setup

  • Grading interpreter: Python 3.11.15 built from fix(scicode): use a pinned scientific grading environment #4892's grading-requirements.lock at e80b5c324cb147aebab44ec8c5afe2ccb5d59a6c:
    • numpy 1.26.4, scipy 1.10.1, h5py 3.12.1, sympy 1.12, matplotlib 3.8.4, networkx 3.2.1
    • every wheel verified against PyPI's sha256
    • macOS arm64
  • Checks: fix(scicode): use a pinned scientific grading environment #4892's simps check and this PR's grading preflight both pass on it.
  • How it's wired in: through the server's grading_interpreters config, so both runners grade in it.
  • Unchanged from the previous run: head 59b507587ce2550b0dbf317a8d86675d2d6d8778, test_data.h5, and the baseline run_substep from 5911d628c.
main runner this PR
model smoke generations (15 sub-steps) 1/15, reward 0.2 1/15, reward 0.2, same as the live run
smoke problems, reference solutions (15 sub-steps) 15/15, 5/5 15/15, 5/5
dev split, reference solutions (50 sub-steps) 48/50, 13/15 48/50, 13/15
each of the five early exits, dev split 50/50, 15/15 0/50, 0/15

Every row has zero per-step differences between the two runners. All 250 PR-side exploit failures are "exited before its tests finished" rejections, and no completion marker appears in any recorded stdout.

Correction: 78.3 and 70.8

I said these looked like the dependency drift #4892 addresses. That was wrong. They fail the same way under the pinned stack, and the cause is in the dataset, not the grader:

  • 78.3: pendulum_analysis picks its timestep by minimising ‖GTE‖ · √(time.time() elapsed) over linspace(min_dt, max_dt, num_timesteps).
    • The stored targets are exactly the dt = max_dt = 10 trajectory (2–3 rows).
    • On this machine dt = 0.001 wins by 9–12 orders of magnitude (e.g. 2e-10 vs 0.23).
    • dt = 10 can only win when its ~20 µs run is timed as 0 s, i.e. on a clock coarser than that. The reference result depends on the machine's timer.
  • 70.8: only the fourth case fails (L = 1.611792e22, Hamiltonian scaled by 1e-9), by up to 1.8e-4.
    • Scaling L by 1 + 1e-15 already moves the probabilities by 1.8e-6, about the np.allclose tolerance.
    • So the case turns on floating-point rounding on whichever machine generated the targets.
    • The outputs are bit-identical under the pinned stack and the server's default venv.

Neither involves the completion marker: both raise (ValueError / AssertionError) and exit non-zero.

Still not covered:

  • A production-model run over the 65-problem test split.
  • CI, which still needs a vetter to authorize 59b507587ce2550b0dbf317a8d86675d2d6d8778.

@github-actions github-actions Bot added the sla:review-overdue Review response is over the one-business-day SLA label Oct 30, 2026
@cmunley1

Copy link
Copy Markdown
Contributor

/ok to test 39d5444

@cmunley1

Copy link
Copy Markdown
Contributor

/review

@svcnvidia-nemo-ci svcnvidia-nemo-ci left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

SHIP

LGTM — no concerns found.

Reviewed the completion gate and output cleanup, regression tests, execution documentation, and affected verifier/agent scoring paths. No qualifying regressions identified.

The supplied real-model smoke and before/after grading results address the validation requirements. Tests and rollouts were not executed or independently reproduced during this read-only review.

Review generated by codex. This was a full review. Request a full review with /review reset=true.

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-maintainers Waiting on maintainers to respond label Nov 2, 2026

@dhruvnathawani dhruvnathawani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

@svcnvidia-nemo-ci svcnvidia-nemo-ci removed the waiting-on-maintainers Waiting on maintainers to respond label Nov 7, 2026
@github-actions github-actions Bot removed the sla:review-overdue Review response is over the one-business-day SLA label Nov 9, 2026
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-maintainers Waiting on maintainers to respond label Nov 9, 2026

This branch was previously deployed

1 inactive (outdated) deployment
public — 39d5444e Deployed Oct 30, 2026 by copy-pr-bot[bot] via release / finalize / notify #8864
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:environment Individual environments, benchmarks, verifiers, and environment-specific resources servers bug Something isn't working community-request Issue reported or requested by someone from the community needs-review PR is ready for code review and waiting on a reviewer waiting-on-maintainers Waiting on maintainers to respond

Projects

None yet

Development

Successfully merging this pull request may close these issues.

scicode: raise SystemExit(0) in the generated code passes every sub-step (exit code 0 is the only pass signal)

4 participants