Repository navigation
improve: speed up legacy imports and transcript replacement - #133546
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 30, 2026, 5:41 PM ET / 21:41 UTC. ClawSweeper reviewWhat this changesThe PR compiles fixed Kysely query shapes once per transcript import or replacement batch and supplies fresh values for each SQLite write. Merge readinessKeep this maintainer-authored, protected PR open. The introduced batch-local binding path preserves the existing SQLite executor and transcript ordering; no concrete patch defect was found, but exact-head CI and a dependency-contract check remain the appropriate merge gates. Priority: P3 Review scores
Verification
How this fits togetherLegacy session import and transcript replacement write normalized events into an agent-local SQLite store. Those rows drive session recency, transcript indexes, and later history reads. flowchart LR
A[Legacy session import] --> C[Transcript write batch]
B[Transcript replacement] --> C
C --> D[Prepared query bindings]
D --> E[SQLite transcript events]
E --> F[Transcript indexes and history]
Decision needed
Why: The source review found no defect, but the review environment could not independently inspect the pinned dependency implementation that the helper relies on. Before merge
Agent review detailsSecurityNone. PR surfaceSource +21, Tests +49, Other 0. Total +70 across 4 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep the single canonical synchronous executor and land the batch-local preparation seam after exact-head CI and Kysely 0.29.5 contract evidence are accepted. Do we have a high-confidence way to reproduce the issue? Not applicable: this PR is an internal performance refactor rather than a report of failing user behavior; its relevant checks are binding parity and transcript-write invariants. Is this the best way to solve the issue? Yes. Reusing the existing synchronous executor with fresh batch-local bindings is cleaner than a second native cache or handwritten positional SQL, and it removes duplicated insert construction. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 00b64b81c407. 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
HistoryReview history (1 earlier review cycle)
|
|
Merged via squash.
|
* origin/main: (55 commits) test: include v2026.8.1 release navigation (#133581) fix: stop cloud work before unrelated provider inspection finishes (#133476) fix(e2e): keep delete fixture target-compatible (#133526) fix(release): detect optional target E2E capability (#133525) fix(package): publish readable dist inventory (#133549) docs: add complete v2026.8.1 maintainer change index (#133585) fix(browser): preserve contextless worker and iframe sessions (#133571) fix(voice): discover configured provider candidates (#133507) refactor(ui): simplify chat rendering and lifecycle state (#133567) test: reduce maturity fixture cleanup time (#133566) improve: speed up legacy imports and transcript replacement (#133546) docs: add draft v2026.8.1 release notes (#133557) test: guard multi-project Vitest cache ownership (#133554) fix(memory): clarify default agent scope in command help (#133560) fix(clawdock): keep credentials out of diagnostic output (#133547) refactor(ui): avoid redundant presence work in avatar lists (#133548) fix(agents): recognize internal requester completion replies (#133543) fix: prevent duplicate queued user messages in chat clients (#133542) chore(ui): refresh control ui locales (#133544) fix(beam): restart delivery when the receiver changes (#133533) ...
…cked-delivery * origin/main: test: include v2026.8.1 release navigation (openclaw#133581) fix: stop cloud work before unrelated provider inspection finishes (openclaw#133476) fix(e2e): keep delete fixture target-compatible (openclaw#133526) fix(release): detect optional target E2E capability (openclaw#133525) fix(package): publish readable dist inventory (openclaw#133549) docs: add complete v2026.8.1 maintainer change index (openclaw#133585) fix(browser): preserve contextless worker and iframe sessions (openclaw#133571) fix(voice): discover configured provider candidates (openclaw#133507) refactor(ui): simplify chat rendering and lifecycle state (openclaw#133567) test: reduce maturity fixture cleanup time (openclaw#133566) improve: speed up legacy imports and transcript replacement (openclaw#133546) docs: add draft v2026.8.1 release notes (openclaw#133557) test: guard multi-project Vitest cache ownership (openclaw#133554) fix(memory): clarify default agent scope in command help (openclaw#133560)
…#133546) * perf(sessions): reuse compiled transcript write queries * chore(sessions): shrink assertion allowance after guard cleanup
Related: #133496
What Problem This Solves
Legacy session imports and transcript replacements repeatedly rebuild the same Kysely insert query. Batch imports also rebuild the same window-recency update for every event. This spends CPU on query construction after SQLite statement caching has already removed most prepare work.
Why This Change Was Made
Compile these fixed query shapes once per synchronous batch and bind fresh values for each execution. A small typed preparation helper uses Kysely's bound-value expressions and compiler ordering, then delegates to the existing synchronous executor. It does not introduce another native statement cache or bypass cache admission, authorizer invalidation, re-entry handling, error reporting, or cleanup. Transcript append and replacement share one insert builder.
The SQL, write order, timestamps, JSON normalization, duplicate handling, idempotency ownership, projections, and transaction boundaries are unchanged. There are no schema, index, configuration, dependency, retention, concurrency, or durable-format changes.
User Impact
Less query-building work during legacy imports and transcript replacement. Isolated Linux median complete file-to-SQLite import time fell 6.8% for deep histories, 4.7% across many sessions, 6.8% for v1 files, and 18.1% for v2 files. Branching, replay, and tiny-import changes were modest; no material gain is claimed for those controls. The packaged stable upgrade and final-head CI both passed after a metadata-only assertion-baseline correction.
Evidence
tslogdeclaration errors in unchangedsrc/logging/logger.ts; the shared install lackstypes/BaseLogger.d.tsand was not modified. Clean exact-head CI subsequently passed, including type checks.Focused command:
node scripts/run-vitest.mjs src/infra/kysely-sync.test.ts src/config/sessions/session-accessor.sqlite-import.test.ts src/config/sessions/session-accessor.sqlite-active-events.test.ts src/config/sessions/session-accessor.conformance.test.ts src/config/sessions/session-transcript-context-eligibility.test.ts --testNamePattern '^(?!.*100k-message)'.Separate follow-up opportunities: Doctor's preliminary transcript-count scan still reparses rows before staging, and the JSONL reader still assembles temporary fragment arrays for complete lines. These are outside this query-construction change.
Isolated Linux measurements
Blacksmith Testbox run, Node 24.19.0 / SQLite 3.53.3, exact candidate
1c410b2575f7b05f96e884558bdd0614685e4c2b. Only the two production owners are overridden for the baseline frome60b4ec5260f91c4969654aa9dee5c4d5396f089; all other source and dependencies are identical. Five fresh processes per side per shape, alternating pair order. Fixture creation and digest verification are outside the timer; stable fixture paths preserve v1 ID derivation.All 35 paired digests match across exact transcript bytes, identities, window metadata, active positions, projection watermarks, and FTS. The separate 10k-event trace retains 100,034 SQL calls across the same 34 shapes. Before/after Node CPU profiles completed separately from the unprofiled timing samples. All samples, including outliers, remain in the evidence; small movements in controls should not be treated as reliable speedups.
Packaged upgrade and final-head scope
The packaged Docker upgrade from stable
2026.7.1-2passed 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 37 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 command exited successfully in 13m14s; proof and CPU profiles were collected and checksum-verified, then the worker was stopped.The package and benchmarks ran at
1c410b2575f7b05f96e884558bdd0614685e4c2b. Final headf29c696bfbd0fe91ea475768bc73fcf0b223b31adiffers only inconfig/assertion-safety-baseline.txt(7 → 2), recording the five removed casts. All production and test file hashes are identical. The baseline file is absent from the package inventory, so that correction does not change the tested runtime. The first CI run correctly caught the stale allowance; its exact ratchet passes after the correction, and independent review of that one-line change is clean. Final-head CI completed successfully atf29c696bfbd0fe91ea475768bc73fcf0b223b31a.Dependency contract and review disposition
ClawSweeper’s final-head review, refreshed at 2026-08-30 21:41 UTC and personally read before landing, found no concrete code defect, but could not inspect the pinned dependency in its environment. I directly inspected installed Kysely 0.29.5 and independently fetched the versioned upstream compiler: compileQuery copies the ordered parameter array; visitValue forwards bound values unchanged; addParameter appends the original value. A separate final-head executable probe confirmed marker identity, repeated marker ordering, and literal preservation in the installed version. The new SQLite tests also execute these bindings and nested callbacks, and all 35 complete import pairs match stored data. This resolves the dependency-inspection gap. I read the latest completed comment and its rank-up list; its exact-head CI request is now satisfied by the successful final run. The dependency contract is verified and accepted on that evidence; all requested rank-up work is addressed, with no skips.
Median process peak RSS (KiB), before → after: single 353,788 → 353,916; deep 512,860 → 512,636; wide 399,612 → 405,784; branch 406,024 → 405,228; replay 395,208 → 400,816; legacy-v1 406,332 → 402,048; legacy-v2 527,984 → 396,640. These are process peaks, not isolated importer allocations; no universal memory reduction is claimed.