Repository navigation
fix(storage): stop the raw-authority obligation guard pinning plan history - #3559
Conversation
…story
Problem: raw_authority_census_plans/_post_plans (a durable source.db tier)
grew ~100k rows/hour, ~870 MiB, 709,264 rows across just 41 of the most
recent ~112 censuses, with fixed_point never reaching 1 on any of 256
censuses ever run. prune_raw_authority_census_history's plan-row window
was gated on every blocker for a census being resolved, but the dominant
blocker reason ("accepted raw authority remains quarantined...") is a
structurally permanent fact that never resolves, and continuous live
ingestion keeps minting fresh ones -- each anchoring whichever census
first observed it, forever.
Solution: a blocker's expected_json/observed_json columns already carry a
complete, self-contained snapshot of the plan and its evidence
(_reconcile_frontier_obligations), and resolve_raw_authority_blocker reads
that plus the census-independent raw_authority_plans table -- never
raw_authority_census_plans/_post_plans. So the plan-row detail window no
longer needs an unresolved blocker to keep it alive; it prunes on the
ordinary retention window unconditionally. The header window keeps its
guard (raw_authority_blockers has a real FK on census_id), and
already-resolved blockers tied to a pruned census are cleaned up in the
same pass. No schema change: source.db's DDL is untouched, this is a
behavior-only fix to an existing maintenance routine.
Verification: devtools test tests/unit/storage/test_raw_authority_ledger.py
tests/unit/storage/test_raw_retention.py -- new
test_census_plan_rows_prune_past_retention_even_with_an_unresolved_blocker
fails against the pre-fix code and passes after; 10 pre-existing failures
in test_raw_authority_ledger.py (an unrelated _write_codex_raw fixture
regression -- empty message text now rejected as "no positive
conversational evidence" by dispatch) are unchanged before/after this
change. devtools verify --quick is green.
Ref polylogue-z7ko
Ref polylogue-f4z9
Co-Authored-By: Claude <[email protected]>
|
Warning Review limit reached
Next review available in: 53 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 (2)
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 |
…ed raws Problem: polylogue-u19l's read-only investigation found ~95% of the ~59GB of raw_sessions rows stuck at revision_authority='quarantined' is directly re-verifiable against still-present live source files/exports (exact byte match, or exact match after stripping a known synthetic Codex header artifact, or parsed-object identity for zip exports). The classifier (polylogue.storage.live_source_reconciliation, exposed as `devtools workspace raw-live-source-reconciliation`) only reports; nothing acted on a "reconcilable" verdict. What changed: adds the "act" half as a new, explicitly operator-invoked actuator, `devtools workspace raw-live-source-reconciliation-apply` (polylogue/maintenance/raw_live_source_reconciliation_apply.py): * Re-runs classification live, inside the same write transaction the promotion runs in -- never trusts a stale 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. * Records the promotion's evidence provenance in a new, additive `revision_authority_evidence` column rather than silently overloading `byte_proven`'s existing meaning -- `raw_sessions.revision_authority` is a CHECK-constrained closed vocabulary on a STRICT table, so widening it needs a table rebuild, not an additive ALTER. NULL means "the pre-existing revision-graph reconciler produced this"; the new column value `live_source_verification_v1` means "promoted because live-source verification re-confirmed the archived bytes, independent of any revision-chain reasoning." Never touches predecessor_raw_id/ baseline_raw_id/acquisition_generation -- this module makes no claim about a row's revision-chain position. * Writes an immutable per-row receipt (what was compared, what matched, when, tool version, backup manifest used) to a new `raw_live_source_reconciliation_receipts` table (migration 017, source schema v17). * 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 missing, wrong- tier, or stale (byte-mismatched) manifests. * Does not run blob GC or VACUUM -- that stays a separate, later, operator-invoked step (storage/raw_retention.py). Audit requested alongside this actuator: whether the raw-authority census/blocker ledger (raw_authority_censuses/_plans/_blockers/ _census_post_plans, RawAuthorityReconciler) becomes redundant now that a mechanical path exists for the historical backlog. Evidence gathered (grep for every call site, plus `git log` on the touched files) says no: `daemon/convergence_stages.py:916` calls `polylogue.product.raw_authority.repair_materialization` on every live convergence pass; `auto_resolve_stale_plan_blockers` (polylogue-d7im, merged days ago) already auto-clears one blocker class from that same daemon loop; `resolve_blocker`/`list_blockers` remain the operator resolution path for genuine cross-route-collision ambiguity this actuator explicitly does not attempt to resolve; and the census/blocker machinery has had 15+ merged PRs in the last few weeks (up to #3559) including crash-recovery and conservation proofs this session did not re-derive. This actuator is a narrow, independent side channel for the historical "bytes are still on disk" backlog; it does not replace the forward-going per-ingest census/blocker mechanism. Nothing in that subsystem was removed in this change -- see the PR body for the full evidence trail. Verification: `devtools test tests/unit/maintenance/test_raw_live_source_reconciliation_apply.py tests/unit/storage/test_live_source_reconciliation.py` (11 passed) proves: dry-run makes zero mutations; --apply promotes exactly the two safe verdicts (exact_match, codex_header_strip_match) and leaves diverged/source_missing rows untouched; applying without a backup manifest is refused before any mutation; an invalid/stale backup manifest is refused the same way. `devtools verify --quick` (format, lint, mypy, render-all-check, topology/layering/schema-versioning policy checks) is clean. Built and proven entirely against synthetic fixture archives, never run against the production archive. Ref polylogue-u19l Co-Authored-By: Claude <[email protected]>
…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
Fixes the census/plan-ledger side of the raw-authority obligation-guard defect:
prune_raw_authority_census_history's per-census plan-row window (RAW_AUTHORITY_CENSUS_PLAN_RETENTION) no longer stays permanently pinned by a structurally-unresolvable blocker. Census headers keep their guard (a real FK), plan-row detail now prunes on the ordinary retention window regardless of blocker state.Problem
polylogue-z7koandpolylogue-f4z9describe the same mechanism from two angles:raw_authority_census_plans/raw_authority_census_post_plans(a durablesource.dbtier) grew ~100k rows/hour, reaching 709,264 rows and ~870 MiB, with only 41 of the ~112 most recent censuses (sequence 820-932) holding plan rows at all — far more thanRAW_AUTHORITY_CENSUS_PLAN_RETENTION=8should allow.fixed_pointnever reached 1 on any of 256 censuses ever measured.Root cause:
prune_raw_authority_census_history's plan-row window required every blocker attached to a census to be resolved before that census'sraw_authority_census_plans/_post_plansrows could be dropped. The dominant blocker reason ("accepted raw authority remains quarantined pending exact refinement proof", ~4,400 rows) is a structurally permanent fact about a raw's own data — nothing about it changes between census passes, so it never resolves. Continuous live ingestion keeps producing new instances of this same permanent obligation; each one anchors whichever census first observed it, and that census's entire plan-row snapshot stays pinned forever. Over time more and more censuses accumulate this pin, which is why the guard eventually stopped bounding growth at all despite existing.I verified this is a genuinely separate exception from
polylogue-wkc6(PR #3530, already merged): that PR fixed pruning of orphanedraw_authority_plansrows (plans no census references at all). This PR's guard is a different code path in the same function — the per-census plan-row retention window itself refusing to advance while any attached blocker is open, whichwkc6did not touch.I also checked
polylogue-u19l(PR #3539, merged,live_source_reconciliation.py): that module is a read-only classifier overraw_sessions.revision_authority='quarantined', entirely separate from theraw_authority_blockers/census obligation mechanism this bug lives in — it never marks a blocker resolved and isn't wired to this guard. It is not usable to unblock this issue's plans, because the underlying obligation here is not "unproven," it's provably permanent (see_strategy_overrides' ineligible branch inraw_reconciler.py, from the already-merged PR #3466).Solution
polylogue/storage/raw_authority.py,prune_raw_authority_census_history:raw_authority_census_plans/_post_plans) now deletes purely by thesequence_noretention floor, unconditionally. A blocker's ownexpected_json/observed_jsoncolumns already carry a complete, self-contained snapshot of the plan and its evidence (written by_reconcile_frontier_obligations), andresolve_raw_authority_blockerreads that plus the census-independentraw_authority_planstable — neverraw_authority_census_plans/_post_plans. So gating this window on blocker resolution bought nothing but the unbounded pin.raw_authority_censuses) keeps its existing guard unchanged:raw_authority_blockershas a real foreign key oncensus_id, so a header can only be dropped once nothing references it.No schema/DDL change:
source.db's table definitions are untouched, this is a behavior-only fix to an existing maintenance routine that already runs inside every census-recording transaction.What's intentionally out of scope
polylogue-u19l's territory, already addressed there.RawAuthorityReconcilerrewrite (polylogue-lkrc/hjpx/yla8) remains explicitly gated on separate operator authorization._reconcile_frontier_obligations's blocker-insert path at all: I initially suspectedblocker_idbeing keyed on(census_id, plan_id)caused duplicate unresolved rows per pass, but a pre-existing partial unique index (idx_raw_authority_blockers_open_planonplan_id WHERE resolved_at_ms IS NULL) already prevents that — there is exactly one unresolved blocker row perplan_id, always. That hypothesis was wrong; I reverted the speculative change once I found the index and re-diagnosed against the actual mechanism above.Verification
New test
test_census_plan_rows_prune_past_retention_even_with_an_unresolved_blockerplants a durable, permanently-unresolved blocker on the first of nine census passes and asserts: the blocker itself is never silently marked resolved; its census header survives (the real FK); its plan-row detail prunes to the retention window like any other census's. Confirmed this test fails against the pre-fix code (assert 'census:1:...' not in {...}— the first census's rows were still present after 8 more passes) and passes after.10 pre-existing failures in
test_raw_authority_ledger.pyare unchanged before and after this diff (verified against both the pre-fix and post-fix tree) — an unrelated_write_codex_rawtest-fixture regression where an empty-text message is now rejected by dispatch ("no messages, no positive conversational evidence"). Not touched by this PR; filing a follow-up bead is worth doing separately.Ref polylogue-z7ko
Ref polylogue-f4z9