Skip to content

fix: agent session searches stall on large histories - #200355

Merged
steipete merged 3 commits into
mainfrom
steipete/perf-micro-agent-sessions-search-full-scan-20260919
Nov 17, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/perf-micro-agent-sessions-search-full-scan-20260919

Conversation

@steipete

@steipete steipete commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: agent session searches stall on large histories because every query first pages through the complete session inventory.

User Impact

Agents can search existing conversation text without listing every session first, with the same bounded result shape and visibility rules. No configuration, schema, index, or migration changes are required.

Short CJK substring searches retain their documented behavior. Because timestamps are not indexed, that fallback completes one streaming text pass even after finding matches, retaining only the best limit + 1 hits and one bounded authorization batch. A miss can still scan the text corpus.

Why This Change Was Made

The transcript worker now discovers candidates using the existing word FTS index; Gateway visibility owners authorize bounded candidate batches before result limits, applying both current Gateway rules and the tool’s captured restrictions. The tool's inventory paging and per-agent 200-key RPC loops are removed. The embedded Gateway and RPC handler share this owner, while explicit-session search keeps its existing path. Broad search reuses the projection’s admitted store topology instead of rediscovering filesystem stores on each request; configured logical agents still retain their shared-store mapping.

The simplification removes a single-use request adapter and duplicate ordering/visibility plumbing. Production delta is +298 lines total: +253 authored and +45 generated predicates; authored code is reduced from the earlier +261 proposal, and tests remove 145 net lines. The initial simplification removed 45 authored lines; preserving the pre-existing pinned caller-policy boundary adds 37 back. Admitted-topology reuse removes three more runtime lines, and keeping its store targets out of the row-selection input contract adds three type-only lines. The remaining growth implements the bounded worker cursor and Gateway authorization boundary that replace 85 inventory pages plus 90 search RPCs per search on the synthetic fixture. No new cache or session-row projection optimization is included.

Integration note: #200076 adds a cold-archive exclusion predicate to the same query kernel. This change moves that kernel from session-transcript-search.ts to session-transcript-search.worker.ts; preserve that predicate there when integrating whichever PR lands second. #160237 shares the scope test file but changes the separate UI search path.

Evidence

The 17,000-session synthetic fixture uses 8 agents, 13,700 archived metadata rows, 30 active runs, and one indexed message per session. It contains no production data. Two baseline controls and candidate runs use 2 warmups and 5 measured searches, with timing and sampled main-thread JS allocation measured separately.

Query Baseline A1 / A2 median Final candidate Main-thread CPU before → after Allocation before → after
Word 2,641 / 2,719 ms 26.9 ms 2,227–2,365 → 8.8 ms 1.982–1.990 GB → 3.79 MB
Short CJK 2,700 / 2,610 ms 68.4 ms 2,134–2,178 → 15.0 ms 1.980–1.981 GB → 3.53 MB

Both candidate paths use 0 inventory pages / 0 inventory rows / 1 search RPC, versus 85 / 17,000 / 90. Final p95 is 29.5 ms (word) and 73.2 ms (CJK). This was a busy shared host; no quiet-host claim. Measurements exercise the real tool, embedded Gateway and native worker, not a remote model round-trip. The fixture represents session cardinality, not a 35-GiB database or a filesystem-scale workload.

Complete top-N result digests match baseline and candidate, including snippets and flags:

  • Word: 378af0fc548a5b970756d143775fbf73a7cd00757250ade78ed5e305f16eca9b
  • CJK: be44535ac95c4887e43eaf52c811c8efdf61821a7d3868f8c330f816f4452375
  • Dense word: 2475ff7a16b61ce3a7675cb156dfa84cf306b4529ebcf5d48832c89f30ce1cbd
  • Miss: 753826edc7256a0e891a56ed820740d2682753e75128c7e72988ec7949b25ee9

Focused tool/protocol/native-search/Gateway tests pass, including no inventory paging, cross-agent and operator privacy, sandbox/tree boundaries, shared stores, and a CJK match at the end of the text rows that must enter the timestamp-ordered top-N. The no-paging regression fails on the exact parent. The final topology rerun passes 36 Gateway/embedded tests; the selection fixture consumer passes 6 tests and the updated selection suite passes 8. The 15 prompt-stability tests, affected UI browser test, and real-Gateway UI-e2e test pass. Codex autoreview reports no actionable P0–P2 findings.

The final-head pnpm check:changed run passes every gate except the inherited dead-export check, including all typecheck, format, lint and database-worker guards. The dead-export gate has 116 unique findings, all reproduced among 121 findings on exact parent aeabca2e109167fe9dbc0037fd698848a2378b63; no new dead-export findings. Three replay-session-state re-exports are attributable to 472cd0a2f542599eea763f013eba2d34033ca25f; the remaining entries have exact-parent reproduction without individual introduction attribution. These are inherited main regressions, not passing checks. CI exposed two stale inventory-shaped consumer suites. Converting the visibility fixture to real indexed search also exposed a lost pinned caller-policy restriction; that regression fails on the first PR head with a foreign hit and now passes. The repaired 62-test focused run, affected UI browser and real-Gateway UI-e2e tests, and fresh Codex review pass. CI also required the static identity-pin allowance to shrink 12→8; the canonical generator lowers that single entry. No runtime configuration changed. Final-head CI run 44006736986 has the heartbeat build-test timeout described below; ClawSweeper revision 2 reviewed final head 32a654caeaad813b75c5f8a1be703085eed7aedd with zero open items (review); both prior items are addressed in the numbered response.

A previous-head CI build-graph timeout also reproduces on exact parent aeabca2e109167fe9dbc0037fd698848a2378b63: the state lease heartbeat optional-import test reaches its 60-second timeout. The 60-second heartbeat build test originated in #191272 (c3b3d56c37c90), and #198194 generalized it; the exact source of build-time variance remains unproven. The same parent also fails the transcript-worker graph guard (623 forbidden Gateway inputs); this branch has the same existing import path plus the new recall module. These are recorded main regressions, not passing proof. Final hosted CI evaluates the current merge context.

On the exact CI parent f57dbb4ff67efb110bed6568f49ea008bc43c4a2, the full build-graph file passes under the local default runtime, and the isolated heartbeat case passes under both default and Bun runtimes. The isolated case also passes on tested merge 7fe920ad2bf412ff9100e77aa135035678dc548c. These passing replays are not a fix. Independent attribution now also compares the complete heartbeat dependency closure: all 559 source inputs, plus the test and build configuration, are identical between that CI parent and tested merge. Together with the exact original-parent timeout reproduction, this qualifies the authorized inherited-only landing exception. The automated CI table remains unknown because its scheduled-main comparison did not execute this heartbeat case. The timeout is an inherited main regression requiring follow-up, and failed hosted CI is not reported as green.

@clawsweeper

clawsweeper Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui gateway Gateway runtime scripts Repository scripts commands Command implementations agents Agent runtime and tooling size: XL labels Nov 17, 2026
@steipete
steipete marked this pull request as ready for review November 17, 2026 02:11
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 17, 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-17T03:01:55.684789Z 32a654c 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.

@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper review

Please review the bounded agent recall path at head 36c35fc, particularly visibility before limits, physical global-session ownership, shared logical-agent stores, and exact CJK timestamp ordering. The accepted CJK contract is one complete streaming text pass on hits and misses with bounded top-N memory; timestamps are unindexed and there is no schema change. Codex autoreview and focused authorization, no-paging, UI browser and real-Gateway UI-e2e tests passed.

@clawsweeper

clawsweeper Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added 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 17, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 36c35fc80b

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@clawsweeper clawsweeper Bot added 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. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 17, 2026
@clawsweeper

clawsweeper Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR replaces session-inventory paging with transcript-first search and bounded visibility filtering.

Example: An agent searches the supplied 17,000-session synthetic history.

  • Before: Discovery uses 85 inventory pages followed by 90 search RPCs.
  • After: Recall uses no inventory pages and one search RPC.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) Useful implementation with resolved prior findings and meaningful production-owner measurements, but the required product-entry-point proof remains incomplete.
Proof confidence 🦪 silver shellfish (2/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Agents wait while broad history searches enumerate every session before looking for matching conversation text.
Reason: The maintainer-authored direction targets measured wasted work and preserves the existing search capability and visibility policy.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR addresses a remaining broad-search bottleneck, both previous findings are fixed, and no new actionable code defect was established.

Priority: P2
Reviewed head: 32a654caeaad813b75c5f8a1be703085eed7aedd

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Provide redacted logs or terminal evidence of broad word and CJK recall through an isolated Gateway with a real agent/model, plus a latest-stable upgrade retaining settings and history for the changed RPC contract.
Agent review details

How this fits together

The agent search tool calls the Gateway, which searches existing transcript indexes in workers and authorizes matching session keys before returning bounded excerpts.

flowchart LR
 A[Agent search tool] --> B[Gateway recall handler]
 B --> C[Admitted store topology]
 C --> D[Transcript worker]
 D --> E[Gateway visibility owner]
 E --> D
 D --> F[Bounded search results]
Loading

Technical review

Best possible solution:

Keep transcript discovery in the existing worker and visibility decisions in the existing Gateway owners, using admitted topology and bounded candidate batches.

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

Current main visibly enumerates the session inventory before broad searches, and the supplied baseline measurements exercise that path; no target code was executed during this read-only review.

Is this the best way to solve the issue?

The implementation removes the demonstrated inventory cost, shares recall between embedded and RPC callers, and preserves explicit-session search without adding persistent state or a cache.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Broad-search inventory discovery changes intended behavior with a stated reason (0971c08: Use lighter summary discovery while preserving visible archived sessions, fresh authorization, and requester-owned globals.)
  • CJK fallback and bounded result ordering keeps the original intent (8eb11ec: Find interior CJK substrings after word-search misses without rebuilding persisted indexes.)
  • Worker-owned transcript search keeps the original intent (b082302: Move transcript reads off the Gateway thread.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Current main retains inventory paging: Current main still runs listVisibleSearchSessions with sequential sessions.list pages before transcript searches; the central broad-search cost remains. (src/agents/tools/sessions-search-tool.ts:217, b4fc05346afb)
  • Previous topology finding resolved: Recall now consumes admitted scope targets and physical aliases instead of invoking filesystem discovery; the shared-store regression checks equivalent results without discovery. (src/gateway/server-methods/sessions-search-recall.ts:37, 32a654caeaad)
  • Previous consumer finding resolved: Factory expectations use recall requests, and the visibility matrix now searches real indexed transcripts while intersecting captured tool restrictions with current Gateway policy. (src/gateway/session-list-viewers.perf.test.ts:442, 32a654caeaad)
  • Published reauthorization concern assessed: The published concern describes revocation during an already authorized request. This task and root policy permit that request to finish; no separately starting unauthorized request was demonstrated, so the concern is not retained as a finding. (AGENTS.md:11, 32a654caeaad)
  • Proof scope verified: The body and author discussion describe real tool, embedded Gateway, and native-worker measurements, explicitly excluding a real-model roundtrip. All four prepared screenshots were inspected and belong to the separate UI-search work at fix(sessions): prevent search failures during session updates #160237. (32a654caeaad)
  • CI failure identified without unsupported attribution: The failed check annotation identifies a 60-second state-lease-heartbeat build-graph timeout, matching the failure discussed in the body. Downloading its full log was blocked by the Azure artifact-host allowlist, so independent base-versus-head attribution remains unavailable. (test/scripts/runtime-process-build-graph.test.ts:112, 32a654caeaad)

PR surface

Source +298, Tests -145, Docs +2, Other +12. Total +167 across 34 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 15 3644 3346 +298
Tests 16 306 451 -145
Docs 1 7 5 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 2 19 7 +12
Total 34 3976 3809 +167

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.

Labels

Label changes:

  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: Large-history agent searches incur substantial avoidable Gateway work, while explicit-session searches remain available.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish 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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-17T02:25:30.157Z sha 36c35fc :: needs changes before merge. :: [P1] Reuse admitted topology instead of rediscovering stores per search | [P2] Migrate the remaining consumers to the recall request contract

Reviewed November 16, 2026, 10:12 PM ET / November 17, 2026, 03:12 UTC (Revision 2).

@steipete

Copy link
Copy Markdown
Contributor Author

Addressing both open items from the latest review on final head 32a654caeaad813b75c5f8a1be703085eed7aedd:

  1. Per-search filesystem discovery: removed resolveAllAgentSessionStoreTargetsAsync. Recall now uses the admitted scope’s durable targets and existing physical aliases, retaining configured logical agents for shared stores (recall lines 37–51, topology line 317). The existing shared-store equivalence test now also asserts no discovery call (lines 446–455). No session-row consume algorithm changed.

  2. Remaining inventory-shaped consumers: updated the tool-factory expectations and replaced the old mocked inventory perf case with real indexed recall (factory tests, visibility matrix at line 442). The matrix also caught a real lost pinned-policy restriction; recall now intersects the tool’s captured restrictions with current Gateway policy before limiting (lines 63–90). It covers all/self/tree/agent, cross-agent access, sandboxing, archived rows, requester globals and hidden sessions without inventory paging.

Validation: the repaired consumer run passed 62 tests; the final topology run passed 36 Gateway/embedded-tool tests; the selection consumer and selection suite passed 6 and 8 tests. Core, core-test shards and scripts typechecks pass. Fresh Codex autoreview is clean. The final 17,000-session word/CJK measurements are 26.9/68.4 ms, with unchanged result digests and zero inventory pages. Affected UI browser and real-Gateway UI-e2e tests pass. This is real tool/embedded Gateway/native-worker proof plus Gateway UI-e2e; it is not a real-model search roundtrip. The PR body records that limit and exact-parent inherited failures. The final complete changed-check and hosted CI runs are pending.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 32a654caea

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +85 to +86
sessionMutationAuthorization?.assertCurrent();
respond(true, result);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Reauthorize recall results at response publication

If a session becomes private or the viewer loses access after its candidate batch is authorized—for example, while recall searches a later agent store—the previously accepted excerpts are still returned here. searchRecallSessionTranscripts checks sharing inside worker callbacks, then retains those hits across subsequent awaits without validating them again; sessionMutationAuthorization?.assertCurrent() does not recheck each hit's sharing policy. Unlike the existing scoped search path, this can disclose transcript text after access has been revoked. Reacquire current visibility for the retained results and associated counts, retrying or discarding changed pages, and publish within the synchronous authorization frame required by the Gateway guidance.

AGENTS.md reference: src/gateway/AGENTS.md:L54-L54

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot removed the status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. label Nov 17, 2026
@clawsweeper clawsweeper Bot added the status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. label Nov 17, 2026
@steipete
steipete merged commit a564030 into main Nov 17, 2026
184 of 190 checks passed
@steipete
steipete deleted the steipete/perf-micro-agent-sessions-search-full-scan-20260919 branch November 17, 2026 03:45
@steipete

Copy link
Copy Markdown
Contributor Author

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

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 17, 2026
* fix: agent session searches stall on large histories

* fix: preserve pinned session recall visibility

* fix(sessions): reuse admitted search store topology
RomneyDa added a commit that referenced this pull request Nov 18, 2026
Search transcript indexes before authorizing bounded batches of matching keys
instead of paging the full session inventory. Keep current and pinned tool
visibility checks, scoped searches, and existing literal FTS behavior.

Adapted for the 2026.11.6 owners without the unrelated CJK substring or async
execution-capture migrations. Regenerate Gateway validators canonically.

Backport-of: a564030
Co-authored-by: RomneyDa <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 19, 2026
* fix: agent session searches stall on large histories

* fix: preserve pinned session recall visibility

* fix(sessions): reuse admitted search store topology

(cherry picked from commit a564030)
Release adaptation: Retain baseline deletion of retired session-identity allowlist.:
Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit e485cc01271ce5f0ad0c2ed5c4a5b8003654d37b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: web-ui App: web-ui commands Command implementations docs Improvements or additions to documentation 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: XL 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