mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-17 05:26:47 +03:00
fix(ai): classify Bedrock throttling as a retryable rate limit (#58759)
This commit is contained in:
committed by
GitHub
Unverified
parent
2dc8db4a9d
commit
1aeb6464d5
@@ -65,6 +65,8 @@ const exclusions = [
|
||||
/too many requests/i,
|
||||
// Cohere reports an output limit above the model maximum as "too many tokens"; compaction cannot fix it.
|
||||
/max[_ ]tokens must be less than/i,
|
||||
// Bedrock phrases throttling as "Too many tokens[, per day], please wait..."; it is a 429 to retry, not overflow.
|
||||
/too many tokens(?: per day)?, please wait/i,
|
||||
]
|
||||
|
||||
export const isContextOverflow = (message: string) =>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { describe, expect, test } from "bun:test"
|
||||
import { isContextOverflow } from "../src/index.js"
|
||||
import { isContextOverflow, isContextOverflowFailure, isRetryable } from "../src/index.js"
|
||||
import { AIError } from "../src/schema/index.js"
|
||||
import { classifyProviderFailure, providerErrorMessage } from "../src/provider-error.js"
|
||||
|
||||
describe("provider error classification", () => {
|
||||
@@ -423,6 +424,31 @@ describe("provider error classification", () => {
|
||||
).toEqual(["RateLimit", "RateLimit"])
|
||||
})
|
||||
|
||||
test("classifies Bedrock throttling as a retryable rate limit, not context overflow", () => {
|
||||
// Bedrock throttles with 429 ThrottlingException and a "Too many tokens" message; the token
|
||||
// phrasing used to classify it as overflow and compact the session instead of retrying.
|
||||
const bodies = [
|
||||
'{"message":"Too many tokens, please wait before trying again."}',
|
||||
'{"message":"Too many tokens per day, please wait before trying again."}',
|
||||
]
|
||||
for (const body of bodies) {
|
||||
const error = new AIError({
|
||||
reason: classifyProviderFailure({
|
||||
message: providerErrorMessage(body),
|
||||
status: 429,
|
||||
rawBody: body,
|
||||
}),
|
||||
})
|
||||
expect(error.reason._tag).toBe("RateLimit")
|
||||
expect(isContextOverflowFailure(error)).toBe(false)
|
||||
expect(isRetryable(error)).toBe(true)
|
||||
}
|
||||
expect(isContextOverflow("Too many tokens, please wait before trying again.")).toBe(false)
|
||||
expect(isContextOverflow("Too many tokens per day, please wait before trying again.")).toBe(false)
|
||||
// Plain overflow phrasing without the throttle cue still compacts.
|
||||
expect(isContextOverflow("Too many tokens")).toBe(true)
|
||||
})
|
||||
|
||||
test("does not let substituted server codes make a 4xx retryable", () => {
|
||||
const openai = { error: { type: "server_error", message: "Upstream request failed: Model is unavailable." } }
|
||||
const anthropic = {
|
||||
|
||||
Reference in New Issue
Block a user