Repository navigation
improve: speed up transcript migration and Doctor scans - #133127
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 30, 2026, 2:53 AM ET / 06:53 UTC. ClawSweeper reviewWhat this changesThe PR reuses SQLite statements during Doctor transcript scans and carries projection state across synchronous transcript batches to eliminate repeated reads and query construction. Merge readinessKeep open. The fetched current main still uses the earlier per-call projection and reader behavior, so this remains a distinct optimization; it is also maintainer-authored and must not be auto-closed. Priority: P2 Review scores
Verification
How this fits togetherDoctor scans agent SQLite transcripts and makes guarded repairs, while the transcript store appends events and maintains the active-history search projection. This PR optimizes both internal paths without changing the stored schema or public configuration. flowchart LR
A[Stored transcript events] --> B[Doctor scan]
B --> C[Read-only transcript reader]
C --> D[Guarded repair]
A --> E[Transcript batch append]
E --> F[Active-history projection]
F --> G[Session history and search]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +20, Tests +73. Total +93 across 8 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Retain the single synchronous-batch projection owner and per-read-pass statement reuse, with the existing dirty-projection reconciliation as the sole fallback path. Do we have a high-confidence way to reproduce the issue? Not applicable as a user bug report. The relevant technical scenario is directly reproducible in node:sqlite and covered by the added healthy-session-after-error regression test. Is this the best way to solve the issue? Yes. The caching is confined to the synchronous transaction batch or one read-only Doctor pass, while ambiguous projections still use the established dirty-and-reconcile owner rather than a parallel path. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 357078cf7087. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
What Problem This Solves
Large upgrades still spent avoidable time importing transcript events and scanning already-current session histories during Doctor. This follows the earlier profiling work in #133068 and #133100.
Why This Change Was Made
The existing synchronous transcript batch now carries forward the projection facts it just persisted, removing redundant reads and query construction between events. Single appends and replacement writes still start with fresh facts. Doctor reuses prepared read statements within its existing read-only database pass, without caching results or retaining a cursor across repairs.
Statement reuse also requires clearing a native SQLite iterator error before reading the next session. A real SQLite regression reproduced that failure in three iterator paths before the cleanup fix; the original read error remains visible. No schema, indexes, durability settings, transaction boundaries, configuration, or persisted data contracts change.
User Impact
Imports and repeated Doctor checks do less work while preserving transcript contents, deduplication, active branches, search projections, recency, and restart behavior. This does not change background update channel selection or plugin capability consent.
Evidence
Matched Node profiling and fresh-process import runs against main
63f265c0ddb9ec80dd0c54bf7b6c76f3c005f6f6, three interleaved runs per variant and shape:These are local synthetic measurements with timing noise, not a guarantee for every machine. A separate 10,001-event trace removed 19,999 queries (120,033 → 100,034); all twelve reported write shapes retained identical counts, including every per-event watermark write.
On a separate unchanged 20,000-session / 500,000-event fixture, full Doctor header detection fell from 404.63 to 203.58 ms (49.7%) and label detection from 1,043.50 to 882.67 ms (15.4%). Each side has nine observations across three fresh processes. Initial label measurements overlapped local review scanning and are retained separately; the reported label result is the quiet confirmation. The database SHA-256 stayed identical.
Native SQLite error isolation: three iterator regressions failed before cleanup, then all four cases passed. All 102 focused tests passed across 11 files, covering imports, active projections, classification convergence, replacements, message cuts, recovery, parent forks, and Doctor repairs. The exact-head packaged Docker lane passed on its first attempt: stable
2026.7.1-2→ candidate tarball at2ef1cee326e2aa3a3fa8689b9e9582733a364e81, with 4,800 sessions, 1,227,946 transcript events, and 10,000 cron jobs. Five exhaustive volume assertions passed, including automatic migration immediately after the update command and before standalone Doctor/plugin consent. Eight Gateway history samples (600 returned messages) were identical across restart. Repeat Doctor took 39 seconds against a 60-second budget; the complete lane took 533 seconds, excluding package build.Exact-head CI passed, including production/test types, Windows, and SQLite lifecycle. Docker proof run returned wrapper exit 0; its delegated lease was stopped after evidence collection. Local aggregate test typing encountered the existing shared-install
pakomismatch, which the clean CI install did not reproduce. Final changed-file lint, core typing, and focused reruns passed.Reproduction: run
node scripts/test-docker-all.mjsin Testbox withOPENCLAW_DOCKER_ALL_LANES=published-upgrade-survivor,OPENCLAW_UPGRADE_SURVIVOR_BASELINE_SPECS=2026.7.1-2,OPENCLAW_UPGRADE_SURVIVOR_SCENARIOS=sqlite-volume,OPENCLAW_UPGRADE_SURVIVOR_VOLUME_SESSIONS=4800,OPENCLAW_UPGRADE_SURVIVOR_VOLUME_EVENTS_PER_SESSION=257, andOPENCLAW_UPGRADE_SURVIVOR_VOLUME_CRON_JOBS=10000. This explicitly selects the candidate package; it proves automatic migration during update, not unattended stable-to-main channel switching. Fixture plugin capability consent remains explicit.The latest ClawSweeper review found no actionable or security defect and listed no Rank-up moves. Its remaining exact-head CI/maintainer-review step is satisfied by the linked CI, local owner review, and fresh committed-patch Codex autoreview.
Production LOC: +238/-218 (net +20). Tests: +76/-3 (net +73). The growth gives the existing batch a bounded projection-fact owner and gives reused read statements explicit native-error cleanup; there is no second index/repair path or persistent cache. Codex autoreview of the complete owner/caller/test evidence found no actionable findings.
The change is bounded query/read reuse under the existing owners. It adds no persistent representation and does not alter the operating model described in
docs/reference/database-schemas.md. Planner-statistics work (#119884) and credential-retention work (#129689) remain separately owned; this PR does not claim to resolve them.