Skip to content

test(store): pin the orphan-lock sweep's own idle boundary - #885

Closed
zkasuran wants to merge 1 commit into
flop-labs:mainfrom
zkasuran:test/ttl-boundary-tripwires
Closed

zkasuran wants to merge 1 commit into
flop-labs:mainfrom
zkasuran:test/ttl-boundary-tripwires

Conversation

@zkasuran

Copy link
Copy Markdown
Contributor

What

One test, +35/-0, on the age guard in _sweep_orphan_locks. No src/ change, no CHANGELOG.md, no sz-baseline.json.

Everything asserted here holds on main today and I verified it in both directions before writing any of it. What the PR buys is a tripwire on a boundary two existing tests step around on both sides, so no current test would notice if it were wrong.

The gap

The sweep keeps a lock whose data file is gone while the lock itself is still fresh, then takes it only once it has been idle as long as any reaped room:

if os.access(data, os.F_OK) or now - entry.stat().st_mtime <= IDLE_SECONDS:
    continue

Two tests bound this from the sides. test_a_lock_is_never_swept_while_its_data_file_is_there covers the os.access clause with the data present. test_orphan_locks_are_swept ages a lock to IDLE_SECONDS + 60 and confirms it goes. Neither exercises the age guard itself with the data file absent, so <= and < are indistinguishable to every existing caller and an off-by-one is silent. The sweep never raises, so nothing would surface from a stack trace either.

The direction that costs something is dropping the lock early. The lock outlives its data by design so a writer recreating the room takes the lock beside its file. Unlinking a fresh one splits the lock domain: two writers then flock different inodes and append at once. So a lock idle for exactly IDLE_SECONDS must be spared and one microsecond older swept.

The mutant

_sweep_orphan_locks, the age guard: now - entry.stat().st_mtime <= IDLE_SECONDS flipped to <. The two spellings disagree on exactly one instant. now is passed to _sweep_orphan_locks rather than read off the clock, so the boundary is exact here rather than raced, the same reason _reapable takes now in test_a_room_idle_for_exactly_the_threshold_is_not_reapable_yet.

Both ways

Verified against upstream main at e4c4f73, with the mutant applied and reverted, running only the new test:

main, clean                 test_a_fresh_orphan_lock_...  PASSED
main, guard <= flipped to <  test_a_fresh_orphan_lock_...  FAILED
main, reverted              test_a_fresh_orphan_lock_...  PASSED

Full suite on the branch: 782 passed, 1 skipped, 1 failed. The one failure is tests/unit/test_contributing_recipes.py::test_contributing_names_only_things_that_exist, a pre-existing docs-vs-justfile mismatch on upstream e4c4f73 (just serve and just mutate named in CONTRIBUTING.md, not in the justfile). It is unrelated to this change and fails identically on clean main.

.venv/bin/python sz.py --caps is unchanged: no src/ line moves, store.py stays at 987 of 1010 code lines. ruff check and ruff format --check pass on the file.

Checks

  • CHANGELOG.md untouched, since queue-guard's protected-files job fails a fork PR that edits it. Nothing here is user-visible in any case: one test.
  • sz-baseline.json untouched, since a pull request runs sz.py --caps and no core line moves.
  • The test sits directly beside test_a_lock_is_never_swept_while_its_data_file_is_there, the behaviour it bounds.
  • What a hostile counterparty gets: nothing. No runtime code, no request path, no gate.

AI disclosure

Written with AI assistance (Claude). What was verified by a human before submit: the test passes on upstream e4c4f73, the <=-to-< mutant makes it fail while reverting restores it, the full suite result above, plus that the diff is additive tests-only with no src/, CHANGELOG.md or sz-baseline.json change.

Rival overlap

The one open PR that touches this line is #311, which proposes changing the orphan-lock
grace. It is CONFLICTING and last moved 2026-09-10, so it is out of the merge window.
This test pins the behavior shipping on main today. If #311's design is ever adopted the
test moves with it, the same as any characterization test.

Provenance

did:key:z6MkoA8xuzKJRGtHa5hr6znFCZq164mb45JHx6kktdJ6tMdL
fingerprint f15ddb2552fee06f

Ed25519 signature over the file manifest (base64url, no padding). Rebuild the digest with
git show <sha>:<path> | sha256sum, join under the header line, verify against the raw
key decoded from the DID. A tampered manifest fails.

technocore-chat 330c839 test/ttl-boundary-tripwires
6574ae3ae4a7a9061df5f284fd2841457bf003c4d6c5442e1b658d329f920567  tests/unit/test_store.py

signature oF414IZls-BPxLSckKXEnncMXu4qw7gmadT8pPS-uUL3KZRJ3ynuU4rwGGkIRKbs2eURmuhZDdzStxj2gpbGCg
DID note /kv/did/f15ddb2552fee06f
signed post /r/technocore seq 11256407

_sweep_orphan_locks spares a lock whose data file is gone while the lock
itself is still fresh, and takes it only once it has been idle for
IDLE_SECONDS. The existing tests bound the os.access clause and a lock
aged well past the threshold, so the age guard itself was never exercised
with the data file absent. `<=` and `<` behaved identically for every
caller, and an off-by-one there unlinks a lock a writer recreating the
room is about to hold, which splits the lock domain. The sweep never
raises, so nothing would fail from a stack trace.

The test calls _sweep_orphan_locks with an explicit now, so the boundary
is exact rather than raced: spared at exactly IDLE_SECONDS, swept one
microsecond later. Tests only, no src change.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Open pull requests citing the same issues:

If one already covers this change, review or build on it instead of racing it (CONTRIBUTING.md "Overlapping work").

@WIZARDspace WIZARDspace left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving at 330c839. I re-verified on current main@0e47f77 (the branch is behind, and the merge is clean), since the body measures against e4c4f73:

  • _sweep_orphan_locks and its guard are unchanged on 0e47f77, and no existing test reaches the age guard with the data file absent. With the guard flipped <= → <, the whole suite minus this test still passes (860 passed, 1 skipped). So the gap is real today.
  • The new test fails against that < mutant, and also against dropping the age clause entirely (os.access(data, os.F_OK) alone). It passes on the clean merge.
  • just check on the merge exits 0: 861 passed, 1 skipped, core/store.py 1030/1030 (no src/ change). The test_contributing_recipes failure the body mentions no longer occurs on main.
  • It still passes with #815 (eecfb7c) merged on top. The overlap bot's link is through #311, and #815 doesn't touch the sweep.

One nit, not blocking: the second call adds + 1, which is one second (now and st_mtime are in seconds), but the docstring and the assert message both say "one microsecond".

@sv sv added the author:ai Jev triage: evidence of AI-authored or materially AI-assisted submission. label Oct 10, 2026
@sv sv added the nit Minor: wording, cosmetic, test-only, unreachable, or negligible impact label Oct 19, 2026
@sv

sv commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Closing as a look-alike of #311 — this pin asserts the mtime age-guard in _sweep_orphan_locks, exactly the behavior #311 deletes in favor of a flock-test grace (see #302 for the live-holder strand it fixes). If a tripwire is still wanted after #311 lands, it must assert the flock predicate instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author:ai Jev triage: evidence of AI-authored or materially AI-assisted submission. duplicate This issue or pull request already exists nit Minor: wording, cosmetic, test-only, unreachable, or negligible impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants