Skip to content

perf(sessions): speed up cold session discovery - #198775

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-sessions-search-cold-walk-20261114
Nov 14, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-sessions-search-cold-walk-20261114

Conversation

@steipete

@steipete steipete commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Large mixed-agent session inventories make sessions_search and archived list pages spend excessive time preparing cold rows, even after selection reuse in #198740.

User Impact

Cold archive traversal uses fewer worker admissions and less main-thread work. A synthetic 15,800-session discovery reduced CPU by 59.9% and sampled allocation by 39.8%, with identical dashboard responses and search candidate keys. Search results, limits, visibility checks, and archive retention are unchanged.

Why This Change Was Made

List pages interleave agents by recency, but the exact-read queue batches only adjacent identities from one physical store. A single preparation request now groups its agent/store-prefixed identities before appending to that queue. Earlier requests retain FIFO order; concurrency, the 64-key batch cap, 12ms materialization slices, capacity checks, and per-store failure isolation remain intact.

This is one production statement plus two explanatory comment lines (runtime LOC +3). It removes repeated worker admission/shared-fact preparation and lets the existing per-batch runtime resolution serve multiple rows. It adds no cache, protocol, schema, or retention change.

Evidence

Synthetic workload: 15,800 rows, 12,800 archived, eight agents, 30 held active runs; real sessions_search discovery through the embedded projection owner, excluding transcript FTS. Every measured sweep still materializes all 12,800 archived rows; selection caches are warm. Timing order is base/candidate/candidate/base, five sweeps per arm (10/side); allocation uses separate five-sweep processes. Baseline is 08ae8c62b83ede02db3a8d2bc3ce36206008d253.

Per discovery Base Candidate
Main-thread CPU 5.279 s 2.118 s
Wall, mean of arm medians 8.875 s 2.640 s
Sampled JS allocation 2.863 GB 1.723 GB
Total GC 149.8 ms 125.5 ms
Post-GC retained heap 439.9 MiB 437.1 MiB
Materialized archive rows 12,800 12,800

A/A context: identical-base CPU was 6.005/4.553 s and wall 11.721/6.030 s. Both paired CPU reductions hold (62.5%, 56.4%); paired wall reductions are 74.5% and 61.9%. End-of-arm one-minute host loads are recorded below. No tail percentile claim is made from five samples. First process-local discovery also pays cold selection preparation: its wall results had mixed pair signs and remain inconclusive; the table does not claim a cold-start improvement.

Arm CPU s/search Wall median s Host load, 1m
base-a 6.005 11.721 30.7
candidate-a 2.251 2.985 35.6
candidate-b 1.986 2.295 22.7
base-b 4.553 6.030 15.0

The cold-walk regression fails on main with 128 worker row-fact reads instead of eight for 128 interleaved archived rows over four pages; it passes with the fix and verifies coverage, displayed fields, and response order. Separate verification passes compare every dashboard page and the complete candidate set: 79 pages, 15,800 rows, 15,801 keys, identical canonical hashes.

Allocation attribution from a one-sweep profile: readSessionRowInputs falls from 402 to 168 MB and prepareSessionRowSharedFacts from 330 to 78 MB (inclusive totals, not additive). Row materialization remains ~401–405 MB, archive trimming ~94–96 MB, and list-row binding ~2 MB. The archive cache still drops to 100 rows after page pins release, so subsequent walks remain cold; enlarging retention is unnecessary for this improvement.

Dispatch remains compatible with hosted in-process, standalone embedded, and remote Gateway callers (openclaw-tools.ts → in-process-gateway.ts). There is no local-only enumeration shortcut.

Reproduce with the committed scripts/perf/session-prepared-list-measure.ts: --list-shape all --sessions 15800 --agents 8 --archived-sessions 12800 --active-runs 30 --updates-per-list 0 --search-discovery --plain-result --iterations 5 --warmup 1, with a synthetic --state-dir, --source-ref <base-or-candidate>, and separate --mode timing, allocation, and verify processes. Run via node --expose-gc --import ./scripts/tsx.mjs; use --reuse-fixture only after the first serial run.

Codex autoreview: scoped-clean through P2 on the complete local diff against the baseline; no accepted/actionable findings. No full-Gateway stress, transport/model-turn, or production latency claim; this follows the lane's focused-proof exception. No Testbox or production load was used.

Local validation passed: 14 archive tests (including the base-red regression), 66 focused prepared-read/worker-read/visibility/search tests, all four pnpm tsgo:test:root shards, the Gateway-root test typecheck, and changed-file oxlint/oxfmt. Visibility coverage includes spawned-only sandbox access, A2A policy, requester-owned global sentinel, archived rows, and incognito exclusion. The full CI run passed on exact head 3741b640fe6f20544333223228163422d46077cf; both required openclaw/ci-gate checks are successful.

@clawsweeper

clawsweeper Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review in progress

ClawSweeper is reviewing this revision. This supersedes any previous blocked status.

View the workflow run.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-14T08:56:06.127599Z 3741b64 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime scripts Repository scripts size: S labels Nov 14, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 14, 2026
@steipete
steipete merged commit ea4f8e0 into main Nov 14, 2026
139 of 141 checks passed
@steipete
steipete deleted the steipete/perf-sessions-search-cold-walk-20261114 branch November 14, 2026 09:08
steipete added a commit that referenced this pull request Nov 14, 2026
Main #198775 groups exact archive reads by store identity. The pinned-page
fixture held archive-pin before main while waiting for main to progress,
causing a reproducible 120-second timeout on the CI main parent.

Sort the held fixture store after main without changing assertions,
timeouts, or production behavior. All 22 cases pass on both the PR branch
and CI parent with this fixture correction; Codex review is clean.
steipete added a commit that referenced this pull request Nov 14, 2026
Main #198775 groups exact archive reads by store identity. The pinned-page
fixture held archive-pin before main while waiting for main to progress,
causing a reproducible 120-second timeout on the CI main parent.

Sort the held fixture store after main without changing assertions,
timeouts, or production behavior. All 22 cases pass on both the PR branch
and CI parent with this fixture correction; Codex review is clean.
steipete added a commit that referenced this pull request Nov 14, 2026
… worker (#198786)

* fix(sessions): bound worker memory during large history cuts

* test(sessions): bind benchmark observers to their native owners

* test(sessions): preserve held archive read ordering

Main #198775 groups exact archive reads by store identity. The pinned-page
fixture held archive-pin before main while waiting for main to progress,
causing a reproducible 120-second timeout on the CI main parent.

Sort the held fixture store after main without changing assertions,
timeouts, or production behavior. All 22 cases pass on both the PR branch
and CI parent with this fixture correction; Codex review is clean.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 15, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 15, 2026
Main openclaw#198775 groups exact archive reads by store identity. The pinned-page
fixture held archive-pin before main while waiting for main to progress,
causing a reproducible 120-second timeout on the CI main parent.

Sort the held fixture store after main without changing assertions,
timeouts, or production behavior. All 22 cases pass on both the PR branch
and CI parent with this fixture correction; Codex review is clean.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 15, 2026
… worker (openclaw#198786)

* fix(sessions): bound worker memory during large history cuts

* test(sessions): bind benchmark observers to their native owners

* test(sessions): preserve held archive read ordering

Main openclaw#198775 groups exact archive reads by store identity. The pinned-page
fixture held archive-pin before main while waiting for main to progress,
causing a reproducible 120-second timeout on the CI main parent.

Sort the held fixture store after main without changing assertions,
timeouts, or production behavior. All 22 cases pass on both the PR branch
and CI parent with this fixture correction; Codex review is clean.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. gateway Gateway runtime scripts Repository scripts size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant