fix: reuse runtime processes across project sessions
Multiple projects could spawn duplicate heavyweight runtimes, while settings changes and remote reconnection could cancel or strand native conversations. Share compatible local OpenCode and DeepSeek Harness process owners and Agent-owned ACP connections, retaining workspace routing, per-session modes, model attribution, question ownership, targeted cancellation and idle cleanup. Restore remote pending questions and terminal task projections across reconnect and desktop restart, and preserve accepted ordinary requests during settings replacement while cancelling expert-team parents with their replaced scheduler. Extend regression coverage and Agent type checks. Record measured resource and real-model validation results, including failures and limitations. Also include the conversation media-generation design drafts (not an implemented feature), documentation entry links and dedicated Linux test-directory guidance. Desktop and Agent changes must be delivered together for shared process results. Validation: typecheck and lint passed; staged content and documentation links checked. Prior full regression and live-model evidence are recorded in progress notes; no new full test suite or model calls were run for this commit. Release note: 多项目会话现在复用兼容的 OpenCode 和 DeepSeek Harness 进程,减少重复启动并保持工作区、工具和取消隔离。修复远端问答在断线、重启及配置更新后的恢复与状态同步问题,Desktop 与 Agent 需配套更新。
This commit is contained in:
@@ -76,7 +76,8 @@ export class SelectedRuntimeManager implements SelectedRuntimeResolver {
|
||||
DEFAULT_MAXIMUM_RETAINED_RUNTIMES,
|
||||
private readonly observeFailure?:
|
||||
DesktopDiagnosticFailureObserver,
|
||||
private readonly createStatusRuntime = createRuntime
|
||||
private readonly createStatusRuntime = createRuntime,
|
||||
private readonly releaseSharedConversation?: (conversationId: string) => Promise<void>
|
||||
) {
|
||||
if (
|
||||
!Number.isSafeInteger(maximumCachedRuntimes) ||
|
||||
@@ -111,21 +112,6 @@ export class SelectedRuntimeManager implements SelectedRuntimeResolver {
|
||||
return existing.operation
|
||||
}
|
||||
this.evictIdleEntries(this.maximumCachedRuntimes - 1)
|
||||
if (this.entries.size >= this.maximumCachedRuntimes) {
|
||||
throw new Error(
|
||||
'Agent Runtime 缓存已被活动会话占满,请先关闭不再使用的会话'
|
||||
)
|
||||
}
|
||||
if (
|
||||
this.entries.size +
|
||||
this.retiringControllers.size +
|
||||
this.pendingRetirementControllers >=
|
||||
this.maximumRetainedRuntimes
|
||||
) {
|
||||
throw new Error(
|
||||
'Agent Runtime 退役容量已满,请先关闭仍由旧设置持有的会话'
|
||||
)
|
||||
}
|
||||
const operation = this.createRuntime(selection, executionSpace).then(
|
||||
async (runtime) => {
|
||||
if (
|
||||
@@ -135,6 +121,21 @@ export class SelectedRuntimeManager implements SelectedRuntimeResolver {
|
||||
await runtime.dispose()
|
||||
throw new Error('Runtime 设置已更改,请重新选择')
|
||||
}
|
||||
if (!runtime.sharedProcess) {
|
||||
const currentCount = [...this.entries.values()].filter(
|
||||
(candidate) => candidate !== entry && !candidate.controller?.sharedProcess
|
||||
).length
|
||||
const retiredCount = [...this.retiringControllers].filter(
|
||||
(candidate) => !candidate.sharedProcess
|
||||
).length + this.pendingRetirementControllers
|
||||
if (
|
||||
currentCount >= this.maximumCachedRuntimes ||
|
||||
currentCount + retiredCount >= this.maximumRetainedRuntimes
|
||||
) {
|
||||
await runtime.dispose()
|
||||
throw new Error('Agent Runtime 退役容量已满,请先关闭仍由旧设置持有的会话')
|
||||
}
|
||||
}
|
||||
const controller = new AgentRuntimeController(
|
||||
runtime,
|
||||
undefined,
|
||||
@@ -234,6 +235,7 @@ export class SelectedRuntimeManager implements SelectedRuntimeResolver {
|
||||
}
|
||||
|
||||
async releaseConversation(conversationId: string): Promise<void> {
|
||||
await this.releaseSharedConversation?.(conversationId)
|
||||
const controllers = await Promise.allSettled([
|
||||
...[...this.entries.values()].map(({ operation }) => operation)
|
||||
])
|
||||
|
||||
Reference in New Issue
Block a user