Skip to content

fix: harden detection layer and rate limit refill clock - #69

Merged
bobrykov merged 4 commits into
masterfrom
fix/detection-and-rate-limit
Aug 4, 2026
Merged

fix: harden detection layer and rate limit refill clock#69
bobrykov merged 4 commits into
masterfrom
fix/detection-and-rate-limit

Conversation

@bobrykov

@bobrykov bobrykov commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@bobrykov, you've reached your PR review limit, so we couldn't start this review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 32dc893b-9474-448e-9edd-285fd3e5a43c

📥 Commits

Reviewing files that changed from the base of the PR and between ad0f2eb and 4ad0ae8.

📒 Files selected for processing (1)
  • src/tool/shield.rs
📝 Walkthrough

Walkthrough

The 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 0.2.1, and records the release changes.

Changes

Correctness fixes

Layer / File(s) Summary
Loop detection input handling
src/detection/loop_detector.rs
Zero window_size values are clamped to 1. File-read matching uses tool-aware normalization, rejects empty parameters, and supports bidirectional path containment. Tests cover these cases.
Unknown-tool candidate selection
src/middleware/unknown_tool.rs
Zero-score candidates are rejected. Equal positive scores use lexicographic tie-breaking. Tests cover both cases.
Token-bucket refill timing
src/stream/rate_limit.rs
Zero-rate buckets remain stable. Full refills advance last_refill only to the fill time. Tests cover future and past timestamps.
Shield threshold normalization and release metadata
src/tool/shield.rs, Cargo.toml, CHANGELOG.md
Non-finite thresholds fall back to defaults. Inverted finite thresholds are swapped before clamping and storage. The package version and changelog are updated to 0.2.1.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main detection-layer fixes and rate-limit refill-clock correction.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/detection-and-rate-limit

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2e65fbc and 9df0601.

📒 Files selected for processing (5)
  • CHANGELOG.md
  • src/detection/loop_detector.rs
  • src/middleware/unknown_tool.rs
  • src/stream/rate_limit.rs
  • src/tool/shield.rs

Comment thread src/detection/loop_detector.rs
Comment thread src/stream/rate_limit.rs Outdated
Comment thread src/stream/rate_limit.rs
Comment thread src/tool/shield.rs
@dch-labs dch-labs deleted a comment from coderabbitai Bot Aug 4, 2026

@coderabbitai coderabbitai 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.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9df0601 and ad0f2eb.

📒 Files selected for processing (5)
  • CHANGELOG.md
  • Cargo.toml
  • src/detection/loop_detector.rs
  • src/stream/rate_limit.rs
  • src/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

Comment thread src/tool/shield.rs
@bobrykov
bobrykov merged commit e3a334a into master Aug 4, 2026
7 checks passed
@bobrykov
bobrykov deleted the fix/detection-and-rate-limit branch August 4, 2026 05:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant