Skip to content

test(#312): make the lock-ownership race prove its own premise - #313

Merged
fdaviddpt merged 1 commit into
mainfrom
fix/312-lock-liveness
Aug 5, 2026
Merged

fdaviddpt merged 1 commit into
mainfrom
fix/312-lock-liveness

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

test_skip_path_does_not_delete_holders_lock_file reddened main on 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 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.

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.sh only unlinks when HAVE_LOCK=true. The test still has teeth — reverting #168 (cleanup() → unconditional rm -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 extract on 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. Raising extract_sleep was 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 reads None for the whole of the EXIT trap, 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 in test_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_env was part of the problem. P2 and P3 each rewrote the same ten scripts, config.json and the session jsonl into the shared tree while P1 was executing those very files. All environments are now built before P1 starts.
  • P2 was never checked to have actually skipped — it was inferred from the lock still being there, and calls2 was 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 SKIPPED naming 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

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>
@fdaviddpt
fdaviddpt merged commit e6be7d3 into main Aug 5, 2026
12 checks passed
@fdaviddpt
fdaviddpt deleted the fix/312-lock-liveness branch August 5, 2026 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant