Repository navigation
refactor(storage): reduce SQLite bookkeeping per turn - #169173
Conversation
|
Codex review: needs maintainer review before merge. What this changesThis PR reduces repeated SQLite snapshot setup, timeout assignments, audit pruning, and transcript-window writes during chat turns. Example: A warmed chat turn reads an Activity recap and persists audit and transcript events.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it delivers a useful, owner-directed storage optimization that current main lacks, with no actionable correctness finding; landing remains gated by incomplete required checks. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherGateway chat events enter the session and audit writers, while Activity reads bounded transcript snapshots; these existing workers consume connection policy and return committed facts or recap source data. flowchart TD
Chat[Chat turn] --> Gateway[Gateway]
Gateway --> Sessions[Session writer]
Gateway --> Activity[Activity reader]
Gateway --> Audit[Audit writer]
Sessions --> SQLite[SQLite databases]
Activity --> SQLite
Audit --> SQLite
Technical reviewBest possible solution: Land the existing-owner optimization once the required storage and SDK validation is satisfied through the applicable inherited-failure landing path. Do we have a high-confidence way to reproduce the issue? Current-main source shows the redundant operations, and the supplied paired workloads quantify them against the candidate; this read-only review ran no target code or tests. Is this the best way to solve the issue? The patch uses existing transaction, writer, and disposal owners, removes superseded work, and preserves the documented synchronous compatibility path without introducing another storage owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against fcf234a0713c. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +88, Tests +304, Docs +14. Total +406 across 14 files. Added test files: 1. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
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 HistoryReviewed October 11, 2026, 12:17 PM ET / 16:17 UTC (Revision 3). |
Retain connection-owned busy-timeout policy, skip empty audit expiry deletes until due, and fold known transcript-root recency into watermark writes. These remove seven deterministic SQLite statements per warmed turn. The original four-item measurement reduced warmed all-thread statements from 336.7 to 321.5 and requests from 89.3 to 88.3. Its six-statement activity snapshot saving also landed upstream in openclaw#169201; retain that path and its regression. Gateway MAIN remains zero. Preserve the released synchronous SessionManager contract under the documented T1 escape hatch. No schema or retention change. Final-head activity/transcript proof: 69 tests. Type-aware lint, T1/dialect ratchets, export collisions, SDK surface, and cycles pass; required CI is green. Knip reports the same 41 UI findings on the final head and its main baseline, with no changed finding files. SDK API diff reports no public API changes.
First-parent upstream 0bc7491..408a1f3 (53 commits, including openclaw#169164 cold session/memory SQL off the Gateway main thread, openclaw#169173 per-turn SQLite bookkeeping, openclaw#169207 coalesced tool-result actor admissions, openclaw#169238 inter-session envelope bytes, openclaw#168989 ACP replies). Conflict: - plugin-sdk-surface-report.mts: upstream budgets 3673/2134; ours stays +11/+4 on top (3684/2138). Drag removed against upstream: - plugin-sdk-surface-report.mts: dropped the "+1: createSessionHeaderLink" budget comments; upstream added them in openclaw#158742 and retired them in openclaw#165334, and no such export exists any more. - normalize-reply.ts: restored upstream's blank line before bindNormalizeReplyTransformOwner (formatting-only overlay noise). Auto-merged files that carry continuation overlay (normalize-reply, sqlite-entry-store, user-turn-transcript, baselines, vitest paths) keep the overlay byte-for-byte. Worker access inventory regenerated. Refs #1475 Co-Authored-By: Claude Opus 5.5 <[email protected]>
What Problem This Solves
Ordinary chat turns repeat activity snapshot setup, read connection policy already owned in process, issue empty audit expiry deletes, and write a transcript window twice.
User Impact
Reduces SQLite work per turn without changing transcript bytes, audit retention, lock-wait policy, permissions, schemas, or update behavior.
Why This Change Was Made
Removed ordinary-path work and accepted edges:
No new freshness probes, generations, or admission handshakes.
Main-thread inventory and escape hatch
Activity, audit, and timeout-owner sites: T1 0 → 0. The shared transcript files retain 15 classified T1 sites; 8 are in changed functions. One actor-guarded update is worker-only. The other 7 changed-function sites also serve the released synchronous
SessionManagerpersistence API, which guarantees commit before return. Moving those requires its SDK owner redesign, so this PR uses the requested escape hatch and preserves that contract. The ordinary Gateway turn remains on its existing actor/worker path. No T1 call added.Evidence
Codex autoreview: scoped clean, no actionable P0–P2 findings (round 1); the timeout correction is clean at P0/P1 in round 2. Focused Testbox proof: 220 tests passed in 12 files, five shards, 137.59s runner wall time. Covers activity post-write reads, audit expiry/rollback, timeout nested overrides/reopen, transcript actor/batch timestamp semantics and dedupe, entry revalidation, WAL/deadlines, memory publication, and SDK runtime guardrails.
Three alternating pairs, M1,C1,M2,C2,M3,C3, ran on one AWS worker using the unchanged shared workload (SHA-256
1de5109a7b89eaf8c10ef943bde724a89bd44772b7d70419bd344caf18d92cd1). Baselineebdc7d54c0842d96c4bb2fb2bb4be4758f07f255; measured production headba8c1993aa0edccb396b8d07a3d979d1477f53b7. The test relocation retained identical production inputs. The later conflict-only merge tob292f4cf100a69b5159ad25d25d975b117074e36integrates main at6e7d21ec8310351584b27926d8cbb09e0585cd49; the one conflict preserves main’s projection-owned watermark. Per the conflict-only proof policy, these measurements are reused and describe the original four-item implementation, not a fresh measurement against the later main baseline.Observed warmed reduction: 15.2 statements (4.5%) and 1.0 requests (1.1%). Changed-owner requests are unchanged; background variation accounts for the remaining request reduction. Warmed duration ratio C/M: 0.994.
The original four-item implementation accounts for 13 deterministic statements removed per warmed turn. Activity’s 6-statement saving is now also on main through #169201; the remaining PR contributes 7 deterministic statements (2 timeout reads, 2 empty expiry deletes, 3 transcript-root UPSERTs), with unchanged owner request counts. Within them, busy-timeout reads are 2 → 0, empty audit expiry DELETEs 2 → 0, and transcript root UPSERTs 3 → 0. The remaining observed reduction is background variation.
First-turn statements decrease 1203 → 1189, while first-turn requests vary 192 → 199 as unchanged memory/session projection work moves between phases. Following RAW TURN INCREASE, one extra pair M4,C4 checked the complete workload: statements 9799 → 9533, requests 1730 → 1721. Across all four pairs, complete-workload medians are 9830 → 9542.5 statements and 1725 → 1718.5 requests; warmed medians are 336.1 → 321.6 statements and 89.15 → 88.5 requests. No new request class appears in the changed owners. All eight workloads succeed; their two expected lock-admission failures are identical (connect and shutdown). Census has no missing context rows or duplicate sends; the same two startup send/receive observations lack target linkage in every run.
Static proof: core, core-test, extension, and extension-test typechecks passed before the conflict-only merge. On final head
b292f4cf100a69b5159ad25d25d975b117074e36, type-aware core/extension lint, formatting, export collisions, SDK surface, Madge (0 runtime cycles), and T1/dialect ratchets pass. T1 is 612 → 612 raw / 610 → 610 normalized against the merged base. The SDK API diff passed with no public API changes before the merge; the conflict resolution introduced no SDK change. The final-head activity/transcript suite passes 69 tests in 4 files, 124.23s runner. Earlier unchanged-owner proof (220 focused tests, 21 timeout/update-contention tests, 52 mocked-SDK tests) is reused.Knip exception: final head and exact main baseline
6e7d21ec8310351584b27926d8cbb09e0585cd49report the identical 41 UI unused-export findings, keyed by scan, file, and symbol; zero added or removed findings, and none of those files differs in this PR. The earlier subagent-store finding is absent after integrating main. The final required CI gates are green (run 38157182225).No published-driver update cell: update, Doctor, schema/migrations, plugin loading, and service lifecycle are unchanged.
Final diff LOC: production +145/−56, tests +308/−4, docs +14/−0 (13 files). Release-note context: internal SQLite turn-overhead reduction; no migration or operator action.
CI found an update-contention regression in the first head: restoring a matching timeout scope overwrote the mutation’s intentional 5000 ms policy. Fixed by restoring only when the wrapper changed policy on entry. Existing regression plus timeout tests: 21/21 pass (47.15s runner).
Native landing initialization refused twice because the trusted tooling checkout could not resolve
@openclaw/proc-safe, including after frozen dependency restoration. Per the authorized relaxed workflow, use the exact-head REST squash fallback after proof gates pass.Pre-merge-head CI’s remaining failure was inherited:
ui/src/e2e/chat-flow.navigation-presentation.e2e.test.ts:921, “keeps derived sidebar titles and accessible state after session patch refreshes”, expectslink "Readable planning title"but receiveslink "Unread Readable planning title". The same assertion fails on main run 38147604740, job 114494370832. This PR changes no UI code. Pre-merge-head evidence. The earlier production-identical head also hit the terminal-canvas timeout independently seen in that main job. These are prior-head CI observations; final-head required CI is green. The static Knip exception above remains inherited.