Skip to content

Commit 5c138d7

Browse files
Colin McCarthyclaude
andcommitted
OpenCode: a free model's refusal is OpenCode's side, never a sign-in
2026-10-12: every one of OpenCode's free models answered "Upstream request failed: Invalid credential" (401), for everyone -- 0.756's first-hour smoke on a bare Mac with nothing signed in among them (anomalyco/opencode#54833). The card told a new person "Its sign-in may have expired -- opencode auth login in a terminal" for an account the free models never needed, and offered nothing to press. The run's model now reaches OpenCode's normalizer; on a free model a 401/403 says OpenCode's service refused it, that free models need no sign-in, and to pick another model or try later. The window reads that as a free model that is down: the card offers the next free model, and the next start passes over this one. A model of the person's own, refused the same way, is still pointed at its sign-in. The test record is the one OpenCode 1.18.27 wrote at 15:04Z. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01HB3pgxh9aVAXnocTMx6kyP
1 parent f9c99ff commit 5c138d7

7 files changed

Lines changed: 110 additions & 5 deletions

File tree

‎apps/desktop/src/main/codex-mission.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,6 +1843,8 @@ export function createCodexMissionService(options: CodexMissionServiceOptions):
18431843
requestedRouteId: routeId,
18441844
resolvedRouteId,
18451845
...(chosen.version?.version === undefined ? {} : { cliVersion: chosen.version.version }),
1846+
// A free model's refusal is OpenCode's side, never a sign-in to renew (opencode-error.ts, 2026-10-12).
1847+
...(runtime === 'opencode' && chosenModel !== undefined ? { model: chosenModel } : {}),
18461848
now,
18471849
// What Antigravity's mode refuses, so only a call it could have refused waits for the result (0.551).
18481850
...(runtime === 'antigravity' ? { sandbox: effectiveSandbox } : {}),

‎apps/desktop/src/renderer/src/a-free-model-that-is-down-offers-the-next.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ describe('a free model that is down', () => {
1414
expect(modelUnavailable({ message: 'OpenCode stopped: Endpoint is unavailable.' })).toBe(true)
1515
})
1616

17+
it('and a free model OpenCode’s service refused outright (2026-10-12, "Invalid credential" on every free model)', () => {
18+
expect(modelUnavailable({ message: "OpenCode's service refused the free model, so OpenCode stopped: Upstream request failed: Invalid credential. Free models need no sign-in, so this is on OpenCode's side: pick another model, or try this one again later." })).toBe(true)
19+
// A paid route's refusal is the person's sign-in, not a model that is down.
20+
expect(modelUnavailable({ message: 'OpenCode was refused by the provider and stopped: Unauthorized.. Its sign-in may have expired -- `opencode auth login` in a terminal.' })).toBe(false)
21+
})
22+
1723
it('and nothing else: a retirement, a busy server or a plain failure is not it', () => {
1824
expect(modelUnavailable({ message: 'OpenCode stopped: Model exo-free has been deprecated.' })).toBe(false)
1925
expect(modelUnavailable({ message: 'Selected model is at capacity. Please try a different model.' })).toBe(false)

‎apps/desktop/src/renderer/src/missionView.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5395,9 +5395,12 @@ export function modelRetired(payload: { readonly message?: string }): boolean {
53955395
* hours at a time: Ling 3.0 answered "Endpoint is unavailable" all of
53965396
* 2026-09-30, and "Upstream request failed: Model is unavailable" on
53975397
* 2026-10-09 while Ling 3.1 answered. Going on with the same model fails
5398-
* again; the card offers the next free model instead.
5398+
* again; the card offers the next free model instead. And refused outright
5399+
* (2026-10-12, "Upstream request failed: Invalid credential" on every free
5400+
* model, for everyone): the adapter's sentence for that says the free model
5401+
* was refused by OpenCode's service (opencode-error.ts), never a sign-in.
53995402
*/
5400-
const UNAVAILABLE_PATTERN = /\b(?:model|endpoint) is unavailable\b/i
5403+
const UNAVAILABLE_PATTERN = /\b(?:model|endpoint) is unavailable\b|\brefused the free model\b/i
54015404

54025405
export function modelUnavailable(payload: { readonly message?: string }): boolean {
54035406
return UNAVAILABLE_PATTERN.test(payload.message ?? '')

‎packages/runtime-adapters/src/opencode-error.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export function sessionCannotContinue(facts: OpenCodeErrorFacts): boolean {
125125
return facts.message !== undefined && /encrypted_content/i.test(facts.message);
126126
}
127127

128-
export function openCodeErrorSentence(facts: OpenCodeErrorFacts): string {
128+
export function openCodeErrorSentence(facts: OpenCodeErrorFacts, onFreeModel = false): string {
129129
const quoted = facts.message === undefined ? undefined : facts.message.trim();
130130
// The one worth naming precisely, because it is the one a person meets on
131131
// their first free run and the wording decides whether they think the app is
@@ -158,6 +158,17 @@ export function openCodeErrorSentence(facts: OpenCodeErrorFacts): string {
158158
return `OpenCode was rate limited by the provider and stopped${quoted === undefined ? "" : `: ${quoted}`}`;
159159
}
160160
if (facts.statusCode === 401 || facts.statusCode === 403) {
161+
/*
162+
* ON A FREE MODEL THERE IS NO SIGN-IN TO EXPIRE (2026-10-12). Every one of
163+
* OpenCode's free models answered "Upstream request failed: Invalid
164+
* credential" that morning, for everyone -- a bare Mac with nothing signed
165+
* in among them (0.756's first-hour smoke; anomalyco/opencode#54833) --
166+
* and this sentence sent a new person to `opencode auth login` for an
167+
* account the free models never needed. Their refusal is OpenCode's side.
168+
*/
169+
if (onFreeModel) {
170+
return `OpenCode's service refused the free model, so OpenCode stopped${quoted === undefined ? "" : `: ${quoted.replace(/\.$/, "")}`}. Free models need no sign-in, so this is on OpenCode's side: pick another model, or try this one again later.`;
171+
}
161172
return `OpenCode was refused by the provider and stopped${quoted === undefined ? "" : `: ${quoted}`}. Its sign-in may have expired -- \`opencode auth login\` in a terminal.`;
162173
}
163174
if (quoted !== undefined && quoted.length > 0) {

‎packages/runtime-adapters/src/opencode-events.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ export interface OpenCodeInvocationContext {
7878
readonly requestedRouteId?: string;
7979
readonly resolvedRouteId?: string;
8080
readonly cliVersion?: string;
81+
/** The model the run was asked for (`opencode/space-bunny-free`): a free one's refusal is never a sign-in. */
82+
readonly model?: string;
8183
/** Test seam and host clock. */
8284
readonly now?: () => Date;
8385
}
@@ -249,6 +251,8 @@ export function createOpenCodeEventNormalizer(
249251
? undefined
250252
: requireContextText(context.cliVersion, "cliVersion");
251253
const now = context.now ?? (() => new Date());
254+
// The same test as the app's free routes (main/free-routes.ts isFreeRoute): an id that ends in "free".
255+
const onFreeModel = context.model !== undefined && /(^|[-/])free$/i.test(context.model);
252256

253257
let runtimeThreadId: string | undefined;
254258
let normalizedSequence = 0;
@@ -594,7 +598,7 @@ export function createOpenCodeEventNormalizer(
594598
return [diagnostic("info", "opencode.context_overflow", OPENCODE_OVERFLOW_RECOVERING, evidence)];
595599
}
596600
overflow = "none";
597-
return [diagnostic("error", "opencode.provider_error", openCodeErrorSentence(facts), evidence)];
601+
return [diagnostic("error", "opencode.provider_error", openCodeErrorSentence(facts, onFreeModel), evidence)];
598602
}
599603
}
600604

@@ -733,7 +737,7 @@ export function createOpenCodeEventNormalizer(
733737
// the HOST did, which the runtime could not know about, and
734738
// above the exit code because a number is not a reason.
735739
: providerError !== undefined
736-
? openCodeErrorSentence(providerError)
740+
? openCodeErrorSentence(providerError, onFreeModel)
737741
: sawStop
738742
? `OpenCode exited with code ${String(completion.exitCode)}.`
739743
: "OpenCode ended without a step that reported it had stopped.",
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { describe, expect, it } from "vitest";
2+
3+
import { createOpenCodeEventNormalizer } from "../src/opencode-events.js";
4+
import type { NormalizedRuntimeEvent } from "../src/codex-events.js";
5+
import type { RuntimeProcessCompletion } from "../src/process-runner.js";
6+
7+
/*
8+
* 2026-10-12, 15:04Z: what OpenCode 1.18.27 wrote for `run --format json -m opencode/space-bunny-free`, while every
9+
* one of its free models answered so, for everyone (anomalyco/opencode#54833) -- trimmed only of the response
10+
* headers. Its server path hands the same record on (opencode-serve-run.ts, session.error). The card said "Its
11+
* sign-in may have expired -- `opencode auth login` in a terminal" to people who never signed in to anything.
12+
*/
13+
const MEASURED = JSON.stringify({
14+
type: "error",
15+
timestamp: 1791817472158,
16+
sessionID: "ses_ecf5c461affe7hz3Cz49cHA0hJ",
17+
error: {
18+
name: "APIError",
19+
data: {
20+
message: "Upstream request failed: Invalid credential",
21+
statusCode: 401,
22+
isRetryable: false,
23+
responseBody: JSON.stringify({ error: { type: "server_error", message: "Upstream request failed: Invalid credential" } }),
24+
metadata: { url: "https://opencode.ai/inference/v1/chat/completions" },
25+
},
26+
},
27+
});
28+
29+
const NOW = "2026-10-12T15:04:32.000Z";
30+
const completion: RuntimeProcessCompletion = {
31+
exitCode: 1,
32+
signal: null,
33+
stderr: "",
34+
stderrTruncated: false,
35+
recordCount: 1,
36+
cancelled: false,
37+
forcedTerminationAttempted: false,
38+
terminationUnconfirmed: false,
39+
inputDeliveryFailed: false,
40+
outputLimitExceeded: false,
41+
startedAt: NOW,
42+
finishedAt: NOW,
43+
};
44+
45+
function said(model: string): { readonly diagnostic: string | undefined; readonly failed: string | undefined } {
46+
const opencode = createOpenCodeEventNormalizer({ runId: "run_1", model, now: () => new Date(NOW) });
47+
const events: NormalizedRuntimeEvent[] = [...opencode.accept({ sequence: 1, raw: MEASURED }), ...opencode.finish(completion)];
48+
const message = (type: string): string | undefined => {
49+
const event = events.find((one) => one.type === type);
50+
const payload = event === undefined ? undefined : (event.payload as { readonly message?: unknown });
51+
return typeof payload?.message === "string" ? payload.message : undefined;
52+
};
53+
return { diagnostic: message("adapter.diagnostic"), failed: message("run.failed") };
54+
}
55+
56+
describe("a free model OpenCode's service refused", () => {
57+
it("says so, as OpenCode's side, while it happens and when the run ends -- never a sign-in", () => {
58+
const { diagnostic, failed } = said("opencode/space-bunny-free");
59+
const sentence = "OpenCode's service refused the free model, so OpenCode stopped: Upstream request failed: Invalid credential. Free models need no sign-in, so this is on OpenCode's side: pick another model, or try this one again later.";
60+
expect(diagnostic).toBe(sentence);
61+
expect(failed).toBe(sentence);
62+
});
63+
64+
it("while a model of the person's own, refused the same way, is still pointed at its sign-in", () => {
65+
const { failed } = said("anthropic/claude-sonnet-5-5");
66+
expect(failed).toMatch(/Its sign-in may have expired -- `opencode auth login` in a terminal\.$/);
67+
});
68+
});

‎packages/runtime-adapters/test/opencode-error.test.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,17 @@ describe("what the person is told", () => {
9393
}
9494
});
9595

96+
it("on a free model says the refusal is OpenCode's side: there is no sign-in to renew", () => {
97+
// 2026-10-12: every free model, for everyone, a bare Mac with nothing signed in among them.
98+
for (const statusCode of [401, 403]) {
99+
const said = openCodeErrorSentence({ message: "Upstream request failed: Invalid credential", statusCode, kind: undefined, retryable: false }, true);
100+
expect(said).toBe("OpenCode's service refused the free model, so OpenCode stopped: Upstream request failed: Invalid credential. Free models need no sign-in, so this is on OpenCode's side: pick another model, or try this one again later.");
101+
expect(said).not.toMatch(/auth login|sign-in may have expired/i);
102+
}
103+
// A paid route's refusal is still a sign-in to look at.
104+
expect(openCodeErrorSentence({ message: "Unauthorized.", statusCode: 401, kind: undefined, retryable: false }, false)).toMatch(/auth login/);
105+
});
106+
96107
it("quotes the runtime rather than paraphrasing it, for anything else", () => {
97108
// A paraphrase of an error is a claim about a system this app cannot see.
98109
const said = openCodeErrorSentence({

0 commit comments

Comments
 (0)