Skip to content

Add suppress-rate-limit-warning patch#662

Open
VitalyOstanin wants to merge 3 commits intoPiebald-AI:mainfrom
VitalyOstanin:feature/suppress-rate-limit-warning
Open

Add suppress-rate-limit-warning patch#662
VitalyOstanin wants to merge 3 commits intoPiebald-AI:mainfrom
VitalyOstanin:feature/suppress-rate-limit-warning

Conversation

@VitalyOstanin
Copy link
Copy Markdown

@VitalyOstanin VitalyOstanin commented Apr 4, 2026

Summary

  • Adds a new suppress-rate-limit-warning patch that suppresses rate limit warning banners while preserving error messages when limits are actually reached
  • Patches the warning getter function by replacing return <var>.message with return null for severity === "warning" case
  • Configurable via misc.suppressRateLimitWarning setting (default: false)

Details

Claude Code shows warning banners when approaching rate limits (allowed_warning status). This patch suppresses those warnings while keeping error-level messages (actual rate limit hits) intact.

The patch targets the function that extracts warning messages from rate limit status objects — a small, stable pattern (severity === "warning") with a single match in the codebase.

Files

File Change
suppressRateLimitWarning.ts Patch implementation
suppressRateLimitWarning.test.ts Tests: success, already patched, pattern not found
index.ts Import, PATCH_DEFINITIONS entry, implementation
types.ts suppressRateLimitWarning: boolean in MiscConfig
defaultSettings.ts Default: false
MiscView.tsx UI toggle in settings

Summary by CodeRabbit

  • New Features

    • New toggle in Settings to suppress rate limit warning banners (off by default).
  • Behavior

    • Option prevents the rate limit warning banner from appearing when enabled.
  • Tests

    • Added tests verifying the suppression behavior, idempotency, and robustness across input variations.

Suppress rate limit warning banners (allowed_warning status) while
preserving error messages when limits are actually reached. Patches the
warning getter function to return null instead of the warning message.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 4, 2026

📝 Walkthrough

Walkthrough

Adds a new misc.suppressRateLimitWarning setting (default false), exposes it in the Misc UI, registers a conditional patch suppress-rate-limit-warning, and implements/tests a patch that replaces the rate-limit warning return with null.

Changes

Cohort / File(s) Summary
Configuration & Types
src/defaultSettings.ts, src/types.ts
Add misc.suppressRateLimitWarning: boolean to default settings and MiscConfig interface (default false).
Patch Implementation & Tests
src/patches/suppressRateLimitWarning.ts, src/patches/suppressRateLimitWarning.test.ts
New writeSuppressRateLimitWarning(oldFile) export that detects and replaces the warning-return pattern to return null; includes tests for successful patching, idempotency, failure cases, and delimiter robustness.
Patch Registration
src/patches/index.ts
Register suppress-rate-limit-warning in patchImplementations and add entry to PATCH_DEFINITIONS, conditioned on config.settings.misc?.suppressRateLimitWarning.
UI Integration
src/ui/components/MiscView.tsx
Add a toggle suppressRateLimitWarning to MiscView, reading/writing settings.misc?.suppressRateLimitWarning and initializing settings.misc via ensureMisc() when needed.

Sequence Diagram(s)

sequenceDiagram
  participant User as User
  participant UI as MiscView (UI)
  participant Config as Settings Store
  participant Registry as Patch Registry
  participant Processor as File Processor

  User->>UI: Toggle "Suppress rate limit warning"
  UI->>Config: updateSettings(misc.suppressRateLimitWarning)
  Config->>Registry: expose config flag
  Registry->>Processor: enable conditional patch "suppress-rate-limit-warning"
  Processor->>Processor: run writeSuppressRateLimitWarning(oldFile)
  Processor-->>Registry: report patch result
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • bl-ue

Poem

🐇 I nibble code by lantern's glow,
I hush the banners soft and low.
A toggle set, the patch takes flight—
Warnings quiet, hop into night. 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title 'Add suppress-rate-limit-warning patch' clearly and directly summarizes the main change—the addition of a new patch that suppresses rate-limit warnings across the codebase.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/patches/suppressRateLimitWarning.test.ts (1)

8-26: Add a regression test that preserves non-warning behavior.

The suite does not directly assert that non-warning branches (e.g. severity==="error") remain untouched after patching, which is a stated behavior goal for this patch.

✅ Suggested test addition
+  it('should preserve error-path message returns', () => {
+    const input =
+      'function X(a){if(a&&a.severity==="warning")return a.message;if(a&&a.severity==="error")return a.message;return null}';
+    const result = writeSuppressRateLimitWarning(input);
+    expect(result).not.toBeNull();
+    expect(result).toContain(
+      'if(a&&a.severity==="error")return a.message;'
+    );
+    expect(result).toContain(
+      'if(a&&a.severity==="warning")return null;'
+    );
+  });

