Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/opencode/src/plugin/codex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,16 @@ export async function CodexAuthPlugin(input: PluginInput): Promise<Hooks> {
output: 0,
cache: { read: 0, write: 0 },
}

// GPT-5.5 has a smaller effective window when routed through Codex OAuth.
if (model.id.includes("gpt-5.5")) {
Comment thread
Astro-Han marked this conversation as resolved.
Resolved
model.limit = {
context: 400_000,
// @ts-expect-error Provider SDK v1 model limits do not type input, but opencode uses it for compaction.
input: 272_000,
output: 128_000,
}
Comment thread
Astro-Han marked this conversation as resolved.
Resolved
}
}

return {
Expand Down
12 changes: 10 additions & 2 deletions packages/opencode/src/provider/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,13 @@ export type ParsedStreamError =
| {
type: "api_error"
message: string
isRetryable: false
isRetryable: boolean
responseBody: string
}

export function parseStreamError(input: unknown): ParsedStreamError | undefined {
const body = json(input)
const raw = json(input)
const body = typeof raw?.message === "string" ? (json(raw.message) ?? raw) : raw
if (!body) return
Comment thread
Astro-Han marked this conversation as resolved.
Resolved

const responseBody = JSON.stringify(body)
Expand Down Expand Up @@ -150,6 +151,13 @@ export function parseStreamError(input: unknown): ParsedStreamError | undefined
isRetryable: false,
responseBody,
}
case "server_error":
return {
type: "api_error",
message: typeof body?.error?.message === "string" ? body?.error?.message : "Server error.",
isRetryable: true,
responseBody,
}
}
}

Expand Down
55 changes: 55 additions & 0 deletions packages/opencode/test/plugin/codex.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, expect, test } from "bun:test"
import {
CodexAuthPlugin,
parseJwtClaims,
extractAccountIdFromClaims,
extractAccountId,
Expand Down Expand Up @@ -143,6 +144,60 @@ describe("plugin.codex", () => {
})
})

describe("CodexAuthPlugin", () => {
test("overrides GPT-5.5 limits for OAuth Codex plans", async () => {
const provider = {
models: {
"gpt-5.5": {
id: "gpt-5.5",
api: { id: "gpt-5.5" },
cost: {
input: 2,
output: 8,
cache: { read: 1, write: 2 },
},
limit: {
context: 1_050_000,
input: 922_000,
output: 128_000,
},
},
},
}
const hooks = await CodexAuthPlugin({
client: {} as never,
project: {} as never,
directory: "",
worktree: "",
experimental_workspace: {
register() {},
},
} as never)

await hooks.auth!.loader!(
async () =>
({
type: "oauth",
access: "access",
refresh: "refresh",
expires: Date.now() + 60_000,
}) as never,
provider as never,
)

expect(provider.models["gpt-5.5"].limit).toEqual({
context: 400_000,
input: 272_000,
output: 128_000,
})
expect(provider.models["gpt-5.5"].cost).toEqual({
input: 0,
output: 0,
cache: { read: 0, write: 0 },
})
})
})

describe("formatOAuthFailure", () => {
test("includes safe JSON error fields and request metadata", async () => {
const response = new Response(
Expand Down
19 changes: 19 additions & 0 deletions packages/opencode/test/session/retry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,4 +294,23 @@ describe("session.message-v2.fromError", () => {
const result = MessageV2.fromError(error, { providerID: ProviderID.make("openai") }) as MessageV2.APIError
expect(result.data.isRetryable).toBe(true)
})

test("converts OpenAI server_error stream chunks to retryable APIError", () => {
const result = MessageV2.fromError(
{
message: JSON.stringify({
type: "error",
error: {
code: "server_error",
message: "An error occurred while processing your request.",
},
}),
},
{ providerID: ProviderID.make("openai") },
)

expect(MessageV2.APIError.isInstance(result)).toBe(true)
expect((result as MessageV2.APIError).data.isRetryable).toBe(true)
expect(SessionRetry.retryable(result)).toBe("An error occurred while processing your request.")
})
Comment thread
Astro-Han marked this conversation as resolved.
Resolved
})
Loading