Skip to content

Commit b4ffbc6

Browse files
fix(sandbox-runner): use OpenAI's own SDK for OpenAI runs, and bump opencode to 1.18.30 (#26)
## What broke Every Layer-2 triage run against `gpt-5.6-luna` was failing. The symptom was maximally misleading: ``` {"is_error":true,"error":"opencode produced no usable reply", "usage":{"input_tokens":0,"output_tokens":0,...}} ``` Zero tokens, valid key. That reads like a credential or connectivity problem, and it is neither. ## Why `@ai-sdk/openai-compatible` always sends `max_tokens`. OpenAI's GPT-5.x reasoning line rejects it: ``` Unsupported parameter: 'max_tokens' is not supported with this model. Use 'max_completion_tokens' instead. ``` OpenCode folds that 400 into an empty assistant turn, so a hard request-shape failure surfaced to us as an empty reply with no spend. `@ai-sdk/openai` rewrites the field per model ([`openai-chat-language-model.ts`](https://github.com/vercel/ai/blob/main/packages/openai/src/chat/openai-chat-language-model.ts)) and is the only one of the two that can: knowing which models need it means knowing the models, which is exactly what "any OpenAI-compatible endpoint" cannot assume. Upstream tracks this as [opencode#45223](anomalyco/opencode#45223), still open with no scheduled fix, so this does not wait on them. ## What changed **`fix`** — `openAiCompatProviderBlock` selects `@ai-sdk/openai` for the `OPENAI` mode, `@ai-sdk/openai-compatible` for everything else. One line plus its rationale, and the two test assertions that pinned the old value. **`chore`** — `opencode-ai` and `@opencode-ai/sdk` 1.18.13 → 1.18.30 across both recipes, `package.json`, and the lockfile. Independent of the fix; it stands on being current. ## For the reviewer **The bump does not fix the bug, and that was measured rather than assumed.** 1.18.30 reproduces the failure identically while on the compat adapter, because [opencode#44710](anomalyco/opencode#44710 provider gating does not recognise a custom `openai-compatible` block like `openai-direct`. Worth knowing before anyone concludes the bump was the cure. **Why only the OPENAI mode moved.** The other modes are not the same case. `api.x.ai/v1` and `generativelanguage.googleapis.com/v1beta/openai/` are deliberately maintained OpenAI-*compatible* surfaces with a stated compatibility contract. OpenAI's `/v1` is the origin of the shape and owes nobody compatibility, which is precisely how it drifted. Pointing the compat adapter at a compat endpoint remains correct. `@ai-sdk/xai` is a closer call than the others: it defaults to the same `api.x.ai/v1` base URL already in use and is a standalone implementation, so it is nearly a drop-in. It was left alone because there is no xAI key here to verify it with, and swapping a working provider blind inside an unrelated fix is how the next quiet zero-token failure gets introduced. Worth doing as its own change. Gemini is genuinely different: `@ai-sdk/google` uses a different endpoint path and an `x-goog-api-key` header instead of Bearer, so it is a credential-plumbing refactor, not a swap. **The rest of the codebase was audited for the same pattern and is clean.** The Java backend cannot hit this defect: `.maxTokens(4096)` appears exactly once in the whole tree ([`ChatModelFactory.java:515`](backend/llm-runtime/src/main/java/ai/tessary/llm/ChatModelFactory.java#L515)), on the Anthropic builder, because Anthropic's API requires it. No OpenAI-wire path sets a token cap at all. Its OpenAI path already uses OpenAI's own LangChain4j client. ## Verification - Reproduced and fixed against a real key inside the agent image, on both 1.18.13 and 1.18.30: compat adapter throws the 400, native package replies. - Confirmed the key, auth, egress and model access were never the problem (`GET /v1/models` → 200, model present). - Launcher suite 42/42. - **Not yet run end-to-end through a rebuilt launcher against a live triage job.** That is the remaining gap. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5 <[email protected]>
1 parent 6cc6a8e commit b4ffbc6

7 files changed

Lines changed: 26 additions & 16 deletions

File tree

‎sandbox-runner/agent-sandbox/Dockerfile‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
# has NO apkInstall, so template.ts's mirror of this line has to be a raw `.runCmd`.
5050
#
5151
# The musl swap itself is verified, not assumed: [email protected] compiles under Alpine's g++ and matches
52-
# correctly, opencode-ai 1.18.13 installs and runs, PyYAML imports, and @opencode-ai/sdk loads.
52+
# correctly, opencode-ai 1.18.30 installs and runs, PyYAML imports, and @opencode-ai/sdk loads.
5353
FROM node:22-alpine3.24
5454

5555
# The `tar` module npm vendors (usr/local/lib/node_modules/npm/node_modules/tar) ships at 7.5.11 on
@@ -99,7 +99,7 @@ RUN python3 -m pip install --no-cache-dir --break-system-packages pyyaml
9999
# `set -e` plus the empty-inode guard matter: if stat ever fails, this must abort the build rather
100100
# than fall through to a loop that deletes every variant including the live one.
101101
RUN set -e; \
102-
npm install -g [email protected].13; \
102+
npm install -g [email protected].30; \
103103
D=/usr/local/lib/node_modules/opencode-ai; \
104104
INO="$(stat -c %i "$D/bin/opencode.exe")"; \
105105
[ -n "$INO" ] || { echo "could not stat opencode.exe" >&2; exit 1; }; \
@@ -138,7 +138,7 @@ WORKDIR /home/user
138138
# is already in the base image). undici pins to ^6 so this line stays byte-identical to
139139
# template.ts's (bump every recipe together; undici 8 needs node >=22.19, fine on node:22-alpine3.24).
140140
# The cache clean is size only: npm leaves ~38 MB in $HOME/.npm that nothing at runtime reads.
141-
RUN npm install acorn@^8.18.0 acorn-walk@^8.3.5 re2@^1.26.1 @opencode-ai/[email protected].13 undici@^6.28.0 \
141+
RUN npm install acorn@^8.18.0 acorn-walk@^8.3.5 re2@^1.26.1 @opencode-ai/[email protected].30 undici@^6.28.0 \
142142
&& npm cache clean --force
143143

144144
# The bundle contract, copied straight from its repo-root source of truth (contract/) rather than

‎sandbox-runner/agent-sandbox/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
"packageManager": "[email protected]",
1111
"dependencies": {
12-
"@opencode-ai/sdk": "1.18.13",
12+
"@opencode-ai/sdk": "1.18.30",
1313
"acorn": "^8.18.0",
1414
"acorn-walk": "^8.3.5",
1515
"e2b": "^2.46.1",

‎sandbox-runner/agent-sandbox/pnpm-lock.yaml‎

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎sandbox-runner/agent-sandbox/pnpm-workspace.yaml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
allowBuilds:
99
esbuild: true
1010
re2: true
11-
# 1.18.13 is younger than pnpm's release-age gate. Excluded rather than pinned lower: it is the
11+
# 1.18.30 is younger than pnpm's release-age gate. Excluded rather than pinned lower: it is the
1212
# version this was exercised against, and it must match the `opencode` CLI in template.ts. Names
1313
# one exact version, so it lapses on the next bump.
1414
minimumReleaseAgeExclude:
15-
- '@opencode-ai/[email protected].13'
15+
- '@opencode-ai/[email protected].30'

‎sandbox-runner/agent-sandbox/template.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export const template = Template()
7979
// SAME version as @opencode-ai/sdk below: they ship in lockstep, and agent-stream.js reads
8080
// message parts whose field names have moved between releases (see partsOf/toolCallsOf). Bump
8181
// both together.
82-
.npmInstall('[email protected].13', { g: true })
82+
.npmInstall('[email protected].30', { g: true })
8383
// Size only, not correctness. opencode ships its runtime as a ~180 MB platform binary in
8484
// optionalDependencies and on musl npm installs every variant matching the arch — 2 on arm64,
8585
// 4 on amd64 (both -baseline flavours too) — while executing exactly one.
@@ -110,7 +110,7 @@ export const template = Template()
110110
// together: here, the sibling Dockerfile, AND agent-sandbox/package.json (the host-local
111111
// backend, also ^6.28.0). agent-stream.js needs it to lift fetch's 300s headers timeout.
112112
.runCmd(
113-
'mkdir -p /home/user && cd /home/user && npm install acorn@^8.18.0 acorn-walk@^8.3.5 re2@^1.26.1 @opencode-ai/[email protected].13 undici@^6.28.0 && npm cache clean --force',
113+
'mkdir -p /home/user && cd /home/user && npm install acorn@^8.18.0 acorn-walk@^8.3.5 re2@^1.26.1 @opencode-ai/[email protected].30 undici@^6.28.0 && npm cache clean --force',
114114
)
115115
// HOME must match the runtime user (e2b runs sandboxes as `user`) so the runtime `opencode`
116116
// finds its config; PIP_BREAK_SYSTEM_PACKAGES lets the agent `pip install` further deps at

‎sandbox-runner/launcher/server.js‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,17 @@ function openAiCompatProviderBlock(mode, credential, model) {
378378
// the alternative and it is WRONG for GEMINI specifically: under the id `google`, OpenCode's
379379
// built-in provider plugin wins over the `npm` override and issues the NATIVE Gemini wire shape
380380
// with no Authorization header at all.
381-
const block = { npm: '@ai-sdk/openai-compatible', options: creds };
381+
// OPENAI is the one mode pointed at OpenAI's own endpoint, and it gets OpenAI's own package.
382+
// `@ai-sdk/openai-compatible` always sends `max_tokens`, which the GPT-5.x reasoning line
383+
// rejects outright ("Unsupported parameter ... use max_completion_tokens instead"), and OpenCode
384+
// folds that 400 into an empty assistant turn, so the run surfaces as "opencode produced no
385+
// usable reply" with a valid key and zero tokens. `@ai-sdk/openai` rewrites the field per model
386+
// and is the only one of the two that can: knowing which models need it requires knowing the
387+
// models, which is exactly what "any OpenAI-compatible endpoint" cannot assume. Upstream tracks
388+
// the gap as opencode #45223, still open. Every other mode here IS such an endpoint, so the
389+
// compat adapter stays right for them.
390+
const npm = mode === OPENAI_COMPAT_MODE ? '@ai-sdk/openai' : '@ai-sdk/openai-compatible';
391+
const block = { npm, options: creds };
382392
if (model) block.models = { [model]: {} };
383393
return { [OPENCODE_PROVIDER_NAME[mode]]: block };
384394
}

‎sandbox-runner/launcher/test/provider-dispatch.test.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ test('providerConfig: GLM/GROK/CUSTOM/OPENAI each declare their own block with t
100100
options: { baseURL: 'https://my-endpoint.example/v1', apiKey: 'canary-custom' },
101101
});
102102
assert.deepEqual(providerConfig(OPENAI_CRED).provider['openai-direct'], {
103-
npm: '@ai-sdk/openai-compatible',
103+
npm: '@ai-sdk/openai',
104104
options: { baseURL: 'https://api.openai.com/v1', apiKey: 'canary-openai' },
105105
});
106106
});
@@ -179,7 +179,7 @@ test('providerConfig: an explicit ANTHROPIC base_url override still wins over th
179179
test('providerConfig: an OpenAI-compat block declares the run\'s own model', () => {
180180
const cfg = providerConfig({ provider: 'OPENAI', api_key: 'k' }, 'openai-direct/gpt-5.5');
181181
assert.deepEqual(cfg.provider['openai-direct'].models, { 'gpt-5.5': {} });
182-
assert.equal(cfg.provider['openai-direct'].npm, '@ai-sdk/openai-compatible');
182+
assert.equal(cfg.provider['openai-direct'].npm, '@ai-sdk/openai');
183183
});
184184

185185
test('providerConfig: an OPENROUTER model keeps the slash in its own id', () => {

0 commit comments

Comments
 (0)