Skip to content

perf(sessions): partition ordered list candidates by archive state - #172406

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-sessions-list-archive-scan-20260919
Oct 14, 2026
Merged

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

Conversation

@steipete

@steipete steipete commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

After session metadata changes, sessions.list walks both open and archived rows even when the caller requests only one archive state. Small pages still pay for the whole inventory.

User Impact

Archive-filtered session lists skip the opposite archive population. Returned rows, totals, owner facets, person-link resolution, sharing checks, and pagination keep their existing behavior. No configuration, schema, or stored-format changes.

Why This Change Was Made

The existing resident selection owner already maintains agent-scoped sorted orders. Extend that owner with lazy archive partitions and update them through the existing row-publication lifecycle. Ordinary reads no longer build the all-session order first or repeat archive checks for every candidate. Full-roster profile-reference, project, and catalog consumers explicitly request all rows.

Owner filters still follow owner-facet aggregation: narrowing by owner earlier would change the response contract. No new top-k implementation or independent cache is introduced. Production code grows by 15 lines to carry the archive partition through ordered insertion/removal and preserve full-roster callers; the per-request archive scan is removed from ordinary reads.

Evidence

  • Focused local tests: node scripts/run-vitest.mjs src/gateway/session-row-selection.test.ts src/gateway/session-utils.filters.test.ts --maxWorkers=1 — 26 tests passed, 2 files; 227.87 s wall time including cold compiled-worker preparation on a constrained Mac. Coverage includes archive/restore, zero archive timestamp, pagination, sentinel precedence, owner facets, profile relations, and deletion/rematerialization. An earlier attempt was discarded because source edits overlapped fixture compilation; no tests ran in that attempt.

  • Changed-file oxfmt, repository run-oxlint.mjs, and git diff --check passed. Broad checks belong to PR CI; no Testbox/Crabbox lease was allocated.

  • Independent subagent review (autoreview route unavailable): scoped clean, no actionable P0–P2 findings. Autoreview refused the provider route because it did not match operator configuration; configuration was left unchanged.

  • CI run 38612846176 caught an unmigrated retention-test caller (entries.map). Fixed it to request entries("all"); the single failing file passed locally (2 tests, 48.53 s wall time), changed-file lint/format passed, and independent review of the follow-up was clean. Production code is unchanged by this repair.

  • Final-head CI run 38614514699: all 35 substantive jobs passed on fd031cb458b66f935093740fa768855dc92b0a52, including the repaired retention stripe, builds, production/test types, lint, UI E2E, and baseline ratchets. No CI reruns were used.

Measurement

Measured the actual WebSocket sessions.list RPC on an isolated Team sandbox, comparing base 66207936af93c0ad90885633ea44e973872fa3ff with the production change in 67065222627eebb165a58f12ea17b0733ebed7a4 (the final head only repairs a test caller). Both use the official team-shape generator with identical seed/time: 5,000 sessions, 1,000 archived, 6,000 retained runs, approvals, cron, and projects; approximately 236 MB agent DB. Synthetic state only, loopback port 41126, startup maintenance completed before sampling. Runtime builds and measurements were restricted to CPUs 64–127, 64 GB memory, nice 10 / idle I/O. No production files or services were touched.

Each variant used three rounds, 100 measured calls per archive mode per round after five warmups, returning 100 rows. The changed-state workload patches one session label before every timed list request; patch latency is excluded. Counts stayed 4,000 open / 1,000 archived / 5,000 all.

Changed-state mean RPC latency Before After
Open 11.09 ms 11.39 ms
Archived 7.01 ms 6.55 ms
All 13.23 ms 11.46 ms

Open reads were neutral (+2.7%, within observed run variation); archived reads improved 6.7% and all reads 13.4% in this first comparison. Cached reads were noisy: open 3.53→4.78 ms, archived 2.94→3.47 ms, all 3.29→3.70 ms. To investigate that apparent regression, repeated the identical workload in reverse variant order with the existing openclaw.session.list diagnostics channel enabled. Cached RPC latency then favored the change (open 5.22→3.09 ms, archived 4.58→2.69 ms, all 4.85→3.17 ms), with preparation CPU below 0.04 ms/call for both variants. Changed-state preparation CPU was open 5.52→3.53 ms, archived 2.55→0.90 ms, all 6.21→3.40 ms; corresponding RPC latency was 18.28→8.79 ms, 10.65→4.42 ms, and 18.05→7.55 ms.

The reverse-order run also made unchanged row rendering faster, so these large diagnostic-run differences cannot be attributed solely to the selection change. There is no consistent regression across the two comparisons, but no precise overall speedup claim: this is an explicitly requested removal of opposite-archive candidate scans, with a neutral open-read result in the first comparison. Remaining limitations: shared-host variability, one operator client, 5,000 rather than the reported ~9,500 production sessions, and no allocation/RSS measurement. The extra lazily maintained ordered partitions retain references to existing rows; reduced retained memory is not claimed.

@clawsweeper

clawsweeper Bot commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@steipete
steipete marked this pull request as ready for review October 14, 2026 18:10
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S labels Oct 14, 2026
@chatgpt-codex-connector

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

Copy link
Copy Markdown
Contributor

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-14T18:13:48.253104Z 6706522 Draft marked ready
ℹ️ 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.

@steipete
steipete merged commit 79a4205 into main Oct 14, 2026
129 checks passed
@steipete
steipete deleted the steipete/perf-micro-sessions-list-archive-scan-20260919 branch October 14, 2026 18:53
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 15, 2026
…penclaw#172406)

* perf(sessions): partition ordered list candidates by archive state

* test(sessions): select all rows in retention coverage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant