Skip to content

perf(sessions): reuse prepared transcript rewrite queries - #139770

Merged
steipete merged 2 commits into
mainfrom
codex/db-next-perf-land
Sep 6, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/db-next-perf-land

Conversation

@steipete

@steipete steipete commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Related: #139768

What Problem This Solves

Transcript maintenance rebuilds and compiles an identical Kysely UPDATE for every rewritten row. Native SQLite statements are already cached, so repeated query construction adds avoidable work to large repairs and migrations.

Why This Change Was Made

Prepare each exact-rewrite and maintenance-repair UPDATE once per existing operation, then bind rows through the shared executor in caller order. Exact JSON predicates and affected-row checks, synchronous transaction boundaries, generation/recency updates, and text-search reconciliation are unchanged. This uses the existing helper and native cache; it adds no schema, configuration, dependency, or retained connection cache.

User Impact

Large transcript repairs and migrations spend less time constructing queries while preserving conflict rollback and all stored/projection state. Single-row operations are not the optimization target.

Evidence

  • 25 focused transcript-store/eligibility tests pass, including repeated-row bindings, caller order, later-row conflict rollback, generation changes and real reconciliation workers.
  • File-backed native proof on Node 24.20.0 and 26.8.1 verifies exact rows, identities, recency, projections, rollback and reopening after every database owner closes.
  • Full changed-file gate and independent P0–P2 review pass on integration base 4e330557ae33e0f003c8b6e17524acd859b1d0de.
  • Complete 2,000-row operation medians, 15 alternating samples after five warmups:
Operation Node 24 before → after Node 26 before → after
Exact metadata rewrite 33.48 → 25.85 ms 23.43 → 13.04 ms
Exact text and search rebuild 87.36 → 70.77 ms 84.77 → 63.68 ms
Maintenance repair and rebuild 100.70 → 84.86 ms 119.13 → 93.52 ms

Warm native UPDATE preparations remained zero on both sides: these gains come from Kysely construction/compilation reuse. A separate 500-sample single-row probe found small differences, including about 7 μs overhead for Node 24 metadata rewrites. Measurements used synthetic state on a shared host; they are not universal latency guarantees.

@clawsweeper

clawsweeper Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added size: S maintainer Maintainer-authored PR labels Sep 6, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 Sep 6, 2026
@clawsweeper

clawsweeper Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 6, 2026, 4:58 AM ET / 08:58 UTC.

ClawSweeper review

What this changes

Reuse compiled SQLite update queries during transcript repairs and add coverage for distinct row bindings, caller ordering, and preserved session state.

Merge readiness

✅ Ready for maintainer review

Keep open: the optimization remains absent from current main and the latest release, and no introduced correctness or security defect was found. The linked issue establishes accepted scope.

Priority: P2
Reviewed head: 8168ca5aa1786fd9ba1390175974b04989a05645

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused optimization using an established executor, with meaningful state-preservation coverage and no blocking findings.
Proof confidence 🌊 off-meta tidepool Not applicable: The external-contributor gate does not apply to this MEMBER-authored PR. Its body nevertheless reports native file-backed runs through the changed rewrite operations, including rollback, projections, reopening, and before/after batch timings; this review did not rerun them.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The external-contributor gate does not apply to this MEMBER-authored PR. Its body nevertheless reports native file-backed runs through the changed rewrite operations, including rollback, projections, reopening, and before/after batch timings; this review did not rerun them.
Evidence reviewed 9 items Verified introduced patch: The local merge-base-to-head diff matches the complete host introduction evidence. Both update loops retain their session and row predicates; exact rewrites retain the expected-JSON predicate and affected-row check.
Existing execution and binding contract: The shared helper compiles once, allocates fresh invocation-local bindings, and executes through the existing synchronous executor. Native statement caching, authorization invalidation, and connection cleanup remain owned by the unchanged cache implementation.
Behavioral coverage: The complete test file covers repeated-row exact rewrites, distinct bindings, caller order, later-row conflict rollback, generation changes, recency, and projection reconciliation. The maintenance test now updates two different rows and verifies both search results. Tests were inspected, not executed during this read-only review.
Findings None None.
Security None None.

How this fits together

OpenClaw’s transcript store receives session edits and maintenance repairs and writes canonical conversation records to SQLite. It also maintains generation markers, activity timestamps, and searchable transcript projections.

flowchart TD
  A[Session edits and maintenance repairs] --> B[Existing write transaction]
  B --> C[Compile update once]
  C --> D[Bind each row in caller order]
  D --> E{Exact rewrite conflict?}
  E -->|Yes| F[Roll back transaction]
  E -->|No| G[Update generation and projections]
  G --> H[Commit transcript changes]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +12, Tests +53. Total +65 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 30 18 +12
Tests 1 63 10 +53
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 93 28 +65

Review metrics

Metric Value Why it matters
Reported batch performance 2,000-row exact metadata rewrite: 33.48 → 25.85 ms on Node 24; 23.43 → 13.04 ms on Node 26 Complete-operation measurements support the batch optimization while the body explicitly retains the small single-row tradeoff.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #139768
Summary: This PR implements the transcript-rewrite portion of the linked performance issue; ACP replay optimization remains separate.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Technical review

Best possible solution:

Use operation-local compiled queries with fresh row bindings while preserving the existing exact-write, rollback, and projection contracts.

Do we have a high-confidence way to reproduce the issue?

Not applicable as a functional bug reproduction: source confirms repeated query compilation on main, and the PR supplies batch timing comparisons.

Is this the best way to solve the issue?

Yes. Reusing the established binding helper at the existing operation boundary removes repeated construction without adding a competing cache or changing stored-data semantics.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against f5d4d6bf53a8.

Labels

Label justifications:

  • P2: This is a bounded performance improvement for transcript maintenance with measured batch benefits and no urgent user-facing 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: The external-contributor gate does not apply to this MEMBER-authored PR. Its body nevertheless reports native file-backed runs through the changed rewrite operations, including rollback, projections, reopening, and before/after batch timings; this review did not rerun them.

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)

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 (2 earlier review cycles)
  • reviewed 2026-09-06T05:14:23.400Z sha 0050e57 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-06T05:51:21.878Z sha 0050e57 :: needs maintainer review before merge. :: none

@steipete
steipete merged commit 30849c2 into main Sep 6, 2026
178 checks passed
@steipete
steipete deleted the codex/db-next-perf-land branch September 6, 2026 09:13
@steipete

steipete commented Sep 6, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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