Skip to content

perf(sessions): serve sessions.list from an incrementally maintained order - #163941

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

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

Conversation

@steipete

@steipete steipete commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Repeated sessions.list calls rebuild candidate arrays and sorted pages after one session changes or clients alternate filters.

User Impact

Lists maintain their order incrementally while preserving current visibility, activity, archive, pinning, owner-first, and pagination behavior. No configuration or storage migration is required.

Why This Change Was Made

The existing revision owner publishes compact accepted metadata after row/index updates and owns listener disposal and board-fact invalidation. The list reader updates the affected physical competitor and winner, retiring orders on topology replacement or disposal. This removes the single-filter candidate cache, option-key serialization, and intermediate visible/candidate arrays for ordinary requests.

Cron/system classification joins the existing selection facts at metadata acquisition, and ready search identity reads reuse maintained order. Transcript search prepares complete selection metadata at its existing awaited boundary. Viewer decisions and time-dependent filters remain per request.

Production delta against main: +70 lines (283 added, 213 removed). Growth preserves concrete federation and lifecycle contracts: deleting a sentinel winner must expose its next physical competitor; ordinary duplicate keys remain read-time errors without failing committed writes; topology/disposal retire derived orders; callback failures cannot interrupt accepted row maintenance. The superseded candidate-cache machinery is deleted, and maintained orders retain metadata rather than materialized row graphs. Raw catalog reads preserve resident order, and direct/child reads retain their existing selection boundary.

This builds on the corrected archive-only projection behavior. It adds no live-row eviction or subscription-pinning hook.

Evidence

Synthetic production-handler rig: 5,000 initial SQLite sessions, ten concurrent clients, mixed sorts/filters, 1,000 calls, 100 inserts, and 100 updates. Timing and sampled allocation use separate processes.

Metric Historical pre-eviction baseline Corrected main, same Testbox Final candidate
p50 180.44 ms 59.46 ms 42.81 ms
p95 277.09 ms 84.72 ms 70.63 ms
Workload 23.99 s 8.250 s 6.885 s
Sampled bytes/call, including writes 9,631,293 9,634,371 6,971,996

Allocation falls 27.6% from the pre-eviction baseline and 27.6% from same-host corrected main, clearing the 15% threshold. The final same-host pair measured p50 −28.0%, p95 −16.6%, and workload time −16.5%. Historical latency used a different host/Node version and is not an attributable speedup; these are synthetic measurements. All four final selection digests match the historical digest.

Final proof used provider blacksmith-testbox, profile openclaw-check, lease tbx_01m3zrbb5b6c4hhxmekqm1nj7v, Node 24.19.0, comparing base ff96d47c3506 with the complete candidate:

  • OPENCLAW_CHECK_CHANGED_REMOTE_CHILD=1 CI=1 node scripts/check-changed.mjs --staged and the four paired rig phases: passed, exit 0, 1,489.701 s combined command time. Gate coverage included production types, all 27 test type graphs, lint, dead-code checks, line caps, and runtime import-cycle checks.
  • node scripts/run-vitest.mjs <focused files> --maxWorkers=1: 104 tests passed across ten files, including both CI-failing files and Gateway/TUI siblings; one existing opt-in benchmark remained skipped. The two perf files took 34.030 s and 18.897 s wall; the sibling invocation took 69.30 s. Targeted lint passed with zero warnings/errors.
  • Earlier complete focused proof passed 110 tests across ten files on lease tbx_01m3zkpnntdmm72bet335dt69p, with the staged gate and paired rig also passing. This proof is retained for unchanged contracts.
Materially changed test file Measured single-file wall time Result
session-row-selection.test.ts 32.232 s, including cold worker compilation 8 passed
session-row-projection.retention.test.ts 18.995 s 2 passed
server-methods/sessions-search-scope.test.ts 105.345 s on the earlier measured base 7 passed
session-utils.perf.test.ts 34.030 s, including cold worker compilation 15 passed
session-list-viewers.perf.test.ts 18.897 s 2 passed; existing opt-in benchmark skipped

The earlier search-file cost was dominated by its existing 205-session/five-agent case (81.733 s), which protects discovery beyond historical scope limits using real stores. Main has independently optimized that fixture; the current repair sibling run includes the updated file. Current-head CI passed on ae04a53355f2: 50 executed jobs, 8,119 summed job seconds and 420 seconds from first job start to last completion (21 conditional jobs skipped). Job seconds are elapsed job time, not billed CPU time.

