Skip to content

improve: speed up legacy session transcript imports - #133641

Merged
steipete merged 1 commit into
mainfrom
codex/importer-performance-pass-ten
Aug 31, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/importer-performance-pass-ten

Conversation

@steipete

@steipete steipete commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

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

  • Extended the existing version 1–4 reader table with unindexed legacy metadata, checking v1 IDs and parent links while retaining malformed-message, opaque-row, and hook coverage.
  • Independent Codex review is scoped-clean through P3, confidence 0.99. Scoped lint and formatting passed.
  • Production +7/-7 (net zero); tests +12/-1 (net +11).
  • All 148 focused tests passed across SessionManager, codec, Doctor, reader, and importer suites. Command: 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.
  • Structural changed-file checks passed through the core graph boundary. Local core types stopped on six pre-existing errors in unchanged src/logging/logger.ts; the shared tslog install lacks types/BaseLogger.d.ts. Shared dependencies were not modified. Exact-head CI passed.
  • Linux Node 24.19.0 / SQLite 3.53.3: 50 full-import pairs across nine shapes, identical stored-data digests, unchanged SQL calls (100,034 across 34 shapes), and eight CPU profiles restricted to the import region. The packaged stable-upgrade proof also 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 at 5f0aa4f7c56870e01fd8103176eb93ca58700c72. 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:

Shape Before After Wall change
single 9.0 ms 9.1 ms +1.8%
deep 5623.9 ms 5601.3 ms -0.4%
wide 672.3 ms 656.9 ms -2.3%
branch 1027.5 ms 1042.5 ms +1.5%
replay 170.4 ms 167.0 ms -2.0%
legacy-v1 705.3 ms 631.2 ms -10.5%
legacy-v2 592.2 ms 583.2 ms -1.5%
legacy-metadata-v1 488.0 ms 360.4 ms -26.1%
legacy-hooks-v2 561.5 ms 489.5 ms -12.8%

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-survivor Docker lane passed from latest stable 2026.7.1-2 to a tarball whose build info identifies exact commit f3645ed77e5077de973e84330372910f74149476. 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 main fbfc46e7272 with 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.

@steipete steipete self-assigned this Aug 31, 2026
@clawsweeper

clawsweeper Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added commands Command implementations agents Agent runtime and tooling size: XS maintainer Maintainer-authored PR labels Aug 31, 2026
@steipete
steipete marked this pull request as ready for review August 31, 2026 00:01
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 31, 2026
@clawsweeper

clawsweeper Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 30, 2026, 8:21 PM ET / August 31, 2026, 00:21 UTC.

ClawSweeper review

What this changes

The PR checks legacy transcript rows with the legacy reader before strict indexed validation and adds Doctor-import coverage for legacy metadata rows.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

No 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
Reviewed head: f3645ed77e5077de973e84330372910f74149476

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, net-neutral optimization preserves the existing recognition rule and extends the appropriate import-boundary coverage.
Proof confidence 🌊 off-meta tidepool Not applicable: This is maintainer-authored work, so the external-contributor proof gate does not apply. The supplied PR body nevertheless reports paired full-import timing and preservation checks for the changed classifier path.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This is maintainer-authored work, so the external-contributor proof gate does not apply. The supplied PR body nevertheless reports paired full-import timing and preservation checks for the changed classifier path.
Evidence reviewed 7 items Introduced classifier change: The exact PR delta reverses only the two recognition predicates: valid legacy rows short-circuit before indexed Zod validation, while indexed validation remains the fallback.
Import owner boundary: The Doctor reader calls the shared classifier for every non-header imported row, then migrates only recognized rows and yields opaque rows unchanged.
Sibling session path: The same classifier is also used by in-memory and persisted SessionManager loading through partitionSessionFileEntries; the boolean reordering preserves the same two recognition arms.
Findings None None.
Security None None.

How this fits together

Doctor 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]
Loading

Before merge

  • Complete next step (P2) - This active maintainer-authored PR has a clean merge result and no concrete repair finding for an automated work lane.
Agent review details

Security

None.

PR surface

Source 0, Tests +11. Total +11 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 7 7 0
Tests 1 12 1 +11
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 19 8 +11

Review metrics

Metric Value Why it matters
Production versus test LOC production +7/-7 (net 0); tests +12/-1 (net +11) The production change is a net-neutral predicate reordering, while the test growth extends the existing version matrix for preservation and v1 migration behavior.

Technical review

Best 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.

Labels

Label justifications:

  • P3: This is a small performance improvement for legacy transcript imports without a reported reliability or user-flow regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This is maintainer-authored work, so the external-contributor proof gate does not apply. The supplied PR body nevertheless reports paired full-import timing and preservation checks for the changed classifier path.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vincent Koc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-08-31T00:09:13.378Z sha f3645ed :: needs maintainer review before merge. :: none

@steipete
steipete merged commit 1a62b4f into main Aug 31, 2026
327 of 328 checks passed
@steipete
steipete deleted the codex/importer-performance-pass-ten branch August 31, 2026 00:30
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling commands Command implementations maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant