-
-
Notifications
You must be signed in to change notification settings - Fork 380
fix(proxy): fail over provider-local model 404s #1354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ding113
merged 6 commits into
ding113:dev
from
Brisbanehuang:codex/provider-local-model-404-failover
Jul 22, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3d65cba
fix(proxy): fail over provider-local model 404s
Brisbanehuang aa432c5
fix(proxy): preserve local 404 failover past rectifiers
Brisbanehuang f0a9ef1
test(proxy): preserve fake-200 classification
Brisbanehuang 4f6f1b7
fix(proxy): keep raw fake-200 payloads out of matching
Brisbanehuang 73387e6
test(proxy): accept deferred commit callback
Brisbanehuang 4defb2c
Merge remote-tracking branch 'origin/dev' into agent/fix-pr1354
ding113 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
tests/unit/proxy/provider-local-model-unavailable.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| import { beforeEach, describe, expect, it, vi } from "vitest"; | ||
| import { | ||
| ErrorCategory, | ||
| ProxyError, | ||
| categorizeErrorAsync, | ||
| isProviderLocalModelUnavailableError, | ||
| } from "@/app/v1/_lib/proxy/errors"; | ||
| import type { ErrorDetectionResult } from "@/lib/error-rule-detector"; | ||
|
|
||
| const mocks = vi.hoisted(() => ({ | ||
| detectAsync: vi.fn<(content: string) => Promise<ErrorDetectionResult>>(), | ||
| })); | ||
|
|
||
| vi.mock("@/lib/error-rule-detector", () => ({ | ||
| errorRuleDetector: { detectAsync: mocks.detectAsync }, | ||
| })); | ||
|
|
||
| describe("provider-local model availability errors", () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| mocks.detectAsync.mockResolvedValue({ matched: true }); | ||
| }); | ||
|
|
||
| it("switches Provider when an account group does not support the requested model", async () => { | ||
| const body = JSON.stringify({ | ||
| error: { | ||
| message: 'Model "gpt-5.6-sol" is not supported by any configured account in this group', | ||
| type: "model_not_found", | ||
| }, | ||
| }); | ||
| const response = new Response(body, { | ||
| status: 404, | ||
| headers: { "content-type": "application/json" }, | ||
| }); | ||
| const error = await ProxyError.fromUpstreamResponse(response, { | ||
| id: 96, | ||
| name: "provider-a", | ||
| }); | ||
|
|
||
| expect(isProviderLocalModelUnavailableError(error)).toBe(true); | ||
| expect(await categorizeErrorAsync(error)).toBe(ErrorCategory.RESOURCE_NOT_FOUND); | ||
| expect(mocks.detectAsync).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("matches the provider-local marker case-insensitively in the extracted message", async () => { | ||
| const error = new ProxyError( | ||
| "MODEL IS NOT SUPPORTED BY ANY CONFIGURED ACCOUNT IN THIS GROUP", | ||
| 404, | ||
| { | ||
| body: "{}", | ||
| providerId: 96, | ||
| providerName: "provider-a", | ||
| } | ||
| ); | ||
|
|
||
| expect(isProviderLocalModelUnavailableError(error)).toBe(true); | ||
| expect(await categorizeErrorAsync(error)).toBe(ErrorCategory.RESOURCE_NOT_FOUND); | ||
| expect(mocks.detectAsync).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("does not use the raw upstream body for provider-local matching", async () => { | ||
| const error = new ProxyError("model_not_found", 404, { | ||
| body: "{}", | ||
| rawBody: "not supported by any configured account in this group", | ||
| providerId: 96, | ||
| providerName: "provider-a", | ||
| }); | ||
|
|
||
| expect(isProviderLocalModelUnavailableError(error)).toBe(false); | ||
| expect(await categorizeErrorAsync(error)).toBe(ErrorCategory.NON_RETRYABLE_CLIENT_ERROR); | ||
| expect(mocks.detectAsync).toHaveBeenCalledOnce(); | ||
| }); | ||
|
|
||
| it("keeps ordinary model_not_found responses non-retryable", async () => { | ||
| const error = new ProxyError("The requested model was not found", 404, { | ||
| body: JSON.stringify({ | ||
| error: { | ||
| code: "model_not_found", | ||
| message: "The requested model was not found", | ||
| }, | ||
| }), | ||
| providerId: 96, | ||
| providerName: "provider-a", | ||
| }); | ||
|
|
||
| expect(isProviderLocalModelUnavailableError(error)).toBe(false); | ||
| expect(await categorizeErrorAsync(error)).toBe(ErrorCategory.NON_RETRYABLE_CLIENT_ERROR); | ||
| expect(mocks.detectAsync).toHaveBeenCalledOnce(); | ||
| }); | ||
|
|
||
| it("does not match a near-miss account-group message", async () => { | ||
| const error = new ProxyError( | ||
| "Model is not supported by every configured account in this group", | ||
| 404, | ||
| { | ||
| body: '{"error":"model_not_found"}', | ||
| providerId: 96, | ||
| providerName: "provider-a", | ||
| } | ||
| ); | ||
|
|
||
| expect(isProviderLocalModelUnavailableError(error)).toBe(false); | ||
| expect(await categorizeErrorAsync(error)).toBe(ErrorCategory.NON_RETRYABLE_CLIENT_ERROR); | ||
| expect(mocks.detectAsync).toHaveBeenCalledOnce(); | ||
| }); | ||
|
|
||
| it("does not override the same wording on a non-404 client error", async () => { | ||
| const error = new ProxyError( | ||
| "Model is not supported by any configured account in this group", | ||
| 400, | ||
| { | ||
| body: "invalid request", | ||
| providerId: 96, | ||
| providerName: "provider-a", | ||
| } | ||
| ); | ||
|
|
||
| expect(isProviderLocalModelUnavailableError(error)).toBe(false); | ||
| expect(await categorizeErrorAsync(error)).toBe(ErrorCategory.NON_RETRYABLE_CLIENT_ERROR); | ||
| expect(mocks.detectAsync).toHaveBeenCalledOnce(); | ||
| }); | ||
|
|
||
| it("does not override a synthetic 404 inferred from a fake-200 response", async () => { | ||
| const error = new ProxyError("not supported by any configured account in this group", 404, { | ||
| body: '{"error":"model_not_found"}', | ||
| statusCodeInferred: true, | ||
| providerId: 96, | ||
| providerName: "provider-a", | ||
| }); | ||
|
|
||
| expect(isProviderLocalModelUnavailableError(error)).toBe(false); | ||
| expect(await categorizeErrorAsync(error)).toBe(ErrorCategory.NON_RETRYABLE_CLIENT_ERROR); | ||
| expect(mocks.detectAsync).toHaveBeenCalledOnce(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.