Skip to content

feat(storage): add actuator to promote live-source-verified quarantined raws - #3568

Merged
Sinity merged 2 commits into
masterfrom
feature/storage/raw-live-source-reconciliation-apply
Aug 2, 2026
Merged

Sinity merged 2 commits into
masterfrom
feature/storage/raw-live-source-reconciliation-apply

Conversation

@Sinity

@Sinity Sinity commented Aug 2, 2026

Copy link
Copy Markdown
Owner

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

@coderabbitai

coderabbitai Bot commented Aug 2, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

@Sinity, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 48 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 0b42ea11-a00e-4355-b629-da223302d285

📥 Commits

Reviewing files that changed from the base of the PR and between 66126d2 and 1bea119.

📒 Files selected for processing (10)
  • .beads/issues.jsonl
  • devtools/command_catalog.py
  • devtools/raw_live_source_reconciliation_apply.py
  • docs/devtools.md
  • docs/plans/topology-target.yaml
  • polylogue/maintenance/raw_live_source_reconciliation_apply.py
  • polylogue/storage/live_source_reconciliation.py
  • polylogue/storage/sqlite/archive_tiers/source.py
  • polylogue/storage/sqlite/migrations/source/017_raw_live_source_reconciliation_receipts.sql
  • tests/unit/maintenance/test_raw_live_source_reconciliation_apply.py

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sinity added a commit that referenced this pull request Aug 2, 2026
… u19l

Appends the PR #3568 implementation summary, the requested raw-authority
ledger dead-weight audit findings, and the operator-supervised live-apply
follow-up steps to polylogue-u19l's notes.

Co-Authored-By: Claude <[email protected]>
Sinity and others added 2 commits August 2, 2026 17:23
…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]>
… u19l

Appends the PR #3568 implementation summary, the requested raw-authority
ledger dead-weight audit findings, and the operator-supervised live-apply
follow-up steps to polylogue-u19l's notes.

Co-Authored-By: Claude <[email protected]>
@Sinity
Sinity force-pushed the feature/storage/raw-live-source-reconciliation-apply branch from 4404a9a to 1bea119 Compare August 2, 2026 15:26
@Sinity
Sinity merged commit 8cac6b8 into master Aug 2, 2026
2 of 3 checks passed
@Sinity
Sinity deleted the feature/storage/raw-live-source-reconciliation-apply branch August 2, 2026 15:27
Sinity added a commit that referenced this pull request Aug 2, 2026
…3573)

## Summary
PR #3566 and PR #3568 (developed concurrently in separate worktrees during a merge-train session) both claimed source-tier migration number 017 with `SOURCE_SCHEMA_VERSION` left at 17. The rebase merged clean at the file level (distinct new files, no textual conflict), but `migration_runner.py`'s `_load_migrations()` hard-fails with `MigrationError` on duplicate version numbers.

## Problem
Reproduced live immediately after both PRs landed on master:
```
MigrationError duplicate source migration versions: [2, 3, ..., 16, 17, 17]
```
Any real `migrate_archive_tier(ArchiveTier.SOURCE, ...)` call — daemon startup against an older archive, `polylogue ops backup`, schema commit — would hit this the moment it actually ran. Caught during merge-train verification, before any live use.

## Solution
- Renamed `017_raw_live_source_reconciliation_receipts.sql` to `018_*`.
- Bumped `SOURCE_SCHEMA_VERSION` 17 → 18 (`archive_tiers/source.py`).
- Fixed `test_durable_migrations.py`'s now-stale `applied_versions`/`to_version` assertions.
- `test_source_publication_backfill_requires_verified_backup` simulated a v9 archive by dropping tables but not the `revision_authority_evidence` column (since `workspace_env` bootstraps via current canonical DDL, which already includes it) — added the missing `ALTER TABLE raw_sessions DROP COLUMN revision_authority_evidence` so the fixture actually represents a pre-v18 archive; without it migration 018's own `ADD COLUMN` failed with "duplicate column name".
- `docs/schema.md`'s hand-maintained `SOURCE_SCHEMA_VERSION` reference line.

