Repository navigation
perf(sessions): batch transcript persistence writes - #175193
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex review: needs maintainer review before merge. What this changesThis PR batches transcript payload, identity, and active-history inserts while preserving the existing transaction owner. Example: Import a transcript containing 130 unique messages.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR provides a distinct persistence optimization with no actionable introduced defect found; PostgreSQL conformance remains pending. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherSession imports and prepared append operations enter the synchronous transcript transaction owner, which persists canonical events and updates identity, history, and search projections for subsequent reads. flowchart TD
A[Imports and prepared appends] --> B[Transcript transaction owner]
B --> C[Identity and key resolution]
C --> D[Bounded payload inserts]
D --> E[Identity and active history inserts]
B --> F[Search projection writes]
E --> G[History and search readers]
F --> G
Technical reviewBest possible solution: Retain bounded batching within the existing transcript owner and preserve its identity, projection, and transaction contracts. Do we have a high-confidence way to reproduce the issue? This is a performance improvement rather than a reported functional defect; the prior source establishes per-event inserts, and no target code was executed during this read-only review. Is this the best way to solve the issue? The implementation places batching in the existing persistence owner, shares inserters with scalar paths, and preserves streaming acceptance feedback without adding a competing store or schema. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 8457e29a4d01. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +339, Tests +189, Docs +4. Total +532 across 10 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 17, 2026, 2:29 AM ET / 06:29 UTC. |
The fault worker delegated iteration with yield*, which does not close the native iterator when next() throws. Its completed wrapper then hid the native return() from Kysely cleanup. On Node 24.19 the cached statement reported the old injected error on its next use after faults were disabled. Explicitly close the native iterator before restoring the TEMP triggers. Production queue and database behavior is unchanged. Preserve every committed-prefix, pending-input and exactly-once assertion. The scalar INSERT ... RETURNING path added by #175193 exposed this latent fixture defect. #174897 did not remove a required predecessor, and #175295 is not the cause. Reproduced the same failure on hourly ab37bc6 and current main 9c12710 using CI's Node 24.19.0; Node 24.22 used all() and passed without the change. Focused full-file proof: 5/5 pass in normal order with --maxWorkers=1, 28.45 s Vitest / 49.62 s command wall. Independent P2 review is clean. All 22 affected consumer files pass: 337 tests using Node 24.19 and --maxWorkers=1. The other 21 files take 509.14 s wall across five native configs. Owning test-helper types, boundary lint, syntax, formatting and whitespace checks pass. Root-test type-aware lint reports the same pre-existing no-map-spread violation at this file's unchanged line 22 on both base and candidate; no new diagnostic or suppression is introduced. No CI dispatch or rerun.
Batch transcript payload, identity, and active-event writes in bounded groups. Prepared arrays resolve conflict facts once; scalar appends fold identity rejection into the payload insert while preserving immediate foreign-key ordering. Preserve iterator acceptance feedback, duplicate and message-key ownership semantics, committed-prefix behavior, and existing search projections. Add regressions for rejected identities, chunk boundaries, and in-process write visibility.
The fault worker delegated iteration with yield*, which does not close the native iterator when next() throws. Its completed wrapper then hid the native return() from Kysely cleanup. On Node 24.19 the cached statement reported the old injected error on its next use after faults were disabled. Explicitly close the native iterator before restoring the TEMP triggers. Production queue and database behavior is unchanged. Preserve every committed-prefix, pending-input and exactly-once assertion. The scalar INSERT ... RETURNING path added by openclaw#175193 exposed this latent fixture defect. openclaw#174897 did not remove a required predecessor, and openclaw#175295 is not the cause. Reproduced the same failure on hourly ea5c031 and current main 6b9b192 using CI's Node 24.19.0; Node 24.22 used all() and passed without the change. Focused full-file proof: 5/5 pass in normal order with --maxWorkers=1, 28.45 s Vitest / 49.62 s command wall. Independent P2 review is clean. All 22 affected consumer files pass: 337 tests using Node 24.19 and --maxWorkers=1. The other 21 files take 509.14 s wall across five native configs. Owning test-helper types, boundary lint, syntax, formatting and whitespace checks pass. Root-test type-aware lint reports the same pre-existing no-map-spread violation at this file's unchanged line 22 on both base and candidate; no new diagnostic or suppression is introduced. No CI dispatch or rerun.
What Problem This Solves
Transcript imports and prepared append batches still issue one identity lookup and three inserts for every event, despite already sharing one owner transaction.
User Impact
This reduces transcript persistence work while preserving event order, duplicate rejection, message-key ownership, search projections, and accepted-prefix behavior when an import iterator fails. No schema migration or user action is required.
Why This Change Was Made
Prepared arrays resolve identity and message-key conflicts once, then write payloads, identities, and active projection rows in groups of at most 64 rows or 1 MiB of pending payloads. Streaming imports retain per-row acceptance feedback and batch accepted writes. The same bounded inserters serve scalar and batch writes.
Scalar appends without complete actor facts fold the identity lookup into the payload insert. Identity-first
INSERT ... ON CONFLICTcannot preserve the current immediate identity-to-payload foreign key without a schema change; the conditional payload insert keeps that constraint and only publishes actor/index facts after acceptance. Payloads precede identities and active rows. Existing per-event search writes and transaction/commit boundaries remain.Removed repeated checks and accepted edges:
next(accepted)contract requires a decision before reading the next input.Evidence
Focused regressions cover three bounded insert groups, contiguous sequences after rejected identities, later in-process writes, all three message-key modes across a flush with persisted and buffered owners, and iterator prefix commit versus rollback. Formatting, basic lint, diff checks, and the line-cap ratchet pass. Both isolated Codex review rounds are complete: the first was clean; the second found only already-corrected index-snapshot type errors, resolved in the committed working tree, with no additional P0–P2 defects. Initial CI exposed bounded-array type annotations and a metadata-read test spy counting lazy write compilation; both are corrected. Corrected-head CI run 39008355548 confirms 100 passing tests across nine focused owner files, both core type-aware lint stripes, source contracts, export collisions, Madge, and the line/T1/dialect ratchets. The merge-ref T1 ratchet is 182→182 (deprecated compatibility sites 10→10). All selected type checks also passed. The local import suite adds 12 passing cases, bringing focused owner coverage to 112 tests. Canonical Knip reports 8 production and 6 full-tree unused-export findings, with no script findings; every finding matches scheduled main run 39006528379 in unchanged files, and this inherited exception is recorded with the main repair owner. The owner microbenchmark, frozen-revision T1 census, and all three alternating Gateway measurement pairs are complete below. All six arms passed with unchanged runtime receipts, complete turn coverage, zero native SQL/prepare errors, and no remaining fixture children. Independent raw recounts agree with the shared harness. No latency claim is made.
PostgreSQL conformance exceeded its 30-minute job limit after four test failures, leaving the aggregate CI gate red. The retained-root 300-second timeout also occurs on scheduled main run 39006528379. A bounded PostgreSQL 17/pgvector replay of the other three failures passes all three cases on both frozen base and candidate: both Git-backup cases and Matrix partial-publication recovery. Those original CI failures remain unreproduced; the passing replay is not a claimed fix. Both isolated clusters were stopped and removed. The final Doctor pgvector case and the extension PostgreSQL groups did not complete in CI, so this is not a full PostgreSQL conformance pass.
Landing uses the authorized relaxed policy after correcting the initial small type/lint/test-spy defects: all changed-owner and static gates are passing or exactly attributed to main, two review rounds are complete, and the focused failed-case PostgreSQL replay passes on both revisions. The inherited Knip exception and incomplete PostgreSQL CI coverage remain explicit. An initial local import attempt stopped before a verdict when the scratch-size sampler encountered a disappearing temporary cache file; its task-only correction preserved the same limits, and the resumed import test passed.
Three unchanged-harness pairs ran in M,C,M,C,M,C order. Tables report median [min–max]. The median of the three raw warmed arm medians is 62 [62–62.5] → 62 [62–63] statements, 18 [18–18] requests on both sides, and zero MAIN. Causal arm medians are exactly 62 statements / 18 requests / 0 MAIN in every arm. Pooled raw MAIN outliers are background lease-expiry reads from deferred plugin startup maintenance (
runGatewayPostReadyStartupMaintenance→withPluginLifecycleLease→assertOperationOwned→readOpenClawStateLeaseExpiry), outside transcript owners. Some bounded stacks end at plugin registry refresh; the outermost captured stacks show deferred post-ready startup maintenance. Raw warm MAIN totals are M1/C1/M2/C2/M3/C3 = 13/0/13/13/0/0; the affected arms have nine reads in turn 1 and four in turn 2. Causal turn MAIN remains zero throughout.Raw phase counts across the three runs:
The standard workload mostly uses scalar appends: payload/identity/active INSERT statements remain 67/67/63 in every arm. The standalone identity/cold-state lookup falls 3→0 in every pair, one each in first-turn, second-session, and compaction windows. All SELECT/WITH statements mentioning the identity table fall 74/74/73→71/71/70. Across the touched owner modules, observed statements fall 528→525 per complete run and 48→47 in the raw first-turn window; the ten warmed turns remain 250→250. Distinct linked request IDs across these touched owners remain 105→105 per complete run, 9→9 in first-turn, and 50→50 across the ten warmed turns; these are deduplicated unions, not sums of overlapping per-operation request counts. Batched inserts therefore show their main gain in the larger owner workloads below.
Whole-run medians rise by 13 statements and one request, while raw and causal warmed medians do not rise. The touched owner statement counts decrease; the aggregate increase is outside the changed owner operations. No whole-workload saving is claimed. Exact-entry, hydration, row-facts, entry-cache, and watermark families have no captured warm reads/associated requests on either side; the compact report retains cold-family counts and observed source stacks.
Offline SQLite append microbenchmark (setup and enclosing transaction statements excluded):
The 36,000-event workload saves 141,300 statements (64.7%). Identity reads fall from 36,000 to 360, and each payload/identity/active insert class falls from 36,000 to 780. Per-event FTS writes remain 72,000. All five cases verify payloads, identities, active/FTS rows, index state, and recency; zero failed native calls. These are offline SQLite counts, not PostgreSQL round trips or Gateway requests.
The frozen-revision inventory is distinct from the CI merge-ref ratchet above: the identical eight-file scope remains 34 T1 sites in five files; whole-repository T1 remains 186 in 89 files, with compatibility sites separately unchanged at 10. Prepared-query factories and returned executor calls are outside the canonical primitive census.
The shared transcript kernels retain released synchronous SDK callers; this change does not claim T1-zero or reclassify them as worker-only. Gateway MAIN and requests are reported independently from the offline owner microbenchmark above. No wall-time claim on the shared host. No update cell or SDK API diff applies to this transcript-only change.
Candidate:
40141fba5e1583dacdc517b0210b017ac2d25641; measurement base:6d578912da668b3011720ac91997669b6383db5a. Scope: ten files, +707/−175 lines (production +507/−168; tests +189/−0; docs +11/−7). Batch lifecycle and exact-row writes are extracted into one sibling to keep the existing store under its line cap. Builds and SQL fixtures are isolated from live Gateway state.