fix(truthbench): keep SystemRoot for the Windows sandbox child; fail closed when it cannot start - #431
Merged
Conversation
On Windows with CPython 3.10 and earlier, the generated-code sandbox child died at startup with "Fatal Python error: _Py_HashRandomization_Init: failed to get random numbers": its scrubbed environment dropped SystemRoot, which CryptGenRandom needs to seed hash randomization (3.11+ uses BCryptGenRandom and is unaffected). Every sandbox case then reported an ordinary "generated code exited 1", so the timeout, canary and input-overwrite checks never observed the generated code while the negative tests still saw a failure and passed. Keep SystemRoot in the child environment on nt only; the POSIX environment is unchanged. Also fail closed when the sandbox child cannot start: the harness now prints a start marker first, and a child that exits without it yields a GeneratedCodeResult with infrastructure_failure set, no "execute" stage, and none of the post-run checks. run_release raises TruthBenchRunError on such a result, so the CLI exits 2 (infrastructure failure) instead of grading the generated_code_sandbox gate. Signal exits keep the existing native-crash retry path.
Contributor
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
FreshData benchmark report —
|
| fixture | n_rows | n_cols | p50 s | p95 s | peak MB | repair % | false-repair % | preserve % | trust | monotonic | export % |
|---|
Authored-code reduction (Metric 6)
10 tasks
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.
Summary
This fixes the TruthBench generated-code sandbox on Windows with CPython ≤ 3.10. It also makes the sandbox fail closed when its child interpreter cannot start.
Root cause
verify_generated_coderuns generated code in a child interpreter with a deliberately minimal environment, and that environment droppedSystemRoot. On Windows, CPython ≤ 3.10 seeds hash randomization with CryptGenRandom, which needsSystemRoot. Without it the child died at startup withFatal Python error: _Py_HashRandomization_Init: failed to get random numbers. CPython 3.11+ uses BCryptGenRandom and is unaffected.Every sandbox case then reported an ordinary
generated code exited 1:This showed up on
windows-latest/ py3.9 (run 34995394282).Behaviour change
os.name == "nt") the sandbox child keepsSystemRoot. The rest of the environment is still scrubbed, and the POSIX environment is unchanged.GeneratedCodeResultwithinfrastructure_failureset, noexecutestage and no post-run checks, instead of a normal "exited N" verdict.run_releaseraisesTruthBenchRunErrorfor such a result, sopython -m benchmarks.truthbench runexits 2 (infrastructure failure), including under--check-regressions. It no longer grades thegenerated_code_sandboxgate on a child that never ran.Default-output changes
None (dev tooling only). Run artifacts, the schema and
baseline.jsonare unchanged, and the sandbox's reported stdout does not include the marker.Tests
_sandbox_envkeepsSystemRooton nt, under either spelling, without needing real Windows.subprocess.runthroughverify_generated_code.executestage and gets no "generated code exited" verdict.INFRASTRUCTURE FAILURE, and no artifacts are written.Verification
ruff check .: clean.pytest tests/truthbench: 300 passed on Python 3.12 and 300 passed on Python 3.9.python -m benchmarks.truthbench run --profile release --backends pandas,polars,duckdb --repeats 2 --checkon macOS: exit 0, with all 48 gates passing, includinggenerated_code_sandbox.