Repository navigation
fix(opencode): replay one Console Go 400 "Invalid upload request." #4310
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
Closed
yxr1995-maker
wants to merge
3
commits into
lidge-jun:dev
from
yxr1995-maker:fix/console-go-upload-retry
Closed
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
134 changes: 134 additions & 0 deletions
134
tests/responses/responses-console-go-upload-retry.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,134 @@ | ||
| import { afterEach, beforeEach, describe, expect, test } from "bun:test"; | ||
| import { mkdtempSync } from "node:fs"; | ||
| import { tmpdir } from "node:os"; | ||
| import { join } from "node:path"; | ||
| import { handleResponses } from "../../src/server/responses/core"; | ||
| import type { RequestLogContext } from "../../src/server/request-log"; | ||
| import type { OcxConfig } from "../../src/types"; | ||
| import { removeTreeWithRetry } from "../helpers/remove-tree"; | ||
|
|
||
| const originalFetch = globalThis.fetch; | ||
| const originalOpenCodexHome = process.env.OPENCODEX_HOME; | ||
|
|
||
| /** The exact Console Go rejection for a payload it accepts moments later. */ | ||
| const UPLOAD_REFUSAL = JSON.stringify({ | ||
| model: "muse-spark-1.3-contributor", | ||
| error: { | ||
| param: null, | ||
| type: "invalid_request_error", | ||
| message: "Error from provider (Console Go): Upstream request failed: [invalid_request_error] Invalid upload request.", | ||
| }, | ||
| }); | ||
|
|
||
| /** A deterministic 400 on the same wire: a verdict on the request, never a flap. */ | ||
| const EFFORT_REFUSAL = JSON.stringify({ | ||
| model: "muse-spark-1.3-contributor", | ||
| error: { | ||
| param: "reasoning.effort", | ||
| type: "invalid_request_error", | ||
| message: "Error from provider (Console Go): Upstream request failed: [invalid_request_error] reasoning_effort max requires an active Muse Code subscription for model muse-spark-1.3-contributor.", | ||
| }, | ||
| }); | ||
|
|
||
| let testDir = ""; | ||
|
|
||
| beforeEach(() => { | ||
| testDir = mkdtempSync(join(tmpdir(), "ocx-console-go-upload-retry-")); | ||
| process.env.OPENCODEX_HOME = testDir; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| globalThis.fetch = originalFetch; | ||
| if (originalOpenCodexHome === undefined) delete process.env.OPENCODEX_HOME; | ||
| else process.env.OPENCODEX_HOME = originalOpenCodexHome; | ||
| removeTreeWithRetry(testDir); | ||
| }); | ||
|
|
||
| function config(): OcxConfig { | ||
| return { | ||
| defaultProvider: "go", | ||
| providers: { | ||
| go: { | ||
| adapter: "openai-responses", | ||
| baseUrl: "https://opencode.ai/zen/go/v1", | ||
| authMode: "key", | ||
| apiKey: "go-test-key", | ||
| }, | ||
| }, | ||
| } as OcxConfig; | ||
| } | ||
|
|
||
| function request(stream = false): Request { | ||
| return new Request("http://localhost/v1/responses", { | ||
| method: "POST", | ||
| headers: { | ||
| "content-type": "application/json", | ||
| "session_id": "thread-console-go-upload-retry", | ||
| }, | ||
| body: JSON.stringify({ | ||
| model: "go/muse-spark-1.3-contributor", | ||
| stream, | ||
| store: false, | ||
| input: [ | ||
| { type: "message", role: "user", content: [{ type: "input_text", text: "hi" }] }, | ||
| ], | ||
| }), | ||
| }); | ||
| } | ||
|
|
||
| function refusal(status = 400, body = UPLOAD_REFUSAL): Response { | ||
| return new Response(body, { status, headers: { "content-type": "application/json" } }); | ||
| } | ||
|
|
||
| function success(id: string): Response { | ||
| return Response.json({ id, object: "response", status: "completed", model: "muse-spark-1.3-contributor", output: [] }); | ||
| } | ||
|
|
||
| describe("Console Go transient upload refusal recovery", () => { | ||
| test("replays the refusal once and serves the retry with a byte-identical body", async () => { | ||
| const outbound: string[] = []; | ||
| globalThis.fetch = (async (_input: RequestInfo | URL, init?: RequestInit) => { | ||
| outbound.push(String(init?.body)); | ||
| return outbound.length === 1 ? refusal() : success("resp-upload-retry-recovered"); | ||
| }) as typeof fetch; | ||
| const logCtx: RequestLogContext = { model: "", provider: "" }; | ||
|
|
||
| const response = await handleResponses(request(), config(), logCtx); | ||
|
|
||
| expect(response.status).toBe(200); | ||
| expect(outbound).toHaveLength(2); | ||
| // The replay must be the same request, not a reshaped one. Evidence: usage ledger | ||
| // ocx-ce696fa4a554e4f3e375cf120904b0da (400) vs ocx-ed78f47b96f7d1bb7c (200, +22s). | ||
| expect(outbound[1]).toBe(outbound[0]); | ||
| expect(logCtx.activeAttempt?.recoveryKinds).toEqual(["console-go-upload-retry"]); | ||
| }); | ||
|
|
||
| test("does not replay a different 400 from the same wire", async () => { | ||
| let sends = 0; | ||
| globalThis.fetch = (async () => { | ||
| sends += 1; | ||
| return refusal(400, EFFORT_REFUSAL); | ||
| }) as typeof fetch; | ||
|
|
||
| const response = await handleResponses(request(), config(), { model: "", provider: "" }); | ||
|
|
||
| expect(response.status).toBe(400); | ||
| expect(sends).toBe(1); | ||
| }); | ||
|
|
||
| test("keeps a repeated refusal visible after the single bounded replay", async () => { | ||
| let sends = 0; | ||
| globalThis.fetch = (async () => { | ||
| sends += 1; | ||
| return refusal(); | ||
| }) as typeof fetch; | ||
| const logCtx: RequestLogContext = { model: "", provider: "" }; | ||
|
|
||
| const response = await handleResponses(request(), config(), logCtx); | ||
|
|
||
| expect(response.status).toBe(400); | ||
| expect(sends).toBe(2); | ||
| expect(logCtx.activeAttempt?.recoveryKinds).toEqual(["console-go-upload-retry"]); | ||
| }); | ||
| }); | ||
|
|
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.