Skip to content

fix(llm): cap retry-after delays#1351

Merged
henrypark133 merged 2 commits intonearai:stagingfrom
G7CNF:codex/issue-1287-retry-after-cap
Mar 18, 2026
Merged

fix(llm): cap retry-after delays#1351
henrypark133 merged 2 commits intonearai:stagingfrom
G7CNF:codex/issue-1287-retry-after-cap

Conversation

@G7CNF
Copy link
Copy Markdown
Contributor

@G7CNF G7CNF commented Mar 18, 2026

Clamps absurd Retry-After values to avoid effectively unbounded sleeps.

Fixes #1287.

@github-actions github-actions Bot added scope: llm LLM integration scope: workspace Persistent memory / workspace size: M 50-199 changed lines risk: low Changes to docs, tests, or low-risk modules contributor: core 20+ merged PRs labels Mar 18, 2026
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a potential issue where LLM providers could return excessively large Retry-After values, leading to effectively unbounded sleep durations. By introducing a maximum cap of one hour on these delays, the system now gracefully handles such responses, preventing prolonged service interruptions while still respecting reasonable rate-limiting directives.

Highlights

  • Introduced Retry-After Capping Logic: A new constant MAX_RETRY_AFTER_SECS (set to 3600 seconds or 1 hour) and a cap_retry_after function were added to prevent excessively long retry delays suggested by LLM providers.
  • Applied Capping to LLM Providers: The cap_retry_after function was integrated into the Retry-After header parsing logic for Anthropic, NearAI Chat, OpenAI Embeddings, and NearAI Embeddings providers, ensuring delays do not exceed the defined maximum.
  • Enhanced Test Coverage: Existing tests for Retry-After parsing were updated, and new tests were added to verify that large Retry-After values are correctly capped to MAX_RETRY_AFTER_SECS.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a cap on Retry-After delays from LLM providers to prevent excessively long sleep periods. A new function cap_retry_after is added in src/llm/retry.rs along with a MAX_RETRY_AFTER_SECS constant, and this is applied consistently across anthropic_oauth.rs, nearai_chat.rs, and workspace/embeddings.rs where Retry-After headers are parsed. The tests have also been updated to verify this new capping behavior. The changes are well-implemented and address the issue described. I have one suggestion to improve the robustness of the cap_retry_after function.

Comment thread src/llm/retry.rs Outdated
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: be863db005

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/llm/retry.rs Outdated
Copy link
Copy Markdown
Collaborator

@henrypark133 henrypark133 left a comment

Choose a reason for hiding this comment

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

Review: Cap retry-after delays to prevent unbounded sleep

Solid defensive fix. A malicious or malformed Retry-After header could previously cause effectively unbounded sleep — now capped at 3600s.

Positives:

  • cap_retry_after() centralized in src/llm/retry.rs with clear doc comment
  • Applied consistently across all 4 parsing sites (anthropic_oauth, nearai_chat, OpenAI embeddings, NearAI embeddings)
  • Gemini's suggestion to use duration.min() instead of Duration::from_secs(duration.as_secs().min(...)) was a good catch — preserves sub-second precision
  • Tests cover both edge cases (u64::MAX and 0)

No missed sites, no security concerns. LGTM.

@henrypark133 henrypark133 merged commit bedc71e into nearai:staging Mar 18, 2026
14 checks passed
bkutasi pushed a commit to bkutasi/ironclaw that referenced this pull request Mar 28, 2026
* fix(llm): cap retry-after delays

* Update src/llm/retry.rs

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

---------

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
drchirag1991 pushed a commit to drchirag1991/ironclaw that referenced this pull request Apr 8, 2026
* fix(llm): cap retry-after delays

* Update src/llm/retry.rs

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

---------

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor: core 20+ merged PRs risk: low Changes to docs, tests, or low-risk modules scope: llm LLM integration scope: workspace Persistent memory / workspace size: M 50-199 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[HIGH] Unbounded Retry-After duration DoS vulnerability — code accepts any valid u64

2 participants