## Verification
```
devtools test tests/unit/storage/test_durable_migrations.py tests/unit/maintenance/test_raw_live_source_reconciliation_apply.py tests/unit/storage/test_raw_authority_ledger.py
# 85 passed
devtools verify --quick
# exit 0
```
Reproduced the pre-fix crash directly: `_load_migrations(ArchiveTier.SOURCE)` raised `MigrationError` before this fix, loads cleanly (18 steps) after.
Sinity added a commit that referenced this pull request Aug 2, 2026
Sinity added a commit that referenced this pull request Aug 2, 2026
Problem: CircleCI's quick-gate job hand-picked five discrete steps
(render-all-check, ruff check, ruff format, mypy) as a stand-in for
`devtools verify --quick`, per its own header comment. That subset had
drifted from the real thing: devtools/verify.py's default `if not commit:`
block has grown to ~17 steps over time (topology/layering/closure-matrix,
lab schema roundtrip, manifests, ci-workflows, doc-commands,
docs-coverage, test-infra-currency, pytest-timeout-overrides,
degrade-loudly, hash-boundary-census, schema-versioning,
classifier-fingerprints, schema promotion audit, and now
demo-tour-freshness), none of which quick-gate ever ran. The
schema-versioning check specifically was wired only into
.github/workflows/ci.yml, a GitHub Actions workflow that does not
execute (GHA is billing-locked; CircleCI is the only live CI in this
repo) -- so the migration-number collision behind PR #3566/#3568 that
made the live archive briefly unqueryable (fixed by hand in PR #3573)
would not have been caught by any CI that actually ran, despite
appearing "CI-gated" in ci.yml. See polylogue-ze5i.

What changed: replaced the four hand-picked ruff/mypy/render-all steps
with a single `devtools verify --quick` call, which is the real superset
and self-heals going forward -- any future step added to build_verify_steps'
default block is automatically covered without a matching CircleCI edit.
`devtools verify public-claims --json` stays separate since it is not
part of that default block. Added a `lab-policies` job, wired into the
existing nightly scheduled workflow alongside full-suite, running the
7 `lab policy *` checks that remain intentionally --lab-only
(timestamp-doctrine, insight-honesty, demo-packet-registry, docs-drift,
campaign-archive-boundaries, backlog-hygiene, bead-graph) so a
continuously-failing policy is at least visible on a schedule instead of
reachable only via a human remembering `devtools verify --lab`. Each
step uses `when: always` so backlog-hygiene/bead-graph's known
pre-existing backlog debt (485 findings / 225 missing-AC beads) does not
mask a regression in one of the other five checks in the same job.

Verification: reintroduced the exact migration-number-collision shape
(bumped INDEX_SCHEMA_VERSION without a lifecycle.py delta declaration)
and confirmed `devtools verify --quick` -- the command now wired into
quick-gate -- fails with "Policy violation: each index schema bump needs
a declared delta class"; reverted. Also confirmed demo-tour-freshness
catches injected drift in docs/examples/demo-tour/report.json; reverted.
`python -c "import yaml; yaml.safe_load(open('.circleci/config.yml'))"`
parses cleanly; `devtools verify ci-workflows` passes (pre-existing
unrelated warning on .github/workflows/ci.yml, not touched here).

Ref polylogue-ze5i

Co-Authored-By: Claude <[email protected]>
Sinity added a commit that referenced this pull request Aug 2, 2026
…_verify_steps (#3587)

## Summary

Closes the gate-placement question in polylogue-ze5i for all 10
`devtools lab policy *` checks. Promotes `demo-tour-freshness`
(previously red) into the default verify gate alongside
`schema-versioning`/`classifier-fingerprints`, fixes CircleCI's
`quick-gate` job so it actually runs that gate instead of a stale
hand-picked subset, and wires the remaining 7 `--lab`-only checks into a
new nightly CircleCI job so a continuously-failing policy is at least
visible.

## Problem

Measured 2026-07-28 (polylogue-ze5i): schema-versioning,
demo-tour-freshness, backlog-hygiene, and bead-graph all sat behind
`devtools verify --lab`, which no standing gate runs. A migration-number
collision (PR #3566/#3568) made the live archive briefly unqueryable and
was only caught by hand afterward (PR #3573).

A prior session moved `schema-versioning` (and
`classifier-fingerprints`) out of `--lab` into `devtools/verify.py`'s
default `if not commit:` block. But investigating further this session
found that promotion was hollow in practice: CircleCI's `quick-gate` job
-- the only CI that actually runs in this repo (GitHub Actions is
billing-locked/dark; `.github/workflows/ci.yml` references
`schema-versioning` but does not execute) -- hand-picked five discrete
steps (`render all --check`, `public-claims`, ruff, mypy) instead of
calling `devtools verify --quick`. None of `verify topology`/`verify
layering`/`schema-versioning`/`classifier-fingerprints`/`schema
promotion audit`/etc. (~17 steps total) ever ran in live CI.

`demo-tour-freshness` itself was red: the committed
`docs/examples/demo-tour/` fixture was missing a `healed_tiers` key the
demo receipts code had already grown.

## Solution

- `devtools/verify.py`: moved `lab policy demo-tour-freshness` from the
`if lab:` block into the default `if not commit:` block, with a comment
on why it's safe to gate every push (deterministic -- wall-clock timing
already masked before comparison -- and fixed-cost against one committed
fixture, unlike the corpus-scanning `backlog-hygiene`/`bead-graph`).
Added an explanatory comment on why those two stay `--lab`-only.
- `docs/examples/demo-tour/`: regenerated via `polylogue demo tour
--out-dir polylogue-demo-tour --force` and copied the fresh evidence in,
fixing the drift.
- `.circleci/config.yml`: replaced `quick-gate`'s four hand-picked steps
with a single `devtools verify --quick` call (public-claims stays
separate since it isn't part of that block) -- this self-heals going
forward, since any future addition to `build_verify_steps`' default
block is automatically covered without a matching CircleCI edit. Added a
`lab-policies` job wired into the existing nightly scheduled workflow,
running the 7 checks that remain intentionally `--lab`-only
(`timestamp-doctrine`, `insight-honesty`, `demo-packet-registry`,
`docs-drift`, `campaign-archive-boundaries`, `backlog-hygiene`,
`bead-graph`), each step using `when: always` so the two known-red
corpus-scan checks don't mask a regression in the other five.
- `tests/unit/devtools/test_verify.py`: fixed
`test_quick_verify_omits_pytest`'s hardcoded step list, which was
already failing on master before this change (missing
`classifier-fingerprints`, added in an earlier PR without a matching
test update).
- Filed polylogue-2bp5f (485 backlog-hygiene findings) and
polylogue-83nhi (225 beads missing acceptance criteria) to track the
corpus-wide debt those two checks report, since fixing it is out of
scope for a gate-placement change.
- Closed polylogue-ze5i with the full per-policy classification table
and rationale.

## Verification

- `devtools test tests/unit/devtools/test_verify.py` -- 88 passed.
- `devtools verify --quick` -- green end-to-end, ~90-105s total.
- Anti-vacuity: reintroduced the exact migration-number-collision shape
(`INDEX_SCHEMA_VERSION` bump with no `lifecycle.py` delta declaration)
and confirmed `devtools verify --quick` -- the exact command now wired
into CircleCI's `quick-gate` -- fails with `Policy violation: each index
schema bump needs a declared delta class`; reverted.
- Anti-vacuity: injected drift into
`docs/examples/demo-tour/report.json` and confirmed `devtools lab policy
demo-tour-freshness` catches it; reverted.
- `python -c "import yaml;
yaml.safe_load(open('.circleci/config.yml'))"` parses cleanly; `devtools
verify ci-workflows` passes (one pre-existing, unrelated warning on
`.github/workflows/ci.yml`, not touched here).

Not run: the actual CircleCI pipeline (can't trigger from here) --
verified locally that the exact command it now calls (`devtools verify
--quick`) behaves as claimed.

Ref polylogue-ze5i

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Bug Fixes**
- Verification now includes additional policy checks, improving
detection of stale demo content and classification issues.
- Nightly validation now covers the complete policy-check suite,
including known backlog items.

- **Documentation**
- Refreshed demo-tour examples with current manifest identifiers, timing
data, output sizes, and report metadata.
- Updated recorded transcripts and reports while preserving command
results and exit statuses.

- **Tests**
- Updated verification expectations to reflect the expanded quick-check
coverage.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant