Skip to content

fix(model): parse non-standard rate limit errors in OpenAIClient to enable auto-retries#1210

Open
jujn wants to merge 2 commits intoagentscope-ai:mainfrom
jujn:feat_761
Open

fix(model): parse non-standard rate limit errors in OpenAIClient to enable auto-retries#1210
jujn wants to merge 2 commits intoagentscope-ai:mainfrom
jujn:feat_761

Conversation

@jujn
Copy link
Copy Markdown
Contributor

@jujn jujn commented Apr 13, 2026

Description

Close #761
Fixes an issue where non-standard gateway errors were swallowed in OpenAIClient, ensuring rate limit (429) errors correctly trigger the auto-retry mechanism.

Checklist

Please check the following items before code is ready to be reviewed.

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (mvn test)
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated (e.g. links, examples, etc.)
  • Code is ready for review

@jujn jujn requested review from a team and Copilot April 13, 2026 09:37
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses #761 by ensuring OpenAI-compatible “gateway” responses that embed rate-limit errors in a non-standard shape (e.g., {code, message, status}) are detected and surfaced as proper OpenAI exceptions so the auto-retry logic can trigger.

Changes:

  • Extend OpenAIResponse to capture non-standard error fields (code, message, status) and treat them as errors via isError().
  • Update OpenAIClient to prefer outer-layer code/message when standard error is absent, and to map "429" body codes to HTTP 429 for retry classification.
  • Add/extend unit tests to cover non-standard error detection in both sync and streaming flows.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
agentscope-core/src/main/java/io/agentscope/core/model/OpenAIClient.java Improves error extraction and attempts to classify non-standard 429 bodies as rate-limit exceptions.
agentscope-core/src/main/java/io/agentscope/core/formatter/openai/dto/OpenAIResponse.java Adds non-standard error fields and broadens isError() detection.
agentscope-core/src/test/java/io/agentscope/core/model/OpenAIClientTest.java Adds regression tests for non-standard 429 errors in sync and streaming.
agentscope-core/src/test/java/io/agentscope/core/formatter/openai/dto/OpenAIResponseTest.java Adds focused tests for standard vs non-standard error detection.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 13, 2026

Codecov Report

❌ Patch coverage is 62.16216% with 14 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...cope/core/formatter/openai/dto/OpenAIResponse.java 61.11% 3 Missing and 4 partials ⚠️
...in/java/io/agentscope/core/model/OpenAIClient.java 63.15% 5 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@LearningGp LearningGp added this to the 1.0.12 milestone Apr 13, 2026
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.

[Bug]:大模型限流需支持配置,现在超过agent不返回

3 participants