The selection regression failed on corrected main b60f9e200987 at its intended assertion: three full-roster selections after metadata changes instead of zero. All preceding ordering/archive assertions passed. Candidate coverage also preserves delete order, paging, pinning, callback failure, and disposal. Deletion's topology publication intentionally rebuilds its scope; the test separately verifies incremental updates before and after that reset.

Initial CI run 37087849005 exposed repeated provenance classification and a search-identity roster rescan; both are repaired at their owners. Viewer coverage now also proves classification changes when an operator removes a heartbeat label and proves warm filter changes reuse accepted facts. A comparator-export spy reported a separate failure: a Testbox probe on unchanged base ff96d47c3506 produced the correct sorted 256-row page while the spy observed zero module-local comparisons. The first-page order/count oracle remains; only that invalid comparison budget and unused spy were removed.

Fresh independent Codex review of the complete PR and CI repair: scoped-clean, no actionable P0–P2 findings. Preparation line-cap and missing-brace failures were fixed without suppressions. Native sync timeouts were resolved with fresh leases and serialized proof payloads. All four owned leases were stopped.

The rig covers the production handler, projection, and response serialization; WebSocket authentication and live deployment load are outside its scope. Allocation includes collected objects and workload writes and is sampled rather than exact.

…order

Maintain per-scope ordering from accepted projection metadata while preserving federation, visibility, archive and pagination behavior. Remove the superseded candidate cache and per-request order rebuilds.
@clawsweeper

clawsweeper Bot commented Oct 3, 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 3, 2026
@steipete
steipete marked this pull request as ready for review October 3, 2026 01:54
@steipete
steipete enabled auto-merge (squash) October 3, 2026 01:55
@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 3, 2026
@clawsweeper

clawsweeper Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 2, 2026, 11:00 PM ET / October 3, 2026, 03:00 UTC (Revision 3).

ClawSweeper review

What this changes

The PR maintains session-list ordering as accepted metadata changes, removes the previous candidate cache, and updates search preparation, regression coverage, and protocol documentation.

Merge readiness

✅ Ready for maintainer review

The optimization remains useful on current main, and the previous review’s concrete concerns are addressed. No actionable introduced defect was found.

Priority: P2
Reviewed head: ae04a53355f2f6b419884301af8c7247f0ca45c5

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, supported optimization with meaningful production-boundary measurements and no actionable correctness finding.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Recorded Testbox output exercises the production session-list handler, real SQLite projection, and response serialization under mixed requests and writes, showing lower allocation and latency with matching selection digests. Tests supplement this scoped performance proof; no stored-data format or migration changes are introduced.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): Recorded Testbox output exercises the production session-list handler, real SQLite projection, and response serialization under mixed requests and writes, showing lower allocation and latency with matching selection digests. Tests supplement this scoped performance proof; no stored-data format or migration changes are introduced.
Evidence reviewed 8 items Pinned introduced changes: Inspected the merge-base-to-head production and test hunks using the host-pinned introduction range; the stale test merge was not used to infer removals from main.
Ordering lifecycle: Retained selections consume compact metadata publications; reset publications clear scopes. Row installation precedes publication, and materialization publishes changed board facts. Listener failures cannot interrupt accepted maintenance.
Current-main necessity: Fetched main still uses revision-based selections and the single-filter candidate cache rather than the introduced incrementally maintained orders. No merged fixing PR was established.
Findings None None.
Security None None.

How this fits together

The Gateway’s session projection receives committed session metadata and prepares the session roster. List and search requests apply current visibility and activity filters before returning selected session details to clients.

flowchart TD
  A[Committed session metadata] --> B[Resident session projection]
  B --> C[Incrementally maintained orders]
  D[List or search request] --> E[Current visibility and activity filters]
  C --> E
  E --> F[Pagination and selected row preparation]
  F --> G[Client response]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +70, Tests +123, Docs +2. Total +195 across 13 files.

View PR surface stats
Area Files Added Removed Net
Source 6 283 213 +70
Tests 6 149 26 +123
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 13 434 239 +195

Review metrics

Metric Value Why it matters
Code growth justification production +70 lines; tests and support +123 lines The PR explains production growth through federation competitors, incremental updates, and lifecycle cleanup while removing superseded cache machinery.
Same-host benchmark sampled allocation −27.6%; p95 latency −16.6% The reported production-handler workload supports a measurable benefit while preserving selection digests.

