Skip to content

fix(sse): trim oversized tool enums on opencode dispatch - #15756

Merged
diegosouzapw merged 1 commit into
diegosouzapw:release/v3.8.52from
timootten:fix/opencode-enum-trim
Oct 8, 2026
Merged

diegosouzapw merged 1 commit into
diegosouzapw:release/v3.8.52from
timootten:fix/opencode-enum-trim

Conversation

@timootten

@timootten timootten commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

OpenCode upstream rejects a request with HTTP 400 when a single enum property carries more than 250 values or the combined enum string length exceeds 15000 characters. Generic SDK clients with VSCode-shaped caller tools (300+ allowed values, no native OpenCode prompt) hit this on otherwise valid oc/* requests.

Change: new shape-agnostic trimOversizedToolEnums helper (open-sse/executors/opencodeEnumTrim.ts) caps every offending enum to 200 values / 12000 combined chars with a description note. Wired into OpencodeExecutor.transformRequest after the free-tier contract prep, so caller tools and contract-borrowed declarations are covered on all surfaces (opencode, opencode-zen, opencode-go).

Complements open PR #15143 (native contract / pause scoping), which does not address the enum 400.

Tests: new tests/unit/opencode-enum-trim.test.ts (5 cases: passthrough, value cap, char cap, non-string enums, transformRequest integration). Verified 5 pass plus 13 existing opencode tests pass. Lint clean.

Live verification (local dev server, isolated DATA_DIR, base + this patch)

  • Keyless oc/big-pickle, generic shape: 403 FreeTierError: OpenCode's free tier can only be used from within OpenCode (reproduces the reported symptom; the free-tier contract already borrows native tool declarations, upstream still refuses with a noauth routing error).
  • Keyed opencode-zen/muse-spark-1.3-contributor-free, bare shape: same 403 (expected for non-contract shapes).
  • Keyed, native shape (system prompt + tools): 200 with content. The keyed native path works with this patch applied.

Relationship to draft #15143

This PR fixes only the enum-400 described above. The 403 FreeTierError for bare/keyless shapes is owned by draft #15143 (native request contract + pause scoping), which is the important follow-up for making opencode free-tier models usable from generic clients. The two PRs are complementary: #15143 without this fix still 400s on VSCode-shaped tools with oversized enums, and this fix without #15143 still 403s on bare shapes.

OpenCode upstream 400s requests whose single enum property exceeds 250 values or 15000 combined chars. Cap offending enums to 200 values / 12000 chars with a description note before dispatch.
@diegosouzapw
diegosouzapw merged commit 9143bf8 into diegosouzapw:release/v3.8.52 Oct 8, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants