Skip to content

improve: reduce repeated work when searching session history - #201490

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-sessions-search-recall-per-key-list-prep-20260919
Nov 18, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-sessions-search-recall-per-key-list-prep-20260919

Conversation

@steipete

@steipete steipete commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Searching session transcripts repeatedly builds the same session-list selection and recipient presentation for every matching key. On larger rosters, that creates unnecessary main-thread work and allocation during recall.

User Impact

Session recall uses less CPU and memory while returning the same visibility decisions. Global transcript ownership, sharing, federation, cron and phantom exclusions, Incognito, spawned-session restrictions, and pinned visibility remain enforced.

Why This Change Was Made

Expose the list owner's existing candidate-key selection through its preparation API, prepare/filter each admitted candidate batch once, and use set membership for individual keys. Global keys retain their separate physical-owner authorization. Nothing is retained across worker yields or requests, and transcript indexing is unchanged.

This preserves the request-scoped runtime reuse from #189322 within the indexed recall path introduced by #200355. Production code is net −3 lines. Runtime-resolution composite keys remain unchanged: replacing their complete nine-field encoding would add separate cache machinery without addressing the repeated preparation.

Evidence

The real search regression fails before the fix: 28 preparations for 14 candidate batches. It passes after the fix. All 54 focused tests pass, including the list selector, filters, retained partitions, search RPC handler, and agent-tool visibility. A mixed-roster differential compares batched verdict bytes with the original exact-key preparation and independently asserts the expected exclusions. The corrected malformed phantom fixture also passed its focused rerun.

Synthetic benchmark: 600 resident rows, 130 indexed matching keys, real recall owner and transcript worker. Five samples per process; serial ABBA fresh processes, 200 recalls per timing sample, separate allocation sampling with collected objects included. The worker limits batches to 26 keys; this removes per-key preparation, not the fresh authorization boundary after each worker yield. The fixture intentionally does not reproduce multi-gigabyte transcript storage or workspace traversal, which are outside this owner path.

Sampled allocation fell from 9.43 MB to 1.53 MB per recall (84%), with same-code process medians within 1%. Both timing pairs improved: 42–55% lower main-thread CPU and 15–33% lower elapsed time. The busy shared host produced substantial A/A timing variation, so these ranges are paired observations, not production latency guarantees. Cold worker initialization is reported separately by the script.

Per-recall metric Baseline median / p95 Candidate median / p95
Main-thread CPU, untraced 3.77 / 5.00 ms 1.89 / 2.82 ms
Elapsed, untraced 6.46 / 13.97 ms 4.75 / 12.20 ms
Sampled allocation 9.43 / 9.48 MB 1.53 / 1.59 MB

Each cell has 10 samples across two fresh processes. Timing sample ranges were CPU 3.00–5.00 → 1.34–2.82 ms and elapsed 5.08–13.97 → 3.36–12.20 ms. Cold first-call ranges were 2.66–10.30 → 2.88–5.65 s, dominated by worker admission and unsuitable for attributing this warm-path improvement. The full five-file test run took 230.64 s including compilation; the changed search-scope tests took about 26 s in the first complete run.

Reproduce with node --expose-gc --import ./scripts/tsx.mjs scripts/perf/session-recall-measure.ts --state-dir <synthetic-directory> --sessions 600 --keys 130 --iterations 200 --samples 5. Reuse serially with --reuse; use --owner-ref a4be1ae09e3ebe021f55fb65dd3663aa2a152504 for the exact baseline recall owner and --allocation in separate processes.

pnpm check:changed completed. Its line-cap and two proof-code typing findings were corrected and their gates rerun successfully. The remaining unused UI export reproduces on exact base a4be1ae09e3ebe021f55fb65dd3663aa2a152504: the same full-tree Knip command exits 1 with only ui/src/e2e/new-session-page.test-support.ts: expectPendingNewSessionPresentation (e2e). #198967 (a90c5419b779d) introduced this main regression by removing every caller while leaving its export. This PR does not change that UI path. All change-caused local failures are resolved; CI remains pending.

Codex autoreview: scoped-clean through P2 on the complete change against a4be1ae09e3ebe021f55fb65dd3663aa2a152504; no actionable findings. Subsequent edits only corrected proof-code types. No Control UI imports of the changed production modules were found. No schema/configuration change or live Gateway modification.

CI run 44411579287 has one investigated failure so far: checks-node-changed-1, sessions-list-privacy.test.ts, “rechecks named role enrichment after a role change during chat.history”. The identical focused test fails on exact CI main parent 777fc99a8993b55fab66e3cb17faf4ef520cd40f and on this head: the admitted request returns two rows instead of rejecting. #201334 (04cb8179ccd66) deliberately changed authority to remain fixed for admitted requests and apply role changes at the next request, leaving this test's old mid-request rejection expectation behind. This is a main test regression, not a passing CI claim; the test and authority owners are unchanged here. Remaining jobs and final-head ClawSweeper review are pending.

