Repository navigation
test(daemon): concurrency/race invariants suite (#1182) - #1206
Conversation
Adds a consolidated suite that pins documented daemon concurrency invariants under interleaved load: - tests/unit/storage/test_blob_gc_concurrency.py — lease bridges acquire-blob → write-row commit window; threaded acquire/commit/GC loop never deletes a referenced blob; hypothesis interleaves randomized commit orderings against multiple blobs. - tests/unit/storage/test_fts_trigger_lifecycle.py — suspend/restore contract: drops all six expected triggers, restore is idempotent, simulated SIGKILL between suspend and restore is recovered by a fresh restore call; hypothesis exercises arbitrary lifecycle sequences. - tests/unit/daemon/test_live_watcher_concurrency.py — CursorStore rejects backward writes under the same parser fingerprint; N-thread monotone-offset race ends at the max committed offset; concurrent raw_conversations upserts converge to a single row by raw_id; hypothesis pins same-fingerprint cursor = max(offsets). - tests/unit/daemon/test_ingest_worker_handoff.py — begin_ingest_attempt persists a durable running row; simulated SIGKILL row becomes abandoned/interrupted on next CursorStore open; finished attempts are not clobbered by the recovery pass; concurrent begin calls produce distinct attempt_ids; in-flight phase update is visible to independent readers. All tests use threading and (for stress files) hypothesis with @settings(deadline=None) and run in under 10s combined. Closes #1182
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughFour new test modules establish concurrent invariants for daemon handoff recovery, cursor monotonicity, blob GC lease protection, and FTS trigger lifecycle. The suite covers persistence under shutdown, race-free cursor advancement, orphan-free lease semantics, and trigger repair recovery. ChangesConcurrency Test Suite
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5668b45c8a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| assert record.byte_size >= max_expected - 100, ( | ||
| f"cursor regressed: got {record.byte_size}, expected >= {max_expected - 100}. " | ||
| "Concurrent writers caused offset rollback." |
There was a problem hiding this comment.
Assert exact maximum cursor offset after concurrent writes
This test is documented as proving that concurrent writers converge to the maximum committed offset, but the assertion accepts any final value >= max_expected - 100. In this setup that still passes when the highest offsets (e.g., 2430, 2420, 2410, 2400) are missing, so a regression that drops the top writes can go undetected while the test remains green. Tightening this to require the exact expected max would match the stated invariant and prevent false positives.
Useful? React with 👍 / 👎.
Summary
Adds a consolidated daemon concurrency/race suite that pins documented invariants from
docs/internals.mdunder threaded and asyncio interleavings, plus Hypothesis-driven randomized orderings. Closes the AC list on #1182.Problem
#997 status flagged daemon concurrency tests as "partially covered piecemeal but no consolidated suite." Race-prone surfaces — blob GC + lease handshake (
commit_archive_write_effects→acquire_blob_leases→ release window), FTS trigger suspend/restore lifecycle, cursor monotonicity under concurrent batch convergence, andlive_ingest_attemptworker handoff under shutdown — had no single suite asserting the invariants. A regression that removed the lease table, skipped the lease check, dropped the SIGKILL recovery pass, or weakened the cursor monotonicity contract would not have been caught by the existing tests.Solution
Four new files, all using
threading(andhypothesisfor randomized interleavings):tests/unit/storage/test_blob_gc_concurrency.py— lease acquired before raw-row commit blocks GC; release without commit makes blob collectable; durable DB reference alone protects without a lease; threaded acquire/commit/GC loop with 20 commits + continuous GC never deletes a referenced blob; Hypothesis test covers N distinct blobs with shuffled commit ordering.tests/unit/storage/test_fts_trigger_lifecycle.py—suspend_fts_triggers_syncdrops all six expected triggers;restore_fts_triggers_syncis idempotent (no duplicates); simulated SIGKILL between suspend and restore leaves detectable drift and is recoverable by a fresh restore; concurrent suspend/restore threads converge; Hypothesis arbitrary sequences end in a recoverable state with no spurious triggers.tests/unit/daemon/test_live_watcher_concurrency.py—CursorStore.set(..., allow_backward=False)rejects regressions under same parser fingerprint;allow_backward=Trueis the documented escape hatch; N-thread monotone-offset race lands at the max committed offset; concurrentraw_conversationsupserts on sameraw_idconverge to exactly one row; Hypothesis pins same-fingerprint cursor = max(offsets).tests/unit/daemon/test_ingest_worker_handoff.py—begin_ingest_attemptpersists a durablerunningrow; opening a freshCursorStoreon a DB with a stalerunningrow marks itabandoned/interrupted(the SIGKILL recovery path); acompletedrow is not clobbered by reopen; concurrentbegin_ingest_attemptcalls produce distinct attempt IDs; mid-flight phase updates are visible to independent readers.pragma: no coverannotations on defensive thread error-capture branches carry inline justifications as required byverify-suppressions.Note on #1190 (
run_blob_gcunlinks at flat path instead ofblob_path): the suite's assertions are framed around the DB-level lease/reference invariant (deletion count andexists()semantics that remain correct under the bug), so none of the new tests trip #1190. The orphan-collection test documents this explicitly.Verification
Closes #1182
Ref #997
Summary by CodeRabbit