fix(server): stop restoring stale OpenCode models#4095
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 runtime behavior for OpenCode model state management, determining when models are dropped vs retained during refresh failures. While well-tested and clearly a targeted bug fix, it affects user-facing model visibility and is the author's first change to this file. You can customize Macroscope's approvability policy. Learn more. |
Treat successful OpenCode inventories, logout, disablement, and confirmed CLI removal as authoritative while preserving the last known-good models during startup and failed or partial probes. Add focused merge and cache-persistence coverage for removal, pending, failure, uninstall, and reconnect behavior. Co-authored-by: codex <codex@users.noreply.github.com>
39b459d to
d381546
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit d381546. Configure here.
- 模型清单命令重试失败后返回探测错误,避免伪装成权威空清单。\n- Agent 元数据查询仍允许降级,不影响已成功获取的模型清单。\n- 更新本地探测回归测试,并通过目标测试、vp check 与类型检查。
Co-authored-by: codex <codex@users.noreply.github.com>
Co-authored-by: codex <codex@users.noreply.github.com>

Closes #4056.
Summary
Verification
corepack pnpm exec vp test run apps/server/src/provider/Layers/ProviderRegistry.test.tscorepack pnpm exec vp run typecheckcorepack pnpm exec vp check(passes with existing warnings outside this change)Note
Medium Risk
Changes provider snapshot merge and OpenCode inventory semantics, which affects which models users see and cached provider state, but scope is limited to the OpenCode driver with broad test coverage.
Overview
Fixes OpenCode model lists staying populated with removed plugins/models after a successful refresh by making merge logic status-aware for the OpenCode driver only.
ProviderRegistry adds
shouldRetainMissingProviderModels: stale models are kept only while the initial probe is still pending (warning+ not yetinstalled) or when an installed provider refresh fails (error). Successful refreshes—including an empty list after logout or plugin removal—replace the cached models instead of unioning with the previous snapshot. Other drivers still retain prior models when a refresh returns an empty list.OpenCode CLI inventory no longer swallows
opencode modelsfailures as an empty inventory; model load errors propagate so health checks surfaceerrorwith a clear message instead ofwarningwith a misleading empty catalog. Agent CLI failures may still degrade to an empty agent list.Tests cover merge cases, cache persistence after authoritative removals, and the updated provider status behavior.
Reviewed by Cursor Bugbot for commit 4892bef. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Stop restoring stale OpenCode models after a successful model inventory refresh
mergeProviderModelsnow uses a newshouldRetainMissingProviderModelshelper to decide whether models absent from the latest snapshot should be kept. For OpenCode, missing models are only retained when the provider is pending its initial probe or reports an error status; otherwise the fresh inventory is authoritative and stale models are dropped.loadInventoryFromCliin opencodeRuntime.ts now fails with anOpenCodeRuntimeErrorwhen the models CLI process exits non-zero, instead of silently returning an empty inventory. Agent loading remains best-effort.errorstatus rather thanwarning, and a failed CLI health check produces an explicit error message instead of an empty model list.Macroscope summarized 4892bef.