Repository navigation
test(#312): make the lock-ownership race prove its own premise - #313
Merged
Merged
Conversation
test_skip_path_does_not_delete_holders_lock_file asserted that P1's save.lock survived P2's skip, on the stated grounds that P1 was still running — and nothing established that. P1 held the lock for a fixed STUB_EXTRACT_SLEEP=3.0; when that window closed before P2 finished, P1 released the lock correctly and the assertion fired accusing P2 of a teardown it never performed. One leg of twelve, macos-3.11. The test had two outcomes where it needed three. An absent lock has an innocent reading and a guilty one that produce the identical filesystem state; only P1's liveness separates them. "P1 had already exited" is neither a pass nor a failure, and now reports itself as inconclusive via pytest.skip(... COVERAGE LOST ...) — the #293 idiom from tests/test_lock_primitive.py. The timing dependency is removed rather than widened. P1 now blocks in its stub extract on a release file the test creates, so its hold covers P2 and P3 by construction; the stub keeps a 60s cap. All environments are built before P1 starts — each _make_env rewrote the same ten scripts and the session jsonl into the tree P1 was executing from, which was both a hazard and most of the work that had to fit in the window. The gate is consulted only on the ambiguous branch: a lock still present is unambiguous. A bare poll() would not have sufficed there either — it reads None throughout save-session.sh's EXIT trap — so liveness is believed only after a 2s grace, paid solely when about to fail or skip. The P3 half rested on the identical unstated premise and got the same treatment. Both inconclusive cases are now constructed deliberately by new tests rather than waited for. Verified: reverting #168 in cleanup() (unconditional rm -rf "$LOCK_DIR") still fails with the accusation intact, so the invariant is not weakened; disabling either liveness gate turns both new tests red with exactly the #312 misattribution. No product change. Co-Authored-By: Max <noreply>
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.
test_skip_path_does_not_delete_holders_lock_filereddenedmainon macos-3.11. It asserted that P1's lock must still exist because P1 is still running — and never established that premise anywhere in the file (grep -n poll tests/test_save_session_lock_ownership.py→ nothing). P1 held the lock for a fixedSTUB_EXTRACT_SLEEP=3.0; when that window closed before P2 finished, P1 released the lock correctly and the assertion fired accusing P2 of a teardown it never performed.Reproduced deterministically rather than by waiting for a loaded runner: release P1 and reap it before P2 starts, and the current test fails with its own message.
No product bug
save-session.shonly unlinks whenHAVE_LOCK=true. The test still has teeth — reverting #168 (cleanup()→ unconditionalrm -rf \"$LOCK_DIR\") keeps it red with the accusation intact.The fix removes the timing dependency rather than widening it
P1 now blocks in its stub
extracton a release file the test creates, so its hold covers P2 and P3 by construction — no budget is guessed anywhere. A 60s cap keeps a defect from hanging a runner. Raisingextract_sleepwas rejected: a bigger number moves the flake, it does not remove the ambiguity.The liveness gate is consulted only on the ambiguous branch. A present lock is unambiguous — P1 cannot have released it and P2 has exited — so the passing path pays nothing and can never be falsely skipped. An absent lock is ambiguous, and only there is P1's liveness checked. A bare
p1.poll()would not have sufficed: it readsNonefor the whole of theEXITtrap, so a lock P1 had already released legitimately would still read as a live holder's lock going missing — the same defect, one microsecond narrower. Liveness is believed only after a 2s grace.Three states, not two
An inconclusive run reports
pytest.skip(... COVERAGE LOST ...)naming the invariant it failed to check — the repo's own idiom from #293 intest_lock_primitive.py, not a new vocabulary. Calling it a pass would retire a real invariant silently; calling it a failure is #312.Also found
_make_envwas part of the problem. P2 and P3 each rewrote the same ten scripts,config.jsonand the sessionjsonlinto the shared tree while P1 was executing those very files. All environments are now built before P1 starts.calls2was captured and never read. There is now a direct, timing-free assertion that P2 ran no extraction.Method
TDD in order: restructure with the assertions kept verbatim → red with the #312 message; add the gates → green. Mutation both ways: disabling either gate turns both new tests red with exactly the misattribution; reverting #168 still fails correctly.
Suite: 1474 passed, 43 skipped, coverage 94.26%. The 43 skips are the documented pre-existing set; none are new.
Honest limit
On a runner that still loses the race, this reports
SKIPPEDnaming the lost coverage rather than a red build blaming P2. That is a real coverage loss on that leg, stated out loud instead of paid silently.Closes #312