Prepare and filter each admitted transcript candidate batch once, retaining physical global ownership and session-tool visibility. Avoid rebuilding selection and recipient presentation for every matching key.
@clawsweeper

clawsweeper Bot commented Nov 18, 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 18, 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-18T22:28:30.606533Z 9a38d54 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: M labels Nov 18, 2026
@clawsweeper clawsweeper Bot added the clawsweeper:intake:bug Preliminary submission classification; full source review pending. label Nov 18, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 18, 2026
@clawsweeper

clawsweeper Bot commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Prepare session-list selection and visibility once per transcript candidate batch instead of once per matching key.

Example: The reported search regression authorizes 28 matching keys across 14 candidate batches.

  • Before: The recall path prepares session-list selection 28 times.
  • After: The recall path prepares selection 14 times while preserving the expected visible results.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful and apparently correct, with reported owner-level measurements and meaningful boundary coverage; proof remains below shipped-entry-point coverage and CI is unresolved.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored, behavior-preserving optimization supplies owner-and-worker benchmark results and focused regression evidence; those measurements do not claim a shipped Gateway round trip.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Searching larger session histories repeatedly allocates and prepares identical selection facts for keys in the same candidate batch.
Reason: The maintainer-authored direction is supported by reported measurements, a smaller production implementation, and preserved visibility contracts.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR removes demonstrated repeated preparation using the existing selection owner, and no introduced correctness or security defect was found; CI still has a failed gate requiring disposition.

Priority: P2
Reviewed head: 9a38d54b33ca993986bc08c689cb99c1ad85a7ce

Before merge

None.

Findings

None.

Agent review details

How this fits together

Gateway and embedded session-search callers send recall queries to the transcript worker, whose matching-key batches are authorized through session-list sharing and agent-tool visibility owners before bounded results return.

flowchart LR
  A[Session search caller] --> B[Recall owner]
  B --> C[Transcript worker]
  C --> D[Candidate key batch]
  D --> E[Existing list selection and sharing]
  E --> F[Agent tool visibility checks]
  F --> B
  B --> G[Bounded search results]
Loading

Technical review

Best possible solution:

Retain the batch-scoped reuse of the existing list owner and its separate physical-global authorization.

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

Fetched main visibly rebuilds selection and presentation inside the candidate-key loop; the PR reports a base-failing work-count regression and supplies a reproducible owner benchmark, neither of which was executed during this read-only review.

Is this the best way to solve the issue?

This is a small, complete optimization using the existing candidate selector, with no cross-request cache, competing policy owner, or unnecessary production machinery.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 3eee09d9b462.

Provenance checked

  • Indexed recall authorization keeps the original intent (a564030: Authorize bounded indexed candidates using current Gateway visibility and captured tool restrictions without enumerating the full inventory.)
  • Shared session-list visibility preparation keeps the original intent (1e028b5: Use the existing list sharing and membership owner to search the complete authorized scope.)
  • Request-scoped runtime reuse keeps the original intent (28fd0cd: Share runtime-policy decisions within synchronous selections while retaining complete identity keys and refreshing after yields.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit a564030 adds src/gateway/server-methods/sessions-search-recall.ts:90 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: a564030a2b6e; files: src/gateway/server-methods/sessions-search-recall.ts)
  • Vincent Koc: Raw commit 712a32e adds src/gateway/session-utils-list.ts:481 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 712a32e5d776; files: src/gateway/session-utils-list.ts)

PR surface

Source -3, Tests +159, Other +204. Total +360 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 15 18 -3
Tests 1 159 0 +159
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 204 0 +204
Total 4 378 18 +360

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
Production versus regression tests Production −3 net lines; tests +159 lines Production reuses an existing selection capability; added coverage checks the repeated-work invariant and independent mixed-roster visibility expectations.

Labels

Label changes:

  • add P2: A measured, bounded performance improvement reduces recall CPU and allocation without changing configuration or intended results.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: A measured, bounded performance improvement reduces recall CPU and allocation without changing configuration or intended results.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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 18, 2026, 6:01 PM ET / 23:01 UTC.

@steipete
steipete merged commit e1e44b1 into main Nov 18, 2026
149 of 154 checks passed
@steipete
steipete deleted the steipete/perf-micro-sessions-search-recall-per-key-list-prep-20260919 branch November 18, 2026 23:19
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

roboclaw-bot added a commit that referenced this pull request Nov 19, 2026
Integrate main 949e51d to resolve the conflict with #201490. Keep its shared candidate-batch preparation in the existing worker/final-publication authorization owner. Retain current sharing-data checks, synchronous response publication, bounded retries and admitted-role policy.

Co-authored-by: vincentkoc <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 19, 2026
…law#201490)

Prepare and filter each admitted transcript candidate batch once, retaining physical global ownership and session-tool visibility. Avoid rebuilding selection and recipient presentation for every matching key.
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: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: M 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