Skip to content

fix(agent-db): stop repeated schema admission on warm turns - #166253

Merged
steipete merged 13 commits into
mainfrom
dbasync/schemaloop
Oct 7, 2026
Merged

steipete merged 13 commits into
mainfrom
dbasync/schemaloop

Conversation

@steipete

@steipete steipete commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

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 72d267fd53b472639c686e9cdc5962dca8bf62e5 versus runtime candidate 1af53aaf615504996c623d40a828521443503004; final head d27e2fab087d982527a6e07834865fc3c143eb38 changes only a test comment and expected count, with production and build inputs verified identical.

Flow, all-thread median Main Candidate
Startup (boot + connect) 4,241 4,241
First turn 6,942 6,126
Warmed statements/turn 3,004.4 2,448.0
Second session + child 9,172 7,697
RPC 61 53
Cron 2,411 1,965
Compaction 1,439 1,052
Shutdown 928 926
Whole workload 55,223 46,576

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.ts dispatches deliveryQueue.outbound, reaching assertOpenClawStateWriteAllowed and the config_machine_state ownership 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.1 was inspected: sqlite-runtime.openOpenClawAgentSqliteWorkerStore accepts publicationSource.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 → 1af53aaf6155 passed in 1,795.94 s, reviewed acknowledgement 2119dc30: 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 at d27e2fab087d; 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-fast passed on d27e2fab087d.

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 run 37559068121 job 112592176509, and five local repetitions on each pinned side. Test-only commit d27e2fab087d retains 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 37563093769 has 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 run 37559068121 job 112592176770 independently 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 baseline 27ba9720f2c5 and tested merge de68b9823d54. 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.

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.
@clawsweeper

clawsweeper Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: M labels Oct 6, 2026
@steipete

steipete commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper

clawsweeper Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed October 6, 2026, 10:49 PM ET / October 7, 2026, 02:49 UTC (Revision 5).

ClawSweeper review

What this changes

The 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 src/infra/sqlite-schema-facts.ts. Prefer a design that avoids changing persisted SQLite tables. Migration or upgrade compatibility proof is recorded, but maintainers should still confirm that the schema change is necessary.

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
Reviewed head: d27e2fab087d982527a6e07834865fc3c143eb38

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, well-supported repair with no established patch defect, while the agreed integrated performance qualification remains open.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Recorded real chat, child, RPC, cron, compaction and shutdown workloads exercise the database executor and show removal of the targeted repeated schema work. Evidence remains bound to its earlier candidate; the integrated raw-phase performance criterion is separately unfinished. Source verifies unchanged persisted contracts, requiring no migration.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): Recorded real chat, child, RPC, cron, compaction and shutdown workloads exercise the database executor and show removal of the targeted repeated schema work. Evidence remains bound to its earlier candidate; the integrated raw-phase performance criterion is separately unfinished. Source verifies unchanged persisted contracts, requiring no migration.
Evidence reviewed 9 items Pinned introduction and review continuity: Reviewed the merge-base-to-head delta. Since the previous reviewed head, the only change adjusts reconciliation's expected retained canonical leases from one to two, matching the integrated four-executor retention owner.
Preparation reuse preserves admission checks: Warm preparation reuses a published generation; explicit readmission, absent or revoked schema receipts, and startup journals still trigger worker preparation. Source, caller, physical-file and operation admission checks remain on the execution path.
Schema facts retain their existing lifecycle: Matching adopted facts preserve identity only after snapshot, transaction and physical-scope lifetime checks. Observed foreign schema changes notify existing receipt-revocation listeners; data-only commits retain facts.
Findings None None.
Security None None.

How this fits together

OpenClaw'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]
Loading

Before merge

  • Complete next step (P2) - Complete the stated isolated paired measurement on the integrated source and document whether the raw RPC phase satisfies the no-increase requirement.
Agent review details

Security

None.

PR surface

Source +68, Tests +81, Docs +19. Total +168 across 15 files.

View PR surface stats
Area Files Added Removed Net
Source 7 149 81 +68
Tests 6 133 52 +81
Docs 2 22 3 +19
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 15 304 136 +168

Review metrics

Metric Value Why it matters
Production and regression coverage production +149/-81; tests +133/-52 Production growth implements lifecycle-aware reuse and explicit SDK compatibility metadata rather than another database owner.

Stored data model

Persistent data-model change detected: database schema: src/infra/sqlite-schema-facts.ts, migration/backfill/repair: src/plugins/compat/session-persistence-records.ts, unknown-data-model-change: src/infra/sqlite-schema-facts.ts. Migration or upgrade compatibility proof is recorded; maintainers should verify it before merge.

