Repository navigation
Description
Context
Found by the bug-class audit for #3432 (and #3401 before it). Many tests poll for a file a child writes, then read a value from it. The child writes it with writeFileSync or Bun.write, which create the file before writing it. A poll can therefore read the file empty or partial. A PID read as Number("") is 0, and PID 0 is special everywhere: /proc/0 never exists, process.kill(0, …) signals the caller's own process group, and process.kill(-0, …) does the same. #3433 (storage-inventory) and #3432 (test-invocation-lifetime) fixed two files. These instances remain on main at 3d3516a02.
None of these has been observed failing. They were found by reading the code. The fix shape is the one #3433 and #3432 use: write a temporary file, then rename it into place. Where a PID is read, also refuse anything but a positive integer.
Vacuous or hazardous (a check can pass without proving anything, or the test signals its own process group):
tests/planning-observer.test.ts:127-129polls forholding, whichtests/helpers/planning-control-fixture.ts:25writes withwriteFileSync. Read empty,namespaceis"", soliving()matches no process andCANCELLED_NAMESPACE_HAS_NO_LIVING_DESCENDANTS(:141) passes vacuously.tests/ci-runner.test.ts:174-181: the child writespidwithBun.write. Thefinallyblock runsprocess.kill(-Number(readFileSync(pid)), "SIGKILL"). Read empty, that isprocess.kill(-0), which sends SIGKILL to the test process's own group. Onlytry {} catch {}stands between it and the runner.
Fail-closed (a false red under load, not a false green):
packages/ui-server/tests/storage-collection.test.ts:74-81: PID published withBun.write. With PID 0,process.kill(0, 0)succeeds, soSTORAGE_CANCEL_REAPS_CHILDfails falsely. This is the in-process form of test(core): storage-inventory 'CLI cancellation … leaves no stalled Git process' fails intermittently #3401.tests/integration-command.test.ts:124(writer) and:209-211(JSON.parseofheld).tests/test-invocation-workers.test.ts:21(writer) and:23-24(JSON.parseof the sibling's file).packages/ui-server/tests/helpers/native-suite-timeout.ts:97(writer) and:110-112(JSON.parseof the checkpoint).packages/ui-server/tests/fixtures/inbox-dispatch-host.ts:67(writer) andpackages/ui-server/tests/integration/inbox-dispatch-recovery.test.ts:56-58(JSON.parseofready.json).scripts/native-proof/hosted-app-child.ts:287withscripts/native-proof/hosted-app.test.ts:100-102, andscripts/native-proof/reference-integration-child.ts:159withscripts/native-proof/reference-integration.native.ts:122-124(ready.json).packages/ui-server/tests/fixtures/storage-notify-process.ts:12(writer) andpackages/ui-server/tests/storage-notify.test.ts:140-142(exact-content check).packages/ui-sdk/tests/worker-turn-temp.test.ts:226,235-236andtests/turn-temp-backends.test.ts:22,29-30(exact-content check after an existence poll).packages/ui-server/tests/boot-probe-deadline.test.ts:370(shellecho … >truncates before it writes) and:375-377.
Audited and already safe: packages/ui-sdk/tests/maintenance-worker-kill-child.ts:113-117 and packages/ui-server/tests/fixtures/inbox-unwind-worker.ts:29-33 (rename), tests/test-script.test.ts:158-159 (rename), scripts/native-proof/native-lease-child.ts:17 (rename), tests/workspace-lease.test.ts:40 (newline-terminated PID). tests/build-concurrency.test.ts:106-108 reads its PID file only during cleanup, where PID 0 skips the cleanup instead of signalling.
Scope
Publish every file listed above atomically (temporary file, then rename) in the child that writes it, or make the reader accept only a complete value (for example a newline-terminated positive PID, as tests/workspace-lease.test.ts does). Where a PID is read, refuse 0, negatives and unparsable text before it is used.
Out of scope
- Product code: every writer listed is a test fixture or proof harness.
- Retries, raised timeouts or skips.
- Files test(core): publish the stalled Git stand-in's PID atomically #3433 and tests: test-invocation-lifetime reads PID files before they are written, so a stopped-compiler check can pass on PID 0 #3432 already cover.
Acceptance criteria
- Items 1 and 2 are fixed. For item 1, a forcing receipt (a widened create/write window) shows the base passing with a descendant left alive and the fix failing. For item 2, a receipt shows the cleanup refusing PID 0.
- Items 3-11 are fixed, or each one left alone is listed in the PR with a reason.
- The PR's audit re-runs the search and lists any new instance.
Verification
bun run test on each touched file, plus forcing receipts for items 1 and 2.
Contract impact
None. Test-only.
Activity
schlessera commentedon Nov 3, 2026
Claiming for implementation (
claim-3435-c8880f39). Branch:fix/3435-atomic-test-file-reads.Collisions (
bun scripts/collisions.ts --pathsover the cited files): path overlap with #3309 (tests/integration-command.test.ts) and #3386 (scripts/native-proof/hosted-app-child.ts,scripts/native-proof/hosted-app.test.ts); the remainder are closure-only. Builds on the pattern of #3439 and #3433, both still open.schlessera commentedon Nov 3, 2026
Implementation is in #3444, a ready-to-confirm draft at head
cbfb142, milestone 0.45.0. It fixes items 1-11 and one new instance found by the audit re-run (packages/core/tests/module-mcp-tools.test.ts). Forcing receipts, mutation receipts and loaded runs are in the PR. Not a proof-system change.