t3code icon indicating copy to clipboard operation
t3code copied to clipboard

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

Open arhxam opened this issue 4 months ago • 2 comments

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

  • [x] This PR is small and focused
  • [x] I explained what changed and why
  • [x] 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 0229ff255cfc51ca7dd270412db3573e5fe62fb5. 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.

arhxam avatar Jul 31 '26 06:07 arhxam

[!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.

coderabbitai[bot] avatar Jul 31 '26 06:07 coderabbitai[bot]

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.

macroscopeapp[bot] avatar Jul 31 '26 06:07 macroscopeapp[bot]