As per coding guidelines: Test edge cases and error conditions in test files.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/patches/suppressRateLimitWarning.test.ts` around lines 8 - 26, Add a
regression test that ensures non-warning branches remain unchanged after
patching: update the test file to include a case that runs
writeSuppressRateLimitWarning on input containing a non-warning branch (e.g. a
branch with severity==="error" or return q.message) and assert that the
non-warning code still exists (expect(result).toContain('severity==="error"') or
expect(result).toContain('return q.message')). Use existing helpers like
makeInput() to construct the input and reuse the test pattern in the file so the
new test verifies only that non-warning behavior is preserved while the warning
branch is replaced.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/patches/suppressRateLimitWarning.ts`:
- Around line 7-10: The current regexes alreadyPatched and pattern are too loose
and can false-match unrelated "severity === 'warning'" branches; tighten them to
only match the exact minified shape used in these patches (an expression like
if(<id>&&<id>.severity==="warning")return null/return <id>.message) and anchor
them with a preceding literal delimiter (e.g., [,;{}]) so they don't trigger on
unrelated code; update the alreadyPatched regex to look for the exact minified
if(<id>&&<id>.severity==="warning")return null pattern and update pattern to
match if(<id>&&<id>.severity==="warning")return (<id>).message (reuse the same
capture name for the identifier) so both are idempotent and narrowly scoped when
testing oldFile and when generating the replacement.

---

Nitpick comments:
In `@src/patches/suppressRateLimitWarning.test.ts`:
- Around line 8-26: Add a regression test that ensures non-warning branches
remain unchanged after patching: update the test file to include a case that
runs writeSuppressRateLimitWarning on input containing a non-warning branch
(e.g. a branch with severity==="error" or return q.message) and assert that the
non-warning code still exists (expect(result).toContain('severity==="error"') or
expect(result).toContain('return q.message')). Use existing helpers like
makeInput() to construct the input and reuse the test pattern in the file so the
new test verifies only that non-warning behavior is preserved while the warning
branch is replaced.
🪄 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

Run ID: ebcf7106-0047-4547-a999-fd819baffafc

📥 Commits

Reviewing files that changed from the base of the PR and between 0cf8b15 and 88a1593.

📒 Files selected for processing (6)
  • src/defaultSettings.ts
  • src/patches/index.ts
  • src/patches/suppressRateLimitWarning.test.ts
  • src/patches/suppressRateLimitWarning.ts
  • src/types.ts
  • src/ui/components/MiscView.tsx

Comment thread src/patches/suppressRateLimitWarning.ts Outdated
Remove \s* patterns (minified code has no whitespace), add [,;{}]
delimiter prefix, and use backreference \1 to tie the variable in
severity check to the same captured identifier. Add delimiter
variation test.
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/patches/suppressRateLimitWarning.test.ts (1)

5-6: Add a $-identifier test case to lock regex intent.

Current inputs only use q; adding a $-prefixed variable case would guard the
[$\w]+ expectation from regressions.

Suggested test addition
 describe('writeSuppressRateLimitWarning', () => {
   const makeInput = (delimiter = '}') =>
     `function Ip8(H,$){let q=d2K(H,$)${delimiter}if(q&&q.severity==="warning")return q.message;return null}`;
+  const makeDollarVarInput = (delimiter = '}') =>
+    `function Ip8(H,$){let $q=d2K(H,$)${delimiter}if($q&&$q.severity==="warning")return $q.message;return null}`;
@@
   it('should work with different delimiters', () => {
     for (const d of [',', ';', '}', '{']) {
       const result = writeSuppressRateLimitWarning(makeInput(d));
       expect(result).not.toBeNull();
       expect(result).toContain('severity==="warning")return null;');
     }
   });
+
+  it('should work when warning var starts with $', () => {
+    const result = writeSuppressRateLimitWarning(makeDollarVarInput('}'));
+    expect(result).not.toBeNull();
+    expect(result).toContain('if($q&&$q.severity==="warning")return null;');
+  });
 });

Based on learnings, patch regexes under src/patches are expected to support [$\w]+ identifiers (including $), and this is a useful edge case to keep tested.

Also applies to: 38-44

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/patches/suppressRateLimitWarning.test.ts` around lines 5 - 6, Update the
test inputs to include a `$`-prefixed identifier to ensure the patch regex
accepts [$\w]+ tokens: modify the test helper makeInput (function makeInput) or
add a sibling test case that uses a `$`-named variable (e.g., `$x` or `$q`) in
the generated function string so the regex exercise covers `$`-prefixed
identifiers; also apply the same addition for the related tests around lines
38-44 to lock the intent across all cases.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/patches/suppressRateLimitWarning.test.ts`:
- Around line 5-6: Update the test inputs to include a `$`-prefixed identifier
to ensure the patch regex accepts [$\w]+ tokens: modify the test helper
makeInput (function makeInput) or add a sibling test case that uses a `$`-named
variable (e.g., `$x` or `$q`) in the generated function string so the regex
exercise covers `$`-prefixed identifiers; also apply the same addition for the
related tests around lines 38-44 to lock the intent across all cases.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a599b694-5ddd-498c-9b5e-4ea616fb1bc6

📥 Commits

Reviewing files that changed from the base of the PR and between 775e9eb and e8b9a24.

📒 Files selected for processing (1)
  • src/patches/suppressRateLimitWarning.test.ts

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