feat: add memoize middleware, drop parking_lot dep#53
Conversation
|
Warning Review limit reached
Next review available in: 15 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughAdds ChangesTool-result memoization
Standard mutex migration
Sequence Diagram(s)sequenceDiagram
participant Caller
participant MemoizingMiddleware
participant ToolPipeline
Caller->>MemoizingMiddleware: Dispatch tool call
MemoizingMiddleware->>MemoizingMiddleware: Build canonical cache key
MemoizingMiddleware->>ToolPipeline: Forward cache miss
ToolPipeline-->>MemoizingMiddleware: Successful ToolDispatchResult
MemoizingMiddleware-->>Caller: Cache result or return cached marker
Possibly related PRs
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (1)
src/middleware/memoize.rs (1)
280-290: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winFailed writes still trigger path invalidation.
is_writeinvalidation (line 282-284) runs regardless ofresult.is_error— a permission-denied or failed write still evicts cache entries for paths it never actually touched. The module docs justify over-invalidation as "safe" (never causes staleness), so this isn't incorrect, just an avoidable cache-thrashing case (e.g. repeated denied writes to the same file will keep evicting an otherwise-valid Read cache entry for no reason).♻️ Optional tightening
if is_write { - let write_paths = self.path_extractor.paths(&ctx.tool_name, &ctx.input); - invalidate_paths(&self.cache, &write_paths); + if !result.is_error { + let write_paths = self.path_extractor.paths(&ctx.tool_name, &ctx.input); + invalidate_paths(&self.cache, &write_paths); + } } else if is_memoized && !result.is_error {🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/middleware/memoize.rs` around lines 280 - 290, Update the write-handling branch after next.dispatch in the memoization flow to invalidate paths only when is_write is true and result.is_error is false. Preserve the existing path extraction and invalidation behavior for successful writes, and leave memoized-read insertion unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/engine/bare.rs`:
- Line 691: Update the set_text_streamer example’s documented buffer-locking
expression to remove the crate-private crate::error::recover_guard helper and
use a public Mutex lock pattern such as unwrap or explicit poisoned-lock
recovery, keeping the example copy-pasteable for external users.
- Line 691: Update the `set_text_streamer` documentation example to replace the
crate-private `crate::error::recover_guard` call with the public mutex guard
recovery pattern using `buf.lock().unwrap_or_else(|e| e.into_inner())`, while
preserving the existing `push_str(delta)` behavior.
In `@src/middleware/memoize.rs`:
- Around line 63-71: Correct the “Generosity” documentation for PathExtractor to
remove the claim that returning an empty string forces intersection with any
write. State that paths are matched by exact verbatim membership, so
implementations must return every concrete or otherwise shared path that can be
affected, consistent with the existing no-prefix/no-wildcard matching guidance.
- Around line 269-278: Remove the let-chain syntax from the memoized lookup
conditions in the async closure and the corresponding block around the later
cache lookup, rewriting both to equivalent nested conditionals compatible with
Rust 1.85. Preserve the existing is_memoized, key, and lookup_fresh checks and
cached-result handling unchanged.
---
Nitpick comments:
In `@src/middleware/memoize.rs`:
- Around line 280-290: Update the write-handling branch after next.dispatch in
the memoization flow to invalidate paths only when is_write is true and
result.is_error is false. Preserve the existing path extraction and invalidation
behavior for successful writes, and leave memoized-read insertion unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 2ce25019-fe2e-4749-b54b-f7c5e4132d98
📒 Files selected for processing (16)
CHANGELOG.mdCargo.tomlsrc/engine/bare.rssrc/engine/bare/dispatch.rssrc/error.rssrc/memory/builtin.rssrc/middleware.rssrc/middleware/memoize.rssrc/observer.rssrc/provider/anthropic.rssrc/provider/gemini.rssrc/provider/openai.rssrc/testing.rssrc/tool.rssrc/tool/health.rssrc/tool/shield.rs
💤 Files with no reviewable changes (1)
- Cargo.toml
No description provided.