fix: repair schema v19 drift - #73
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the database schema baseline to v19 and introduces robust schema drift detection by generating and comparing canonicalized schema manifests. It also refactors database initialization and migration to handle concurrent openers safely. Feedback on these changes highlights a potential concurrency bottleneck where Atomics.wait is used on the main thread during WAL mode negotiation, suggesting a read-only check of the journal mode first to avoid write contention. Additionally, performance improvements are recommended in the schema manifest generation to replace inefficient JSON.stringify serialization inside sorting comparators with a direct, type-safe comparison function for foreign keys.
teedole
left a comment
There was a problem hiding this comment.
Addressed review findings; inline replies include the implementation and validation evidence.
teedole
left a comment
There was a problem hiding this comment.
Addressed review findings; inline replies include the implementation and validation evidence.
|
Validator follow-up complete at signed tip 52325c8.
Evidence: focused database suite 38/38; combined #73-#79 gate 781/781 plus TypeScript, Biome, and distribution staging smoke. |
Summary
idx_block_tool_use, and timestamp-fallback tool duration backfill.schema_driftconflict response.Why
A dogfooding archive recorded migration v18 before the final review edits landed, so its migration history said v18 while required columns and an index were absent. Watcher syncs and analytics reports then failed repeatedly with raw SQLite errors.
The repair must also distinguish real drift from harmless SQLite representation differences caused by
ALTER TABLE, FTS renames, and the historicalimpact_label_checkeddefault. The new manifest compares schema semantics while preserving SQL literal contents and reporting exact missing or changed objects.User and developer impact
Validation
just checkpasses: 651 tests, TypeScript, Biome (154 files), and distribution staging smoke.Focused coverage includes full v8-to-v19 equivalence, exact pre-review-v18 repair and data preservation, rollback on unrelated drift, malformed/gapped histories, bounded hostile identifiers, SQL-literal-sensitive fingerprints, schema error routing, and 10 barrier-synchronized two-process initialization races.
Archive schema
The baseline is
LATEST_SCHEMA_VERSIONinsrc/db.ts. Check one: