Repository navigation
perf(sessions): bound list materialization after invalidation - #162280
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed October 1, 2026, 8:26 AM ET / 12:26 UTC (Revision 5). ClawSweeper reviewWhat this changesThe 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 Review scores
Verification
How this fits togetherThe 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]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +173, Tests +353, Docs +5. Total +531 across 29 files. View PR surface stats
Review metrics
Technical reviewBest 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. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (4 earlier review cycles)
|
3175650 to
5cce2d6
Compare
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.
02ea1b7 to
3ed0d25
Compare
…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.
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.
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.
…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
sessions.listwaited 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. ItsreadEnteredpromise never resolved. The fixture now observes the actualprepareSelection(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 callssessionMutationAuthorization.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 Testboxtbx_01m3td35vm97hebr2wzzw90hy9, providerblacksmith-testbox, profileopenclaw-check.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, profileopenclaw-check, at head3ed0d25791332fb79377e2f9a0be130eb1828b3b, with the rebased candidate pinned to base855bba498797bae1abf256999f430e352e0ce0bcand its complete patch verified on the lease.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.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.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/mainpassed 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 as1b896e6327f74f275d6fad7e0ef2d30de652a109on 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):
There are no
session-utils-list*.test.tsfiles;session-utils.test.tssupplies 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.