Skip to content

feat(ops): fast-forward index v36 without raw replay - #2931

Merged
Sinity merged 11 commits into
masterfrom
feature/ops/index-v37-fast-forward
Jul 16, 2026
Merged

Sinity merged 11 commits into
masterfrom
feature/ops/index-v37-fast-forward

Conversation

@Sinity

@Sinity Sinity commented Jul 16, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds a proof-gated clone-first index v36→v37 actuator for the exact schema transition that retires three run-projection cache tables. It preserves the active v36 generation as rollback and avoids replaying 52,066 raw rows / 74.7 GB.

Problem

The documented blanket derived-tier rebuild spent about 86 seconds of one CPU core before writing its first session and would reread 74.7 GB, even though v37 changes no surviving schema object. Current master cannot run against the live v36 index, blocking deployment of the browser-capture reliability repair.

Solution

  • Add devtools workspace index-v37-fast-forward prepare|activate.
  • Reflink-clone the stopped active generation under the archive rebuild lease.
  • Fail unless v36 is exactly canonical v37 plus the three retired cache tables and their indexes.
  • Drop only those tables in the inactive clone and advance user_version transactionally.
  • Prove canonical schema equality, every surviving table count, quick-check, foreign keys, source snapshot stability, active-file identity, owned generation state, and receipt integrity before atomic promotion.
  • Preserve the previous active generation through IndexGenerationStore rollback retention.

Ref polylogue-n3an

Verification

  • devtools test tests/unit/devtools/test_index_v37_fast_forward.py → 4 passed in 18.94s.
  • devtools verify --quick → all 16 checks passed; run 20260716T100223Z-quick-111389-3f295a18.
  • Pre-push devtools verify --quick → all checks passed; run 20260716T100312Z-quick-113641-65d7e0ab.

Summary by CodeRabbit

  • New Features
    • Added a workspace devtools command and CLI to upgrade an index from v36 to v37 via a validated clone-forward process (separate prepare/activate steps).
    • Includes receipt-based safety checks to ensure integrity before activation.
  • Bug Fixes
    • Improved attachment write and dependent-deletion handling to avoid stale attachment_native_ids when bulk operations affect foreign key enforcement.
  • Documentation
    • Documented the new workspace command.
  • Tests
    • Added unit coverage for prepare/activate success and failure cases, plus attachment and lineage normalization regression scenarios.

Index v37 only retires three derived run-projection cache tables, but the
blanket rebuild path replays 74.7 GB of unchanged raw evidence. Add a
clone-first, receipt-backed actuator that proves the exact v36 schema surplus,
preserves every surviving table count, validates foreign keys and quick-check,
and promotes through the owned generation lifecycle.

Ref polylogue-n3an

Co-Authored-By: Claude <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 16, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

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

Next review available in: 44 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

Run ID: 84de1a4c-9fa5-4ee7-823c-29c797168162

📥 Commits

Reviewing files that changed from the base of the PR and between 1b4b63d and 145b9d1.

📒 Files selected for processing (3)
  • devtools/index_v37_fast_forward.py
  • tests/unit/devtools/test_index_v37_fast_forward.py
  • tests/unit/storage/test_lineage_normalization.py
📝 Walkthrough

Walkthrough

Adds a clone-first CLI workflow that advances a Polylogue SQLite index from schema v36 to v37 by removing retired caches, validating evidence, writing receipts, and promoting the prepared generation. It also cleans stale attachment mappings during writes and lineage re-extraction.

Changes

Index v37 Fast-Forward and Attachment Cleanup

Layer / File(s) Summary
Schema proof and preflight safeguards
devtools/index_v37_fast_forward.py
Adds receipt hashing, SQLite schema and integrity inspection, daemon and sidecar checks, and exact validation of the permitted v36 schema surplus.
Clone transformation and preparation
devtools/index_v37_fast_forward.py
Creates an inactive clone, repairs orphan attachment mappings, removes retired cache tables, sets user_version to 37, validates the clone, and records prepared evidence.
Activation, CLI wiring, and migration validation
devtools/index_v37_fast_forward.py, devtools/command_catalog.py, docs/devtools.md, tests/unit/devtools/test_index_v37_fast_forward.py
Revalidates and promotes prepared generations, exposes and documents prepare and activate, and tests successful, rejected, and recoverable workflows.
Attachment mapping cleanup and lineage regressions
polylogue/storage/sqlite/archive_tiers/write.py, tests/unit/storage/test_lineage_normalization.py
Removes stale native-id mappings during attachment replacement and dependent-row deletion, with regression coverage for creation and cleanup.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Operator
  participant FastForwardCLI
  participant SQLiteIndex
  participant GenerationStore
  Operator->>FastForwardCLI: run prepare
  FastForwardCLI->>SQLiteIndex: validate v36 and capture evidence
  FastForwardCLI->>GenerationStore: create and clone inactive generation
  FastForwardCLI->>SQLiteIndex: repair mappings, retire caches, set v37
  FastForwardCLI-->>Operator: print prepared receipt
  Operator->>FastForwardCLI: run activate
  FastForwardCLI->>GenerationStore: revalidate and promote generation
  FastForwardCLI-->>Operator: print activated receipt
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: fast-forwarding v36 indexes without raw replay.
Description check ✅ Passed The description covers Summary, Problem, Solution, and Verification well, but omits the template's Changelog and Risks/Follow-ups sections.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/ops/index-v37-fast-forward

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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7366b18ac7

ℹ️ 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".

Comment thread devtools/index_v37_fast_forward.py Resolved
Comment thread devtools/index_v37_fast_forward.py Resolved
Sinity added 2 commits July 16, 2026 12:07
A cleanly stopped daemon may leave committed pages in the active index WAL. The schema-forward actuator previously rejected that valid state before it could establish clone evidence.\n\nCheckpoint and truncate the stopped database under the rebuild lease, then retain the existing strict sidecar and schema checks. Cover the production failure shape with a focused actuator test.\n\nRef polylogue-n3an.\n\nCo-Authored-By: Claude <[email protected]>
SQLite can retain a non-empty shared-memory sidecar after the final writer exits even when WAL checkpointing completed successfully. Treat the checkpoint tuple as the proof boundary and remove WAL/SHM coordination files only after a complete checkpoint under the stopped-daemon rebuild lease.\n\nExercise the observed non-empty SHM residue in the actuator test.\n\nRef polylogue-n3an.\n\nCo-Authored-By: Claude <[email protected]>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@devtools/index_v37_fast_forward.py`:
- Around line 49-52: Update _normalize_ddl so schema comparisons preserve SQL
token boundaries and whitespace within string literals instead of removing all
whitespace and quoting. Prefer comparing structured PRAGMA metadata; otherwise
tokenize the DDL while retaining identifiers, literals, and token boundaries,
and ensure both preflight and postflight use the safer comparison.
- Around line 292-319: Update the activation flow around RebuildLease and
store.promote to call IndexGenerationStore.recover_promotion() after loading the
generation, allowing interrupted promoting states to resume. When the receipt is
still prepared but its verified generation is already the active pointer,
finalize the receipt metadata without attempting a second promotion; preserve
the existing ownership, state, snapshot, identity, schema, and count
validations, and add coverage for interruptions before metadata completion and
after promotion before receipt persistence.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 4a104aac-a488-467e-9c22-344e366c057e

📥 Commits

Reviewing files that changed from the base of the PR and between d2573d4 and 6ac3fa2.

📒 Files selected for processing (4)
  • devtools/command_catalog.py
  • devtools/index_v37_fast_forward.py
  • docs/devtools.md
  • tests/unit/devtools/test_index_v37_fast_forward.py

Comment thread devtools/index_v37_fast_forward.py Resolved
Comment thread devtools/index_v37_fast_forward.py Resolved
Sinity added 5 commits July 16, 2026 12:23
Persist activation intent before promotion and reconcile interrupted pointer swaps through IndexGenerationStore recovery. Bind the prepared receipt to the clone's exact bytes and canonical schema so count-preserving in-place mutations cannot be promoted.\n\nReuse the completed prepare proof during activation instead of repeating full integrity and row-count scans; exact byte identity is the activation boundary.\n\nRef polylogue-n3an.\n\nCo-Authored-By: Claude <[email protected]>
Prove the v36-to-v37 drop-only transition with zero DML changes and stable root-page identities for every surviving table and index. Retain one final integrity and foreign-key pass, exact canonical DDL, and byte identity while removing full pre/post table-count scans.\n\nRecord active evidence, reflink, postflight, hash, and total phase timings in the receipt so maintenance cost is observable.\n\nRef polylogue-n3an. Ref polylogue-6mvg.\n\nCo-Authored-By: Claude <[email protected]>
The live index intentionally carries safe runtime index extensions outside the base INDEX_DDL. Build the exact v37 target schema from both the canonical DDL and the runtime index registry, and make the v36 fixture reflect the same production initialization path.\n\nRef polylogue-n3an.\n\nCo-Authored-By: Claude <[email protected]>
Bulk ingest can suspend foreign-key enforcement while FTS triggers are dropped. The manual lineage cleanup removed attachment refs but left their native-id children behind, producing 1,108 live FK violations in the derived index.\n\nDelete native identifiers explicitly before prefix/session ref cleanup and ref replacement. Repair the existing orphan set only in the inactive v37 clone, recording the exact repaired count before full integrity verification.\n\nRef polylogue-n3an.\n\nCo-Authored-By: Claude <[email protected]>
A completed production foreign-key scan showed every live violation belonged to the orphan attachment-native-id relation. For the drop-only forward, prove no surviving FK targets a retired table, preserve every surviving root page, and validate the repaired child relation directly.\n\nKeep the full physical quick check and exact-byte identity while avoiding a logically redundant archive-wide FK rescan.\n\nRef polylogue-n3an. Ref polylogue-6mvg.\n\nCo-Authored-By: Claude <[email protected]>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@devtools/index_v37_fast_forward.py`:
- Around line 343-360: The activation flow around recover_promotion and the
active-state branch must preserve an already-activated receipt as immutable
historical evidence. When the existing receipt is already activated, return it
unchanged without refreshing generation, active_identity_after, or
activated_at_ms; only update and write the receipt when recovering an activating
state.

In `@tests/unit/storage/test_lineage_normalization.py`:
- Around line 754-765: Add an assertion in the test flow after the parent is
written and the child’s prefix is extracted or deleted, verifying that the
attachment_native_ids table count drops from one to zero. Anchor the assertion
to the existing write_parsed_session_to_archive and child-prefix cleanup logic,
preserving the current insertion-count assertion.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: d89fa616-69af-4510-9b54-6658e1187ce4

📥 Commits

Reviewing files that changed from the base of the PR and between 6ac3fa2 and 1b4b63d.

📒 Files selected for processing (4)
  • devtools/index_v37_fast_forward.py
  • polylogue/storage/sqlite/archive_tiers/write.py
  • tests/unit/devtools/test_index_v37_fast_forward.py
  • tests/unit/storage/test_lineage_normalization.py

Comment thread devtools/index_v37_fast_forward.py Resolved
Sinity added 3 commits July 16, 2026 14:16
Fail before checkpointing or cloning the production index when the requested receipt cannot be written atomically. This prevents a long proof run from being discarded only at its final persistence step.\n\nAdd a regression proving an invalid receipt parent creates no generation and never reaches active-index checkpointing.\n\nRef polylogue-n3an.\n\nCo-Authored-By: Claude <[email protected]>
An already-activated receipt could be rewritten against later database state, corrupting the historical activation proof. Schema comparison also erased token and literal boundaries while normalizing DDL.\n\nReturn completed receipts unchanged and tokenize SQLite DDL while preserving identifier, literal, numeric, and operator boundaries. Cover both invariants with focused regressions.\n\nCo-Authored-By: Claude <[email protected]>
The child-before-parent lineage regression inserted an attachment mapping but did not assert its removal after prefix extraction with foreign keys suspended. Add the missing production-route assertion.\n\nCo-Authored-By: Claude <[email protected]>
@Sinity
Sinity merged commit e4be612 into master Jul 16, 2026
2 checks passed
@Sinity
Sinity deleted the feature/ops/index-v37-fast-forward branch July 16, 2026 13:32
Sinity added a commit that referenced this pull request Jul 16, 2026
## Summary

Records the completed and live-activated v36→v37 fast-forward in
`polylogue-n3an`.

## Problem

PR #2931 merged the proof-gated actuator and the live activation
succeeded, but the owning Bead remained in progress. That stale state
made an already-v37 archive appear to need another cutover.

## Solution

Close `polylogue-n3an` with the activated receipt and live-schema
evidence. Keep the ongoing raw-revision CAS retries explicitly separate
in their existing authority work.

## Verification

- `jq` over `/realm/tmp/polylogue-index-v37-fast-forward/receipt.json` →
`status: activated`.
- `PRAGMA user_version` on the live index → `37`.
- Retired-table census → `0`.
- `systemctl --user is-active polylogued.service` → `active`.
- `.agent/scripts/bd-graph-lint` → zero cycles/violations.

Co-authored-by: Codex <[email protected]>
@Sinity

Sinity commented Oct 1, 2026

Copy link
Copy Markdown
Owner Author

Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.

Only the rows listed above are dispositioned. Held findings remain open.

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