Repository navigation
improve: speed up legacy session transcript imports - #133496
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 30, 2026, 4:25 PM ET / 20:25 UTC. ClawSweeper reviewWhat this changesThe branch avoids a redundant planning pass for version-2-and-newer legacy JSONL session imports and reuses a per-row classifier between Doctor import and runtime loading. Merge readinessNo introduced correctness defect was found. This PR remains open because it is maintainer-authored and carries the protected Priority: P3 Review scores
Verification
How this fits togetherDoctor reads legacy JSONL session transcripts, normalizes recognized rows, preserves opaque rows, and stages them for SQLite import. Runtime session loading uses the same codec rules to distinguish valid session entries from opaque persisted data. flowchart LR
A[Legacy JSONL transcript] --> B[Import planning]
B --> C[Shared row classification]
C --> D[Versioned migration]
D --> E[SQLite staging and commit]
F[Runtime session loader] --> C
Decision needed
Why: Repository policy keeps maintainer-authored and Before merge
Agent review detailsSecurityNone. PR surfaceSource +7, Tests +105. Total +112 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 the single shared classifier and version-specific planning boundary, then land only after a maintainer confirms the exact-head required checks and prior rank-up state. Do we have a high-confidence way to reproduce the issue? Not applicable: this PR is a performance optimization rather than a report of a current failing behavior. The affected versioned import path is source-traceable and has focused coverage. Is this the best way to solve the issue? Yes. The migration code only needs precomputed future row targets for version 1; extracting the existing row-classification rule avoids the prior synthetic two-row partition allocation without adding a parallel import policy. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against d37f9a1ad683. LabelsLabel 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
HistoryReview history (1 earlier review cycle)
|
|
Merged via squash.
|
Related: #133446
What Problem This Solves
Large legacy-session upgrades spend time parsing modern-format JSONL histories twice inside the import reader and repeatedly constructing synthetic two-row files just to classify individual events.
Why This Change Was Made
The reader now stops planning at the first version-2-or-newer header: only version 1 needs original-row compaction targets before migration. Newer files enforce the same 100,000-distinct-target limit during streaming. Runtime loading and migration share a single-row classifier instead of rebuilding a temporary partition for every event.
Version-1/headerless planning, original-index links, header canonicalization, hook normalization, opaque-row preservation, file fingerprints, accepted-row deduplication, and canonical transaction boundaries remain intact. A malformed newer-file tail may reach the disposable staging spool before failing; all source reads and revalidation still finish before any canonical write. There are no schema, SQL, index, configuration, dependency, concurrency, retention, or durable data-format changes.
User Impact
Less parsing and allocation during session migration, with the same imported data and failure limits. Version-1 histories retain their required planning pass. In isolated Linux measurements, median complete JSONL-to-SQLite import time fell 7.8% for deep histories, 11.1% across many sessions, and 14.5% for repeat imports. Branching results varied between runs, so no reliable branching speedup is claimed.
Evidence
tslogdeclaration errors in unchangedsrc/logging/logger.ts; the shared dependency tree was not modified. Clean exact-head CI passed, including the complete typechecks.609db0dda18918d610df3b5f80a0032ddda3961aagainst16421ec0b0b3f55d00b1ad1d65dff8774bcb1bdb. Packaged stable-upgrade proof passed on the same commit; details below.Local commands:
node scripts/run-vitest.mjs src/commands/doctor-session-sqlite-readers.test.ts src/config/sessions/session-accessor.sqlite-import.test.ts src/agents/sessions/session-manager-codec.test.ts src/agents/sessions/session-migrate-id-dedup.test.ts src/agents/sessions/session-manager.test.ts;node scripts/run-vitest.mjs src/commands/doctor-session-sqlite.test.ts --testNamePattern 'repairs legacy transcript|aborts import when|aborts a batch|imports and validates legacy';node scripts/check-changed.mjs -- src/agents/sessions/session-manager-codec.ts src/commands/doctor-session-sqlite-readers.ts src/commands/doctor-session-sqlite-readers.test.ts.Complete file-import measurements
Blacksmith Testbox run, Node 24.19.0 / SQLite 3.53.3. Five fresh processes per side per shape; pair order alternates. Both variants share all other source/dependencies and stable synthetic JSONL fixture paths, including version-1 ID derivation. Fixture generation and verification are outside the import timer.
The initial branching result was 3.6% slower. An eight-pair follow-up with balanced starting order instead measured 4.4% faster wall time and 4.9% less CPU. These small movements are not consistent enough for a branching performance claim; neither result is hidden. Version-1 movement is also modest and retains the required full planning pass.
All 38 paired data digests match across exact transcript bytes, identities, window metadata, active positions, projection watermarks, and FTS. A separate 10k-event trace retains 100,034 SQL calls across the same 34 shapes. Separate before/after Node CPU profiles completed; timing samples were unprofiled.
ClawSweeper’s final-head review found no actionable code issues. Its rank-up request—confirm exact-head CI and inspect the latest review—is satisfied. The stored-data heuristic names the migration-reader path; this diff changes no schema, SQL, indexes, durable shape, or canonical write boundary. Data parity is verified above, and the packaged upgrade proof below passed.
Packaged upgrade and memory
Packaged Docker upgrade from stable
2026.7.1-2to the exact candidate609db0dda18918d610df3b5f80a0032ddda3961apassed with 4,800 synthetic sessions, 1,227,946 events, and 10,000 cron jobs. Five full-state assertions passed, including automatic migration immediately after update and before standalone Doctor. Eight Gateway history samples across two agents returned 600 messages identically after restart. Repeat Doctor completed in 39 seconds against the unchanged 60-second budget; startup took 11 seconds, and health/readiness/status probes each took 1 second. The scenario uses an explicit candidate tarball, manual Gateway restart, and expected synthetic-plugin capability consent; it does not claim unattended update-channel switching. The Testbox command exited successfully in 13m15s. Proof and CPU profiles were collected and checksum-verified, then the worker was stopped.Median process peak RSS (KiB), before → after: deep 551,500 → 523,824; wide 405,404 → 405,716; branching 414,112 → 414,436; replay 455,672 → 401,376; v1 400,968 → 404,048; v2 409,064 → 397,180. These are process peaks, not isolated importer allocations; no universal memory-reduction claim is made.