Skip to content

perf(sessions): bound list materialization after invalidation - #162280

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-sessions-list-materialize-20260919
Oct 1, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-micro-sessions-list-materialize-20260919

Conversation

@steipete

@steipete steipete commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

sessions.list waited for every dirty display row to rebuild before selecting its page. An unrelated subagent snapshot renewal could also discard current SQLite facts and repeat the same read.

User Impact

Lists prepare current selection metadata, then materialize only their selected pages. Sorting, search, board filters, counts, sharing, and current authorization retain their existing contracts. There are no configuration, schema, persistence, or update changes.

Why This Change Was Made

The resident projection remains the owner of metadata and accepted database facts. Lists share selection readiness, reuse those facts across catalog and registry renewal, and give selected pages the existing bounded exact-read priority. Related-row presentation reuses current metadata. Broad metadata invalidation still refreshes the inventory in batches of at most 64 keys before selection; correct filters and counts require that work. A previously admitted background batch may finish, and the remaining display drain resumes after foreground pages finish.

The deterministic CI timeout in runs 36803112955 and 36819794431 came from an incomplete test-fixture cutover: the synthetic plugin role-revocation test still spied on ensureMaterialized(), which the list reader no longer calls. Its readEntered promise never resolved. The fixture now observes the actual prepareSelection(true) call, delegates to the original owner method, and asserts that the spy ran before revoking the role. The revocation-error assertion is unchanged. The list handler still calls sessionMutationAuthorization.assertCurrent() after readiness and immediately before responding.

Sibling list fixtures preserve readiness arguments and explicitly assert that their injected wait was consumed. Describe's guard against joining bulk readiness remains intact. This continuation changes six test files and makes no additional production changes.

Evidence

Original synthetic benchmark: 8,000 sessions, eight approximately 1 MB transcripts, and 20 overlapping lists requesting four distinct 50-row pages. Baseline source: 5ca201627d3dffe97381c6aa1e4e675450b114f7. Blacksmith Testbox tbx_01m3td35vm97hebr2wzzw90hy9, provider blacksmith-testbox, profile openclaw-check.

Case Materialize mean before → after Maximum before → after Display rows before → after
Warm 41.5 → 41.2 ms 59.0 → 58.4 ms 0 → 0
Catalog invalidation 534.4 → 96.9 ms 548.5 → 114.4 ms 8,000 → 200
Full metadata invalidation 1,238.6 → 841.0 ms 1,253.5 → 858.5 ms 8,000 → 264

Catalog invalidation used zero worker tasks/transfers. Full metadata invalidation used 252 worker tasks. Existing diagnostics do not isolate response structured-clone time from worker execution. No transcript worker restarted during either measured burst. The original source fails the page-bound and registry-renewal regressions; the candidate passes them.

Continuation validation uses provider blacksmith-testbox, profile openclaw-check, at head 3ed0d25791332fb79377e2f9a0be130eb1828b3b, with the rebased candidate pinned to base 855bba498797bae1abf256999f430e352e0ce0bc and its complete patch verified on the lease.

  • Before repair, tbx_01m3vkg870kpa9zz9tvbt1r67t (run): node scripts/run-vitest.mjs src/gateway/server-plugin-in-process-dispatch.session-reads.test.ts -t 'honors role revocation during projection readiness on sessions.list' reproduced the timeout at 120,058 ms. The first attempt found missing dependencies; one frozen-lockfile installation succeeded before reproduction.
  • Setup-only tbx_01m3vkv2n2nfa5rswy2we21kf1 (run) was stopped during an unbounded Git fetch before validation. A shallow fetch on the replacement lease resolved this. A patch-fingerprint check initially differed only in abbreviated object IDs; full object IDs match exactly.
  • Final validation: tbx_01m3vm37qh5q58r2dyq7s60hgr (run). The requested focused run passed 435/435 tests across 40 files, with no skipped tests, in 351.88 seconds (365.189 seconds for the remote command including the one frozen-lockfile installation). The formerly timed-out list revocation case passed in 670 ms, and its describe sibling in 514 ms. node scripts/check-changed.mjs --base origin/main passed in 1,778.567 seconds: production types, all 27 test type graphs, formatting, lint, and boundary guards. Core lint checked 29,427 files with zero warnings/errors; script lint checked 1,277 files with zero warnings/errors. All three leases were stopped after use.

Hosted CI run 36861040131 completed successfully on 3ed0d25791332fb79377e2f9a0be130eb1828b3b; all Node test jobs passed. The automatic merge flow merged this PR as 1b896e6327f74f275d6fad7e0ef2d30de652a109 on October 1, 2026 at 12:31:34 UTC.

Measured test execution with --maxWorkers=1 (sum of reported case times; shared startup is included only in the whole-run wall time): synthetic plugin reads 5.504 s; active 10.838 s; async 4.817 s; cache 14.613 s; diagnostics 15.213 s; describe-worker 11.438 s. These retain the existing worker-backed and authority boundary fixtures; no new test cases were added.

Requested test command (with unmatched globs omitted):

node scripts/run-vitest.mjs \
  src/gateway/server-plugin-in-process-dispatch.session-reads.test.ts \
  src/gateway/server-methods/sessions-read-*.test.ts \
  src/gateway/server-methods/sessions-describe-worker.test.ts \
  src/gateway/server-methods/sessions-list-persisted-worker.test.ts \
  src/gateway/session-row-projection*.test.ts \
  src/gateway/session-utils-list*.test.ts \
  src/gateway/session-utils.test.ts --maxWorkers=1
node scripts/check-changed.mjs --base origin/main

There are no session-utils-list*.test.ts files; session-utils.test.ts supplies the existing list/transcript-limit coverage. The timing table is the original benchmark, not a new production-contention measurement. All heavy validation runs remotely. Independent Codex review completed within the 15-minute deadline: scoped-clean, no actionable P0–P2 findings. No review waiver, timeout increase, skipped test, or removed revocation case was used.

@clawsweeper

clawsweeper Bot commented Oct 1, 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 gateway Gateway runtime size: L labels Oct 1, 2026
@steipete
steipete enabled auto-merge (squash) October 1, 2026 02:03
@clawsweeper

clawsweeper Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 1, 2026, 8:26 AM ET / 12:26 UTC (Revision 5).

ClawSweeper review

What this changes

The PR prepares session-list metadata before selecting pages, rebuilds only selected display rows, reuses unchanged database facts during registry renewal, and updates regression fixtures and documentation.

Merge readiness

✅ Ready for maintainer review

The optimization remains useful because current main still waits for full display-row materialization. The prior fixture blocker is resolved, and no actionable introduced defect was found.

Priority: P2
Reviewed head: 3ed0d25791332fb79377e2f9a0be130eb1828b3b

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent performance repair with meaningful regression coverage, reported bounded-work improvements, and no actionable correctness finding.
Proof confidence 🌊 off-meta tidepool Not applicable: Verified repository admin authorship exempts this PR from external-contributor proof. The supplied synthetic benchmark exercises the projection/list path and reports reduced display work; focused tests supplement it, and no stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Verified repository admin authorship exempts this PR from external-contributor proof. The supplied synthetic benchmark exercises the projection/list path and reports reduced display work; focused tests supplement it, and no stored-data contract changes.
Evidence reviewed 9 items Pinned introduced change: Reviewed the merge-base-to-head introduced hunks, rather than endpoint drift. The existing refresh owner shares selection preparation, refreshes missing metadata in bounded batches, and retains foreground priority through selected-page consumption.
Still necessary on current main: Fetched main still calls ensureMaterialized before selecting the list page and rechecks needsMaterialization. The central optimization has not been absorbed by that implementation.
Prior fixture blocker resolved: The synthetic plugin fixture now observes the actual prepareSelection call, delegates its arguments, and asserts that the wait was consumed with true. The captured PR body reports reproducing the former 120,058 ms timeout and a repaired 670 ms run; those executions were not repeated during this read-only review.
Findings None None.
Security None None.

How this fits together

The Gateway’s resident session projection combines persisted session metadata with current runtime and sharing facts. Session-list requests filter and sort that inventory, then return authorized session pages to clients.

flowchart TD
  A[Session publications] --> C[Resident session projection]
  B[Database and runtime facts] --> C
  D[List request] --> E[Prepare selection metadata]
  C --> E
  E --> F[Filter and select page]
  F --> G[Prepare selected display rows]
  G --> H[Authorize and return page]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +173, Tests +353, Docs +5. Total +531 across 29 files.

View PR surface stats
Area Files Added Removed Net
Source 9 396 223 +173
Tests 19 498 145 +353
Docs 1 10 5 +5
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 29 904 373 +531

Review metrics

Metric Value Why it matters
Production versus test growth production +173 net lines; tests and support +351 net lines Production growth implements shared metadata readiness and foreground page priority, with a stated performance justification.

Technical review

Best possible solution:

Keep current metadata preparation and selected-page display rebuilding under the resident projection’s existing freshness, priority, and authorization contracts.

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

Yes, from source: current main drains all dirty display rows before selecting a bounded page. The supplied benchmark reports the resulting latency; this reviewer did not execute a reproduction.

Is this the best way to solve the issue?

Yes. Preparing current selection metadata and using the existing exact-row preparation path avoids a competing cache or owner while preserving list semantics.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 9faca1d10477.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This addresses session-list latency after invalidation without changing user configuration or adding a capability.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Verified repository admin authorship exempts this PR from external-contributor proof. The supplied synthetic benchmark exercises the projection/list path and reports reduced display work; focused tests supplement it, and no stored-data contract changes.

Evidence

What I checked:

  • Pinned introduced change: Reviewed the merge-base-to-head introduced hunks, rather than endpoint drift. The existing refresh owner shares selection preparation, refreshes missing metadata in bounded batches, and retains foreground priority through selected-page consumption. (src/gateway/session-row-projection-refresh.ts:225, 3ed0d2579133)
  • Still necessary on current main: Fetched main still calls ensureMaterialized before selecting the list page and rechecks needsMaterialization. The central optimization has not been absorbed by that implementation. (src/gateway/session-utils-list.ts:474, 9faca1d10477)
  • Prior fixture blocker resolved: The synthetic plugin fixture now observes the actual prepareSelection call, delegates its arguments, and asserts that the wait was consumed with true. The captured PR body reports reproducing the former 120,058 ms timeout and a repaired 670 ms run; those executions were not repeated during this read-only review. (src/gateway/server-plugin-in-process-dispatch.session-reads.test.ts:110, 3ed0d2579133)
  • Current authorization remains at response: The list consumer performs selection and presentation synchronously after preparation. Its production handler still calls sessionMutationAuthorization.assertCurrent immediately before responding; the patch changes read scheduling rather than granting or persisting authority. (src/gateway/server-methods/sessions-read.ts:277, 3ed0d2579133)
  • Database freshness and persistence boundary: Registry renewal is prepared before accepting database facts, while database-owner, physical-store, projection-revision, row-generation, and row-fact-revision checks remain. The introduced production changes alter resident preparation only, with no schema, serialized format, migration, or configuration change. (src/gateway/session-row-projection-read.ts:195, 3ed0d2579133)
  • Captured performance and validation evidence: The complete supplied body reports an 8,000-session synthetic benchmark: catalog-invalidation materialization averaged 534.4 to 96.9 ms and rebuilt 8,000 to 200 display rows. It also reports 435 passing tests and changed-source checks at the pinned head. These are contributor-reported results, not reviewer executions; the body explicitly distinguishes the original benchmark from continuation validation. (3ed0d2579133)

Likely related people:

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

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-01T02:05:41.034Z sha 3175650 :: blocked before merge. :: none
  • reviewed 2026-10-01T04:45:01.356Z sha 5cce2d6 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-01T04:57:28.910Z sha 5cce2d6 :: blocked before merge. :: [P2] Migrate the remaining list-readiness regression fixtures
  • reviewed 2026-10-01T05:33:18.830Z sha 02ea1b7 :: needs maintainer review before merge. :: none

@steipete
steipete force-pushed the steipete/perf-micro-sessions-list-materialize-20260919 branch from 3175650 to 5cce2d6 Compare October 1, 2026 04:37
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed 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 1, 2026
@clawsweeper clawsweeper Bot added 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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 1, 2026
After a catalog or metadata invalidation, sessions.list materialized the
display rows of every session before selecting the page, so a burst of
concurrent lists spent seconds in the materialize phase (avg 4.7 s, max
19 s on Team with 334 slow lists per hour).

Select first, then materialize only the rows the page returns, and share
the post-invalidation work across concurrent lists. The reply contract is
unchanged.

Testbox fixture (8,000 sessions, 20 concurrent lists): average
materialization 534 -> 97 ms after catalog invalidation and 1,239 -> 841 ms
after metadata invalidation; selected display work 8,000 -> 200 rows.
Align session-list fixtures with metadata readiness and selected-page
materialization. Fixtures that need every display row now drain their own
setup explicitly, while list wait tests observe prepareSelection and
preserve its arguments.

The synthetic plugin role-revocation test still waited for the retired
ensureMaterialized list call and deterministically timed out after 120 s.
Observe the actual reader readiness call, assert that each injected wait
was consumed, and retain the revocation-error expectation and describe's
bulk-read isolation guard.

Testbox: 435 tests across 40 files passed; the reproduced 120,058 ms
revocation timeout now completes in 670 ms. PR #162280.
@steipete
steipete force-pushed the steipete/perf-micro-sessions-list-materialize-20260919 branch from 02ea1b7 to 3ed0d25 Compare October 1, 2026 12:19
@steipete
steipete merged commit 1b896e6 into main Oct 1, 2026
133 of 134 checks passed
@steipete
steipete deleted the steipete/perf-micro-sessions-list-materialize-20260919 branch October 1, 2026 12:31
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 2, 2026
…aw#162280)

* perf(sessions): bound list materialization after invalidation

After a catalog or metadata invalidation, sessions.list materialized the
display rows of every session before selecting the page, so a burst of
concurrent lists spent seconds in the materialize phase (avg 4.7 s, max
19 s on Team with 334 slow lists per hour).

Select first, then materialize only the rows the page returns, and share
the post-invalidation work across concurrent lists. The reply contract is
unchanged.

Testbox fixture (8,000 sessions, 20 concurrent lists): average
materialization 534 -> 97 ms after catalog invalidation and 1,239 -> 841 ms
after metadata invalidation; selected display work 8,000 -> 200 rows.

* test(sessions): align list fixtures with bounded materialization

Align session-list fixtures with metadata readiness and selected-page
materialization. Fixtures that need every display row now drain their own
setup explicitly, while list wait tests observe prepareSelection and
preserve its arguments.

The synthetic plugin role-revocation test still waited for the retired
ensureMaterialized list call and deterministically timed out after 120 s.
Observe the actual reader readiness call, assert that each injected wait
was consumed, and retain the revocation-error expectation and describe's
bulk-read isolation guard.

Testbox: 435 tests across 40 files passed; the reproduced 120,058 ms
revocation timeout now completes in 670 ms. PR openclaw#162280.
steipete added a commit that referenced this pull request Oct 4, 2026
Startup admission and the catalog-triggered background drain could acquire
the same session facts concurrently. The asynchronous acquisition introduced
in 42263f8 (#155388) left that overlap possible; selected-page readiness
in 1b896e6 (#162280) no longer joins the entire background drain.

Keep one pending batch in the refresh owner so both callers share its work.
Preserve exact-read priority, retained facts, invalidation and failure cleanup.
Extend the registered list regression to hold admission against the background
drain and assert one acquisition per row, while keeping the zero-read catalog
refresh and concurrent committed-update assertions.

Validation: original production acquires both fixture rows twice; the fixed
producer acquires each once. All 169 tests across 17 owner and sibling files
pass. Both cycle checks report zero cycles; core plus Gateway root, server
and method test types, strict targeted lint and formatting pass.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 5, 2026
Startup admission and the catalog-triggered background drain could acquire
the same session facts concurrently. The asynchronous acquisition introduced
in 64e58bb (openclaw#155388) left that overlap possible; selected-page readiness
in d13db6a (openclaw#162280) no longer joins the entire background drain.

Keep one pending batch in the refresh owner so both callers share its work.
Preserve exact-read priority, retained facts, invalidation and failure cleanup.
Extend the registered list regression to hold admission against the background
drain and assert one acquisition per row, while keeping the zero-read catalog
refresh and concurrent committed-update assertions.

Validation: original production acquires both fixture rows twice; the fixed
producer acquires each once. All 169 tests across 17 owner and sibling files
pass. Both cycle checks report zero cycles; core plus Gateway root, server
and method test types, strict targeted lint and formatting pass.
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 gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL 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