Skip to content

Commit 3f864ec

Browse files
anandgupta42claude
andcommitted
fix: build release binaries against the live models.dev catalog
`.github/workflows/release.yml` built every platform binary with `MODELS_DEV_API_JSON: test/tool/fixtures/models-api.json`, so each shipped binary embedded a checked-in test fixture as its bundled models.dev catalog instead of a release-time one. The fixture's newest entry is `2026-03-30`. Verified against the shipped `0.9.7` binary in an isolated `HOME`: its snapshot-only `openai` set is exactly the fixture's (46 of 47 ids, missing only `gpt-5-chat-latest`, which is filtered elsewhere), with zero ids the fixture does not have. That catalog still offers 11 ids the live catalog has dropped (`gpt-5-codex`, `gpt-5.1-codex`, `gpt-5.1-codex-max`, `gpt-5.1-codex-mini`, `gpt-5.2-codex`, `codex-mini-latest`, `o1-mini`, `o1-preview`, and three others) and is missing `gpt-5.5` plus every `gpt-5.6` variant. It carries 105 providers against the live catalog's 207, so the staleness is not OpenAI-specific. Upstream's `publish.yml` sets no such override and fetches live at release time; `git log -S` shows ours has been there since the initial fork commit `f2cd5c1245` with no explanatory comment, and reads as copy-paste from the CI job where a hermetic build genuinely is correct. Removing the override makes release builds depend on models.dev, so `build.ts` now validates the payload before writing the snapshot: - non-2xx responses throw instead of flowing an error page into the snapshot (`fetch` resolves for 4xx/5xx, and a JSON error body is valid TypeScript that would have shipped as a catalog with no providers) - the payload must parse, be a provider object, carry at least 50 providers, and include `anthropic`, `openai` and `google` `ci.yml` and `pre-release-check.ts` keep the fixture pin — a hermetic build is correct there. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VqnuBDGkh1ZT65Ti7e6DHZ
1 parent c59a5a2 commit 3f864ec

2 files changed

Lines changed: 56 additions & 3 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,12 @@ jobs:
9898
OPENCODE_CHANNEL: ${{ contains(github.ref_name, '-') && 'beta' || 'latest' }}
9999
OPENCODE_RELEASE: "1"
100100
GH_REPO: ${{ env.GH_REPO }}
101-
MODELS_DEV_API_JSON: test/tool/fixtures/models-api.json
101+
# altimate_change — MODELS_DEV_API_JSON is deliberately NOT set here.
102+
# Pointing it at test/tool/fixtures/models-api.json (as ci.yml does, where
103+
# a hermetic build is correct) made every shipped binary embed that fixture
104+
# as its bundled models.dev catalog — newest entry 2026-03-30. Release
105+
# builds fetch models.dev live, matching upstream's publish.yml. build.ts
106+
# validates the payload and fails the build if it is unusable.
102107

103108
# Smoke-test: verify the compiled binary actually starts.
104109
# Only possible for native linux-x64 builds on the ubuntu runner.

‎packages/opencode/script/build.ts‎

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,58 @@ const changelog = fs.existsSync(changelogPath) ? await Bun.file(changelogPath).t
2828
console.log(`Loaded CHANGELOG.md (${changelog.length} chars)`)
2929

3030
const modelsUrl = process.env.OPENCODE_MODELS_URL || "https://models.dev"
31-
// Fetch and generate models.dev snapshot
31+
32+
// A models.dev catalog small enough to trip this is a fetch that went wrong, not
33+
// a real shrink: the live catalog carries 200+ providers and the checked-in test
34+
// fixture carries 105. The named providers are the ones whose absence would make
35+
// a shipped binary visibly broken.
36+
const MIN_CATALOG_PROVIDERS = 50
37+
const REQUIRED_CATALOG_PROVIDERS = ["anthropic", "openai", "google"]
38+
39+
/** Fetch the models.dev catalog, failing loudly on a non-2xx.
40+
*
41+
* `fetch` resolves for 4xx/5xx, so without this check a load-balancer error page
42+
* flows straight into the snapshot. An HTML body would at least break the build
43+
* at parse time, but a JSON error body (`{"error": ...}`) is valid TypeScript and
44+
* would ship as a catalog with no providers in it. */
45+
async function fetchModelsCatalog(url: string): Promise<string> {
46+
const res = await fetch(url)
47+
if (!res.ok) throw new Error(`models.dev fetch failed: HTTP ${res.status} ${res.statusText} from ${url}`)
48+
return await res.text()
49+
}
50+
51+
/** Reject a catalog that parses but is obviously not usable.
52+
*
53+
* Release builds embed this in every binary, so an empty or truncated payload
54+
* has to stop the release rather than ship a CLI that offers no models. */
55+
function assertUsableCatalog(text: string, origin: string): void {
56+
let parsed: unknown
57+
try {
58+
parsed = JSON.parse(text)
59+
} catch (e) {
60+
throw new Error(`models.dev catalog from ${origin} is not valid JSON`, { cause: e })
61+
}
62+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed))
63+
throw new Error(`models.dev catalog from ${origin} is not a provider object`)
64+
const providers = Object.keys(parsed)
65+
if (providers.length < MIN_CATALOG_PROVIDERS)
66+
throw new Error(
67+
`models.dev catalog from ${origin} has only ${providers.length} providers, expected at least ${MIN_CATALOG_PROVIDERS}`,
68+
)
69+
const missing = REQUIRED_CATALOG_PROVIDERS.filter((p) => !providers.includes(p))
70+
if (missing.length > 0)
71+
throw new Error(`models.dev catalog from ${origin} is missing required providers: ${missing.join(", ")}`)
72+
console.log(`models.dev catalog from ${origin}: ${providers.length} providers`)
73+
}
74+
75+
// Fetch and generate models.dev snapshot. MODELS_DEV_API_JSON pins the catalog to
76+
// a local file for hermetic builds (ci.yml, pre-release-check.ts); release builds
77+
// leave it unset so the shipped binary embeds a release-time catalog.
78+
const modelsOrigin = process.env.MODELS_DEV_API_JSON ?? `${modelsUrl}/api.json`
3279
const modelsData = process.env.MODELS_DEV_API_JSON
3380
? await Bun.file(process.env.MODELS_DEV_API_JSON).text()
34-
: await fetch(`${modelsUrl}/api.json`).then((x) => x.text())
81+
: await fetchModelsCatalog(`${modelsUrl}/api.json`)
82+
assertUsableCatalog(modelsData, modelsOrigin)
3583
await Bun.write(
3684
path.join(dir, "src/provider/models-snapshot.ts"),
3785
`// Auto-generated by build.ts - do not edit\nexport const snapshot = ${modelsData.trim()} as const\n`,

0 commit comments

Comments
 (0)