Skip to content

improve: reduce repeated SQLite work during chat turns - #168093

Merged
steipete merged 27 commits into
mainfrom
dbasync/w11turnpub
Oct 10, 2026
Merged

steipete merged 27 commits into
mainfrom
dbasync/w11turnpub

Conversation

@steipete

@steipete steipete commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Chat turns repeatedly read session entries, participant metadata, transcript versions, and context that the current transaction or bounded hydration already established.

Stacked on #167965 (dbasync/noprobe). Measurement baseline: a4ca20f1f8b29b5bf4f98f337ef71bf8962e84de; candidate: 3015835815b489bff435ff29067326a2988f6056. The branch includes its initial main integration; this lane adds no schema migration.

Stack handoff: the parent branch advanced after this lane's initial integration. Local Git reports multiple merge bases against dbasync/noprobe; GitHub currently shows the PR as conflicting, with 274 files (+13,243/-5,298) because the comparison includes inherited changes. The measured lane diff is the 24-file a4ca20f1f8b2..3015835815b4 comparison (+992/-335). The lander must reconcile the stack when the parent lands; the proof below applies to the exact measured head, not future conflict resolution.

User Impact

Fewer SQLite statements and worker requests during ordinary chat turns, with no intended behavior change. Separate durable user and assistant commits, idempotency, FIFO ordering, live authority, retention, and released SDK entrypoints remain intact. No operator action is required.

Why This Change Was Made

Turn preparation and commit carry current entry and participant facts to custody and publication. Entry writers certify persisted postimages at their native transaction revision; intervening mutations and serialization hooks invalidate reuse. Transcript mutation postimages supply transaction-local version facts, with rollback and raw mutations retiring them. Assistant rebase validation now shares the append write reservation.

Bounded hydration carries its projection watermark/version. A complete, unchanged view can provide detached, sanitized initial model context, guarded by the selected physical reader's write token. The normal legacy selector still resolves through that physical reader. Single-statement lifecycle reads drop redundant transaction envelopes; composite snapshots and the final count after awaited maintenance remain current reads. No transaction spans a model, network, or file await, and no foreign-commit probes or repeated format checks are added.

Evidence

Five alternating pairs (M4,C4 through M8,C8), all on the exact pins above, passed the fixed synthetic workload. Each run has thirteen top-level turns, one awaited child, a completed cron run, compaction, and graceful shutdown. All native statements across MAIN, workers, and helper processes are counted, including background work and transaction controls. Calibration and phase/thread/SQL conservation passed, with no warmed native failures or freshness probes.

Warmed medians fall 852.2→811.1 statements and 203.3→198.6 requests. Matched changed-owner classes directly remove 25 statements and one request per turn; the remaining raw reduction includes timing-dependent background variation. One canonical-key SELECT overlaps the constants lane and must not be credited twice. The 45/3 target is an aim, not a publication gate; this lane does not reach the campaign-wide goal of fewer than 500 statements per warmed turn.

Supplementary startup-to-shutdown check

The original non-turn increases were investigated before publication. One predeclared additional alternating M9,C9 pair used the same exact source pins and unchanged workload/counting harness, after both builds finished. This is the requested entire-workload check, not a replacement for the original median series.

Metric M9 C9 Delta
all 19977 18771 -1206
main 2732 2641 -91
worker-thread 17083 15968 -1115
helper-process 162 162 +0
requests 3884 3672 -212
seconds 207.781 156.044 -51.737

All 31 original growth families have equal or lower startup-to-shutdown SQL and requests in this pair. The specifically investigated memory commands remain equal/lower after combining database.domain.execute subcommands with same-named directly dispatched commands. The additional pair meets the coordinator’s whole-workload equal/lower numeric criterion. The reductions here include runtime/timing variation and are not claimed as directly attributable implementation savings.

The original cron/compaction increases are classified as timing redistribution/coalescing under this check. No additional publication/lifecycle producer work was found: the changed paths decrease, scheduling and memory-sync owners are unchanged, and all originally growing families are equal/lower over the follow-up run. Only the matched 25-statement/one-request reduction is directly credited to this implementation.

Additional pair: every phase, original growth families, and memory commands

Arrows show M9→C9; successful SQL includes all threads and helper processes. The ten warmed rows are individual observed turns, not medians.

Phase All SQL MAIN SQL Requests Seconds C/M duration
01.boot 3107→3069 1980→1947 70→70 58.863→48.412 0.822
01.connect 695→224 78→44 90→36 5.348→1.852 0.346
02.first-turn 1215→1806 31→78 264→343 40.719→21.226 0.521
03.turn-01 1217→738 55→0 278→180 8.305→3.191 0.384
03.turn-02 941→912 22→22 227→225 4.419→3.635 0.823
03.turn-03 958→755 22→7 235→189 7.639→3.116 0.408
03.turn-04 951→919 22→15 228→218 6.083→5.091 0.837
03.turn-05 941→915 22→22 225→224 4.133→3.859 0.934
03.turn-06 766→913 0→22 182→225 4.612→4.527 0.982
03.turn-07 941→749 22→4 225→181 5.752→3.945 0.686
03.turn-08 957→944 22→23 228→228 5.745→4.693 0.817
03.turn-09 946→965 22→35 225→242 5.21→4.823 0.926
03.turn-10 971→940 26→22 229→234 5.562→6.713 1.207
04.second-session 3446→3009 132→87 779→686 22.486→22.435 0.998
05.control-plane 216→193 22→22 49→44 1.461→1.212 0.830
06.cron 1261→1271 161→198 252→249 16.723→12.792 0.765
07.compaction 327→324 24→24 83→82 1.744→2.094 1.201
08.shutdown 121→125 69→69 15→16 2.961→2.185 0.738
done 0→0 0→0 0→0 0.016→0.243 15.188

Warmed averages: all 958.9→875, main 23.5→17.2, requests 228.2→214.6.

Every standard measured phase has a C/M duration ratio ≤1.5; the zero-work done marker is excluded. The host was loaded (recorded load averages approximately 62–102); these instrumented durations do not establish a latency improvement.

Limits: this additional pair’s first-turn SQL rises 1215→1806, while boot+connect+first rises 5017→5099. Cron rises 1261→1271 (+10); shutdown rises 121→125 (+4). The original five-pair first-turn median remains 1822→1807 and warmed median 852.2→811.1. This supplementary whole-workload result must not be presented as every individual phase passing, or as a replacement median series.

The set is the union of positive cron/compaction family-median SQL deltas and positive SQL/request types in the representative median-run attribution.

Family M SQL C SQL Δ SQL M requests C requests Δ requests
agentDatabaseDeletion.snapshot 41 36 -5 5 5 +0
bootstrap.prune 6 4 -2 3 2 -1
channelIngress.failedHealth 4 3 -1 4 3 -1
channelIngress.pressureHealth 4 3 -1 4 3 -1
closeResource 0 0 +0 368 361 -7
cron.loadMutable 33 27 -6 16 13 -3
cron.maintainHistory 18 12 -6 3 2 -1
cron.observeRunRecovery 20 16 -4 5 4 -1
database.domain.bind 710 553 -157 140 114 -26
database.domain.close 111 85 -26 140 114 -26
database.domain.execute 996 812 -184 200 156 -44
deliveryQueue.countFailed 8 6 -2 4 3 -1
pluginState.entries 32 23 -9 32 23 -9
pluginState.sweep 12 8 -4 3 2 -1
session-corpus-inventory 202 161 -41 32 26 -6
session-entry 83 68 -15 16 13 -3
session-entry-list 50 44 -6 5 4 -1
session-identity-evidence 12 9 -3 3 2 -1
session-store-target 0 0 +0 222 216 -6
session-target-inventory 147 144 -3 138 137 -1
session-tombstones 120 100 -20 30 25 -5
session.maintenance.read 176 172 -4 41 40 -1
sessionUpstream.listWatched 6 4 -2 3 2 -1
unassigned 2879 2786 -93 0 0 +0
workerEnvironments.pruneCandidates 6 4 -2 6 4 -2
workerPlacements.changeSnapshot 14 10 -4 14 10 -4
workerPlacements.read 8 8 +0 4 4 +0
workers.placementPendingResults 12 9 -3 12 9 -3
workers.placementProjection 101 100 -1 102 101 -1
workers.placementRecoveryCandidates 36 30 -6 6 5 -1
worktrees.findLiveByOwner 0 0 +0 0 0 +0

Semantic memory commands

Domain-dispatched and directly dispatched forms are added once each. Transport labels do not create an apparent saving.

Command M SQL C SQL Δ SQL M requests C requests Δ requests C direct SQL/requests
cache.prune 16 13 -3 16 13 -3 0/0
cache.read 15 11 -4 15 11 -4 0/0
cache.stage.start 0 0 +0 15 11 -4 0/0
cache.write 181 133 -48 15 11 -4 0/0
source.hash 16 12 -4 16 12 -4 0/0
source.refresh 5 10 +5 1 2 +1 0/0
source.replace 358 263 -95 15 11 -4 21/1
source.state 18 15 -3 18 15 -3 2/2
stage.append 39 29 -10 30 22 -8 1/1
stage.start 0 0 +0 15 11 -4 0/1

All listed memory commands combined: SQL 648→486; requests 156→119. source.refresh is the disclosed exception among individual commands (1→2 requests, 5→10 SQL); it was not one of the original growing commands. The targeted hash/state/replace/prune/append/start commands all decrease.

Both fixtures completed all 13 top-level turns, child completion, cron work, compaction, and clean shutdown. Calibration and the existing census verifier passed. Independent checks match raw compact statement counts to native-class totals and logical send-event totals to request counts. No runtime freshness probes or non-shutdown native failures were observed.

M9 recorded one failed BEGIN IMMEDIATE during MAIN agent-database lease release at idle close. C9 recorded the same lease-release lock refusal plus one worker audit.writer.prune lock refusal during shutdown. These are failed native executions and excluded from successful SQL counts; all are retained in the adjacent JSON and original census. The extra audit refusal is disclosed, not counted as a savings mechanism.

All six pairs retained: mixed pooled medians

Pooling M4–M9/C4–C9 does not make every median favorable. This table is included to prevent favorable-run selection; it is not a new gate definition.

Metric M median [min–max] C median [min–max] Δ median
whole SQL 18211.5 [18003–19977] 18239.5 [17920–18771] +28
whole requests 3481 [3438–3884] 3556 [3480–3672] +75
warmed SQL/turn 852.45 [831.8–958.9] 813.1 [809.2–875] -39.35
warmed requests/turn 203.5 [198.6–228.2] 199.05 [198.2–214.6] -4.45
first-turn SQL 1821.5 [1215–1914] 1806.5 [1746–1817] -15
cron SQL 932.5 [875–1268] 1112.5 [904–1413] +180
compaction SQL 334.5 [326–381] 367.5 [324–416] +33

The original report, additive representative attribution, and this one-pair whole-workload check remain distinct. No additional rerun was performed for this analysis.

Exact accounting of the original cron and compaction median increases

Actual median representatives are M4/C6 for cron and M5/C4 for compaction. They are not temporal pairs; this table explains the median outcomes, while paired-series and follow-up workload results govern the comparison.

06.cron: M4 → C6

SQL 915 → 982 = +67. Logical requests 185 → 214 = +29. Native groups reconcile as +87 + (-20) = +67.

