fix(server): use CLI for OpenCode health check instead of spawning server#4153
Conversation
|
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 Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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: Needs human review This PR changes the health check mechanism from spawning a server to using CLI commands for local OpenCode installs. This is a significant runtime behavior change with new parsing logic and retry mechanisms, not a simple bug fix, warranting human review. You can customize Macroscope's approvability policy. Learn more. |
…rver The OpenCode provider health check previously spawned a full opencode serve process to fetch inventory (models + agents) via HTTP. On Windows under heavy load, this takes 15-20s+, causing timeout errors. Instead, use 'opencode models --verbose' and 'opencode agent list' CLI commands to fetch the same data without starting a server. These complete in under 2s. External server configurations still use the existing HTTP SDK path. When CLI commands fail non-zero, surface the error through the existing fallback() path instead of silently returning empty inventory. Also adds missing loadInventoryFromCli stubs to OpenCodeAdapter and OpenCodeTextGeneration test doubles, and fixes regex nullability issues.
Adds 11 tests for parseModelsCliOutput and parseAgentListCliOutput covering: - Single and multiple providers/models - Empty input handling - Unparseable JSON graceful degradation - CRLF line endings - Complex nested permission blocks - Variants and nested model fields
122303c to
b981159
Compare
…ully Retry 'opencode models --verbose' and 'opencode agent list' once after 1s on failure to handle SQLite 'database is locked' contention with concurrent opencode serve processes. Return empty inventory on persistent failure (warning status, not error) so the health check remains resilient.
Update AGENT_HEADER_RE to capture everything before the (mode) suffix instead of only non-whitespace tokens. Adds tests for names with spaces and for the known-hidden-agent flag.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 3983e4a. Configure here.

What Changed
The OpenCode provider health check no longer spawns
opencode serveto fetch inventory (models and agents). Instead, it runs two CLI commands directly:opencode models --verboseto get all connected models with full metadataopencode agent listto get agents with permission rulesExternal server configurations (where
serverUrlis set) still use the existing HTTP SDK path unchanged.CLI commands are retried once after 1s on transient failures (e.g. SQLite "database is locked" contention with concurrent serve processes). CLI failure degrades gracefully to empty inventory (warning status) instead of error status.
Why
The health check spawns a full
opencode serveprocess just to call two HTTP endpoints (provider.listandapp.agents). Under heavy load (git operations, port discovery, diagnostics queries all running concurrently), this server startup takes 15-20s+ (see #4132), causing the health check to time out and show an error to the user.The CLI commands
opencode models --verboseandopencode agent listreturn the same data without starting any server, and complete in under 2s regardless of system load.Checklist
Note
Medium Risk
Changes provider status probing and model/agent discovery for local installs; external-server path is unchanged but parsing CLI output could diverge from SDK data if formats drift.
Overview
Local OpenCode provider health checks no longer start
opencode serveor use the HTTP SDK to load models and agents.checkOpenCodeProviderStatuscalls the newloadInventoryFromClipath, which runsopencode models --verboseandopencode agent listin parallel, with a one-second retry on transient CLI failures.Runtime support adds CLI output parsers (
parseModelsCliOutput,parseAgentListCliOutput) and maps results into the same inventory shape the SDK used. CLI inventory failures return empty providers/agents instead of failing the probe, so local installs can show warning with zero models rather than error. ConfiguredserverUrlinstalls still use scoped server connect +loadOpenCodeInventory.Tests are updated for no local server teardown on health check and for graceful degradation when CLI inventory fails.
Reviewed by Cursor Bugbot for commit e2f8d52. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Fix OpenCode health check to use CLI instead of spawning a local server
serverUrl),checkOpenCodeProviderStatusnow callsloadInventoryFromCliinstead of spawning or connecting to a local server during health checks.loadInventoryFromClirunsopencode models --verboseandopencode agent listin parallel, retries once on transient failure, and degrades gracefully by returning empty inventory rather than failing.connectToOpenCodeServerwith SDK and optionalserverPassword.closeCallsdrops from 1 to 0); CLI failures now yield awarningstatus with zero models instead of an error.Macroscope summarized e2f8d52.