Repository navigation
fix(storage): auto-resolve stale-plan blockers, no operator judgment needed - #3287
Conversation
…needed Problem: unresolved_raw_replay_blockers (the gate repair_materialization checks every 30s pass) counts ANY unresolved non-frontier (stale_plan) blocker archive-wide, and if nonzero, skips repair for the WHOLE archive -- not just the affected raw. Its own docstring says the intent is that "one missing or conflicting authority must not starve unrelated, independently proven raw components", but a plain stale_plan blocker (a TOCTOU race between a census and its apply) does exactly that: it halts ordinary materialization for every other raw until someone runs `raw-authority-blocker-resolve` with a human-supplied resolution string. That resolution string turns out to be pure ceremony: for a non-frontier (stale_plan) blocker, resolve_raw_authority_blocker only checks it is non-empty, then recomputes the plan from current evidence via build_raw_replay_plan (a pure read/snapshot -- no writes) and tombstones the blocked state so the ordinary convergence pipeline can retry. No judgment content changes that outcome; the equivalent crash-recovery path (recover_interrupted_raw_authority_censuses) already does the same recompute unattended. Verified directly: reproduced the archive-wide stall with a real stale-plan fixture, confirmed the acknowledgment string is never inspected beyond a truthiness check. What changed: new auto_resolve_stale_plan_blockers (raw_authority.py) clears every unresolved stale_plan blocker automatically -- explicitly scoped to exclude frontier-schema blockers (frontier_judgment still requires its accepted-assertion-id + disposition gate, enforced inside resolve_raw_authority_blocker itself; this function's query never selects those rows in the first place). Wired into the daemon's existing periodic raw-materialization pass (_drain_raw_materialization_once), right before repair_materialization, so a stale plan clears on the very next tick instead of waiting indefinitely for a manual CLI invocation. Verification: devtools test tests/unit/storage/test_raw_authority_ledger.py tests/unit/daemon/test_daemon_cli.py tests/unit/storage/test_repair.py tests/unit/product/ (255 passed, including a regression proving the exact archive-wide-halt scenario, an idempotency check, and a negative test proving frontier_judgment blockers are never touched); devtools verify --quick (pass). Ref polylogue-d7im Co-Authored-By: Claude <[email protected]>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
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: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
✨ 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 |
## Summary Shortens the FTS5 periodic-merge interval from 300s to 60s to break a self-reinforcing degradation spiral discovered live while investigating why PR #3287's stale-plan auto-resolve hadn't taken effect after deploy. ## Problem Live incident, 2026-07-27: a single live-watcher catch-up append held the daemon's sole-writer lock for 860 seconds (14+ minutes) parsing/writing one modest (~7MB, 547-block) session. At the previous 300s merge interval this starved `_periodic_fts_merge` during exactly the backlog conditions it exists to help with. Root cause chain, verified against the live archive (not speculation): 1. `messages_fts` runs with `automerge=0` (`fts_automerge.py`, #1851) — segment consolidation depends entirely on the periodic merge task, bounded to a small 500-work-unit (2-4 MiB) chunk per call by design. 2. `messages_fts_data` (the FTS5 shadow table) had grown to 705,281 rows live — far past steady state, consistent with the merge task being starved for an extended period. 3. Unmerged segment bloat degrades per-block FTS5 insert cost (a documented FTS5 characteristic), so ordinary append writes get progressively slower. 4. Slower writes → longer writer holds → less chance the merge task ever gets a turn → more bloat. Self-reinforcing, not a one-off slow pass. ## Solution Interval 300s → 60s. The per-call work bound is unchanged — still the same deliberately small, bounded chunk (the merge pass itself must never become a long writer hold). This only asks for the writer's turn 5x more often, so once contention eases the backlog clears roughly 5x faster. **Not a complete fix**: a single very long writer hold still blocks every queued actor regardless of how often they ask. The harder question — writer-lock fairness/priority, or bounding how long a single ingest pass can hold the lock without yielding — is tracked separately as polylogue-de2a, deliberately out of scope for this narrow, low-risk cadence change. ## Verification - `devtools test tests/unit/daemon/test_daemon_cli.py` — 116 passed. - `devtools verify --quick` — pass. Ref polylogue-de2a <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Improvements** * Full-text search maintenance now runs every 60 seconds, helping search indexes stay up to date more frequently. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
…ed raws (#3568) ## Summary Adds the "act" half of polylogue-u19l's live-source-reconciliation work: a new, explicitly operator-invoked actuator (`devtools workspace raw-live-source-reconciliation-apply`) that promotes quarantined `raw_sessions` rows the existing read-only classifier proves are still byte-identical to their live source. **This is a new actuator only — it has not been run against the production archive.** Live application is a follow-up operator step (exact command at the end of this body). ## Problem polylogue-u19l's investigation (see bead notes, 2026-08-02) found ~59GB of `raw_sessions` rows stuck at `revision_authority='quarantined'`, an absorbing state the existing revision-graph reconciler never resolves for most of them. A read-only classifier (`polylogue/storage/live_source_reconciliation.py`, `devtools workspace raw-live-source-reconciliation`) already exists and found ~95% of that GB (56.1 of 58.9) directly re-verifiable against still-present live source files today, by plain byte or parsed-object equality. Nothing acted on that verdict. ## Solution `polylogue/maintenance/raw_live_source_reconciliation_apply.py` + `devtools/raw_live_source_reconciliation_apply.py` (thin CLI wrapper): * Re-runs classification **live**, inside the same write transaction as the promotion — never trusts a previously computed report. * Promotes ONLY `exact_match` / `codex_header_strip_match` verdicts to `revision_authority='byte_proven'`. `diverged` and `source_missing` rows (including genuinely irreplaceable browser-capture spool files) are never touched, no exceptions. * **Design decision on the evidence vocabulary**: `raw_sessions.revision_authority` is a `CHECK`-constrained closed vocabulary (`asserted`/`byte_proven`/`quarantined`) on a `STRICT` table — widening it needs a full table rebuild, not an additive `ALTER`. Rather than silently reusing `byte_proven`'s existing meaning, migration 017 (source schema v17) adds a new, additive `revision_authority_evidence` column: `NULL` means "the pre-existing revision-graph reconciler produced this" (every row promoted before this migration); `'live_source_verification_v1'` means "promoted because live-source verification re-confirmed the archived bytes are still present at the recorded source path," independent of any revision-chain reasoning. The actuator never touches `predecessor_raw_id`/`baseline_raw_id`/`acquisition_generation` — it makes no claim about a row's position in a revision chain, only that its bytes are still verifiable. * Writes an immutable per-row receipt (verdict, previous authority, source path, blob hash/size, comparison timestamp, tool version, backup manifest path used) to a new `raw_live_source_reconciliation_receipts` table, same migration. * **Default is dry-run** (zero mutation). `--apply` requires `--backup-manifest` pointing at a verified `source` tier backup, validated with the *identical* gate durable-tier schema migrations already use (`validate_migration_backup_manifest`) — fails closed on a missing, wrong-tier, or stale (byte-mismatched) manifest. Validated twice (lock-free precheck, then authoritative re-check once the write lock is held), mirroring `migrate_archive_tier`'s own pattern. * Does **not** run blob GC or `VACUUM` — that stays a separate, later, explicitly operator-invoked step (`polylogue/storage/raw_retention.py`). ### Requested audit: is the raw-authority census/blocker ledger now dead weight? Alongside this actuator, the operator asked for an evidence-based audit of whether `raw_authority_censuses`/`_plans`/`_blockers`/`_census_post_plans` and `RawAuthorityReconciler` become redundant now that a mechanical resolution path exists for the bulk of the backlog. **Finding: no, none of it is removable given current evidence.** This actuator only burns down the *historical* backlog once; it is not in the forward-going ingest path. * `polylogue/daemon/convergence_stages.py:916` calls `polylogue.product.raw_authority.repair_materialization` on every live daemon convergence pass — this is the mechanism that classifies every NEW raw as it's captured, not backlog-only bookkeeping. * `auto_resolve_stale_plan_blockers` (polylogue-d7im, `#3287`, merged days before this PR) already auto-clears the `stale_plan` blocker class from that same daemon loop — a distinct failure mode (TOCTOU race between a census and its apply) this actuator does not address. * `resolve_blocker`/`list_blockers` (`polylogue/product/raw_authority.py`) remain the operator-facing resolution path for `frontier_judgment` blockers — genuine cross-route-collision ambiguity (e.g. a GDPR export vs. a browser-DOM scrape disagreeing) this actuator explicitly never attempts to resolve. * `git log --oneline -- devtools/raw_authority_restart_proof.py devtools/raw_authority_scale_proof.py devtools/raw_authority_daemon_health_proof.py polylogue/storage/raw_authority.py` shows 15+ merged PRs in the weeks before this one (up to `#3559`), including crash-recovery and conservation proofs — active, maintained infrastructure, not legacy scaffolding. Nothing in that subsystem was removed in this change. If a future audit wants to revisit this once the historical backlog this actuator targets has actually shrunk in production, that's a separate, later evidence-gathering pass — not something this PR's evidence supports doing now. ## Verification * `devtools test tests/unit/maintenance/test_raw_live_source_reconciliation_apply.py tests/unit/storage/test_live_source_reconciliation.py` — **11 passed**. Proves, against a synthetic fixture archive with one row of each verdict: dry-run makes zero mutations; `--apply` promotes exactly `raw-exact` and `raw-codex-header-strip` (leaving `raw-diverged`/`raw-missing` at `quarantined` with `revision_authority_evidence IS NULL`) and writes exactly two correctly-labeled receipts; applying without `--backup-manifest` is refused before any mutation; an invalid/stale backup manifest (simulated via the same monkeypatch pattern `tests/unit/maintenance/test_raw_authority_reset.py` already uses for this gate) is refused the same way. * `devtools verify --quick` (format, lint, mypy --strict, render-all-check, topology/layering/schema-versioning policy checks) — clean, exit 0. * `devtools render topology-projection` run after adding `polylogue/maintenance/raw_live_source_reconciliation_apply.py`. * Not run: `devtools verify --all` (full non-integration suite) — the touched surface is narrow and testmon-affected coverage plus the quick gate cover it; not run against the production archive at `/realm/db/polylogue` (explicitly out of scope for this PR — built and proven entirely against synthetic fixtures per the task's safety instruction). ## Follow-up: applying this live (a separate, explicitly operator-supervised step) 1. `polylogue backup --output-dir /realm/staging/polylogue-backup --verify` (produces a verified `manifest.json` + `verification-receipt.json` for the source tier). 2. Dry run first: `devtools workspace raw-live-source-reconciliation-apply --json` — inspect the promotable count/bytes against the archived investigation's ~56GB estimate. 3. Apply: `devtools workspace raw-live-source-reconciliation-apply --apply --backup-manifest /realm/staging/polylogue-backup/manifest.json --json`. 4. Blob GC/VACUUM is a separate, later step this PR does not run. Ref polylogue-u19l
Summary
A single stale-plan raw-authority blocker halts
repair_materializationfor the entire archive, not just the affected raw — and resolving it requires only a throwaway acknowledgment string that is never actually checked. This closes that gap: stale-plan blockers now clear automatically on the daemon's next materialization pass.Problem
unresolved_raw_replay_blockers— the gaterepair_materializationchecks every ~30s pass before doing any repair work — counts every unresolved non-frontier (stale_plan) blocker archive-wide. If nonzero, the whole pass fails closed withsuccess=False, for every raw, not just the one behind the blocker. The function's own docstring states the design intent is the opposite: "one missing or conflicting authority must not starve unrelated, independently proven raw components" — that's exactly why frontier-schema blockers are excluded from this count, but a plainstale_planblocker (a TOCTOU race between a census and its apply) isn't, and does exactly the thing the docstring says shouldn't happen.Worse, clearing it manually via
raw-authority-blocker-resolveturns out to add nothing: for a non-frontier blocker,resolve_raw_authority_blockeronly checks theresolutionstring is non-empty, then recomputes the plan from current evidence viabuild_raw_replay_plan(a pure read/snapshot — no writes) and tombstones the blocked state. No judgment content changes that outcome. The equivalent crash-recovery path (recover_interrupted_raw_authority_censuses) already performs the same recompute completely unattended. Verified directly with a real stale-plan fixture: reproduced the archive-wide stall, confirmed the "resolution" text is never inspected beyond a truthiness check.Solution
auto_resolve_stale_plan_blockers(archive_root)instorage/raw_authority.py: clears every unresolvedstale_planblocker automatically, using the exact same non-frontier-only queryunresolved_raw_replay_blockersuses, so it never touches afrontier_judgmentblocker (those still require their accepted-assertion-id + disposition gate, enforced insideresolve_raw_authority_blockeritself)._drain_raw_materialization_once), right beforerepair_materializationruns, so a stale plan clears on the very next tick instead of waiting on a manual CLI invocation.product/raw_authority.pyfollowing the module's existing convention.Verification
devtools test tests/unit/storage/test_raw_authority_ledger.py tests/unit/daemon/test_daemon_cli.py tests/unit/storage/test_repair.py tests/unit/product/— 255 passed, including:frontier_judgmentblockers are never touched by this function.devtools verify --quick— pass.Ref polylogue-d7im