Skip to content

perf(coding-agent): cache grouped search results for skip pagination#3263

Draft
wolfiesch wants to merge 1 commit into
can1357:mainfrom
wolfiesch:wolfiesch/pagination-search-cache
Draft

perf(coding-agent): cache grouped search results for skip pagination#3263
wolfiesch wants to merge 1 commit into
can1357:mainfrom
wolfiesch:wolfiesch/pagination-search-cache

Conversation

@wolfiesch

Copy link
Copy Markdown
Contributor

What

Add a short-lived, bounded, per-session cache for grouped search results so paginated skip pages reuse the first page's grouped filesystem matches instead of rerunning native grep for each page. Output semantics are unchanged.

  • New SearchResultCache (LRU + TTL: 45s, max 8 entries) owned per ToolSession.
  • SearchTool.execute looks up the cache only for skip > 0; skip = 0 recomputes and refreshes the entry. The cache key encodes the query, scope, options, and missing-path set.
  • Cache is bypassed for line-range selectors, archive members, and internal-URL inputs.
  • Successful filesystem mutations clear the per-session cache via invalidateFsScanAfter{Write,Delete,Rename} (now passed the session); handler-owned internal-URL writes call clearSearchResultCache directly.

Why

Paginating a large plain-filesystem search reran the same expensive native grep + grouping for every page. Later pages now reuse the grouped result until the query changes, the TTL expires, or the session mutates files — avoiding repeated work while preserving correctness.

Testing

  • bun --cwd=packages/coding-agent test test/tools/search-pagination-cache.test.ts test/tools/search-internal-urls.test.ts test/tools/search-path-lists.test.ts test/tools/multi-search-path.test.ts test/tools/multi-path-missing.test.ts test/tools/search-invalid-regex.test.ts → 70 pass, 0 fail
  • bun --cwd=packages/coding-agent run check → biome + tsgo pass
  • TDD: new cache tests were written first and confirmed to fail (extra grep calls) before the cache was implemented.

  • bun check passes
  • Tested locally
  • CHANGELOG updated (if user-facing)

Plain-filesystem search calls with skip now reuse a short-lived,
per-session grouped result cache instead of rerunning native grep
for each page. The cache is bypassed for archive, internal-URL, and
line-range searches, and is cleared on successful write/delete/rename
mutations (including handler-owned internal-URL writes).
@github-actions github-actions Bot added the vouched Passed the vouch gate label Jun 22, 2026
@wolfiesch wolfiesch changed the title Cache grouped search results for skip pagination feat(coding-agent): cache grouped search results for skip pagination Jun 23, 2026
@wolfiesch wolfiesch changed the title feat(coding-agent): cache grouped search results for skip pagination perf(coding-agent): cache grouped search results for skip pagination Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

vouched Passed the vouch gate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant