Repository navigation
improve: speed up legacy session transcript imports - #133641
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 30, 2026, 8:21 PM ET / August 31, 2026, 00:21 UTC. ClawSweeper reviewWhat this changesThe PR checks legacy transcript rows with the legacy reader before strict indexed validation and adds Doctor-import coverage for legacy metadata rows. Merge readinessNo blocking correctness or security finding. Current main still performs strict indexed validation first, so this narrow legacy-import optimization remains necessary and should stay open for normal maintainer review. Priority: P3 Review scores
Verification
How this fits togetherDoctor imports old JSONL session transcripts into SQLite. Each row is normalized and classified before it is migrated as a recognized session event or retained as opaque data. flowchart LR
A[Legacy JSONL transcript] --> B[Doctor import reader]
B --> C[Row normalization]
C --> D[Legacy or indexed classification]
D --> E[Session migration]
E --> F[SQLite transcript storage]
D --> G[Opaque row preservation]
Before merge
Agent review detailsSecurityNone. PR surfaceSource 0, Tests +11. Total +11 across 2 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Retain the shared classifier’s two existing recognition paths, with the legacy path first only for pre-current transcript versions, and preserve the versioned import assertions. Do we have a high-confidence way to reproduce the issue? Not applicable: this PR optimizes an existing import path rather than reporting a failing user behavior; the relevant path is source-traceable through the Doctor import reader. Is this the best way to solve the issue? Yes. Reordering the existing recognition arms at their shared classifier avoids discarded strict-validation errors without adding a second import path or changing migration policy. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against afac389cee3e. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
|
Merged via squash.
|
Related: #133611
What Problem This Solves
Importing older session histories spends CPU rejecting each record against modern requirements before accepting it through the existing legacy reader. Genuine v1 records lack modern IDs, and old hook messages use a retired role, so successful imports repeatedly construct and discard validation errors.
Why This Change Was Made
Try the existing legacy predicate first for legacy versions, while retaining the modern predicate as the other arm of the same recognition rule. Within legacy validation, validate message content only for message records. All schemas, hook normalization, opaque-row preservation, and migration rules stay unchanged.
User Impact
Less validation overhead when importing old session histories. Current and future transcript versions keep the existing indexed validation path. No SQLite schema, queries, transactions, configuration, dependencies, or persistence semantics change.
Evidence
node scripts/run-vitest.mjs src/agents/sessions/session-manager-codec.test.ts src/agents/sessions/session-manager.test.ts src/commands/doctor-session-sqlite-readers.test.ts src/commands/doctor-session-sqlite.test.ts src/config/sessions/session-accessor.sqlite-import.test.ts.src/logging/logger.ts; the sharedtsloginstall lackstypes/BaseLogger.d.ts. Shared dependencies were not modified. Exact-head CI passed.The preliminary local classifier screen identified discarded Zod errors as the hotspot. Local full-import wall time was dominated by filesystem stalls, so those samples are retained as exploratory evidence and are not used for speed claims. A separate batch identity-query candidate was not selected because that screen did not establish a gain.
Linux measurements
Candidate
f3645ed77e5077de973e84330372910f74149476; baseline overrides only the codec owner with its contents at5f0aa4f7c56870e01fd8103176eb93ca58700c72. All other code/dependencies are identical. Fresh processes alternate before/after order. Fixture generation and exact parity checks are outside the timer. These are complete file-to-SQLite imports, not classifier-only measurements. Five pairs per shape, ten for the modern deep control:The first five modern deep pairs showed a 4.0% slower candidate median; five additional pairs with reversed starting order showed a 2.3% faster median. All ten combined give 5623.9 → 5601.3 ms, with CPU 5832.6 → 5836.8 ms. No modern deep-history speedup or consistent slowdown is claimed; both runs are retained. Other small control differences are not claimed as meaningful gains. The clear improvements are genuine v1 messages without IDs (10.5%), v1 metadata (26.1%), and v2 hook messages (12.8%).
Median CPU time also fell for the targeted legacy shapes: v1 messages 970.6 → 860.8 ms (11.3%), v1 metadata 738.1 → 574.9 ms (22.1%), and v2 hook messages 803.6 → 700.9 ms (12.8%).
Every full-import pair preserves exact transcript JSON, identities, window metadata, active positions, watermarks, and FTS. Raw results and eight profiles were collected with SHA-256
9347b6f42ddf2544ecdafb10341ad8894802811d868ed780723c8cebe198195a. The Testbox workflow hosts the dedicated worker; Crabbox command exits/timings provide the proof verdict. Exact-head CI is green on the candidate commit.The latest ClawSweeper review found no source-level correctness or security issue. Its missing-benchmark finding and rank-up move are addressed by the paired wall/CPU measurements and exact preservation-parity results above.
Packaged stable upgrade
The existing
published-upgrade-survivorDocker lane passed from latest stable2026.7.1-2to a tarball whose build info identifies exact commitf3645ed77e5077de973e84330372910f74149476. The volume fixture preserved 4,800 sessions, 1,227,946 transcript events and 10,000 cron jobs. Automatic migration was asserted immediately after the update and before the later standalone Doctor check. All survival assertions passed, including eight Gateway history samples (600 messages across two agents) that were identical after restart. The repeat Doctor run completed in 38 seconds against its 60-second budget. The lane took 520 seconds; the full build/package/lane command took 795 seconds.This uses an explicit candidate tarball, a manual Gateway restart and the expected synthetic plugin-capability consent step; it does not prove unattended update-channel switching. The large volume fixture uses v3 transcript headers and proves packaged upgrade integrity. The genuine v1/v2 performance improvements are established separately by the paired full-import benchmarks above.
Proof archive SHA-256:
aa2e370910c7681b3f917f47c89204b23ef52a1a8dab6a9d7a9956ac9eccc1db. Native review compared latest mainfbfc46e7272with the benchmark baseline; neither touched file changed there. A shared-ref fetch collision during review preparation was recovered through the native lock-recovery command and a successful retry; no source or shared dependency changes were needed.