Repository navigation
Fix ETXTBSY flake in hatch version-gate test - #1760
Conversation
hatch_on_an_absolute_path_entry_passes_the_version_gate flaked in coverage: the fake `hatch` script is written and then first exec'd by the production version probe. A sibling test thread that forks while fs::write holds the file open keeps a write fd until its own exec, so the probe's exec can fail with ETXTBSY. The probe turns any spawn error into the "Hatch too old" refusal, so the test saw an Err. fake_hatch now execs the script once through the existing output_of_fresh_shim helper (retries ETXTBSY only), then deletes the marker that run created. Once one exec succeeds, no process holds a write fd and none can gain one, so the probe can't race. Production code is unchanged. Stress (64 threads, hatch + utils::process tests): 6/1500 failures on main, 0/3000 with this change. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011f9aeP9eHg6uhzuSY2Qg8D
|
bugbot run Generated by Claude Code |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 1a61d16. Configure here.
|
Labeled Ready for review at
Generated by Claude Code |
|
Ready for review at
Generated by Claude Code |
Final review briefWhat it does — Test-only fix for an ETXTBSY flake in Risk — low. Look here
Verified — read the full diff and surrounding tests; the marker is removed after the settle run, so the "planted hatch never runs" assertion still tests the probe. Ran Changes I made — none. Open questions — none. Auto-merge is armed: approving sends it straight to the merge queue. Generated by Claude Code |
Problem
vendor::pypi_hatch::tests::hatch_on_an_absolute_path_entry_passes_the_version_gateflakes in thecoverage (1)leg, whichci-okneeds. That makes it a merge-queue eviction risk.pypi_hatch.rs:1141:10: called Result::unwrap() on an Err value: ("pypi_hatch_unsupported", "vendored environment dependencies require Hatch >=1.2 on PATH ...")Root cause
The test writes a fake
hatchscript, and the first exec of that script happens inside the production version probe. A sibling test thread that forks whilefs::writeholds the script open keeps a write fd until its own exec. Exec'ing the script in that window fails with ETXTBSY.require_environment_context_support_withturns any spawn error (.ok()) into the same refusal as a Hatch that is too old, so the test sees anErr. This is the same class asexec_freshly_writtenin the CLI tests andoutput_of_fresh_shiminutils::process.Fix
fake_hatchnow execs the script once through the existingutils::process::tests::output_of_fresh_shimhelper, which retries ETXTBSY only. It then deletes the marker that run created. Once one exec succeeds, no process holds a write fd and none can gain one, so the probe's own spawn can't race. The only other change is making that helperpub(crate). Production code is unchanged and no assertion is weakened:planted_hatch_in_the_project_is_never_executedstill checks the marker after the probe.Proof
Stress run with
--test-threads=64onpypi_hatch::tests::hatch_on pypi_hatch::tests::planted utils::process(skipping the 10s hung/timeout probes):The full
vendor::pypi_hatchandutils::processmodules pass (33 tests).rustfmt --checkis clean on the touched file.cargo clippy -p socket-patch-core --all-targetsreports only errors that already exist on main in other files; CI'sclippyjob (--workspace --all-features, no test targets) is unaffected bycfg(test)code.Removed or moved tests
None.
Generated by Claude Code
Note
Low Risk
Test-only changes (
cfg(test)/ test helpers); production Hatch probing is unchanged.Overview
Fixes flaky
pypi_hatchHatch version-gate tests on Unix by avoiding a fork/exec race (ETXTBSY) when a freshly written fakehatchscript is first executed inside the real version probe (spawn failures are treated like “Hatch too old”).fake_hatchnow runs the script once through the existingoutput_of_fresh_shimhelper (ETXTBSY-only retries), clears the marker from that warmup run, and documents why the probe must not be the first exec.utils::processexposes that helper and its test module aspub(crate)so the vendor test can reuse it—no production behavior changes.Reviewed by Cursor Bugbot for commit 1a61d16. Configure here.
Generated by Claude Code