Repository navigation
perf(sessions): reuse selections for object-based session discovery - #198740
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 Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex review: needs changes before merge. What this changesThis 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.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete 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 Before merge
Findings
Agent review detailsHow this fits togetherSession 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]
Technical reviewBest 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:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 2e77b6be8b67. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource -3, Tests +117, Other +41. Total +155 across 4 files. Added test files: 0. View PR surface stats
Preflight sourceSource 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
LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment 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.
2539e6a to
cbf60da
Compare
…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
What Problem This Solves
Unscoped
sessions_searchrepeatedly 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
listProjectedSessionsonly 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.dashboardis already the lightest existing row shape:sidebarextends it, whilecompactretains 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.
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.
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.tsandsessions-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 insession-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 against2e77b6be8b673742f5849e6a386829203f2a1fd2of 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 oncbf60da95464e750a86879e170308fd3b5df88b1; both requiredopenclaw/ci-gatechecks 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>withnode --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.