Repository navigation
fix(agent-db): stop repeated schema admission on warm turns - #166253
Conversation
Carry index names and trigger definitions in the existing admitted catalog snapshot. Reuse those facts for canonical session validation and first-use schema installation, removing separate committed-schema caches while preserving foreign changes, rollback, reopen, and dynamic authorizer checks.
Keep schema facts collected under synchronous read admission after data-only transaction settlement. Unmanaged snapshots and sibling schema publications observed in a transaction still expire, and the next operation still checks foreign commits. Cover warm worker commands after lazy schema installation.
Merge main to integrate the session reader and admission optimizations. Retire cached metadata with its native connection so closed handles cannot retain expanded catalog facts throughout large archive batches. The existing Doctor scale regression passes five Linux Bun replays after failing all five on the original PR head.
Reuse settled native preparation and unchanged admitted schema facts. Keep explicit host readmission, startup journal checks, and schema receipt revocation for observed foreign DDL. Skip covered standing-intent DDL instead of repeating post-commit structural scans. Addresses repeated schema preparation attributed to #165680; builds on the schema-fact owner in #166102. Schemas, stored bytes, and update behavior are unchanged.
Retain the landed schema-fact prerequisite, background integrity publication, execution scope owner, and current dependency lock. Preserve the focused schema-admission diff without changing its behavior.
|
🦞👀 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. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Codex review: needs changes before merge. Reviewed October 6, 2026, 10:49 PM ET / October 7, 2026, 02:49 UTC (Revision 5). ClawSweeper reviewWhat this changesThe PR reduces repeated SQLite work during chat turns by reusing unchanged schema facts and completed database preparation, while preserving explicit readmission and SDK compatibility. Warning SQLite table change This PR modifies persisted SQLite tables in Merge readiness⛔ Needs changes before merge - 1 item remains This remains a useful, distinct follow-up to the merged database optimizations. No actionable correctness or security finding was established; the previously requested isolated performance comparison remains unfinished. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw's agent database executor runs database work in a worker and publishes validated schema facts to callers. Those facts let subsequent chat and memory operations reuse admitted storage without repeating structural inspections. flowchart TD
A[Chat and memory operations] --> B[Agent database executor]
B --> C{Preparation still valid?}
C -->|Yes| D[Reuse admitted facts]
C -->|No or explicit readmission| E[Worker schema validation]
E --> D
D --> F[Database operations]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +68, Tests +81, Docs +19. Total +168 across 15 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Keep warm execution within the existing admission owner, with unchanged storage and SDK contracts and measured reductions across the agreed workload. Do we have a high-confidence way to reproduce the issue? Yes, source establishes the repeated preparation and schema-fact replacement on pinned current main, and the recorded workload measures the affected cohorts. This read-only review did not execute a reproduction. Is this the best way to solve the issue? Yes, reusing the existing owner's admitted generation is a focused repair; explicit readmission and lifecycle invalidation remain intact. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 27ba9720f2c5. LabelsLabel changes: No label 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
HistoryReview history (4 earlier review cycles)
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
…#166253) * perf(sqlite): reuse admitted catalog facts across schema owners Carry index names and trigger definitions in the existing admitted catalog snapshot. Reuse those facts for canonical session validation and first-use schema installation, removing separate committed-schema caches while preserving foreign changes, rollback, reopen, and dynamic authorizer checks. * perf(sqlite): retain admitted facts across managed transactions Keep schema facts collected under synchronous read admission after data-only transaction settlement. Unmanaged snapshots and sibling schema publications observed in a transaction still expire, and the next operation still checks foreign commits. Cover warm worker commands after lazy schema installation. * fix(sqlite): attach schema query rationale to guarded call * fix(sqlite): break the agent schema admission loop Reuse settled native preparation and unchanged admitted schema facts. Keep explicit host readmission, startup journal checks, and schema receipt revocation for observed foreign DDL. Skip covered standing-intent DDL instead of repeating post-commit structural scans. Addresses repeated schema preparation attributed to openclaw#165680; builds on the schema-fact owner in openclaw#166102. Schemas, stored bytes, and update behavior are unchanged. * fix(sqlite): avoid shadowing preparation options * test(sdk): preserve released agent preparation call forms * test(sessions): preserve canonical leases after reconcile shutdown
…ession tests (#176630) ## What Problem This Solves Performance work in OpenClaw keeps fixing the same waste twice: caches that stop hitting, batches that get reverted, and PRs that land with a regression their own numbers already show. Agents had no repository guide for this work, and three flows where the same waste keeps returning had no test that counts it. ## User Impact No user-visible change. Agents doing performance work now have one OpenClaw skill: measure the real flow with a committed workload, count operations first, delete waste before batching or caching, and land only when every user-facing metric holds or improves. Three work-count tests fail CI if known waste comes back. ## Why This Change Was Made A corpus of 103 performance cases from the last 90 days on `main` (70 randomly sampled, 33 seeded with every perf revert; each judged from its diff and PR text): - **Deleting waste lasts:** 3 of 31 random-sample deletes were later re-fixed, and those failed deletes broke a guard, not because the waste returned. - **Caches, batches and worker moves come back:** 4 of 5, 6 of 7 and 5 of 8 were later re-fixed (biased set, a signal not a rate). In 3 of the 4 cache re-fixes the cache silently stopped hitting, e.g. #115369 → #174741 and #149773 → #149879. - **Own regressions predict reverts:** 21 PRs landed while their own numbers showed a large regression; 11 of them were later reverted or re-fixed, against 25 of the other 82. Five of the six reverts had shown the regression in their own body. - **Same waste, again and again:** SQLite schema/admission re-checks (14 PRs, one revert), session list rows (two reverts in two days), model catalog rebuilds. Changes: - `.agents/skills/openclaw-performance/SKILL.md`: measure (committed bench per flow, counts first, acceptance rule before the first run, interleaved samples), find waste (10 recurring OpenClaw patterns with real cases), fix order (delete → once at the owner → carry the prepared fact → batch → cache with a written reason, cache-identity rules and an interleaved work-count test), land (no user-facing metric worse unless the owner accepts it). - Root `AGENTS.md`: the "Do less work" line keeps its core rule and points to the skill. - Work-count tests (counts, never wall time): - `src/state/openclaw-agent-execution.schema-admission.test.ts`: warm chat turns make only their own write requests; no re-open, schema prepare or integrity validation. - `src/gateway/session-row-projection.list-page.test.ts`: after an unrelated subagent renewal, repeating the same pages renders 0 rows, materializes 0 more and does 0 worker reads or SQL. - `src/gateway/server-methods/models-auth-status.work-count.test.ts` (own file, to keep the existing test under its line cap): interleaved `models.authStatus` and `usage.status` page loads add no provider probes, auth-health builds or catalog loads after warm-up. ## Evidence | Test | Back-test (parent of the historical fix) | |---|---| | Schema admission | fails at `8b7917c79b8^` (#166253): each warm turn adds `open` and `prepare` again | | Session list | fails at `1b896e6327f^` (#162280): 80 rows materialized instead of 10, plus 1 worker read | | Models page | fails at `c3f0b6abc01^` (#174741): 3 provider probes in 2 loads; the readers evict each other | - All three pass on head (each file about 0.3–1.7 s); `models-auth-status.test.ts` still passes 52/52. The Models page test still fails at `c3f0b6abc01^` with real-module mocks (one extra provider probe). - The pre-commit hook (line-cap ratchet, `AGENTS.md` size) passed; root `AGENTS.md` is 18,917 characters. - Every PR cited by the skill is merged; every named bench script exists on `main`. Blind replay of 8 held-out performance tasks (none cited by the skill; each from the parent of its known-good fix), Codex agent with and without the skill, 2 seeds; stopped early after 12 judged pairs to free the host: | | Without skill | With skill | |---|---|---| | Pair wins (blind Codex judge) | 3 | 8 (1 tie) | | Removed the same waste as the reference fix | 11/14 runs | 11/13 runs | | Proof includes a work-count test | 5/14 | 11/13 | | Added a cache | 1 | 1 | | Judge: proof / waste found / fix order (1-5) | 3.08 / 4.50 / 4.83 | 4.33 / 4.42 / 4.50 | The skill does not change whether agents find the waste; it changes how they prove it, which is what keeps the waste from returning. One judge and 12 pairs: the win split is not significant (p ≈ 0.23). **Merge danger:** two-way door; a revert removes the skill and the tests. No runtime change. Blast radius: agent instructions for performance work, and three test files. Co-authored-by: Ayaan Zaidi <[email protected]>
…ession tests (openclaw#176630) ## What Problem This Solves Performance work in OpenClaw keeps fixing the same waste twice: caches that stop hitting, batches that get reverted, and PRs that land with a regression their own numbers already show. Agents had no repository guide for this work, and three flows where the same waste keeps returning had no test that counts it. ## User Impact No user-visible change. Agents doing performance work now have one OpenClaw skill: measure the real flow with a committed workload, count operations first, delete waste before batching or caching, and land only when every user-facing metric holds or improves. Three work-count tests fail CI if known waste comes back. ## Why This Change Was Made A corpus of 103 performance cases from the last 90 days on `main` (70 randomly sampled, 33 seeded with every perf revert; each judged from its diff and PR text): - **Deleting waste lasts:** 3 of 31 random-sample deletes were later re-fixed, and those failed deletes broke a guard, not because the waste returned. - **Caches, batches and worker moves come back:** 4 of 5, 6 of 7 and 5 of 8 were later re-fixed (biased set, a signal not a rate). In 3 of the 4 cache re-fixes the cache silently stopped hitting, e.g. openclaw#115369 → openclaw#174741 and openclaw#149773 → openclaw#149879. - **Own regressions predict reverts:** 21 PRs landed while their own numbers showed a large regression; 11 of them were later reverted or re-fixed, against 25 of the other 82. Five of the six reverts had shown the regression in their own body. - **Same waste, again and again:** SQLite schema/admission re-checks (14 PRs, one revert), session list rows (two reverts in two days), model catalog rebuilds. Changes: - `.agents/skills/openclaw-performance/SKILL.md`: measure (committed bench per flow, counts first, acceptance rule before the first run, interleaved samples), find waste (10 recurring OpenClaw patterns with real cases), fix order (delete → once at the owner → carry the prepared fact → batch → cache with a written reason, cache-identity rules and an interleaved work-count test), land (no user-facing metric worse unless the owner accepts it). - Root `AGENTS.md`: the "Do less work" line keeps its core rule and points to the skill. - Work-count tests (counts, never wall time): - `src/state/openclaw-agent-execution.schema-admission.test.ts`: warm chat turns make only their own write requests; no re-open, schema prepare or integrity validation. - `src/gateway/session-row-projection.list-page.test.ts`: after an unrelated subagent renewal, repeating the same pages renders 0 rows, materializes 0 more and does 0 worker reads or SQL. - `src/gateway/server-methods/models-auth-status.work-count.test.ts` (own file, to keep the existing test under its line cap): interleaved `models.authStatus` and `usage.status` page loads add no provider probes, auth-health builds or catalog loads after warm-up. ## Evidence | Test | Back-test (parent of the historical fix) | |---|---| | Schema admission | fails at `04c36511d39^` (openclaw#166253): each warm turn adds `open` and `prepare` again | | Session list | fails at `d13db6a6cc8^` (openclaw#162280): 80 rows materialized instead of 10, plus 1 worker read | | Models page | fails at `c373547bbbd^` (openclaw#174741): 3 provider probes in 2 loads; the readers evict each other | - All three pass on head (each file about 0.3–1.7 s); `models-auth-status.test.ts` still passes 52/52. The Models page test still fails at `c373547bbbd^` with real-module mocks (one extra provider probe). - The pre-commit hook (line-cap ratchet, `AGENTS.md` size) passed; root `AGENTS.md` is 18,917 characters. - Every PR cited by the skill is merged; every named bench script exists on `main`. Blind replay of 8 held-out performance tasks (none cited by the skill; each from the parent of its known-good fix), Codex agent with and without the skill, 2 seeds; stopped early after 12 judged pairs to free the host: | | Without skill | With skill | |---|---|---| | Pair wins (blind Codex judge) | 3 | 8 (1 tie) | | Removed the same waste as the reference fix | 11/14 runs | 11/13 runs | | Proof includes a work-count test | 5/14 | 11/13 | | Added a cache | 1 | 1 | | Judge: proof / waste found / fix order (1-5) | 3.08 / 4.50 / 4.83 | 4.33 / 4.42 / 4.50 | The skill does not change whether agents find the waste; it changes how they prove it, which is what keeps the waste from returning. One judge and 12 pairs: the win split is not significant (p ≈ 0.23). **Merge danger:** two-way door; a revert removes the skill and the tests. No runtime change. Blast radius: agent instructions for performance work, and three test files. Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
Related: #165680.
Ordinary chat turns repeatedly replaced unchanged admitted schema facts and reran standing-intent DDL, revoking shared receipts and triggering structural readmission. Execution also requested native preparation after its generation was already prepared.
User Impact
The matched isolated workload uses 556.4 fewer SQLite statements per warmed turn (18.5%), and 8,647 fewer statements across the whole workload. Every predefined measured flow is unchanged or lower. Counts include MAIN, worker threads, helper processes and background work; this is not a latency claim.
No schema, stored-byte, retention, durability, permission, configuration or worker-protocol changes; no migration or new environment names. Released preparation calls remain compatible.
Why This Change Was Made
Preserve unchanged admitted facts within the existing connection, snapshot, transaction and physical-scope lifecycle. Existing freshness observations revoke borrowed proof after foreign DDL. Standing-intent bindings skip additive DDL already covered by admitted facts, retaining native column lookup once per admitted generation for TEMP shadowing and generated columns. Remove the redundant post-commit structural scan.
Ordinary execution reuses settled native preparation. Explicit host readmission, revoked receipts and startup deletion journals still request worker validation. Physical identity, live authority, FIFO ordering, registration publication, rollback, eviction and accepted-work settlement keep their existing owners.
Production delta: +149/−81 (net +68), including 22 lines of SDK compatibility metadata; runtime net +46. Fifteen files total after the inherited test-expectation repair.
Evidence
Controlled all-thread SQL comparison
Three complete runs per revision on one isolated Hetzner 8-vCPU host, Node 24.21.0 / SQLite 3.53.4, using the unchanged restored campaign harness and synthetic model provider. Before-run CPU-idle samples were 99.31–100%. Pinned main
72d267fd53b472639c686e9cdc5962dca8bf62e5versus runtime candidate1af53aaf615504996c623d40a828521443503004; final headd27e2fab087d982527a6e07834865fc3c143eb38changes only a test comment and expected count, with production and build inputs verified identical.Warmed ranges: 2,982.1–3,009.5 → 2,442.7–2,456.0 statements/turn. All ten individual warmed windows decrease. The targeted schema-refresh, standing-intent post-commit and MAIN-adoption loops disappear.
All six workloads completed 13 top-level turns, a native child, RPCs, cron, committed compaction and graceful shutdown, with zero failed SQL executions or failed prepares. Calibration on MAIN and a worker produced eight calls, two prepares, seven statements and zero failures. Source hashes, runtime, fixture containment and process cleanup were verified; the lease is released.
The raw connect window is 362 → 363 (+1) and boot is 3,879 → 3,878 (−1). Exact stacks identify the same existing outbound-delivery custody check moving across the timestamp marker, not connection-owned work:
openclaw-state-read.worker.tsdispatchesdeliveryQueue.outbound, reachingassertOpenClawStateWriteAllowedand theconfig_machine_stateownership read. It executes once per startup in every run. Startup totals are the identical multiset [4,239, 4,241, 4,245]; remaining connect SQL cohort medians are identical. Startup grouping predates this run. All raw counts remain retained: the extra diagnostic requiring every raw timing window not to increase remains false, while every predefined flow meets the no-increase requirement. No query or background work is excluded from the totals.Memory MAIN work is exactly 38 statements in compaction and 24 in shutdown on all six runs. The older 27→45 compaction MAIN observation was independently traced to the same 18 existing Memory statements moving out of shutdown, with the combined cohort unchanged. No new Memory MAIN work was introduced.
The earlier shared-Mac pair remains recorded: warmed 3,038.9→2,490.6, RPC 62→65, whole workload 57,620→48,796. Its RPC difference was eight existing child-completion statements crossing a phase boundary, offset by five fewer background statements. The controlled comparison resolves that RPC concern at 61→53; no blind rerun, harness/window edit or data deletion was used.
Integration, tests and SDK
Merged main with merge commits, preserving main's source-map-js repair, MCP SDK fix #166217 (
c39d9b0692db) and #165993's bounded idle-executor cache/config retirement. The only text conflict combined four existing test cases: warm rollback, foreign index removal, idle index removal and revoked idle proof. All are retained and pass.At runtime head
1af53aaf6155: 181 focused tests passed, one existing capability skip, across 17 files in 798.69 s. This covers real foreign DDL from a second connection, rollback, eviction/replacement, explicit readmission, idle retention, startup journals, lifecycle cleanup, SDK contracts, runtime process build graphs and indirect import closures. Core types passed in 33.19 s, UI in 21.90 s, all 27 core-test type lanes in 411.55 s; Madge found zero cycles in 101.73 s. Fresh P2 review was clean.Released tag
v2026.10.1-beta.1was inspected:sqlite-runtime.openOpenClawAgentSqliteWorkerStoreacceptspublicationSource.execution.prepare. The released(source, signal?) => Promise<void>caller and implementation forms remain supported; the third readmission argument is optional. An active compatibility record, documentation and public-surface type test preserve the contract; no API is deprecated or removed.The local SDK diff
72d267fd53b4→1af53aaf6155passed in 1,795.94 s, reviewed acknowledgement2119dc30: 164 reachable fingerprints, zero direct export-signature/entrypoint changes, only optional parameters and compatibility metadata. Complete Git comparison proves its production/declaration/package/build inputs unchanged atd27e2fab087d; the report retains its actual source pins. Temporary SDK worktrees and processes were removed.CI and inherited failures
The original MCP advisory failure is fixed by integrated main; security is not waived.
security-fastpassed ond27e2fab087d.Main #165993 changed canonical idle retention from one slot to four but left the reconciliation test expecting one lease across two completed owners. The same two failures occurred in PR run
37559618477, scheduled main run37559068121job112592176509, and five local repetitions on each pinned side. Test-only commitd27e2fab087dretains the exact-count assertion with expected two, plus every planner-lease, identity, shutdown and drain check. Its six tests passed locally in 308.64 s, and on exact-head CI in 5.959 s of test time (passing job). The real native-lease/lifecycle fixture is unchanged; no timers, retries, weaker assertions or new boots were added. Typed lint and fresh P2 review passed.Current CI run
37563093769has one failed root:board-store.test.ts:348, expecting “board session changed” but receiving “Agent publication and cleanup failed”; the aggregate gate failed and fail-fast cancelled siblings. Scheduled main run37559068121job112592176770independently has the same failure. Source inspection points to main's config-change retirement interacting with subsequent TEMP-binding cleanup, in unchanged board/publication/config/error owners. Five local repetitions on each pinned side reproduce only that same failure, with all four sibling cases passing each time. The six failure-related input blobs also match the actual CI baseline27ba9720f2c5and tested mergede68b9823d54. Complete native admin evidence binds the checkout, both main/PR logs, all ten reproduction logs, source hashes, the aggregate failure and all 19 fail-fast cancellations. This qualifies the explicitly authorized inherited-failure route; cancelled coverage is not claimed as passing, and security/enforced reviews remain mandatory.A body edit briefly omitted the required Evidence heading; restoring it passed the local policy and GitHub check. No product change or blind CI rerun was involved.
Retained proof and follow-up
Published-driver
2026.9.8→ candidate update proof passed with readiness 200 and durable/incognito checks: https://github.com/openclaw/openclaw/actions/runs/37509589354. This is retained prior-source upgrade proof, not current-head CI. Canonical DDL and stored formats remain unchanged; ClawSweeper's generic table-change warning is contradicted by its detailed source review, which found no introduced code/security defect.Retained follow-up debt: the existing worker transcript authority guard performs an indexed shared-state placement lookup at
src/gateway/worker-environments/worker-turn-rpc.ts:226→src/gateway/worker-environments/placement-turn-claims.ts:423(query owner:placement-row-codec.ts:122). It keeps placement revocation live immediately before agent transcript commit; this PR adds no SQL to grant callbacks. Environment credential and session-registry guards inspected here consume in-memory facts.Overlap includes merged #166102, #166112 and #165993, plus #166183, #165901, #165921 and the ongoing session/placement/worktree work. Main's ownership and integrity changes are preserved. #162433's broader restructuring is not adopted. No wrapper/launcher module is added by this PR; main's dependency inventory remains intact.