Repository navigation
fix(doctor): bound recovered session migrations - #126265
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 21, 2026, 2:25 PM ET / 18:25 UTC. ClawSweeper reviewWhat this changesThis PR changes Doctor’s legacy-media migration to scan transcript and trajectory records in 64-row keyset batches and adds a low-heap pagination regression. Regression provenancePossible regression — probable (reproduction; failure trace). No predecessor PR is attributed. Merge readinessKeep open for maintainer review. Current main still eagerly materializes the relevant transcript and trajectory rows; this PR replaces that path with bounded scans and preserves the existing transaction and drift checks. Priority: P1 Review scores
Verification
Live VerificationCommand: Result: PASS (completed) Assertions:
How this fits togetherDoctor migrates persisted agent SQLite state during update finalization, before the Gateway resumes. This migration reads recovered transcript and trajectory data, rewrites legacy media fields when needed, and records the repaired state. flowchart LR
A[Update finalization] --> B[Doctor]
B --> C[Recovered agent SQLite state]
C --> D[Ordered 64-row batches]
D --> E[Media rewrite decision]
E --> F[Immediate SQLite transaction]
F --> G[Gateway resumes]
Before merge
Agent review detailsSecurityNone. PR surfaceSource 0, Tests +146. Total +146 across 2 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain one canonical bounded scan-and-rewrite flow, with the existing source-drift and atomic schema-advance guarantees validated on the final merge head. Do we have a high-confidence way to reproduce the issue? Yes, from source with high confidence: current main materializes the complete stored event corpus before migration; this review did not run the private recovered database. Is this the best way to solve the issue? Yes: an ordered, owner-level batch scan directly removes the whole-corpus allocation while retaining the existing migration boundary and exact rewrite helper. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against f33952eca4cb. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles) |
9552a64 to
df41e20
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
79fc111 to
2960f57
Compare
|
Rebased onto current Local proof on head
The obsolete tracked-path buffer commit was dropped during conflict resolution because current @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Land-ready at exact head
Proceeding through the repository-native review-artifact, prepare, and merge gates. |
|
Merged via squash.
|
* fix(doctor): bound recovered session migrations * refactor(doctor): trim bounded migration flow * test(doctor): strengthen migration heap regression * test(doctor): cover media migration page boundary --------- Co-authored-by: Josh Lehman <[email protected]>
What Problem This Solves
A package-to-
devupdate can activate the new core and then abort during post-core Doctor when a large recovered SQLite session corpus exhausts Node's heap. PR #126353 bounded session-entry and canonical-repair paths, but the authentic #126115 corpus still failed earlier inmigrateLegacyMediaPersistence, which eagerly materialized all transcript and trajectory JSON. The Gateway remained stopped until manual recovery.Why This Change Was Made
Doctor now scans transcript and trajectory rows in ordered 64-row keyset batches. Current-schema detection runs in a deferred read transaction; required rewrites rescan inside the existing immediate write transaction.
PRAGMA data_version, constant-memory fingerprints, exact-row transcript rewrites, event identity, index maintenance, and all-or-nothing schema advancement remain intact.The rebase dropped the former tracked-path buffer commit because current
mainreplaced that child-process scan withlistRepoFilesSync; resurrecting the old path would be obsolete.No heap override, schema-version bump, config, dependency, protocol, or public CLI contract change.
User Impact
Operators with large retained or recovered agent databases can complete Doctor and update finalization without an 8 GiB heap override. The authentic 1.13 GiB recovered corpus completed Doctor in 25 seconds at 911.6 MiB peak RSS after the original path failed at 2,147.6 MiB.
Evidence
origin/main81ace374f99.+200/-200(net zero).+146, including second-page rewrites for transcript and trajectory rows at sequence 64 and preservation through sequence 127.node scripts/run-vitest.mjsacross all eightstate-migrations.media-persistence*.test.tsfiles: 33 tests passed.node scripts/check-changed.mjs -- src/infra/state-migrations.media-persistence.ts src/infra/state-migrations.media-persistence.large-corpus.test.ts: passed.pnpm build: passed.origin/main: clean, no accepted/actionable findings.Follow-up for #126115 and #126353.