Skip to content

Commit 293494c

Browse files
committed
fix(quota): identify OpenCode Go by where it routes, not what it is named
A multi-account setup points several provider rows at the same OpenCode Go endpoint under names the registry has never heard of -- opencode-go-2 through -5. Quota dispatch gated on the literal name "opencode-go", so those rows had no dashboard quota panel and no report in `ocx provider quota --refresh --json` even though each one holds a working key for the same upstream (#1924). Identity is now answered by registryEntryForProviderDestination, the predicate this repository already uses for renamed fixed-key rows: it matches on normalized endpoint plus adapter plus key auth. A bare URL comparison would have been enough for the reported symptom but would also probe a row that points at that host through a different adapter, which speaks a different protocol and is not the provider whose quota shape we parse. The defensive canonical-URL check inside fetchOpenCodeGoQuota stays. Whether an API key may be sent to a host must not depend on the dispatch gate above it being correct. Absorbed from #2027 by @yzxcj797.
1 parent 4b9814c commit 293494c

2 files changed

Lines changed: 66 additions & 2 deletions

File tree

‎src/providers/quota.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { getAccountCredential, getAccountSet, getCredential } from "../oauth/sto
1313
import { antigravityUserAgent } from "../adapters/client-fingerprint";
1414
import { apiKeyPoolEntryId } from "./api-keys";
1515
import { XAI_GROK_CLIENT_VERSION, XAI_GROK_COMPATIBILITY } from "./xai-transport";
16-
import { getProviderRegistryEntry, providerCodexAccountMode } from "./registry";
16+
import { getProviderRegistryEntry, providerCodexAccountMode, registryEntryForProviderDestination } from "./registry";
1717
import type { OcxConfig, OcxProviderConfig } from "../types";
1818
import { isCanonicalOpenAiForwardProvider, OPENAI_CODEX_PROVIDER_ID } from "./openai-tiers";
1919
import {
@@ -2084,7 +2084,14 @@ async function maybeFetchProviderQuota(
20842084
&& isCanonicalCommandCodeBaseUrl(provider.baseUrl)) {
20852085
return fetchCommandCodeQuota(name, provider);
20862086
}
2087-
if ((provider.authMode ?? "key") === "key" && name === "opencode-go") {
2087+
// Identify OpenCode Go by where it routes, not by what the row is called. Multi-account
2088+
// setups keep the same destination under names like `opencode-go-2` (#1924), and those rows
2089+
// silently had no quota panel and no `ocx provider quota --json` report while the literal
2090+
// name was the gate. `registryEntryForProviderDestination` is the existing predicate for
2091+
// exactly this question: normalized endpoint + adapter + key auth, so a canonical URL behind
2092+
// a different adapter is still not OpenCode Go. The defensive URL check inside
2093+
// `fetchOpenCodeGoQuota` stays — sending a key anywhere must not depend on this gate.
2094+
if ((provider.authMode ?? "key") === "key" && registryEntryForProviderDestination(provider)?.id === "opencode-go") {
20882095
return fetchOpenCodeGoQuota(name, provider);
20892096
}
20902097
if ((provider.authMode ?? "key") === "key" && isCanonicalA6apiBaseUrl(provider.baseUrl)) {

‎tests/opencode-go-quota.test.ts‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,61 @@ describe("OpenCode Go provider quota", () => {
8787
expect(fetchCalls).toBe(0);
8888
expect(result.reports).toEqual([]);
8989
});
90+
91+
// #1924: a multi-account setup points several rows at the same OpenCode Go endpoint under
92+
// names the registry has never heard of. Gating dispatch on the literal name `opencode-go`
93+
// meant those rows had no dashboard quota panel and no `ocx provider quota --json` report,
94+
// even though each one holds a working key for the same upstream.
95+
test("a canonical sibling row under any name is probed and reported", async () => {
96+
const bearers: string[] = [];
97+
globalThis.fetch = (async (_input: RequestInfo | URL, init?: RequestInit) => {
98+
const headers = init?.headers as Record<string, string> | undefined;
99+
if (headers?.Authorization) bearers.push(headers.Authorization);
100+
return new Response(JSON.stringify({
101+
usage: { rolling: { status: "ok", percent: 12, resetsAt: "2026-08-12T20:00:00.000Z" } },
102+
}), { status: 200, headers: { "content-type": "application/json" } });
103+
}) as typeof fetch;
104+
105+
const config = openCodeGoConfig();
106+
config.providers["opencode-go-2"] = {
107+
adapter: "openai-chat",
108+
authMode: "key",
109+
baseUrl: "https://opencode.ai/zen/go/v1",
110+
// Kept under the privacy scanner's bearer-token length floor: a longer fixture reads as
111+
// a real credential to `privacy:scan` even inside a test.
112+
apiKey: "sibling-secret",
113+
};
114+
115+
const result = await fetchProviderQuotaReports(config, true);
116+
117+
expect(result.reports.map(report => report.provider).sort()).toEqual(["opencode-go", "opencode-go-2"]);
118+
expect(bearers.sort()).toEqual(["Bearer opencode-go-secret", "Bearer sibling-secret"]);
119+
expect(JSON.stringify(result)).not.toContain("sibling-secret");
120+
});
121+
122+
// The distinction between "routes to the OpenCode Go endpoint" and "is the OpenCode Go
123+
// provider": a bare URL match would probe this row, but a different adapter speaks a
124+
// different protocol to that host and is not the provider whose quota shape we parse.
125+
test("a canonical URL behind a different adapter is not OpenCode Go", async () => {
126+
let fetchCalls = 0;
127+
globalThis.fetch = (async () => {
128+
fetchCalls += 1;
129+
return new Response("{}", { status: 200, headers: { "content-type": "application/json" } });
130+
}) as typeof fetch;
131+
132+
const result = await fetchProviderQuotaReports({
133+
defaultProvider: "not-really-go",
134+
providers: {
135+
"not-really-go": {
136+
adapter: "anthropic",
137+
authMode: "key",
138+
baseUrl: "https://opencode.ai/zen/go/v1",
139+
apiKey: "unrelated-secret",
140+
},
141+
},
142+
} as OcxConfig, true);
143+
144+
expect(fetchCalls).toBe(0);
145+
expect(result.reports).toEqual([]);
146+
});
90147
});

0 commit comments

Comments
 (0)