Repository navigation
perf(state): reuse admitted schema facts on database reads - #156643
Conversation
Keep schema facts with admitted handles and bound cache data-version probes to one per event-loop turn. Native open owns DDL, rollback, authorizer, and handle-lifecycle invalidation; consistency brackets retain fresh probes.
|
🦞👀 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 23, 2026, 1:58 PM ET / 17:58 UTC. ClawSweeper reviewWhat this changesThe branch makes agent and shared-state SQLite readers reuse schema facts recorded at database admission, invalidates those facts after schema changes, and bounds cache-freshness probes to one per event-loop turn. Warning SQLite table change This PR modifies persisted SQLite tables in Merge readiness⛔ Blocked before merge - 3 items remain Keep this PR open. Current main still carries the expected-failure query-budget guard, and this branch supplies the production change that makes it pass. The warm-read measurement is credible; upgrade compatibility needs one required check. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw stores sessions and shared state in SQLite. Database admission supplies schema facts to session and state readers, which use those facts to decide whether a handle remains safe to read. flowchart LR
A[SQLite database open] --> B[Schema admission]
B --> C[Retained schema facts]
D[Local schema change] --> E[Invalidate facts]
F[Foreign commit probe] --> E
E --> B
C --> G[Session and state reads]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +385, Tests +310, Docs +8. Total +703 across 30 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep schema facts with their admitted SQLite handle and verify that the shipped updater can hand existing state to the candidate without changing stored schema or recovery behavior. Do we have a high-confidence way to reproduce the issue? Yes. The merged expected-failure guard exercises the real session and state read entry points, and current main still contains it; I did not run current-main code in this read-only review. Is this the best way to solve the issue? Yes. Retaining facts at SQLite admission and invalidating them at the native owner follows the repository's documented boundary, subject to the required shipped-updater check. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 16908037a034. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
#156643 made src/infra/sqlite-coordinator.ts and src/infra/sqlite-readonly-location.worker.ts import sqlite-pinned-read-snapshot.ts and sqlite-schema-facts.ts, but the scripts/pr wrapper inventory did not list them. The anchored wrapper closure then cannot resolve those modules, which fails pr-wrapper-source-closure, the extracted-anchor pr-wrappers case, and the pr-main-refresh suite on every PR.
…156643) * perf(state): reuse admitted schema facts on database reads Keep schema facts with admitted handles and bound cache data-version probes to one per event-loop turn. Native open owns DDL, rollback, authorizer, and handle-lifecycle invalidation; consistency brackets retain fresh probes. * perf(state): preserve schema facts across native handle lifecycles * perf(state): admit worker reads after the cached probe turn
openclaw#156643 made src/infra/sqlite-coordinator.ts and src/infra/sqlite-readonly-location.worker.ts import sqlite-pinned-read-snapshot.ts and sqlite-schema-facts.ts, but the scripts/pr wrapper inventory did not list them. The anchored wrapper closure then cannot resolve those modules, which fails pr-wrapper-source-closure, the extracted-anchor pr-wrappers case, and the pr-main-refresh suite on every PR.
What Problem This Solves
Session-entry and session-list reads repeatedly query schema versions and table existence on already-admitted SQLite handles, multiplying synchronous work during streaming and frequent reads.
User Impact
Warm reads reuse admitted schema facts, with at most one cache-freshness probe per event-loop turn per handle. Local DDL remains visible immediately; foreign commits are detected on the next turn. Authorization requests latest metadata and preserves per-request batching. Shared-state worker admission joins the previous probe’s expiry before executing another operation, preserving current receipt/schema reads without a second probe in the same turn. Stored schemas, configuration, durability, and update/migration behavior remain unchanged.
Why This Change Was Made
The native SQLite owner tracks revisions from open; agent/shared-state admission enables retained version and table facts. DDL execution, transaction settlement, rollback, deferred version publication, and close/replacement revoke those facts. Committed schema revisions publish to sibling handles by physical file identity. Explicit and implicit snapshots retain facts only for their lifetime. Dynamic authorizers retain uncached behavior; exact-read and migration/snapshot consistency probes remain fresh.
The merged #156610 guard is now a normal assertion, with separate-process migration refusal coverage. Windows identity lookup uses native realpath, and statement wrappers preserve both retained native observers and statement-owned methods.
Evidence
The guard performs 100 session-entry reads, 100 session-list reads, and 100 cached state acquisitions in one synchronous turn after warm admission, asserting the read results.
user_version, before → afterdata_version, before → after600 counted queries eliminated. Warm-up consumed the turn's freshness probe; the allowance is ≤1 per handle per turn. The composed catalog budget also improves from six to two SQLite reads per list. These are query-count measurements; production CPU/RSS impact remains unmeasured. No Gateway was modified or restarted.
All heavy validation used blacksmith-testbox, profile openclaw-check. No local suites, typechecks, or builds ran. All task-owned leases are stopped.
tbx_01m37eyty4jsz01swtkrpmk1jw(run)5b29899f06ab733ee25334f1d3590d5aebb0aba8: reproduced the intended budget failure and baseline counts.tbx_01m37fxwq97bg4a8k5pg817zs2(run)pnpm test <focused owner file> --maxWorkers=1: established the zero-query result and passing runtime-fence/cache coverage.tbx_01m37h32e3zx5v1gfw3c9f4s56(run)tbx_01m37kea3dwh7z58vc6h7vzg76(run)node scripts/run-vitest.mjs <focused files> --maxWorkers=1: 399 passed, six existing skips. Production types andnode scripts/run-tsgo-core-test-shards.mjs --stripe 1/1 --concurrency 4: all 25 test-type shards passed. Final schema/committed-reader/guard/observer replay passed; targeted lint and affected type graphs passed. The ownership budget retained 12 SELECTs and zero catalog reads.tbx_01m37pqcsvhftsvew18dzb1cnw(run)node scripts/run-vitest.mjs ... --maxWorkers=1: 216 passed in 202.03 s. Production, extension, UI E2E, and four selected core test-type graphs passed; repository formatting and core/UI lint passed. All 44 candidate-file checksums matched, and the scoped line-cap ratchet passed for 43 source files. One sync timed out before testing; the single retry succeeded.tbx_01m37rrd7xw1p8fsbky4kykdap(run)node scripts/run-vitest.mjs src/state/database-runtime-schema-checks.test.ts src/infra/sqlite-schema-facts.test.ts src/infra/sqlite-worker-identity.test.ts --maxWorkers=1: 17 passed in 34.35 s, including zero warmed queries. After adopting upstream UI validation fixes, all 42 remaining PR files were byte-for-byte unchanged from the validated candidate.tbx_01m37sg5vjrwxhzvm62snn2dnt(run)pnpm test src/state/openclaw-state.worker.settlement.test.ts --maxWorkers=1: 4 passed, 8.97 s wall; the new regression took 57 ms in the owner replay.The final type selection used
node scripts/run-tsgo-core-test-shards.mjs --changed-paths-json <affected tests> --concurrency 4, selecting gateway-root, state-logging, gateway-methods, and agents-sessions. Other graphs usednode scripts/run-tsgo.mjs -p <canonical config> --incremental. The Testbox's Git baseline initially included four untouched upstream files in the ratchet; a temporary index containing only the checksum-verified PR diff passedscripts/check-line-cap-ratchet.mts --staged --base 80c3c7424677dbc86dd79c188a8c4f62940a1451.Measured focused costs (
pnpm test <file> --maxWorkers=1, including runner/compiler preparation):sqlite-schema-facts.test.tsdatabase-runtime-schema-checks.test.tsopenclaw-state-db.runtime-fence.test.tssession-accessor.sqlite-data-version.test.tsopenclaw-agent-db-readonly-scope.test.tsopenclaw-agent-db.committed-read.test.tsCI exposed sibling DDL publication, native observer, Windows path, and multi-target authorization gaps; each has a repair and focused passing proof. Existing same-turn foreign-write fixtures advance a mocked turn while retaining their data/refusal assertions. Lifecycle cleanup restores synthetic future versions, and budget observers no longer install real authorizers. Upstream formatting/type fixes, including
3d66eb56567andee558121d1b, were adopted and their UI files are no longer in this PR. The original receipt failure passed unchanged in isolation; the deterministic backend regression established the stale-admission defect, and the required standalone/shard repetitions passed after repair. No assertion was weakened to obtain those passes.Fresh independent Codex autoreview is scoped-clean through P2. The final PR diff passes
git diff --check. Squash auto-merge is enabled via GraphQL. Final-head CI 35909995880 passed on2db15a62830574ced7e12f6c82028ee2939945fc, including native Windows jobs and the formerly failing receipt/type gates. The final check rollup has 170 passing checks, zero failures or pending checks (41 skipped). GitHub completed the requested GraphQL-enabled squash auto-merge at 2026-09-23 19:48:51Z asbc6fedbe4633d3ccc0e4bb84ef323fa62794c6fd.