|
1 | 1 | import { describe, expect, test } from "bun:test" |
2 | 2 | import { isContextOverflow, isContextOverflowFailure, isRetryable } from "../src/effect.js" |
3 | | -import { AIError } from "../src/schema/index.js" |
| 3 | +import { AIError, HttpContext } from "../src/schema/index.js" |
4 | 4 | import { classifyProviderFailure, providerErrorMessage } from "../src/provider-error.js" |
5 | 5 |
|
6 | 6 | describe("provider error classification", () => { |
@@ -449,6 +449,37 @@ describe("provider error classification", () => { |
449 | 449 | expect(isContextOverflow("Too many tokens")).toBe(true) |
450 | 450 | }) |
451 | 451 |
|
| 452 | + test("does not infer context overflow from known throttling exceptions", () => { |
| 453 | + const cases = [ |
| 454 | + { status: 429, data: { code: "ThrottlingException" } }, |
| 455 | + { status: 429, rawBody: '{"__type":"com.amazonaws.bedrock#ThrottlingException"}' }, |
| 456 | + { rawBody: '{"exception":{"type":"throttlingException"}}' }, |
| 457 | + { |
| 458 | + status: 429, |
| 459 | + http: new HttpContext({ |
| 460 | + url: "https://bedrock.test/model/example/converse-stream", |
| 461 | + status: 429, |
| 462 | + headers: { "x-amzn-errortype": "ThrottlingException:http://internal.amazon.com/coral/" }, |
| 463 | + }), |
| 464 | + }, |
| 465 | + ] |
| 466 | + for (const input of cases) { |
| 467 | + for (const message of ["Token limit exceeded", "Too many tokens, please try again later"]) { |
| 468 | + const error = new AIError({ reason: classifyProviderFailure({ ...input, message }) }) |
| 469 | + expect(error.reason._tag).toBe("RateLimit") |
| 470 | + expect(isContextOverflowFailure(error)).toBe(false) |
| 471 | + expect(isRetryable(error)).toBe(true) |
| 472 | + } |
| 473 | + } |
| 474 | + expect( |
| 475 | + classifyProviderFailure({ |
| 476 | + message: "prompt is too long", |
| 477 | + status: 400, |
| 478 | + data: { code: "ValidationException" }, |
| 479 | + }), |
| 480 | + ).toMatchObject({ _tag: "InvalidRequest", classification: "context-overflow" }) |
| 481 | + }) |
| 482 | + |
452 | 483 | test("does not let substituted server codes make a 4xx retryable", () => { |
453 | 484 | const openai = { error: { type: "server_error", message: "Upstream request failed: Model is unavailable." } } |
454 | 485 | const anthropic = { |
|
0 commit comments