Request M SQL C SQL SQL delta Requests delta
unassigned 148 160 +12 +0
agentDatabaseDeletion.snapshot 0 11 +11 +1
cron.maintainHistory 0 11 +11 +1
session-entry-list 6 12 +6 +1
workers.placementRecoveryCandidates 6 12 +6 +1
session-identity-evidence 6 11 +5 +1
cron.loadMutable 15 19 +4 +2
cron.observeRunRecovery 8 12 +4 +1
pluginState.sweep 0 4 +4 +1
workerPlacements.changeSnapshot 4 8 +4 +4
workers.placementPendingResults 3 6 +3 +3
bootstrap.prune 0 2 +2 +1
deliveryQueue.countFailed 0 2 +2 +1
sessionUpstream.listWatched 0 2 +2 +1
workerEnvironments.pruneCandidates 1 3 +2 +2
workerPlacements.read 2 4 +2 +1
channelIngress.failedHealth 0 1 +1 +1
channelIngress.pressureHealth 0 1 +1 +1
pluginState.entries 2 3 +1 +1
session-target-inventory 7 8 +1 +1
workers.placementProjection 5 6 +1 +1
closeResource 0 0 +0 +2
session-store-target 0 0 +0 +1
session.entry.patch.commit 141 139 -2 +0
transcript-hydration 27 24 -3 +0
session-row-backfill 16 11 -5 -1
database.domain.publish 154 146 -8 +0

07.compaction: M5 → C4

SQL 342 → 408 = +66. Logical requests 87 → 100 = +13. Native groups reconcile as +71 + (-5) = +66.

Request M SQL C SQL SQL delta Requests delta
database.domain.bind 24 48 +24 +4
unassigned 24 45 +21 +0
database.domain.execute 8 16 +8 +4
session-corpus-inventory 10 15 +5 +1
session-entry 5 10 +5 +1
database.domain.close 4 8 +4 +4
session-tombstones 8 12 +4 +1
database.domain.publish 22 21 -1 +0
open 3 1 -2 +0
pluginState.entries 2 0 -2 -2

Cron's unassigned +12 is +14 MAIN (an additional reconcilePublications sweep: +10 state-ownership guards and +3 publication-coordinator reads; runSessionRegistryMaintenance: +1 config read) and -2 worker transaction controls. Compaction's unassigned +21 is entirely MAIN: resolveSessionIndexEntry adds 8 memory lease statements and 5 database-context PRAGMAs, while a memory-sync follow-up adds 5 lease statements and 3 revision/metadata/chunk reads.

Memory worker stacks reach manager-publication.worker.ts bind/close and manager-source-state.ts/manager-source-index-kernel.ts; corpus/tombstone sender stacks include processSessionUpdateBatch → resolveArchiveFilesForSyncTargets → listSessionCorpusEntries. Maintenance reads are issued by session-accessor.sqlite-reclamation-run.ts, with some sender origins ending at FIFO frames. Those truncated origins remain a limitation, rather than being automatically classified as background.

The memory sync/debounce, maintenance scheduling, and cron recovery source files are byte-identical to baseline. The existing memory debounce is five seconds; maintenance batches age writes for one second and repeats planning when its generation changes. This source evidence establishes a timing/coalescing mechanism, not by itself a passing measurement. The original whole-run medians were SQL 18,091→18,031, requests 3,444→3,511, and duration 88.067→106.764 seconds.

Focused owner tests passed 134 tests in 443.69 seconds with pnpm test <owner files> --maxWorkers=1. The later codec/publication selection passed in 106.77 seconds. The normal-selector regression failed before the physical-reader fix and all six reuse/freshness cases passed afterward. Negative controls on baseline failed at the intended lifecycle-envelope and version-reread assertions. Coverage includes durable commit/custody, publication postimages, rollback and raw-write invalidation, bounded/incomplete hydration, changed views, and incognito behavior. These are local wall times; hosted CI seconds have not been measured.

Three isolated Codex P2 review rounds are clean, including the final physical-reader fix. T1 is unchanged at 707. Madge, runtime import cycles, Knip, exact-head targeted lint, types, and ratchets passed. SDK comparison reports 153 reachable declaration changes, with no added or removed SDK entrypoints or exports; later edits preserve those signatures.

Known check gap: full check-changed stopped on inherited internal-config-api use of transformConfigFileWithRetry in unchanged src/gateway/server-methods/agents.ts. It is identical to the measurement baseline and fixed upstream by 959197ba0923; remaining guards were run separately. The inherited MockConfig fixture type error was repaired in this branch. Published-driver × candidate update cell: pending (lander). No update-proof claim is made.

Production LOC versus the measurement baseline: +642/-332; tests +333/-3; docs +17. Most production growth certifies and invalidates reusable facts at the existing owners; old reread paths remain only where the certificate cannot establish freshness or authority. The anchor request and final lifecycle count remain explicit.

Original five-pair phase statement/request table

Cells are median [min–max]. Warmed values are each run's ten-turn mean. Individual owner medians need not sum to the workload median.

Phase Base all SQL Candidate all SQL Base MAIN SQL Candidate MAIN SQL Base requests Candidate requests
01.boot 3102 [3086–3103] 3103 [3101–3118] 1980 [1979–1980] 1980 [1980–1980] 69 [66–70] 69 [69–70]
01.connect 208 [185–219] 216 [183–247] 21 [20–44] 44 [20–44] 39 [36–44] 37 [36–42]
02.first-turn 1822 [1769–1914] 1807 [1746–1817] 88 [78–114] 79 [78–102] 342 [323–364] 342 [333–345]
warm 852.2 [831.8–854.6] 811.1 [809.2–829.3] 11 [8.1–11] 8.8 [8.8–11.4] 203.3 [198.6–204.2] 198.6 [198.2–202.6]
04.second-session 3226 [2983–3330] 3249 [3210–3322] 105 [74–116] 110 [102–120] 724 [655–742] 737 [734–754]
05.control-plane 22 [18–52] 29 [18–90] 0 [0–13] 4 [0–19] 6 [5–17] 6 [5–25]
06.cron 915 [875–1268] 982 [904–1413] 24 [17–163] 42 [24–171] 187 [171–258] 214 [193–299]
07.compaction 342 [326–381] 408 [326–416] 24 [24–44] 45 [24–49] 87 [82–103] 100 [82–107]
08.shutdown 122 [112–125] 115 [112–122] 66 [63–69] 66 [63–66] 16 [15–17] 15 [15–16]
Direct changed-owner savings
Owner Base SQL/turn Candidate SQL/turn Base requests/turn Candidate requests/turn
session.turn.prepare 13 [13–13.1] 9 [9–9] 1 [1–1] 1 [1–1]
session.turn.commit 41 [41–41] 39 [39–39] 1 [1–1] 1 [1–1]
session.lifecycle.project 25 [25–25] 21 [21–21.1] 1 [1–1] 1 [1–1]
transcript-hydration 32 [32–32] 30 [30–30] 2 [2–2] 2 [2–2]
model-context 7 [7–7] 0 [0–0.7] 1 [1–1] 0 [0–0.1]
transcript-anchors 12 [12–12] 12 [12–12] 1 [1–1] 1 [1–1]
database.domain.publish:session.metadata.append 48.1 [48–48.2] 44.1 [44–44.2] 2 [2–2] 2 [2–2]
database.domain.publish:prepare 5 [5–5] 3 [3–3] 1 [1–1] 1 [1–1]
database.domain.publish:count 1 [1–1] 1 [1–1] 1 [1–1] 1 [1–1]
database.domain.publish:claim 3 [3–3] 3 [3–3] 1 [1–1] 1 [1–1]

Removed classes: turn preparation 4 (entry/owner, participant, canonical-key, cold presence); turn commit 2 (entry/owner and participant); metadata append 4 (one read envelope and two postimage reads); lifecycle authority 4 (two read envelopes); no-removal lifecycle prepare 2 (one read envelope); hydration 2 (version reads folded into projection); initial model context 7 + one worker request. No saving is credited merely for moving work to a worker.

The synthetic workload does not establish production-history, arbitrary plugin/tool-mix, or uninstrumented latency behavior. Instrumented durations and RSS include observer overhead. Proof retains compact summaries and cited logs; raw SQL streams and fixture databases are removed after aggregation. The shared workload/counting harness is unchanged.

Original five-pair instrumented durations

Seconds include observer overhead and settling; these are not uninstrumented latency claims. Warmed duration covers all ten turns.

Phase Base seconds Candidate seconds Candidate/base median
01.boot 27.592 [17.451–33.94] 28.448 [23.017–64.832] 1.031023
01.connect 1.349 [1.263–1.593] 1.733 [1.19–2.186] 1.284655
02.first-turn 12.254 [7.888–13.485] 13.005 [10.686–22.849] 1.061286
warm 26.435 [22.738–30.722] 27.178 [23.999–32.274] 1.028107
04.second-session 9.689 [7.956–15.254] 13.107 [8.99–15.471] 1.352771
05.control-plane 1.18 [1.121–1.432] 1.218 [1.15–1.575] 1.032203
06.cron 9.751 [6.81–14.476] 10.983 [9.034–14.307] 1.126346
07.compaction 1.646 [1.36–3.251] 1.567 [1.387–2.316] 0.952005
08.shutdown 1.538 [0.961–1.896] 1.125 [0.873–8.22] 0.731469

Landing validation

Final candidate: 1a67c1acd4fd12f08182b775117e70a3ffbc98f1. Main was merged without conflicts, including the cold-rebuild retry-cooldown test fix 696e8256e55f655bb23e9a6adaeba81caea6419c. Earlier lander fixes corrected one stale maintenance-error expectation and removed one unused test type import; both received clean scoped P0/P1 autoreview.

Current-head CI passed. Merged through the native workflow as da965e09656e399bbe07f91b82e385e412cc2088; no admin CI override was used. The earlier candidate run failed the damaged-archive memory test identically to scheduled main; its four cancelled jobs were not passing evidence. The subsequent main merge includes the fix for that failure.

Published-driver 2026.9.9 × candidate bd5eef6c9869b7fc7d751699e9141b24e84f8b5d passed on AWS in 485 seconds: update finished, readyz=200, running version verified, and durable/incognito state preserved. Both focused test shards passed in 51.40 seconds, with clean targeted lint. This proof is reused after the main-only merge under the coordinator's explicit rule; it is not presented as a run of the new head. Tested candidate tarball SHA-256: a5fa82f164da02f78f8009a59b43f6500ef44c7415a73cf52ffbdfc1e7675987.

…odules

Merge current main while preserving shared physical admission, cancellation, reader validation birthtime, and live deletion authority. Split worker usage, pool construction, failure settlement, and schema owner types to keep the existing line caps.
Checkpoint the single-owner cutover, cache invalidation regressions, and request-owned read transactions. Keep explicit migration verification. Paired measurement and final validation are still in progress.
Route retained existing-state writer coverage through the host-owned worker project, preserve first-admission incompatibility refusal, and match the final deletion-authority contract. Keep the gateway test under its inherited line count by moving existing pure fixture helpers. Regenerate assertion allowances without adding production assertions.
Include the thirteen transitive admission modules required by the native wrapper import-closure proof. Carry the existing birthtime through the worker validation fixture to preserve its physical-file identity.
Merge current main and preserve its optional settlement-only receipt delivery through the extracted owner. Keep the worker refusal error with the leaf contract to stay within the existing admission line cap. End the marker-free read-only fixture transaction normally; dedicated rollback and explicit revocation coverage remains unchanged.
Preserve snapshot-local reuse without freshness queries, publish dedicated archive writes, and remove Workboard polling. Retain native authority and settlement boundaries. Checkpoint reviewed corrections and focused regression repairs; final integrated proof remains in progress.
@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review in progress

ClawSweeper is reviewing this revision. This supersedes any previous blocked status.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime extensions: memory-core Extension: memory-core scripts Repository scripts commands Command implementations agents Agent runtime and tooling plugin: file-transfer labels Oct 10, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 10, 2026
@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

This PR reuses transaction-owned session facts and complete transcript hydration to reduce repeated SQLite work during chat turns.

Example: The supplied synthetic workload completes an ordinary warmed chat turn.

  • Before: Median successful SQLite statements per turn: 852.2.
  • After: Median successful SQLite statements per turn: 811.1, with unchanged intended chat behavior.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful measured optimization with focused freshness coverage and no definite introduced defect; authority-chain validation remains unresolved.
Proof confidence 🦐 gold shrimp (3/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦐 gold shrimp (3/6) Security review found an item that needs attention.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Ordinary chat turns repeat database reads for facts already established by their transaction or bounded hydration.
Reason: The supplied measurements identify attributable savings at existing owners, and the maintainer-authored direction adds no option, schema, or intended behavior change.

Merge readiness

⛔ Blocked before merge - 3 items remain

This PR provides a useful, distinct SQLite optimization; no definite introduced bug was found in the reviewed diff.

Priority: P2
Reviewed head: 1a67c1acd4fd12f08182b775117e70a3ffbc98f1

Before merge

  • Add real behavior proof - Authority-chain proof required: the supplied chat workload exercises turn preparation, commit, publication, hydration, and initial context, but does not show allowed writes and denial before transcript I/O after owner revocation or reassignment, member removal, or generation replacement during queued preparation; provide production-path logs or terminal output with credentials, IPs, phone numbers, and non-public endpoints redacted. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve security concern: Validate reused authority facts at the final write - Transaction-local entry reuse now feeds source and custody checks across preparation and commit; the existing checks remain visible in source, but supplied execution evidence does not cover the nearest forbidden principal after authority changes.
  • Resolve merge risk - Before merge, establish that reusing entry facts for source and custody checks cannot let revoked or reassigned authority reach transcript writes.

Findings

  • [medium] Validate reused authority facts at the final write — src/config/sessions/session-turn.worker.ts:307

Tests

  • Missing end-to-end proof: The supplied chat workload does not demonstrate allowed and denied final transcript writes after authority changes during queued preparation.
Agent review details

How this fits together

Chat preparation and completion pass session entries and messages through the existing database workers, which commit transcripts and publish facts used by custody checks, session projections, and model context.

flowchart TD
A[Chat turn] --> B[Turn preparation]
B --> C[Existing worker transaction]
C --> D[SQLite session and transcript state]
C --> E[Committed publication facts]
D --> F[Bounded hydration and model context]
E --> A
F --> A
Loading

Technical review

Best possible solution:

Retain the existing worker owners and revision-scoped reuse while demonstrating final-effect rejection of stale authority.

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

The supplied alternating workload measures repeated SQLite work through chat execution; this read-only review did not run target code.

Is this the best way to solve the issue?

Reusing certified facts within existing transaction and physical-reader lifetimes is a coherent optimization that preserves fresh-read fallbacks when reuse cannot be certified.

AGENTS.md: found and applied where relevant.

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

Merge-risk options

Maintainer options:

  1. Demonstrate denial at the transcript boundary (recommended)
    Provide production-path output showing an allowed append and denial before transcript I/O after applicable owner revocation, reassignment, member removal, and generation replacement during queued preparation.

Provenance checked

  • Compound turn preparation, commit, custody, and publication keeps the original intent (ca77256: Keep authoritative predicates, ordered appends, entry writes, and receipts together on the existing worker, with host-held current authority.)
  • Transcript hydration and model-context preparation keeps the original intent (ab5fd51: Compose bounded transcript reads while preserving physical source identity, snapshot freshness, and synchronous acceptance.)
  • Committed entry publication keeps the original intent (892911b: Publish complete transaction postimages rather than invalidating known entry and membership facts.)
  • Assistant append validation keeps the original intent (b6340c7: Move streaming transcript persistence off the Gateway thread while retaining live transaction and commit authority.)
  • Lifecycle and descendant snapshots keeps the original intent (26dffe7: Preserve fresh durable cleanup predicates and selected physical storage while moving cleanup off the Gateway thread.)

Testing

Proof path: shipped entry point.

Security

Needs attention: No reachable authorization bypass was established, but the changed authority-fact reuse needs final-effect validation.

Evidence

Security concerns:

  • [medium] Validate reused authority facts at the final write — src/config/sessions/session-turn.worker.ts:307
    Transaction-local entry reuse now feeds source and custody checks across preparation and commit; the existing checks remain visible in source, but supplied execution evidence does not cover the nearest forbidden principal after authority changes.
    Confidence: 0.91

What I checked:

PR surface

Source +310, Tests +329, Docs +17. Total +656 across 24 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 17 642 332 +310
Tests 6 333 4 +329
Docs 1 17 0 +17
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 24 992 336 +656

Review metrics

Metric Value Why it matters
Production versus test LOC Production +642/-332; tests +333/-4. Production growth chiefly certifies and invalidates reusable facts at existing owners; added coverage exercises persisted bytes, mutation invalidation, hydration completeness, and read budgets.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a normal-priority performance improvement without an established urgent user-facing regression.
  • merge-risk: 🚨 security-boundary: The diff changes which entry facts feed source and custody authorization; ordinary workload success does not establish rejection of stale authority at the final write.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Add final transcript-write proof that revocation, reassignment, member removal, and generation replacement invalidate applicable prepared authority before I/O.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (4 earlier review cycles)
  • reviewed 2026-10-10T14:06:14.932Z sha 3015835 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-10T14:14:45.015Z sha e0fa7f7 :: needs real behavior proof before merge. :: [P2] Expect the typed maintenance conflict in the new test
  • reviewed 2026-10-10T15:03:01.136Z sha bd5eef6 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-10T15:22:12.420Z sha bd5eef6 :: needs real behavior proof before merge. :: none

Reviewed October 10, 2026, 12:11 PM ET / 16:11 UTC (Revision 5).

@openclaw-barnacle openclaw-barnacle Bot removed extensions: memory-core Extension: memory-core scripts Repository scripts commands Command implementations plugin: file-transfer plugin: workboard plugin: logbook Logbook automatic work journal plugin plugin: team-reports labels Oct 10, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Oct 10, 2026
@steipete
steipete merged commit da965e0 into main Oct 10, 2026
134 checks passed
@steipete
steipete deleted the dbasync/w11turnpub branch October 10, 2026 16:24
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 11, 2026
* perf(sqlite): checkpoint shared admission across workers (WIP)

* test(sqlite): align worker fixtures with shared admission

* perf(sqlite): avoid repeated quarantine reads in retained scopes

* docs(sqlite): define single-owner database freshness

* perf(sqlite): replace runtime probes with writer publications

Checkpoint the single-owner cutover, cache invalidation regressions, and request-owned read transactions. Keep explicit migration verification. Paired measurement and final validation are still in progress.

* test(sqlite): align first-admission coverage and deletion fixtures

Route retained existing-state writer coverage through the host-owned worker project, preserve first-admission incompatibility refusal, and match the final deletion-authority contract. Keep the gateway test under its inherited line count by moving existing pure fixture helpers. Regenerate assertion allowances without adding production assertions.

* build(sqlite): include shared admission in compiled wrappers

Include the thirteen transitive admission modules required by the native wrapper import-closure proof. Carry the existing birthtime through the worker validation fixture to preserve its physical-file identity.

* test(sqlite): use the canonical settlement owner in publication proof

* fix(sqlite): complete writer custody and snapshot cache lifetimes

Preserve snapshot-local reuse without freshness queries, publish dedicated archive writes, and remove Workboard polling. Retain native authority and settlement boundaries. Checkpoint reviewed corrections and focused regression repairs; final integrated proof remains in progress.

* fix(sqlite): retain integrity and worker admission through cleanup

* test(sqlite): preserve reader coverage in existing fixture owners

* fix(sqlite): preserve cache receipts across sibling writers and temp DDL

* fix(workboard): type the replacement card-list promise

* fix(sessions): reconcile listing receipts with single owner reads

* perf(sessions): reuse turn preparation and publication facts

* refactor(sessions): keep model context encoding in the codec

* fix(sessions): bind prepared context to its physical reader

* test(sessions): expect maintenance mutation conflict

* test(gateway): remove unused agent mutation fixture type
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant