fix: harden detection layer and rate limit refill clock - #69
Conversation
|
Warning Review limit reached
Next review available in: 48 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. 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 (1)
📝 WalkthroughWalkthroughThe pull request adds correctness fixes for loop detection, unknown-tool matching, token-bucket refill timing, and shield threshold normalization. It adds tests, updates the package version to ChangesCorrectness fixes
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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
🤖 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/detection/loop_detector.rs`:
- Around line 1592-1598: Update the containment matching in the loop-detector
logic around sig.is_file_read_tool and normalize_param_for_comparison to reject
empty raw primary parameters, file paths, and normalized values before calling
contains. Preserve matching for non-empty normalized paths, and add a regression
test covering a recorded Read operation with an empty primary parameter.
In `@src/stream/rate_limit.rs`:
- Around line 145-147: Update the documentation for available_at to state that
elapsed_refill advances last_refill to the fill instant when the bucket reaches
capacity, rather than always advancing it to at; retain the description of lazy
refill and token availability.
- Around line 169-190: Update elapsed_refill so repeated calls with the same at
cannot reuse elapsed time after the bucket reaches capacity; ensure last_refill
advances to at, or otherwise enforce a monotonic-instant contract consistently
with take_at. Add a regression test covering a drained bucket queried repeatedly
at one fixed future instant, verifying only the capacity number of takes
succeeds.
In `@src/tool/shield.rs`:
- Around line 596-609: Update ToolShield::with_thresholds to validate warn and
block with is_finite() before the existing threshold-swapping logic. Apply the
established finite-safe rejection policy for either non-finite value, ensuring
NaN or infinities are never stored or passed to later clamping and finite
thresholds continue through the current ordering behavior.
🪄 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: 9129735e-5ed1-4880-8f74-1795acc99c5a
📒 Files selected for processing (5)
CHANGELOG.mdsrc/detection/loop_detector.rssrc/middleware/unknown_tool.rssrc/stream/rate_limit.rssrc/tool/shield.rs
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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/tool/shield.rs`:
- Around line 602-617: Update UnixShield::new and with_thresholds to use shared
fixed default constants (0.4 for warn and 0.7 for block) whenever thresholds are
non-finite, rather than falling back to self.warn_threshold or
self.block_threshold. Add a test covering chained with_thresholds calls with NaN
and infinity to verify the documented defaults are restored.
🪄 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: e87b9a07-419b-40d7-b29c-e8451978eabb
📒 Files selected for processing (5)
CHANGELOG.mdCargo.tomlsrc/detection/loop_detector.rssrc/stream/rate_limit.rssrc/tool/shield.rs
🚧 Files skipped from review as they are similar to previous changes (2)
- src/stream/rate_limit.rs
- src/detection/loop_detector.rs
No description provided.