Repository navigation
fix(storage): upgrade v7 archives to schema v8 - #850
Conversation
Problem: #847 bumped the archive schema to v8 when the legacy runs ledger was removed, but the declared in-place upgrade set still stopped at v6->v7. Existing production v7 archives were rejected by the daemon after deploy.\n\nWhat changed: add the narrow v7->v8 upgrade plan that drops the retired runs index/table, include that final step in older upgrade chains, and allow both sync and async schema bootstrap paths to execute the new action.\n\nVerification: ruff format --check polylogue/storage/sqlite/schema.py polylogue/storage/sqlite/schema_bootstrap.py tests/unit/storage/test_backend.py; ruff check polylogue/storage/sqlite/schema.py polylogue/storage/sqlite/schema_bootstrap.py tests/unit/storage/test_backend.py; mypy --strict polylogue/storage/sqlite/schema.py polylogue/storage/sqlite/schema_bootstrap.py tests/unit/storage/test_backend.py; pytest tests/unit/storage/test_backend.py tests/unit/storage/test_provider_events_schema.py -q; devtools verify.
|
Caution Review failedPull request was closed or merged during review No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis PR adds a new schema upgrade path (v7 to v8) that removes a retired batch-run ledger by dropping the ChangesSchema Upgrade Path v7→v8
Sequence DiagramsequenceDiagram
participant DB as SQLite Database
participant Bootstrap as Schema Bootstrap
participant Executor as Schema Upgrade Executor
participant Verify as Verification
DB->>Bootstrap: Check current schema version (v7)
Bootstrap->>Bootstrap: Determine upgrade path (v7→v8)
Bootstrap->>Executor: build_v7_to_v8_upgrade_plan()
Executor-->>Bootstrap: [DROP TABLE runs, DROP INDEX idx_runs_timestamp]
Bootstrap->>DB: Execute upgrade statements
DB->>DB: Remove runs table & index
DB-->>Executor: Upgrade complete (now v8)
Executor->>Verify: Confirm runs table absent
Verify-->>Executor: ✓ Upgrade successful
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly Related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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. Comment |
There was a problem hiding this comment.
Pull request overview
Adds the missing SQLite archive upgrade step from schema v7 to v8 so existing production archives can be opened by runtimes expecting schema v8 (post-#847 removal of the legacy batch-run ledger).
Changes:
- Introduces a v7→v8 upgrade plan that drops the retired
runstable andidx_runs_timestampindex. - Wires the new upgrade action into both sync (
_ensure_schema) and async (ensure_schema_async) schema bootstrap/upgrade dispatch. - Adds unit tests that pin (a) v7 archives upgrade in-place to v8 and (b) the v7→v8 migration remains narrowly scoped to the run ledger removal.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
tests/unit/storage/test_backend.py |
Adds regression tests covering v7→v8 in-place upgrade behavior and migration scope. |
polylogue/storage/sqlite/schema.py |
Allows _ensure_schema / ensure_schema_async to execute the new upgrade_v7_to_v8 decision path. |
polylogue/storage/sqlite/schema_bootstrap.py |
Implements build_v7_to_v8_upgrade_plan() and integrates it into upgrade chains and bootstrap decisions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
## Summary Keeps `polylogued status` responsive while the daemon is converging a large archive. ## Problem During the Sinnix deployment of #847/#850, the daemon was healthy and had live attempt state in SQLite, but `polylogued status --format json` exceeded a 30s timeout while convergence was starting. The status path was doing work that scales with archive size or takes deep archive locks: recursive blob-size walking, deep readiness imports, async insight status, and duplicate status probes. ## Solution Make the local daemon status path bounded: blob size is reported as unmeasured `0`, FTS readiness and insight freshness use small read-only SQLite probes, and JSON rendering reuses the typed `DaemonStatus` probe results instead of recomputing them. The live busy-daemon probe that timed out before returned in 1.7s with this branch. Ref #845 ## Verification - `ruff format --check polylogue/daemon/status.py tests/unit/daemon/test_daemon_status.py` - `ruff check polylogue/daemon/status.py tests/unit/daemon/test_daemon_status.py` - `mypy --strict polylogue/daemon/status.py tests/unit/daemon/test_daemon_status.py` - `pytest tests/unit/daemon/test_daemon_status.py -q` → `8 passed in 10.84s` - `.venv/bin/polylogued status --format json` against the live busy daemon → returned in `1.731s` - `devtools verify` → `verify: all checks passed` - pre-push `devtools verify --quick` → `verify: all checks passed`
## Summary Follow-up to the daemon-first #845 work after deploying #847/#850/#851 on the workstation. The live daemon exposed two deployment-scale problems: status payloads became huge with thousands of retryable live cursor failures, and full-ingest attempts could look stale while the worker was actually busy inside storage replacement. The same live run also exposed an unindexed SQLite foreign-key path that made conversation replacement scan millions of provider events. ## Problem During the Sinnix switch, `polylogued status --format json` returned quickly after #851 but emitted thousands of file paths. The active attempt was marked stale in `full_blob_copy`, while `py-spy` showed the daemon was actually in `_process_ingest_batch_sync -> replace_conversation_runtime_state_sync`. The live archive has ~4.0M `provider_events` rows, and `provider_events.source_message_id` referenced `messages(message_id)` without an index, so deleting messages during replacement caused repeated child-table scans and ~91GB of read I/O before I stopped the old service. ## Solution - Bound live cursor file samples in daemon status while preserving exact failed/excluded/retry counts. - Heartbeat full-ingest file scanning, blob materialization, and worker-write handoff with current path and payload-read counters. - Add schema v9 with indexes on `provider_events(source_message_id)` and `attachment_refs(message_id)` so message deletion during replacement has supporting FK indexes; v8 archives upgrade in place. - Split live-batch helper code and the new focused tests out of oversized modules, then refresh topology projections. ## Verification - `ruff check polylogue/sources/live/batch.py polylogue/sources/live/batch_support.py polylogue/storage/sqlite/schema_bootstrap.py tests/unit/sources/test_live_batch_support.py tests/unit/storage/test_schema_upgrades.py tests/unit/sources/test_live_watcher.py tests/unit/storage/test_backend.py` -> all checks passed. - `mypy polylogue/sources/live/batch.py polylogue/sources/live/batch_support.py polylogue/storage/sqlite/schema_bootstrap.py tests/unit/sources/test_live_watcher.py tests/unit/sources/test_live_batch_support.py tests/unit/storage/test_backend.py tests/unit/storage/test_schema_upgrades.py` -> success, no issues. - `pytest tests/unit/sources/test_live_watcher.py tests/unit/sources/test_live_batch_support.py tests/unit/daemon/test_daemon_status.py tests/unit/storage/test_backend.py tests/unit/storage/test_schema_upgrades.py tests/unit/devtools/test_verify_file_budgets.py -q` -> 110 passed. - `devtools verify-file-budgets` -> clean. - `devtools render-all --check` -> OK. - `devtools verify` -> all checks passed. - pre-push quick verification -> all checks passed. Ref #845
## Summary Adds the missing in-place archive upgrade from schema v7 to schema v8 so existing archives can run the daemon build merged in #847. ## Problem #847 removed the legacy batch-run ledger and bumped `SCHEMA_VERSION` to 8, but the declared upgrade dispatcher still stopped at v6→v7. On the production archive, `polylogued` started successfully but every live convergence batch failed with `Database schema version 7 is incompatible with expected version 8`. ## Solution Add a narrow `build_v7_to_v8_upgrade_plan()` that drops only the retired `idx_runs_timestamp` index and `runs` table, include that final step in older upgrade chains, and allow the sync/async schema bootstrap paths to execute the new action. Tests pin both the actual `_ensure_schema()` upgrade and the fact that the v8 migration carries no unrelated archive-wide work. Ref #845 ## Verification - `ruff format --check polylogue/storage/sqlite/schema.py polylogue/storage/sqlite/schema_bootstrap.py tests/unit/storage/test_backend.py` - `ruff check polylogue/storage/sqlite/schema.py polylogue/storage/sqlite/schema_bootstrap.py tests/unit/storage/test_backend.py` - `mypy --strict polylogue/storage/sqlite/schema.py polylogue/storage/sqlite/schema_bootstrap.py tests/unit/storage/test_backend.py` - `pytest tests/unit/storage/test_backend.py tests/unit/storage/test_provider_events_schema.py -q` → `38 passed in 11.54s` - `devtools verify` → `verify: all checks passed` - pre-push `devtools verify --quick` → `verify: all checks passed` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Chores** * Added support for database schema version 8 upgrade, which removes the legacy batch-run ledger during the migration process. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
## Summary Keeps `polylogued status` responsive while the daemon is converging a large archive. ## Problem During the Sinnix deployment of #847/#850, the daemon was healthy and had live attempt state in SQLite, but `polylogued status --format json` exceeded a 30s timeout while convergence was starting. The status path was doing work that scales with archive size or takes deep archive locks: recursive blob-size walking, deep readiness imports, async insight status, and duplicate status probes. ## Solution Make the local daemon status path bounded: blob size is reported as unmeasured `0`, FTS readiness and insight freshness use small read-only SQLite probes, and JSON rendering reuses the typed `DaemonStatus` probe results instead of recomputing them. The live busy-daemon probe that timed out before returned in 1.7s with this branch. Ref #845 ## Verification - `ruff format --check polylogue/daemon/status.py tests/unit/daemon/test_daemon_status.py` - `ruff check polylogue/daemon/status.py tests/unit/daemon/test_daemon_status.py` - `mypy --strict polylogue/daemon/status.py tests/unit/daemon/test_daemon_status.py` - `pytest tests/unit/daemon/test_daemon_status.py -q` → `8 passed in 10.84s` - `.venv/bin/polylogued status --format json` against the live busy daemon → returned in `1.731s` - `devtools verify` → `verify: all checks passed` - pre-push `devtools verify --quick` → `verify: all checks passed`
## Summary Follow-up to the daemon-first #845 work after deploying #847/#850/#851 on the workstation. The live daemon exposed two deployment-scale problems: status payloads became huge with thousands of retryable live cursor failures, and full-ingest attempts could look stale while the worker was actually busy inside storage replacement. The same live run also exposed an unindexed SQLite foreign-key path that made conversation replacement scan millions of provider events. ## Problem During the Sinnix switch, `polylogued status --format json` returned quickly after #851 but emitted thousands of file paths. The active attempt was marked stale in `full_blob_copy`, while `py-spy` showed the daemon was actually in `_process_ingest_batch_sync -> replace_conversation_runtime_state_sync`. The live archive has ~4.0M `provider_events` rows, and `provider_events.source_message_id` referenced `messages(message_id)` without an index, so deleting messages during replacement caused repeated child-table scans and ~91GB of read I/O before I stopped the old service. ## Solution - Bound live cursor file samples in daemon status while preserving exact failed/excluded/retry counts. - Heartbeat full-ingest file scanning, blob materialization, and worker-write handoff with current path and payload-read counters. - Add schema v9 with indexes on `provider_events(source_message_id)` and `attachment_refs(message_id)` so message deletion during replacement has supporting FK indexes; v8 archives upgrade in place. - Split live-batch helper code and the new focused tests out of oversized modules, then refresh topology projections. ## Verification - `ruff check polylogue/sources/live/batch.py polylogue/sources/live/batch_support.py polylogue/storage/sqlite/schema_bootstrap.py tests/unit/sources/test_live_batch_support.py tests/unit/storage/test_schema_upgrades.py tests/unit/sources/test_live_watcher.py tests/unit/storage/test_backend.py` -> all checks passed. - `mypy polylogue/sources/live/batch.py polylogue/sources/live/batch_support.py polylogue/storage/sqlite/schema_bootstrap.py tests/unit/sources/test_live_watcher.py tests/unit/sources/test_live_batch_support.py tests/unit/storage/test_backend.py tests/unit/storage/test_schema_upgrades.py` -> success, no issues. - `pytest tests/unit/sources/test_live_watcher.py tests/unit/sources/test_live_batch_support.py tests/unit/daemon/test_daemon_status.py tests/unit/storage/test_backend.py tests/unit/storage/test_schema_upgrades.py tests/unit/devtools/test_verify_file_budgets.py -q` -> 110 passed. - `devtools verify-file-budgets` -> clean. - `devtools render-all --check` -> OK. - `devtools verify` -> all checks passed. - pre-push quick verification -> all checks passed. Ref #845
Summary
Adds the missing in-place archive upgrade from schema v7 to schema v8 so existing archives can run the daemon build merged in #847.
Problem
#847 removed the legacy batch-run ledger and bumped
SCHEMA_VERSIONto 8, but the declared upgrade dispatcher still stopped at v6→v7. On the production archive,polyloguedstarted successfully but every live convergence batch failed withDatabase schema version 7 is incompatible with expected version 8.Solution
Add a narrow
build_v7_to_v8_upgrade_plan()that drops only the retiredidx_runs_timestampindex andrunstable, include that final step in older upgrade chains, and allow the sync/async schema bootstrap paths to execute the new action. Tests pin both the actual_ensure_schema()upgrade and the fact that the v8 migration carries no unrelated archive-wide work.Ref #845
Verification
ruff format --check polylogue/storage/sqlite/schema.py polylogue/storage/sqlite/schema_bootstrap.py tests/unit/storage/test_backend.pyruff check polylogue/storage/sqlite/schema.py polylogue/storage/sqlite/schema_bootstrap.py tests/unit/storage/test_backend.pymypy --strict polylogue/storage/sqlite/schema.py polylogue/storage/sqlite/schema_bootstrap.py tests/unit/storage/test_backend.pypytest tests/unit/storage/test_backend.py tests/unit/storage/test_provider_events_schema.py -q→38 passed in 11.54sdevtools verify→verify: all checks passeddevtools verify --quick→verify: all checks passedSummary by CodeRabbit