Technical review

Best 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.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded database-efficiency repair with demonstrated warm-turn improvement.
  • merge-risk: 🚨 compatibility: The reachable SDK preparation contract gains an optional argument; the documented accepted design preserves existing calls and implementations through compatibility assertions.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): Recorded real chat, child, RPC, cron, compaction and shutdown workloads exercise the database executor and show removal of the targeted repeated schema work. Evidence remains bound to its earlier candidate; the integrated raw-phase performance criterion is separately unfinished. Source verifies unchanged persisted contracts, requiring no migration.
  • proof: sufficient: Contributor real behavior proof is sufficient. Recorded real chat, child, RPC, cron, compaction and shutdown workloads exercise the database executor and show removal of the targeted repeated schema work. Evidence remains bound to its earlier candidate; the integrated raw-phase performance criterion is separately unfinished. Source verifies unchanged persisted contracts, requiring no migration.

Evidence

What I checked:

  • Pinned introduction and review continuity: Reviewed the merge-base-to-head delta. Since the previous reviewed head, the only change adjusts reconciliation's expected retained canonical leases from one to two, matching the integrated four-executor retention owner. (src/config/sessions/session-transcript-reconcile-pool.test.ts:272, d27e2fab087d)
  • Preparation reuse preserves admission checks: Warm preparation reuses a published generation; explicit readmission, absent or revoked schema receipts, and startup journals still trigger worker preparation. Source, caller, physical-file and operation admission checks remain on the execution path. (src/state/openclaw-agent-execution-native.ts:509, d27e2fab087d)
  • Schema facts retain their existing lifecycle: Matching adopted facts preserve identity only after snapshot, transaction and physical-scope lifetime checks. Observed foreign schema changes notify existing receipt-revocation listeners; data-only commits retain facts. (src/infra/sqlite-schema-facts.ts:594, d27e2fab087d)
  • Current main still needs the change: The pinned current-main comparison retains both the unconditional preparation condition and replacement of matching schema-fact objects. The merged catalog and cold-admission prerequisites therefore do not implement this PR's central warm-path repair. (src/state/openclaw-agent-execution-native.ts:515, 27ba9720f2c5)
  • SDK compatibility is explicitly preserved: The maintainer-authored proposal documents the additive readmission argument while retaining existing callers and two-argument implementations. The compatibility record and public-surface type test cover that contract; no removal or migration is proposed. (src/plugin-sdk/sqlite-runtime.preparation-compat.test.ts:9, d27e2fab087d)
  • Real workload evidence and remaining qualification: The captured body, sourceRevision 6c66123421bc7556615ec8e8dc32ebc223ea3e6c94bcd95a5e1e5c15f3f314e2, reports three complete real workloads per revision on Node 24.21.0/SQLite 3.53.4. Warmed statements fall from 3038.9 to 2490.6 and the targeted repeated schema cohorts reach zero. These measurements are bound to candidate 8ca9ffc, not the latest head; the isolated integrated comparison remains pending because raw RPC statements increased from 62 to 65. The previous review's concrete rank-up request therefore remains applicable. (8ca9ffcc432b)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

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

  • Complete the isolated paired comparison on the integrated source and record whether the raw RPC phase meets the stated no-increase criterion.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (4 earlier review cycles)
  • reviewed 2026-10-06T19:02:20.229Z sha 378c156 :: blocked before merge. :: none
  • reviewed 2026-10-06T19:08:39.859Z sha 378c156 :: blocked before merge. :: none
  • reviewed 2026-10-07T01:52:27.128Z sha 8ca9ffc :: blocked before merge. :: none
  • reviewed 2026-10-07T02:09:08.382Z sha 1af53aa :: needs changes before merge. :: none

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 6, 2026
@steipete

steipete commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@steipete

steipete commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Oct 7, 2026
@steipete

steipete commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@steipete
steipete merged commit 8b7917c into main Oct 7, 2026
147 of 169 checks passed
@steipete
steipete deleted the dbasync/schemaloop branch October 7, 2026 03:54
@steipete

steipete commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 7, 2026
…#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
steipete added a commit that referenced this pull request Oct 7, 2026
Merge current main to include the warm schema-admission fix from #166253 and startup integrity-proof retention from #166412. The profile cutover delta is unchanged; repeat its integration gates and matched measurements on this baseline before landing.
obviyus added a commit that referenced this pull request Oct 19, 2026
…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]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 19, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant