Skip to content

perf(sessions): reuse selections for object-based session discovery - #198740

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-sessions-search-visibility-walk-20261114
Nov 14, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-sessions-search-visibility-walk-20261114

Conversation

@steipete

@steipete steipete commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Unscoped sessions_search repeatedly filters the entire session roster while discovering visible transcripts, even when list metadata is unchanged.

User Impact

Session search spends less main-thread CPU discovering the same visible sessions. Results, ordering, visibility rules, archived coverage, and query/result/byte caps are unchanged. No protocol, schema, or configuration changes.

Why This Change Was Made

listProjectedSessions only reused its existing selection cache when the caller accepted serialized JSON. In-process and embedded callers consume objects, so they bypassed that cache. Remove the transport-format condition; the existing owner still keys by viewer and query, retires selections on metadata/config/identity changes, and bypasses retention for invited membership, spawned queries, active-only queries, activity pulses, and text search. Exact-key reads keep their existing path. Object rows still receive their own copies and enrichment bindings. Object responses also retain independent owner/person arrays and person records instead of exposing the selection owner's frozen facets.

dashboard is already the lightest existing row shape: sidebar extends it, while compact retains additional fields and detail work. No row-mode change is appropriate. Ordering is maintained upstream; the uncached filter visits the complete roster on every page regardless of offset, making a 200-row-page walk quadratic in roster size. The change removes repeated preparation for an unchanged page and subsequent sweeps, not cold archive materialization or initial filtering of each distinct page.

One tool invocation awaits each list page and each transcript-search chunk sequentially. Concurrent walkers therefore represent concurrent tool invocations, not internal fan-out. The earlier single-sweep fix remains intact.

Runtime production LOC: +4. The required growth preserves mutable object-response facet containers and person counts; CI caught this existing contract when the selection became shared. Benchmark harness growth is solely the requested active-run fixture option, offset diagnostics, and symmetric baseline/candidate source loading. Test allocation records 117 new lines.

Evidence

Acceptance: preserve candidate keys byte-for-byte and fail closed after viewer/metadata changes; demonstrate reduced repeated owner work plus a repeatable main-thread CPU or allocation improvement on 15,800 rows, eight agents, 12,800 archived rows, and 30 active synthetic runs. Timing and sampled allocation are separate passes; report A/A spread, host load, and absolute GC deltas. Tail percentiles from five sweeps are descriptive only.

Regression: current main fails the object-consumer case with 1,024 owner projections for eight unchanged reads; candidate performs zero. Existing invalidation cases cover metadata/visibility changes, viewer identity, time expiry, and profile updates. Differential search coverage compares cached versus uncached candidates across self/agent/tree/all, sandbox spawned visibility, A2A policy, requester-owned global sentinel, archived rows, and incognito exclusion.

Workload / metric Base Candidate Change Measured iterations
Repeated object page: main-thread CPU (ms/read) 5.199 0.748 -85.6% 2,000 / side
Repeated object page: sampled allocation (MB/read) 1.419 1.415 -0.3% 2,000 / side
Full discovery: main-thread CPU (s/search) 6.330 4.905 -22.5% 10 / side
Full discovery: mean of arm-median wall (s/search) 8.019 6.396 -20.2% 10 / side
Full discovery: sampled allocation (GB/search) 2.874 2.864 -0.4% 5 / side, separate traced pass
Full discovery: total GC (ms/search) 165.054 143.175 -13.3% 10 / side, untraced

Allocation differences are neutral at this sampling precision. Timing and allocation were collected in separate processes. Full-discovery timing uses a predeclared base/candidate/candidate/base block; baseline A/A CPU was 6.701 / 6.937 s per sweep, and final baseline endpoints were 6.877 / 5.782 s as host load declined. Both final pairs improve CPU (32.1% / 11.1%; signed paired mean 21.6%). Wall percentiles from five samples per arm are descriptive only.

Final timing arm CPU s/search Wall median s/search GC ms/search Host load (1 min)
final-base-a 6.877 8.774 175.1 20.7
final-candidate-a 4.673 6.044 125.9 18.2
final-candidate-b 5.138 6.748 160.5 13.6
final-base-b 5.782 7.265 155.0 10.9
Offset Prepare ms, base → candidate Materialization/yield wait ms, base → candidate Row presentation ms, base → candidate
0 13.654 → 0.140 35.86 → 31.39 6.05 → 5.87
3,600 12.180 → 0.077 113.05 → 99.21 4.43 → 4.19
7,200 12.133 → 0.077 114.34 → 97.84 4.09 → 3.55
12,800 10.786 → 0.064 19.05 → 18.88 5.88 → 5.34

The wait column includes archive materialization, worker/yield waits and host scheduling; it is not synchronous prepare time. Each probe selected 200 rows and materialized 154–164 archived rows. First-sweep cold-selection CPU averaged 7.801 → 7.353 s and wall 10.673 → 9.954 s, but paired signs differed; treat first-sweep speed as inconclusive.

All full discoveries returned 79 pages, 15,800 roster rows, and 15,801 candidate keys including the requester; SHA-256 of sorted candidate-key bytes: 94f5b13907b73a986cb1d337f6317254c71b0a2798ac0a01381418c3e134c5ad. Repeated-page initial/final output digests also match.

Focused validation: session-list-viewers.perf.test.ts (5 passed), sessions-search-tool.test.ts and sessions-search-tool.matching.test.ts (36 passed); pnpm tsgo:test:root (all four shards passed); gateway-root test typecheck; changed-file oxfmt and oxlint. No Testbox allocated, per lane policy.

Codex autoreview: local diff against f40a774f81f00c4afecbff22c3d7409a5629511e, P0–P2, scoped-clean with no accepted/actionable findings. Only two lint-only local-variable renames followed the first review. CI then caught a real mutable-response contract in session-row-projection.invalidation.test.ts: object readers must be able to mutate response-local person records without affecting retained facets. Reproduced locally (6 passed, 1 failed), repaired at the object-response boundary, then both that file and the selection/visibility file passed (12 tests). Targeted types and lint passed again. A second Codex P0–P2 review against 2e77b6be8b673742f5849e6a386829203f2a1fd2 of the repaired diff returned scoped-clean, with no accepted/actionable findings. Rebased over unrelated main changes before publication; no affected runtime owners changed. Exact-head CI run 43574645017 passed on cbf60da95464e750a86879e170308fd3b5df88b1; both required openclaw/ci-gate checks passed. The PR is ready and intentionally unmerged for maintainer review.

Reproduction uses scripts/perf/session-prepared-list-measure.ts --search-discovery --list-shape all --sessions 15800 --agents 8 --archived-sessions 12800 --active-runs 30 --updates-per-list 0 --iterations 5 --warmup 1 --state-dir <synthetic-state> with node --expose-gc --import ./scripts/tsx.mjs, separate --mode timing|allocation, and --source-ref <base>|working-tree. The workload exercises the real tool and embedded projection owner, excluding transcript FTS and network/model transport. No whole-Gateway stress or production load was run: this focused change reuses an existing bounded cache and preserves live-query bypasses. RSS/heap, event-loop/RPC tails, and per-kind/max GC pauses were not measured; the reported measurements are owner-level CPU/allocation and total GC, not a whole-Gateway non-regression claim.

@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 complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

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:14:01.115033Z cbf60da New commits
ℹ️ 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: M labels Nov 14, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 14, 2026
@clawsweeper

clawsweeper Bot commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR lets object-based session discovery reuse the existing viewer- and query-keyed selection cache.

Example: Eight unchanged object-mode list reads over 128 sessions.

  • Before: The reported regression run performs 1,024 owner projections.
  • After: The reported candidate run performs zero owner projections.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) Focused owner evidence supports the optimization, but CI confirms an introduced response-mutability regression.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the contributor proof gate; supplied measurements exercise the real tool and embedded list owner in a synthetic in-process workload, with final matched-loader measurements still pending.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Repeated broad session searches spend main-thread CPU rediscovering unchanged visible sessions.
Reason: The maintainer-authored direction removes redundant work through an existing bounded cache without adding configuration or another owner.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep this PR open: the optimization is useful, but it introduces a mutable-result contract regression confirmed by the failed CI check.

Priority: P2
Reviewed head: 2539e6abfdee0c3d5228b46b46a64040151d813f

Before merge

  • Preserve mutable facets for object-mode list consumers (P2) - Object-mode reads now enter presentation.select(), which deeply freezes the selection facets. buildSessionsListResult forwards list.people directly, so a caller editing a returned person's label or sessionCount now throws instead of modifying its private response. The existing profile-display invalidation test exercises exactly this contract, and the failed CI job reports the readonly-property exception at line 490. Keep the cached selection immutable, but copy response-owned facets for object consumers rather than weakening or removing that test.

Findings

  • [P2] Preserve mutable facets for object-mode list consumers — src/gateway/session-utils-list.ts:581
Agent review details

How this fits together

Session search discovers candidate transcripts through the embedded Gateway list owner, which selects authorized session metadata and returns projected rows and facets.

flowchart LR
  A[Session search tool] --> B[Embedded Gateway adapter]
  B --> C[Session list owner]
  C --> D[Selection cache]
  D --> E[Authorized session metadata]
  E --> F[Object rows and facets]
Loading

Technical review

Best possible solution:

Reuse the existing immutable selection cache while returning private mutable facet data to object consumers through the list-result owner.

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

Current-main source shows the object-mode cache bypass, and the PR reports a failing baseline work-count regression; no target code was executed during this review.

Is this the best way to solve the issue?

Removing the transport-format restriction is a small, appropriate optimization, but the result boundary must preserve the existing mutable object-consumer contract.

Full review comments:

  • [P2] Preserve mutable facets for object-mode list consumers — src/gateway/session-utils-list.ts:581
    Object-mode reads now enter presentation.select(), which deeply freezes the selection facets. buildSessionsListResult forwards list.people directly, so a caller editing a returned person's label or sessionCount now throws instead of modifying its private response. The existing profile-display invalidation test exercises exactly this contract, and the failed CI job reports the readonly-property exception at line 490. Keep the cached selection immutable, but copy response-owned facets for object consumers rather than weakening or removing that test.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 2e77b6be8b67.

Provenance checked

  • Object versus serialized selection reuse changes intended behavior with a stated reason (4d94a9f: Shared list views deliberately retained immutable facets while embedded consumers retained private wrappers.)
  • Selection work-count regression keeps the original intent (6401ea6: Bound repeated owner work while preserving viewer isolation, pagination, publication invalidation, and activity expiry.)
  • Benchmark source loading and discovery workload keeps the original intent (fix: reduce session search stalls with large archives #197013: Measure real search discovery through the embedded projection owner separately from transcript search and transport.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test src/gateway/session-row-projection.invalidation.test.ts src/gateway/session-list-viewers.perf.test.ts src/agents/tools/sessions-search-tool.test.ts src/agents/tools/sessions-search-tool.matching.test.ts --maxWorkers=1
  • pnpm tsgo:test:root
  • node scripts/run-oxlint.mjs --tsconfig tsconfig.json src/gateway/session-utils-list.ts
  • git diff --check

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 9cb3c14 adds src/gateway/session-list-viewers.perf.test.ts:399 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 9cb3c14855e5; files: src/gateway/session-list-viewers.perf.test.ts)

PR surface

Source -3, Tests +117, Other +41. Total +155 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 1 4 -3
Tests 1 123 6 +117
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 2 64 23 +41
Total 4 188 33 +155

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Runtime versus regression coverage Runtime production net −3 lines; tests net +117 lines. The runtime deletion reuses an existing owner; test growth covers object-mode work reduction and differential search visibility.

Labels

Label changes:

  • add P2: This improves repeated session discovery work, but the introduced object-result regression requires a focused repair before merge.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦐 gold shrimp and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: This improves repeated session discovery work, but the introduced object-result regression requires a focused repair before merge.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦐 gold shrimp and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 14, 2026, 3:06 AM ET / 08:06 UTC.

Let in-process and embedded list readers use the existing viewer- and query-keyed selection owner. Preserve exact reads, live-query bypasses, invalidation, object row copies, and search visibility/caps. Extend the owner workload and regression coverage for unchanged selection work and differential search visibility.
@steipete
steipete force-pushed the steipete/perf-sessions-search-visibility-walk-20261114 branch from 2539e6a to cbf60da Compare November 14, 2026 08:11
@steipete
steipete merged commit 08ae8c6 into main Nov 14, 2026
143 of 144 checks passed
@steipete
steipete deleted the steipete/perf-sessions-search-visibility-walk-20261114 branch November 14, 2026 08:31
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 15, 2026
…penclaw#198740)

* perf(sessions): reuse selections for object-based session discovery

Let in-process and embedded list readers use the existing viewer- and query-keyed selection owner. Preserve exact reads, live-query bypasses, invalidation, object row copies, and search visibility/caps. Extend the owner workload and regression coverage for unchanged selection work and differential search visibility.

* perf(sessions): preserve mutable list response facets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. scripts Repository scripts size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant