fix(server): OpenCode model parsing drops models with a slash in the JSON body
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
[!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 0229ff255cfc51ca7dd270412db3573e5fe62fb5. 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.
[!IMPORTANT]
Review skipped
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
3f36a8e7-0faa-4ac7-ae9d-6d3abc8c4babYou can disable this status message by setting the
reviews.review_statustofalsein 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.
Comment @coderabbitai help to get the list of available commands.
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.