Skip to content

fix(server): OpenCode model parsing drops models with a slash in the JSON body - #5072

Merged
maria-rcks merged 1 commit into
pingdotgg:mainfrom
arhxam:fix/opencode-model-slug-misclassification
Aug 11, 2026
Merged

fix(server): OpenCode model parsing drops models with a slash in the JSON body#5072
maria-rcks merged 1 commit into
pingdotgg:mainfrom
arhxam:fix/opencode-model-slug-misclassification

Conversation

@arhxam

@arhxam arhxam commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

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 models output alternates a provider/model slug line and the model's single-line JSON.stringify body. The two were told apart with SLUG_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 whose id is vendor/model and whose string values contain no spaces —

openrouter/qwen/qwen3-coder
{"id":"qwen/qwen3-coder","providerID":"openrouter","name":"qwen3-coder","status":"active"}

— has its body line 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 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

  • This PR is small and focused
  • I explained what changed and why
  • No UI changes

Open in Devin Review

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 models output includes a JSON body line that contains a / but no spaces (typical OpenRouter id values like qwen/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.

parseModelsCliOutput now skips slug matching for lines that start with { after trimming, since model bodies are always single-line JSON.stringify output 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 parseModelsCliOutput dropping models with a slash in their JSON body

In opencodeRuntime.ts, parseModelsCliOutput was applying SLUG_LINE_RE to 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.

…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>
@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3f36a8e7-0faa-4ac7-ae9d-6d3abc8c4bab

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:XS 0-9 changed lines (additions + deletions). labels Jul 31, 2026
@macroscopeapp

macroscopeapp Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: 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.

@maria-rcks
maria-rcks merged commit 2ea51bd into pingdotgg:main Aug 11, 2026
17 checks passed
github-actions Bot added a commit to omarcresp/t3code-flake that referenced this pull request Aug 11, 2026
## 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS 0-9 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants