Repository navigation
perf(doctor): snapshot SQLite migration validation - #125361
Conversation
|
Codex review: needs maintainer review before merge. Reviewed August 17, 2026, 5:54 PM ET / 21:54 UTC. ClawSweeper reviewWhat this changesThis PR snapshots SQLite session entries and grouped transcript counts once per Doctor migration target, replacing repeated validation reads and adding a multi-session bounded-read regression. Regression provenancePossible regression — probable (reproduction; reviewed change). No predecessor PR is attributed. Merge readinessNo actionable patch defect found. The prior multi-record regression gap is addressed; this maintainer-authored, protected PR should remain open for normal exact-head CI and human merge handling. Priority: P2 Review scores
Verification
How this fits togetherDoctor imports legacy JSONL session data into per-agent SQLite, validates the resulting rows, then archives legacy sources only after validation passes. The snapshot sits in the validation phase between import and archival. flowchart LR
A[Legacy session files] --> B[Doctor import]
B --> C[SQLite session store]
C --> D[Read-only validation snapshot]
D --> E[Validation checks]
E --> F[Archive gate]
F --> G[Legacy source archive]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +11, Tests +57. Total +68 across 3 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep one target-level snapshot reader and retain the existing validate-before-archive contract, with the new cardinality regression guarding against per-record read growth. Do we have a high-confidence way to reproduce the issue? Yes, source provides a focused current-head real SQLite migration regression comparing one and three session imports; this read-only review did not execute it. Is this the best way to solve the issue? Yes. Moving repeated reads into one target-owned snapshot preserves the existing validation and archive boundary without adding a fallback or a test-only production seam. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 0b75ea3cefcd. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
340b1e4 to
f803757
Compare
|
Addressed the review's two proof gaps on exact head
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Merged via squash.
|
* perf(doctor): snapshot SQLite migration validation Amp-Thread-ID: https://ampcode.com/threads/T-01a00a6a-b64e-74a5-8b15-2d3b966a468d * test(doctor): bound SQLite validation reads Amp-Thread-ID: https://ampcode.com/threads/T-01a00a6a-b64e-74a5-8b15-2d3b966a468d --------- Co-authored-by: Amp <[email protected]>
What Problem This Solves
Fixes large JSONL→SQLite upgrades timing out during Doctor's post-import safety validation. After import completed, Doctor validated every legacy session by reopening SQLite, loading and parsing the full session table, and issuing a separate transcript-count query for each record. With 4,800 sessions this made validation quadratic in session rows and performed thousands of database opens before archival could complete.
Why This Change Was Made
Doctor now opens each target database once and takes a read-only validation snapshot containing session entries keyed by exact stored key plus transcript counts grouped by session ID. Import validation, explicit validation, and already-migrated transcript checks use map lookups while preserving the existing sessionId, exact-key, malformed-prefix, count, idempotence, and archive gating semantics.
The earlier
4 → 256pending-archive publication change was removed after the combined packaged stress disproved it as the update timeout's cause. The final PR does not alter archive publication behavior.Production LOC: +138/-127 (net +11) | Tests: +57/-0. The small production growth is the target-level snapshot/error contract replacing two per-record query APIs. The focused regression compares one-session and three-session real imports at the SQLite-open boundary, proving target-bounded validation reads without timing assertions or a production-only test seam.
User Impact
Large stable-to-current upgrades no longer spend the bounded update window repeatedly scanning the same SQLite rows after migration. Validation remains fail-closed before source archival.
Evidence
expected 8 to be 4). With the fix both cardinalities are equal and all entries/events import and archive successfully.[email protected]→[email protected]survivor passed with 4,800 sessions, 23,890 transcript events, and 2,200 cron jobs: migration Doctor 21s, idempotence Doctor 20s, Gateway startup 14s, then health/readiness/status passed. All 62 recorded phases passed. The rebased production files are byte-identical to the packaged candidate's reviewed production head; the new head adds only the regression test.src/commands/doctor-session-sqlite.test.ts: 84 passed, 2 skipped.oxfmt --checkandgit diff --checkpassed.f803757dc7ebf997b60b979a2c82714130be46db: no accepted/actionable P0–P2 findings; patch correct at 0.9 confidence.Provenance
The per-record helpers came from #98236 (
0a8e3604ba24, 2026-07-11), authored by @jalehman and merged by @steipete. They were correct for small stores but made the later all-record post-import validation path quadratic at realistic volume.