Skip to content

fix(server): use CLI for OpenCode health check instead of spawning server#4153

Merged
juliusmarminge merged 12 commits into
pingdotgg:mainfrom
UtkarshUsername:fix/opencode-health-check-cli
Jul 20, 2026
Merged

fix(server): use CLI for OpenCode health check instead of spawning server#4153
juliusmarminge merged 12 commits into
pingdotgg:mainfrom
UtkarshUsername:fix/opencode-health-check-cli

Conversation

@UtkarshUsername

@UtkarshUsername UtkarshUsername commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

What Changed

The OpenCode provider health check no longer spawns opencode serve to fetch inventory (models and agents). Instead, it runs two CLI commands directly:

  • opencode models --verbose to get all connected models with full metadata
  • opencode agent list to get agents with permission rules

External server configurations (where serverUrl is 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 serve process just to call two HTTP endpoints (provider.list and app.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 --verbose and opencode agent list return the same data without starting any server, and complete in under 2s regardless of system load.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes
  • I included a video for animation/interaction changes

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 serve or use the HTTP SDK to load models and agents. checkOpenCodeProviderStatus calls the new loadInventoryFromCli path, which runs opencode models --verbose and opencode agent list in 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. Configured serverUrl installs 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

  • For local installs (no serverUrl), checkOpenCodeProviderStatus now calls loadInventoryFromCli instead of spawning or connecting to a local server during health checks.
  • loadInventoryFromCli runs opencode models --verbose and opencode agent list in parallel, retries once on transient failure, and degrades gracefully by returning empty inventory rather than failing.
  • External server behavior is unchanged: connections still go through connectToOpenCodeServer with SDK and optional serverPassword.
  • Behavioral Change: health checks for local installs no longer create a local server scope (closeCalls drops from 1 to 0); CLI failures now yield a warning status with zero models instead of an error.

Macroscope summarized e2f8d52.

@coderabbitai

coderabbitai Bot commented Jul 19, 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

Run ID: 2dc24c30-27a5-461d-9f1b-d2c100c4f1fc

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
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 size:L 100-499 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. labels Jul 19, 2026
@UtkarshUsername
UtkarshUsername marked this pull request as draft July 19, 2026 12:37
Comment thread apps/server/src/provider/Layers/OpenCodeProvider.ts
Comment thread apps/server/src/provider/opencodeRuntime.ts
@macroscopeapp

macroscopeapp Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: 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
@UtkarshUsername
UtkarshUsername force-pushed the fix/opencode-health-check-cli branch from 122303c to b981159 Compare July 19, 2026 14:31
Comment thread apps/server/src/provider/opencodeRuntime.ts
UtkarshUsername and others added 3 commits July 19, 2026 23:54
…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.
@UtkarshUsername
UtkarshUsername marked this pull request as ready for review July 19, 2026 19:32
Comment thread apps/server/src/provider/opencodeRuntime.ts
Comment thread apps/server/src/provider/opencodeRuntime.ts
Comment thread apps/server/src/provider/opencodeRuntime.ts Outdated
UtkarshUsername and others added 4 commits July 20, 2026 02:18
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.

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.

Fix All in Cursor

❌ 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.

Comment thread apps/server/src/provider/opencodeRuntime.ts
Comment thread apps/server/src/provider/opencodeRuntime.ts
@juliusmarminge
juliusmarminge merged commit 0ca3240 into pingdotgg:main Jul 20, 2026
14 checks passed
adamfgr pushed a commit to agriffiths-bots/t3code that referenced this pull request Jul 21, 2026
* fix(server): resolve Claude SDK executable path on Windows npm installs (pingdotgg#3740)

* Fix project action preview settings persistence (pingdotgg#3842)

* fix(desktop): allow clipboard writes in the preview browser (pingdotgg#3889)

* fix(web): handle sidebar shortcut before editors (pingdotgg#3921)

* fix(server): recognize Bedrock-backed Claude as authenticated (pingdotgg#3931)

* Fix incorrect pluralization of “entry” (pingdotgg#3933)

* feat(server): title background-task work-log rows with the task name (pingdotgg#3751)

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>

* fix: delegate OpenCode session titles to provider (pingdotgg#3720)

* Archive selected threads from the context menu (pingdotgg#3895)

* fix(cli): support force removing projects (pingdotgg#3922)

* fix: allow sidebar to be shrunk when wider than viewport (pingdotgg#2456)

Co-authored-by: Shoaib Ansari <shoaibansari@Shoaibs-Mac-mini.local>
Co-authored-by: Julius Marminge <julius0216@outlook.com>

* fix(codex): show web search query and url in tool call details (pingdotgg#2093)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

* Add Codex launch arguments setting (pingdotgg#2892)

Co-authored-by: Julius Marminge <julius0216@outlook.com>
Co-authored-by: Julius Marminge <jmarminge@gmail.com>
Co-authored-by: root <root@localhost.localdomain>

* [orchestration] Clear stale active turn when session becomes inactive (pingdotgg#3159)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

* Regenerate Codex reset credit protocol bindings (pingdotgg#4173)

Co-authored-by: codex <codex@users.noreply.github.com>

* fix(preview): preserve direct localhost navigation (pingdotgg#3939)

Co-authored-by: Julius Marminge <julius0216@outlook.com>
Co-authored-by: codex <codex@users.noreply.github.com>

* Synchronize mobile threads with authoritative shell snapshots (pingdotgg#4163)

Co-authored-by: codex <codex@users.noreply.github.com>

* Gate iOS glass layout on native support (pingdotgg#4032)

Co-authored-by: codex <codex@users.noreply.github.com>

* fix(opencode): resume the OpenCode session on follow-ups instead of starting an empty one (pingdotgg#3617)

Co-authored-by: codex <codex@users.noreply.github.com>

* fix(server): use CLI for OpenCode health check instead of spawning server (pingdotgg#4153)

* fix(web): scope timeline minimap hover target to the side gutter (pingdotgg#3869)

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>

* [codex] show complete approval details (pingdotgg#4111)

* fix(web): paint text selection over composer chips (pingdotgg#4139)

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>

* [codex] preserve custom model slugs (pingdotgg#4168)

* fix(web): preview workspace images in the file panel (pingdotgg#3996)

Co-authored-by: Rhiz3K <rhiz3k@protonmail.com>
Co-authored-by: Julius Marminge <julius0216@outlook.com>

* feat(web): drag files from the explorer into the chat composer (pingdotgg#4140)

Co-authored-by: Julius Marminge <julius0216@outlook.com>
Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>

* fix(desktop): preserve main window bounds (pingdotgg#3851)

Co-authored-by: Julius Marminge <julius0216@outlook.com>
Co-authored-by: codex <codex@users.noreply.github.com>

* perf(orchestration): speed up new-chat propagation and offline catch-up (pingdotgg#4177)

Co-authored-by: codex <codex@users.noreply.github.com>
Co-authored-by: Julius Marminge <julius0216@outlook.com>

* Finale: upgrade changed files card to fix various UI issues (pingdotgg#4113)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

* fix(web): always show environment chip for remote projects (pingdotgg#4217)

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>

* chore: reconcile upstream sync (20260721) — typecheck/test fixups

Post-cherry-pick reconciliation of the shell/thread sync rewrite:
- adopt upstream's client shell.ts + shell-sync.test.ts (drops the fork's
  superseded #142 replay-gap watchdog; server no longer emits 'caught-up')
- remove the orphaned 'caught-up' contract member and obsolete fork shell
  server tests (upstream's coalescing tests cover the behavior)
- keep the fork's thread reconciliation, resubscribing via subscribeDynamic
  (establish base once; foreground/session resubscribe via the live cursor)
- add latestSequence to OrchestrationEngine test mocks; thread dispatch
  authority in bin.test; narrow stream-item unions past the new 'synchronized'

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

---------

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
Co-authored-by: David Whatley <nsxdavid@gmail.com>
Co-authored-by: coach007 <6238600+keeperxy@users.noreply.github.com>
Co-authored-by: Carlos Rico-Ospina <carlosricojr@gmail.com>
Co-authored-by: Andrew Barnes <bortstheboat@gmail.com>
Co-authored-by: Pieter van Zyl <20579513+PieterVanZyl-Dev@users.noreply.github.com>
Co-authored-by: mel <mcmelon@nodiumhosting.com>
Co-authored-by: Theo Browne <me@t3.gg>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Co-authored-by: Tristan Knight <tris203@gmail.com>
Co-authored-by: Christoph Herzog <a.github@omega-id.com>
Co-authored-by: Shoaib <shoaib050326@gmail.com>
Co-authored-by: Shoaib Ansari <shoaibansari@Shoaibs-Mac-mini.local>
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Co-authored-by: Guilherme Vieira <46866023+GuilhermeVieiraDev@users.noreply.github.com>
Co-authored-by: James <105842516+jamesx0416@users.noreply.github.com>
Co-authored-by: Julius Marminge <jmarminge@gmail.com>
Co-authored-by: root <root@localhost.localdomain>
Co-authored-by: Andrew Forster <76947376+Andrew-Forster@users.noreply.github.com>
Co-authored-by: codex <codex@users.noreply.github.com>
Co-authored-by: Chris Michael Guzman <67719167+Chrrxs@users.noreply.github.com>
Co-authored-by: Vadym Kotai <vdmkotai@gmail.com>
Co-authored-by: Utkarsh Patil <73941998+UtkarshUsername@users.noreply.github.com>
Co-authored-by: xxashxx-svg <xxanshxx9@gmail.com>
Co-authored-by: Maxwell Young <maxtheyoung@gmail.com>
Co-authored-by: Yordis Prieto <yordis.prieto@gmail.com>
Co-authored-by: Rhiz3K <33246262+Rhiz3K@users.noreply.github.com>
Co-authored-by: Rhiz3K <rhiz3k@protonmail.com>
Co-authored-by: Anirudh Coontoor <me@anirudhs.net>
Co-authored-by: Rusiru Sadathana <rusirusadathana@gmail.com>
Co-authored-by: ss <69873514+sandersonstabo@users.noreply.github.com>
Co-authored-by: wizzoapp[bot] <254688279+wizzoapp[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants