fix: release runtime status probes after checks

Chat startup and Runtime switching previously cached status-only Runtime instances, leaving managed OpenCode servers running without active conversations. Status checks now resolve the selected or configured default Runtime through a disposable probe and release it immediately.

Project execution Runtimes remain cached by model selection and execution space, preserving parallel work across different projects.

Release note: 修复启动或切换 Runtime 后空闲 OpenCode 服务持续驻留的问题;状态检查完成后会立即回收,多个项目仍可并行执行。
This commit is contained in:
mesalogo
2026-08-31 01:35:04 +08:00
parent 8c580a9174
commit f6f8d5e053
5 changed files with 75 additions and 6 deletions
@@ -265,6 +265,29 @@ describe('SelectedRuntimeManager', () => {
await manager.dispose()
})
it('disposes a status-probe runtime without caching it', async () => {
const probed = runtime()
const cached = runtime()
const create = vi
.fn()
.mockResolvedValueOnce(probed.value)
.mockResolvedValueOnce(cached.value)
const manager = new SelectedRuntimeManager(create)
const selection = { provider: 'opencode' as const }
await expect(manager.getStatus(selection)).resolves.toMatchObject({
available: true
})
expect(probed.value.getStatus).toHaveBeenCalledOnce()
expect(probed.testConnection).not.toHaveBeenCalled()
expect(probed.dispose).toHaveBeenCalledOnce()
await manager.getRuntime(selection)
expect(create).toHaveBeenCalledTimes(2)
await manager.dispose()
expect(cached.dispose).toHaveBeenCalledOnce()
})
it('disposes a native-inventory runtime without caching it', async () => {
const inspected = runtime()
const cached = runtime()