fix(server): OpenCode model parsing drops models with a slash in the JSON body - #5072
Conversation
…slash in the body
`parseModelsCliOutput` reads the `opencode models` output as alternating lines:
a `provider/model` slug line, then the model's single-line `JSON.stringify`
body. It told the two apart with `SLUG_LINE_RE = /^(\S+\/\S+)\s*$/`, which
matches any line that has no interior whitespace and contains a `/`. A JSON
body line can satisfy both: an OpenRouter-style model whose `id` is
`vendor/model` and whose string values contain no spaces (e.g.
`{"id":"qwen/qwen3-coder","providerID":"openrouter","name":"qwen3-coder","status":"active"}`)
is classified as a new slug, so `flushModel` runs against an empty body and the
model is silently dropped from the provider list.
A model body is always a single `JSON.stringify` line starting with `{`, and a
slug line never is, so only treat non-`{` lines as slug candidates. Added a
regression test (fails before, passes after).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
ApprovabilityVerdict: Approved 0229ff2 This is a straightforward bug fix that adds a guard to prevent JSON body lines (which start with '{') from being incorrectly matched as provider/model slugs. The fix is minimal, well-documented with comments, and includes a test case demonstrating the bug scenario. You can customize Macroscope's approvability policy. Learn more. |
## What's Changed * fix(mobile): keep chat composer above the Android gesture bar by @PollyGlot in pingdotgg/t3code#5988 * fix(server): OpenCode model parsing drops models with a slash in the JSON body by @arhxam in pingdotgg/t3code#5072 * fix(web): persist sidebar shelf collapse state by @PixPMusic in pingdotgg/t3code#5136 * perf(web): skip base64 for oversized image candidates by @tarik02 in pingdotgg/t3code#5220 * fix(server): skip Linux libc detection on Windows/macOS by @bkntr in pingdotgg/t3code#5354 * fix(server): advertise 256-color TERM on Windows terminals by @yassiEmp in pingdotgg/t3code#5693 * fix(server): handle unborn HEAD in VCS status by @t3-code[bot] in pingdotgg/t3code#5944 ## New Contributors * @bkntr made their first contribution in pingdotgg/t3code#5354 * @yassiEmp made their first contribution in pingdotgg/t3code#5693 **Full Changelog**: pingdotgg/t3code@v0.0.34-nightly.20260811.1063...v0.0.34-nightly.20260811.1064 Upstream release: https://github.com/pingdotgg/t3code/releases/tag/v0.0.34-nightly.20260811.1064
What Changed
parseModelsCliOutput(apps/server/src/provider/opencodeRuntime.ts) now only treats a non-{line as a provider/model slug header. Added a regression test.Why
The
opencode modelsoutput alternates aprovider/modelslug line and the model's single-lineJSON.stringifybody. The two were told apart withSLUG_LINE_RE = /^(\S+\/\S+)\s*$/, which matches any line with no interior whitespace that contains a/. A JSON body line can satisfy that: an OpenRouter-style model whoseidisvendor/modeland whose string values contain no spaces —— has its body line classified as a new slug, so
flushModelruns against an empty body and the model is silently dropped from the provider list.A model body is always a single
JSON.stringifyline starting with{, and a slug line never is, so a line starting with{is never a slug candidate. The added test fails before this change and passes after; all existing parser tests still pass.Checklist
Note
Low Risk
Narrow parser guard in CLI inventory loading with a targeted regression test; no auth, security, or UI surface.
Overview
Fixes silent loss of OpenCode models when CLI
modelsoutput includes a JSON body line that contains a/but no spaces (typical OpenRouteridvalues likeqwen/qwen3-coder). Those lines incorrectly matched the slug regex and were parsed as new headers, so the preceding model was flushed with an empty body and dropped from the provider list.parseModelsCliOutputnow skips slug matching for lines that start with{after trimming, since model bodies are always single-lineJSON.stringifyoutput and slug headers never start that way.Adds a regression test for the OpenRouter-style slug + body pair.
Reviewed by Cursor Bugbot for commit 0229ff2. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Fix
parseModelsCliOutputdropping models with a slash in their JSON bodyIn opencodeRuntime.ts,
parseModelsCliOutputwas applyingSLUG_LINE_REto every line, causing JSON body lines that start with{and contain a/(e.g.id: 'qwen/qwen3-coder') to be misclassified as new provider/model slugs, which flushed the current model prematurely. The fix skips slug matching for any trimmed line starting with{, so those lines are correctly appended to the current JSON body instead.Macroscope summarized 0229ff2.