Repository navigation
fix(live): retain proven append frontiers - #2837
Conversation
Problem: a source that appended after append persistence but before cursor\nbookkeeping lost its accepted cursor and retried through archive_full.\n\nWhat changed: retain a byte-proven append frontier across later growth while\nkeeping the original observation as the next authorization boundary. Replacements,\ntruncation, and changed accepted bytes still invalidate the cursor.\n\nVerification: focused live race, replacement, and truncation tests; devtools\nverify --quick.
|
Warning Review limit reached
Next review available in: 35 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (3)
✨ Finishing Touches🧪 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 |
…ULL (#3193) ## Summary Narrows the polylogue-emx2 deferred-membership fix (PR #3129, commit de0b2df) so it applies only to the genuinely async-pending case (`decision IS NULL`), restoring the fail-closed invariant for decided `'ambiguous'`/`'deferred'` membership conflicts that de0b2df's shipped code had accidentally started treating as successes. ## Problem The polylogue-lvz6 clean-master triage bisected 5 failing tests in `tests/unit/sources/test_live_batch_support.py` to de0b2df: - `test_rewrite_plus_growth_before_planning_fails_closed_to_full_route` - `test_live_multi_session_divergence_reopens_raw_authority` - `test_bundle_replay_respects_unconvertible_single_session_head[bundle_texts1-False-False]` - `test_single_session_full_cannot_overwrite_divergent_membership_head` - `test_append_cursor_redetects_source_rewrite_after_handoff[in-place-prefix]` de0b2df's intent was narrow: treat only `raw_session_memberships.decision IS NULL` (genuinely async-pending, arbitrated later by the raw-materialization conveyor, `sources/revision_backfill.py`) as not-a-failure. The shipped code used the pre-existing coarse boolean `ArchiveStore.raw_membership_authority_complete()`, which returns `False` for `decision IS NULL` **or** `'ambiguous'` **or** `'deferred'` -- three distinct states collapsed into one. Net effect: genuinely divergent/ambiguous raws (rewrites, multi-session divergence, unconvertible bundle heads, divergent membership heads) were recorded as `SUCCEEDED` instead of `FAILED`, defeating the fail-closed invariants pinned by #2684/#2716/#2718/#2837. A second injection point (`classify_raw_revision_cohort(...).accepted_raw_ids` empty, in the non-membership single-session route) was also treated as deferred, but that classification is synchronous byte comparison with no conveyor revisiting -- "empty" there is always terminal, never pending. I also traced (direct DB inspection, see Verification) that de0b2df's own regression test exercises `decision = 'ambiguous'`, not `NULL` -- its assertion that this must defer was itself an instance of the bug this PR fixes. ## Solution - `polylogue/storage/sqlite/archive_tiers/archive.py`: new `ArchiveStore.raw_membership_decision_pending(raw_id)` isolates the `decision IS NULL` case. `raw_membership_authority_complete` had exactly one caller in the whole tree (audited via grep), so it stays as-is for its original "fully complete" semantics -- no other legitimate caller to preserve. - `polylogue/sources/live/batch.py`: - The membership-governed injection point now branches: complete -> succeeded; `raw_membership_decision_pending` -> deferred (unchanged behavior for the true async-pending case); otherwise (decided `ambiguous`/`deferred`) -> falls through to the caller's existing failed-set aggregation in `_ingest_full_paths_sync`, now with a `logger.warning` (the pre-fix path failed silently, no exception, no log at all -- part of what made the original bug invisible in production). - The `classify_raw_revision_cohort` injection point drops the `deferred_raw_ids` branch entirely (empty accepted cohort is always terminal there) and logs a warning too. - `tests/unit/sources/test_live_watcher.py`: corrected `test_live_full_ingest_over_ambiguous_membership_defers_instead_of_failing` -> `..._fails_closed_with_diagnostic`. Its two-conflicting-browser-snapshot scenario produces `decision = 'ambiguous'`, not `NULL` (verified by direct DB inspection); the original assertion that it must defer was wrong. It now asserts the corrected fail-closed outcome, the diagnostic log line, and that the first accepted snapshot's content is untouched. - `tests/unit/sources/test_live_batch_support.py`: added `test_raw_membership_decision_pending_distinguishes_null_from_ambiguous`, a focused archive-tier regression test for the exact narrow scoping (NULL -> pending; ambiguous -> decided/not-pending). This is archive-tier rather than a full watcher scenario because `LiveBatchProcessor`'s two call sites into `_apply_membership_sessions` both pass `allow_current_complete_raw=True`, which always resolves a raw's own decision synchronously within the same call -- so NULL is never observed at that exact checkpoint via the live watcher path. Genuine NULL persistence happens only across the conveyor's decoupled census-then-classify phases (`census_historical_revision_evidence` / `backfill_historical_revision_evidence` in `sources/revision_backfill.py`), which this test reproduces directly. ## Verification - `devtools test tests/unit/sources/test_live_batch_support.py tests/unit/sources/test_live_cursor_persistence.py tests/unit/sources/test_live_watcher.py` -- 160 passed (was 5 failed on clean master before this fix). - `devtools verify --quick` -- exit 0 (format, lint, mypy --strict, render all --check, topology/layering/manifest/doc-commands/clock-hygiene/timeout/degrade-loudly gates). - Direct DB-state inspection (ad hoc script against the archive tier, not committed) confirmed the emx2 regression test's second observation produces `raw_session_memberships.decision = 'ambiguous'` for both raws, not `NULL`, before deciding how to correct that test. - Not run: the heavy `test` suite (skipped per-PR by CI policy, runs post-merge). Ref polylogue-emx2 Ref polylogue-lvz6 Co-authored-by: Claude <[email protected]>
Summary
Retain an append cursor at the byte-proven accepted newline when a live Claude/Codex JSONL grows after append persistence but before cursor bookkeeping. The following batch consumes only the later tail instead of falling back to
archive_full.Problem
Live daemon logs showed repeated
source changed after append persistence; cursor invalidated for full retryevents for actively written 50–80 MB JSONLs._record_append_cursortreated every observation change as a rewrite, cleared the frontier, and made the next minute-scale batch re-capture the complete raw source. The active-writer case is later append growth, not a replacement.Static trace and harness results:
stale_cursor_write_count=1; next batch enters full route0; next batch is append-only, zero full-route pathsSolution
LiveBatchProcessor._record_append_cursornow accepts only a surviving, byte-proven accepted range: device/inode must match, size may only grow, and the accepted payload plus tail witness must match. It records the original planned observation—not the newest size—as the cursor authority. Therefore later growth resumes from the proven newline, while a same-size rewrite remains observable through the ctime-bearing cursor authority and is forced through the full route on the next authorization.The regression harness exercises the real planner, cursor writer, and batch routing while lightweight-ingest stubs count a second-tick full route and blob reads. It verifies the cursor moves first to the accepted frontier and then to the file end after consuming only the later record.
Verification
devtools test tests/integration/test_live_read_amplification.py::TestActiveAppendNoFullReread::test_growth_after_append_persistence_keeps_the_append_frontier tests/unit/sources/test_live_batch_support.py::test_append_cursor_redetects_source_rewrite_after_handoff tests/unit/sources/test_live_batch_support.py::test_append_cursor_rejects_truncation_after_append_persistence— 4 passed.devtools verify --quick— 15/15 checks passed (run20260713T093220Z-quick-3756646-fb34ba60).What I decided not to change
No cgroup cache cap, SQLite cache policy, or generic retry/quarantine setting changed: the measured trigger was the append-cursor observation branch, and those controls would only hide its full rereads.