Repository navigation
perf(sqlite): reuse compiled plugin state point reads - #138758
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: blocked before merge. Reviewed September 4, 2026, 11:01 PM ET / September 5, 2026, 03:01 UTC. ClawSweeper reviewWhat this changesReuse a compiled SQLite query for plugin-state lookups while supplying fresh plugin, namespace, key, and expiry values on every read. Merge readiness⛔ Blocked before merge - 1 item remains The optimization remains useful: current main still recompiles point reads. No introduced correctness or security defect was found, and the prior review contains no outstanding code findings. Priority: P2 Review scores
Verification
How this fits togetherPlugin-state storage holds persistent, plugin-scoped values in OpenClaw’s shared SQLite database. Synchronous and asynchronous store operations use its point reader, including Reef audit reconstruction and Buzz reconnect cursors. flowchart TD
A[Plugin store operations] --> B[Shared database owner]
B --> C{Reader compiled for connection?}
C -->|No| D[Compile fixed query]
C -->|Yes| E[Bind current scope and expiry]
D --> E
E --> F[Execute fresh SQLite read]
F --> G[Current value or missing result]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +16, Tests +47. Total +63 across 2 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep one prepared reader per physical connection at the shared store owner, with fresh scope and expiry bindings through the existing executor. Do we have a high-confidence way to reproduce the issue? Not applicable to a functional bug: this is a performance optimization. Current-main source confirms repeated compilation, and the supplied regression report measures seven compilations becoming one; this review did not run a benchmark. Is this the best way to solve the issue? Yes. Reusing the existing preparation helper at the common reader removes repeated compilation without introducing consumer-specific snapshots or changing fresh-read semantics. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against c748cd5714b8. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
|
I completed the direct dependency inspection requested by the latest ClawSweeper review. Installed Kysely 0.29.5 The actual native owner-path proof also passed: a 30,000-link Reef chain still performs 30,001 SELECTs with the same values while warm Kysely compilation falls to zero; Buzz still observes fresh interleaved writes, and uncommitted corrupt overflow records remain outside the read scope. Two physical connections bind independently, and fresh-process reopen preserves the stored rows. The 190 focused tests, full changed-file gate, and independent P0–P2 review passed. This resolves the reviewer's dependency-access limitation without changing the prepared head or adding a result cache. |
9456ed0 to
2a06189
Compare
|
Refreshed proof on The latest ClawSweeper review reports only that its environment could not retrieve dependency sources. I directly inspected the installed Kysely 0.29.5 compiler and official Node 24.20.0 |
|
Merged via squash.
|
* refs/remotes/origin/main: (602 commits) fix(plugins): trace trust refusals and repair legacy provenance (openclaw#138746) perf(sqlite): reuse compiled plugin state point reads (openclaw#138758) refactor: type chat prefetch dependencies and clean loading tests (openclaw#138793) ci: reduce Doctor test startup and core lint jobs (openclaw#138796) feat(update): retain run history and share outcome reports (openclaw#138690) chore(deps): update @openclaw/fs-safe to 0.8.1 (openclaw#138500) fix: preserve global board ownership from pinning to notifications (openclaw#138675) fix(gateway): deliver session catalog updates from slow hosts (openclaw#138674) perf(sessions): index pending conversation replies (openclaw#127182) perf(auth): reuse ordered provider alias entries (openclaw#138805) docs(diagnostics): clarify whole-process CPU metrics (openclaw#138804) perf(memory): narrow source reads and stream embedding cache rows (openclaw#138766) fix: allow older source on newer Testbox checkouts (openclaw#138782) fix(agents): preserve recovered task progress and lifecycle ownership (openclaw#138785) perf(codex): reduce rollout tail scan CPU (openclaw#138784) perf(gateway): stop projecting history deltas at the byte budget (openclaw#138655) fix(build): bound native declaration inputs to checkout (openclaw#138742) fix(cli): preserve foreground Gateway argument handling (openclaw#138765) fix(ui): align task toolbar with side-panel tabs (openclaw#138769) fix(logbook): drain accepted work before closing SQLite (openclaw#138754) ... # Conflicts: # src/agents/embedded-agent-runner/compact.queued.ts
What Problem This Solves
Plugin state point reads rebuild and compile the same Kysely query for every lookup. Reconstructing a large Reef audit chain or Buzz reconnect cursor set repeats that JavaScript work thousands of times even though the physical connection and query shape are unchanged.
Why This Change Was Made
Reuse the existing
prepareSqliteQuerySynchelper once per physical SQLite connection at the shared point-read owner. Every invocation still binds its current plugin, namespace, key, and expiry time and executes the same fresh read. Native statement invalidation remains owned by the existing helper, and the compiled runner has weak connection ownership.This preserves exact point-read timing. Replacing these callers with namespace snapshots would change concurrent reconnect observations or expose unrelated malformed audit rows. No result rows, authorization decisions, or expiry facts are cached.
User Impact
Existing plugin-state consumers perform less repeated query-building work without changing their results or setup. Schema, stored rows, transactions, error handling, quotas, and public APIs are unchanged.
Evidence
Production delta is +16 lines for one connection-owned compiled reader; tests add 47. There is no new cache framework, dependency, configuration, or test-only production hook.