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
+24 -1
View File
@@ -154,7 +154,16 @@ export class SelectedRuntimeManager implements SelectedRuntimeResolver {
async getStatus(
selection: AgentRuntimeSelection
): Promise<AgentRuntimeStatus> {
return (await this.getRuntime(selection)).getStatus()
if (this.disposed) {
throw new Error('Agent Runtime 正在关闭')
}
const operation = this.runStatusProbe(selection)
this.tests.add(operation)
try {
return await operation
} finally {
this.tests.delete(operation)
}
}
async testStatus(
@@ -276,6 +285,20 @@ export class SelectedRuntimeManager implements SelectedRuntimeResolver {
}
}
private async runStatusProbe(
selection: AgentRuntimeSelection
): Promise<AgentRuntimeStatus> {
const runtime = await this.createRuntime(selection)
try {
if (this.disposed) {
throw new Error('Agent Runtime 正在关闭')
}
return await runtime.getStatus()
} finally {
await runtime.dispose()
}
}
private async runNativeSnapshot(
selection: AgentRuntimeSelection,
executionSpace?: ExecutionSpaceDescriptor