Technical review

Best possible solution:

Keep ordering derived from the existing projection owner while applying current viewer and clock-dependent decisions synchronously for each response.

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

Not applicable as a functional bug report; the recorded same-host production-handler benchmark provides a concrete comparison for the performance problem, without reviewer-side execution.

Is this the best way to solve the issue?

Yes. Extending the existing projection’s publication lifecycle and removing the superseded candidate cache provides one ordering owner while preserving request-time visibility checks.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 0e17a464f0d3.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded session-list performance improvement with preserved behavior and no demonstrated urgent user-facing regression.
  • 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 Testbox output exercises the production session-list handler, real SQLite projection, and response serialization under mixed requests and writes, showing lower allocation and latency with matching selection digests. Tests supplement this scoped performance proof; no stored-data format or migration changes are introduced.
  • proof: sufficient: Contributor real behavior proof is sufficient. Recorded Testbox output exercises the production session-list handler, real SQLite projection, and response serialization under mixed requests and writes, showing lower allocation and latency with matching selection digests. Tests supplement this scoped performance proof; no stored-data format or migration changes are introduced.

Evidence

What I checked:

  • Pinned introduced changes: Inspected the merge-base-to-head production and test hunks using the host-pinned introduction range; the stale test merge was not used to infer removals from main. (ae04a53355f2)
  • Ordering lifecycle: Retained selections consume compact metadata publications; reset publications clear scopes. Row installation precedes publication, and materialization publishes changed board facts. Listener failures cannot interrupt accepted maintenance. (src/gateway/session-row-projection-record.ts:130, ae04a53355f2)
  • Current-main necessity: Fetched main still uses revision-based selections and the single-filter candidate cache rather than the introduced incrementally maintained orders. No merged fixing PR was established. (src/gateway/session-utils-list.ts:184, 0e17a464f0d3)
  • Previous review disposition: The current head prepares cron/system classification at metadata acquisition and requests maintained ordering for search identities. The first-page order/count oracle remains. The captured PR body documents a base-code probe where the removed comparator spy observed zero comparisons despite correct sorting, plus passing repaired suites. (src/gateway/session-utils.perf.test.ts:47, ae04a53355f2)
  • Production-handler performance evidence: The captured body, sourceRevision 4d3e39224fbbcac05abc0f490443658928b1dc908518234ab2791736c6112595, reports a Testbox production-handler rig with 5,000 SQLite sessions, ten clients, 1,000 calls, and concurrent writes. Same-host candidate results show sampled allocation −27.6%, p95 −16.6%, and matching selection digests. WebSocket authentication and deployment load are explicitly outside this evidence.
  • Behavior and retention regressions: Inspected coverage for metadata ordering, archive rematerialization, pagination, pinning, duplicate rejection, observer failure, disposal, viewer changes after waits, and collection of superseded entries. The captured body reports the intended scan regression failing on corrected main and 104 focused tests passing on the final candidate; this reviewer executed no tests. (src/gateway/session-row-selection.test.ts:45, ae04a53355f2)

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 (2 earlier review cycles)
  • reviewed 2026-10-03T01:59:34.891Z sha 864e4f4 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-03T02:05:55.789Z sha 864e4f4 :: needs changes before merge. :: none

Prepare static discovery facts with accepted metadata and reuse maintained ordering for ready search identity reads. Preserve cold-page ordering coverage while removing a comparator counter that did not observe the original module-local sort.
@steipete
steipete merged commit 2a4dacc into main Oct 3, 2026
127 of 129 checks passed
@steipete
steipete deleted the steipete/perf-micro-sessions-list-incremental-20260919 branch October 3, 2026 03:01
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 3, 2026
…order (openclaw#163941)

* perf(sessions): serve sessions.list from an incrementally maintained order

Maintain per-scope ordering from accepted projection metadata while preserving federation, visibility, archive and pagination behavior. Remove the superseded candidate cache and per-request order rebuilds.

* perf(sessions): reuse prepared discovery facts for list readers

Prepare static discovery facts with accepted metadata and reuse maintained ordering for ready search identity reads. Preserve cold-page ordering coverage while removing a comparator counter that did not observe the original module-local sort.
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. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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