Repository navigation
fix(storage): upgrade schema v2 archives in place - #742
Conversation
Problem: schema v3 added the stored message_type facet, but older binaries could leave an otherwise-current archive marked as user_version 2. The current runtime then rejected the DB and scheduled runs could fall back into expensive reimport/catch-up behavior.\n\nWhat changed: add a narrow transactional v2-to-v3 upgrade that adds the message_type column/index, backfills it from existing role/content-block flags, and updates PRAGMA user_version without deleting archive rows. Unsupported versions and legacy raw layouts still block with a reset diagnostic.\n\nVerification: PYTHONPATH=. /realm/project/polylogue/.venv/bin/python -m pytest -q tests/unit/storage/test_backend.py tests/unit/storage/test_schema_safety.py; ruff check/format on changed Python files; git diff --check.\n\nRef #618
Problem: devtools verify --quick failed in clean worktrees because docs-media coverage declared .local/readme-demo/example.tape as a required path. That file is machine-local state, not committed repository evidence.\n\nWhat changed: mark VHS tape coverage as absent from committed sources and document .local/readme-demo as optional local experiment state.\n\nVerification: /realm/project/sinnix/scripts/sinnix-scope build -- nix develop --command devtools verify --quick.
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughThis PR adds support for upgrading SQLite schema from v2 to v3 in place, introducing a new ChangesSchema v2 to v3 In-Place Upgrade
Sequence DiagramsequenceDiagram
actor User
participant Backend as Backend Process
participant Bootstrap as Bootstrap Decision
participant Executor as Upgrade Executor
participant DB as SQLite Connection
User->>Backend: open existing v2 archive
Backend->>Bootstrap: decide_schema_bootstrap(snapshot={current_version:2})
Bootstrap->>Bootstrap: Check version mismatch:<br/>v2 vs SCHEMA_VERSION=3
alt v2 → v3 possible (messages table exists)
Bootstrap->>Bootstrap: build_v2_to_v3_upgrade_plan()
Bootstrap-->>Bootstrap: Return action="upgrade_v2_to_v3"<br/>+ extension_plan
else Unsupported mismatch
Bootstrap-->>Bootstrap: action="version_mismatch"
end
Bootstrap-->>Backend: decision (action, extension_plan)
alt action == "upgrade_v2_to_v3"
Backend->>Executor: _apply_version_upgrade_plan(plan)
Executor->>DB: BEGIN IMMEDIATE
Executor->>DB: ALTER TABLE messages<br/>ADD COLUMN message_type
Executor->>DB: INSERT/UPDATE message_type<br/>via backfill SQL
Executor->>DB: CREATE INDEX<br/>idx_messages_conversation_message_type
Executor->>Executor: ensure_vec0_table()
Executor->>DB: PRAGMA user_version = 3
Executor->>DB: COMMIT
Executor-->>Backend: ✓ upgrade complete
else On failure
Executor->>DB: ROLLBACK
Executor-->>Backend: ✗ exception
end
Backend-->>User: v3 schema ready
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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. Review rate limit: 0/1 reviews remaining, refill in 60 minutes.Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1bc14c8cb1
ℹ️ 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".
Summary Avoids an unnecessary archive-wide message-type backfill when a schema v2 archive already has the v3 `messages.message_type` column. Problem PR #742 added the right v2-to-v3 upgrade path, but the upgrade plan still appended the message-type backfill whenever `messages` existed. That is wasteful for the live failure shape: a physically v3-shaped DB whose `PRAGMA user_version` was rewritten to 2 by an older binary. Running the backfill there would scan the archive even though the column already exists. Solution Only append the message-type backfill when `messages.message_type` is absent. Already-extended v2 archives now repair missing version/index state without rereading all messages/content blocks. Verification - `PYTHONPATH=. /realm/project/polylogue-schema-v2-upgrade/.venv/bin/python -m pytest -q tests/unit/storage/test_backend.py tests/unit/storage/test_schema_safety.py` -> `61 passed in 8.72s` - `PYTHONPATH=. /realm/project/polylogue-schema-v2-upgrade/.venv/bin/ruff check polylogue/storage/backends/schema_bootstrap.py tests/unit/storage/test_backend.py` -> `All checks passed!` - `PYTHONPATH=. /realm/project/polylogue-schema-v2-upgrade/.venv/bin/ruff format --check polylogue/storage/backends/schema_bootstrap.py tests/unit/storage/test_backend.py` -> `2 files already formatted` - `git diff --check` - Pre-push hook under the Polylogue devshell -> `verify: all checks passed` Ref #618
Summary Adds a narrow in-place schema v2 to v3 upgrade for the additive `messages.message_type` archive facet, and fixes a broken devtools manifest gate that required untracked `.local` demo state. Problem A live archive can be physically compatible with schema v3 while carrying `PRAGMA user_version = 2` after an older binary rewrites only the version marker. Current schema bootstrap then rejects the database and scheduled runs can drift into expensive reimport/catch-up behavior instead of applying the small additive delta. The publish gate was also not reproducible in clean worktrees: `docs/plans/docs-media-coverage.yaml` required `.local/readme-demo/example.tape`, which is machine-local state and not committed evidence. Solution - Add a transactional v2-to-v3 upgrade path that adds `messages.message_type`, creates `idx_messages_conversation_message_type`, backfills message types from existing role/content-block flags, and updates `PRAGMA user_version` without deleting archive rows. - Keep unsupported schema versions and legacy raw layouts rejected with the reset/re-import diagnostic. - Update architecture/assurance docs and changelog to describe the explicit-upgrade posture. - Mark VHS tape coverage as absent from committed sources instead of requiring `.local/readme-demo`. Verification - `PYTHONPATH=. /realm/project/polylogue/.venv/bin/python -m pytest -q tests/unit/storage/test_backend.py tests/unit/storage/test_schema_safety.py` -> `60 passed in 8.31s` - `PYTHONPATH=. /realm/project/polylogue/.venv/bin/ruff check polylogue/storage/backends/schema.py polylogue/storage/backends/schema_bootstrap.py tests/unit/storage/test_backend.py tests/unit/storage/test_schema_safety.py` -> `All checks passed!` - `PYTHONPATH=. /realm/project/polylogue/.venv/bin/ruff format --check polylogue/storage/backends/schema.py polylogue/storage/backends/schema_bootstrap.py tests/unit/storage/test_backend.py tests/unit/storage/test_schema_safety.py` -> `4 files already formatted` - `git diff --check` - `/realm/project/sinnix/scripts/sinnix-scope build -- nix develop --command devtools verify --quick` -> `verify: all checks passed` - Pre-push hook under the Polylogue devshell -> `verify: all checks passed` Ref #618
Summary Avoids an unnecessary archive-wide message-type backfill when a schema v2 archive already has the v3 `messages.message_type` column. Problem PR #742 added the right v2-to-v3 upgrade path, but the upgrade plan still appended the message-type backfill whenever `messages` existed. That is wasteful for the live failure shape: a physically v3-shaped DB whose `PRAGMA user_version` was rewritten to 2 by an older binary. Running the backfill there would scan the archive even though the column already exists. Solution Only append the message-type backfill when `messages.message_type` is absent. Already-extended v2 archives now repair missing version/index state without rereading all messages/content blocks. Verification - `PYTHONPATH=. /realm/project/polylogue-schema-v2-upgrade/.venv/bin/python -m pytest -q tests/unit/storage/test_backend.py tests/unit/storage/test_schema_safety.py` -> `61 passed in 8.72s` - `PYTHONPATH=. /realm/project/polylogue-schema-v2-upgrade/.venv/bin/ruff check polylogue/storage/backends/schema_bootstrap.py tests/unit/storage/test_backend.py` -> `All checks passed!` - `PYTHONPATH=. /realm/project/polylogue-schema-v2-upgrade/.venv/bin/ruff format --check polylogue/storage/backends/schema_bootstrap.py tests/unit/storage/test_backend.py` -> `2 files already formatted` - `git diff --check` - Pre-push hook under the Polylogue devshell -> `verify: all checks passed` Ref #618
|
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. |
Summary
Adds a narrow in-place schema v2 to v3 upgrade for the additive
messages.message_typearchive facet, and fixes a broken devtools manifest gate that required untracked.localdemo state.Problem
A live archive can be physically compatible with schema v3 while carrying
PRAGMA user_version = 2after an older binary rewrites only the version marker. Current schema bootstrap then rejects the database and scheduled runs can drift into expensive reimport/catch-up behavior instead of applying the small additive delta.The publish gate was also not reproducible in clean worktrees:
docs/plans/docs-media-coverage.yamlrequired.local/readme-demo/example.tape, which is machine-local state and not committed evidence.Solution
messages.message_type, createsidx_messages_conversation_message_type, backfills message types from existing role/content-block flags, and updatesPRAGMA user_versionwithout deleting archive rows..local/readme-demo.Verification
PYTHONPATH=. /realm/project/polylogue/.venv/bin/python -m pytest -q tests/unit/storage/test_backend.py tests/unit/storage/test_schema_safety.py->60 passed in 8.31sPYTHONPATH=. /realm/project/polylogue/.venv/bin/ruff check polylogue/storage/backends/schema.py polylogue/storage/backends/schema_bootstrap.py tests/unit/storage/test_backend.py tests/unit/storage/test_schema_safety.py->All checks passed!PYTHONPATH=. /realm/project/polylogue/.venv/bin/ruff format --check polylogue/storage/backends/schema.py polylogue/storage/backends/schema_bootstrap.py tests/unit/storage/test_backend.py tests/unit/storage/test_schema_safety.py->4 files already formattedgit diff --check/realm/project/sinnix/scripts/sinnix-scope build -- nix develop --command devtools verify --quick->verify: all checks passedverify: all checks passedRef #618
Summary by CodeRabbit
New Features
Documentation
Tests