Repository navigation
improve: speed up large history upgrades and Doctor checks - #133068
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 30, 2026, 12:27 AM ET / 04:27 UTC. ClawSweeper reviewWhat this changesThis PR reuses one read-only SQLite connection per Doctor pass and batches transcript imports to avoid repeated setup during large history upgrades. Merge readinessKeep open. This member-authored, maintainer-labeled PR remains necessary: current main still performs the repeated per-event and per-session work the branch removes, and no introduced correctness defect was found in the transcript-state paths reviewed. Priority: P2 Review scores
Verification
How this fits togetherDoctor scans agent SQLite transcript histories for repairs, while the session importer writes recovered history into the canonical agent database. Both paths feed the persisted transcript and derived session projections. flowchart LR
A[Legacy session history] --> B[Doctor transcript scan]
B --> C[Read-only SQLite connection]
C --> D[Guarded repair transaction]
A --> E[SQLite session importer]
E --> F[Batch transcript append]
D --> G[Canonical transcript store]
F --> G
G --> H[Session projections]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +42, Tests +58. Total +100 across 8 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Land the single transcript-store-owned batch path after exact-head upgrade proof confirms preserved rows, identities, projections, and rerun behavior on a released baseline. Do we have a high-confidence way to reproduce the issue? Not applicable: this is a performance refactor, with the PR body supplying benchmark and released-baseline upgrade evidence rather than a discrete failing report. Is this the best way to solve the issue? Yes. Moving the batching cursor into the transcript-store owner avoids a parallel importer-specific append implementation while preserving the existing single-append behavior and state invariants. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against ecb0386e89b3. 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
|
|
Merged via squash.
|
What Problem This Solves
Large stable-to-main upgrades spend unnecessary time importing transcript events and checking already healthy histories. Doctor opens SQLite twice per session across its header and label passes; the importer repeats session-root, generation and next-sequence setup for every event even inside one synchronous batch.
Why This Change Was Made
Doctor now owns one read-only connection per agent store and pass. Each session's iterators finish before the existing guarded repair transaction, so later reads see newly committed data. Detection still parses every required event, retains full snapshots for positive repairs, rejects concurrent changes and isolates malformed histories.
The transcript store owns a private cursor for the existing synchronous batch append. Root/generation setup and the first sequence lookup happen once; successful inserts advance the cursor. The importer streams its staged events through that same owner and records byte deduplication only after an insertion succeeds. Each attempted event still updates window recency before identity rejection. Single appends retain their existing callback behavior.
No schema, index, config, transaction boundary, locking, retention or recovery contract changes. Exact SQLite handoffs remain separate and preserve original bytes. Existing array-based fork/reset/recovery callers share the batch owner. Production delta is +42 lines; tests +58. The growth provides bounded streaming insertion feedback and private batch state, avoiding a second importer-specific write path or an escaping appender callback. Duplicate projection scheduling branches were folded into one common tail.
User Impact
Large upgrades and repeated Doctor checks complete faster with the same migration checks, archives, timestamps, duplicate handling and runtime history. No new setting or operator action is required.
Evidence
Focused reader benchmark, 20,000 sessions / 500,000 events, same canonical SQLite schema and data, three runs (median):
These isolate the readers; they are not whole-upgrade timings. The label probe parses all events with a no-repair predicate, so it measures connection/query/parsing costs without the normalizer's extra work.
A real 10,001-event import executes 160,033 SQL operations before and 120,033 after. The 40,000 eliminated operations are repeated root/generation/sequence setup; all 10,001 window updates remain. Quiet, interleaved fresh-process measurements (three pairs per scenario, Node 26.8.1) show:
Every paired candidate run was faster; these are focused importer timings, not whole-upgrade timings.
Focused verification: 176 tests passed across seven files: importer, active/context projections, Doctor headers/labels, migration memory and the broader session accessor suite (including concurrent writers, reset/lifecycle and recovery). Coverage includes an append-abort rollback, source revalidation, mixed existing/duplicate/new events, exact bytes and timestamps, unchanged generation, final rejected-duplicate recency, later-session visibility, malformed histories, Unicode-escaped labels and shared stores. Existing batch and 100,000-event branched imports completed under a 256 MiB JavaScript heap with exact-byte, projection and rerun checks.
Matched Docker proof on the same Blacksmith Testbox (
tbx_01m18cvvdk3kn4wsp9vpwab35v, holder run): published stable2026.7.1-2to baseline5d07c11ccef2755ca569082b7c278f5eeb5bf67b, then that same baseline plus this exact reviewed patch. The full source diff SHA-256 was checked before packaging. Both runs passed with 20,000 sessions, 497,750 events, 10,000 cron jobs and 512 released SDK state records.The complete lane used 18% less time; the update command used 22% less, and repeated Doctor used 35% less. These are one paired end-to-end run, not a universal latency guarantee. Automatic migration is asserted before any standalone Doctor or fixture capability consent. Full row checks run five times, including after repeated Doctor and restart. Eight real Gateway session/history samples (144 messages) retain identical hashes across all four before/after/restart probes. Integrity, archives, pairing/workspace data and budgets are unchanged. Fixture plugin capability consent remains explicit; this does not claim background stable-to-main channel switching.
Reproduction uses
OPENCLAW_DOCKER_ALL_LANES=published-upgrade-survivor,OPENCLAW_UPGRADE_SURVIVOR_BASELINE_SPECS=2026.7.1-2,OPENCLAW_UPGRADE_SURVIVOR_SCENARIOS=sqlite-volume, and volume knobsSESSIONS=20000,EVENTS_PER_SESSION=25,CRON_JOBS=10000under theOPENCLAW_UPGRADE_SURVIVOR_VOLUME_prefix withnode scripts/test-docker-all.mjs.Committed-head deep Docker proof also passed: 4,800 sessions / 1,227,946 events / 10,000 cron jobs / 512 released SDK records in 562 seconds, with five exhaustive row checks. Repeated Doctor took 40 seconds (unchanged 60-second budget), startup 11 seconds. Eight Gateway samples (600 messages, bounded to the normal history page size) retained identical hashes across restart; API probe times were 6.619 and 6.745 seconds. The packed build-info commit is exactly
c6ebf69c94eb4415f5a2120fb92567456e203acc. Blacksmith Testboxtbx_01m18ebmqmzkjdxfbxfw3hwap8, holder run; same Docker command with volume settings 4800/257/10000. Both Testbox leases were stopped after evidence capture. Exact-head hosted CI completed successfully onc6ebf69c94eb4415f5a2120fb92567456e203acc, including all production/test types, tests and required CI gate.Local production typecheck and repository guards passed. The aggregate test typecheck encountered the pre-existing shared dependency mismatch in
ui/vite.config.ts(installedpakolacks the expected declarations); no dependency workaround was added. Fresh hosted CI subsequently passed the production and test typechecks and aggregate CI gate on the PR head.After the final scheduling simplification, the 22 importer/active-projection tests and a fresh review passed again.
Independent Codex autoreview: no accepted/actionable P0 findings. This is a P0-scoped review, not a broader correctness certificate.
Separate follow-up: branch-heavy FTS rebuilds still scan their unindexed session field. This change does not alter index design or claim to resolve #119884's planner-statistics report. Existing native stable auth-credential retention work in #129689 also remains outside this change.
ClawSweeper review and Rank-up moves addressed: the declared committed-head million-event upgrade and exact-head hosted CI both passed. The review found no actionable correctness/security issue; maintainer-requested landing proceeds with the existing schema and persistence contracts unchanged.