perf(tool): add caching and retry logic to web tools#7036
Open
romancircus wants to merge 1 commit intoanomalyco:devanomalyco/opencode:devfrom
romancircus:pr/perf-web-tools-cachingromancircus/opencode:pr/perf-web-tools-cachingCopy head branch name to clipboard
Open
perf(tool): add caching and retry logic to web tools#7036romancircus wants to merge 1 commit intoanomalyco:devanomalyco/opencode:devfrom romancircus:pr/perf-web-tools-cachingromancircus/opencode:pr/perf-web-tools-cachingCopy head branch name to clipboard
romancircus wants to merge 1 commit intoanomalyco:devanomalyco/opencode:devfrom
romancircus:pr/perf-web-tools-cachingromancircus/opencode:pr/perf-web-tools-cachingCopy head branch name to clipboard
Conversation
Contributor
|
The following comment was made by an LLM, it may be inaccurate: No duplicate PRs found. The search returned only the current PR (#7036) and one unrelated PR (#6782 about remote skills). This PR appears to be addressing a novel feature set:
There are no existing open PRs with the same scope or addressing the same performance and reliability improvements. |
Add LRU cache with disk persistence and retry with exponential backoff to websearch, codesearch, and webfetch tools to improve performance and reliability. Cache configuration: - websearch: 1 hour TTL, 500 entries - codesearch: 2 hour TTL, 500 entries - webfetch: 30 min TTL, 200 entries (skips dynamic URLs) Retry configuration: - 3 attempts with exponential backoff (1s, 2s, 4s) - Retries network errors, rate limits (429), server errors (5xx) - Does not retry client errors (4xx) Performance impact: - Repeated queries: ~300ms -> <5ms (cache hit) - Network failures: graceful retry instead of immediate failure - Restart: warm cache from disk persistence
5f85654 to
0f9cd78
Compare
3 tasks
00637c0 to
71e0ba2
Compare
f1ae801 to
08fa7f7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add LRU cache with disk persistence and retry with exponential backoff to
websearch,codesearch, andwebfetchtools to improve performance and reliability.Problem
The web tools currently:
Solution
1. LRU Cache with Disk Persistence
New utility at
packages/opencode/src/util/cache.ts:~/.cache/opencode/{namespace}/for warm restartslivecrawl: "preferred"2. Retry with Exponential Backoff
Extended
packages/util/src/retry.tswith new exports:isRetryableError()- Combines all retryable error checksisRateLimitError()- Detects 429 errorsisServerError()- Detects 5xx errorsConfiguration: 3 attempts, 1s → 2s → 4s backoff, max 10s delay
Retries: Network errors, rate limits (429), server errors (5xx)
Does NOT retry: Client errors (4xx) - those indicate request issues
Performance Impact
Observability
Cache operations are logged at INFO level:
Stats available via
cache.stats():Changes
packages/opencode/src/util/cache.tspackages/util/src/retry.tsisRetryableError,isRateLimitError,isServerErrorpackages/opencode/src/tool/websearch.tspackages/opencode/src/tool/codesearch.tspackages/opencode/src/tool/webfetch.tspackages/opencode/test/tool/cache.test.tspackages/opencode/test/util/retry.test.tsTesting
Breaking Changes
None. Existing behavior preserved, just faster and more reliable.