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:
@@ -138,6 +138,13 @@ export class RemotePromptRecoveryUnavailableError extends Error {
|
||||
}
|
||||
}
|
||||
|
||||
export class RemotePromptCancelledError extends Error {
|
||||
constructor(message: string, options?: ErrorOptions) {
|
||||
super(message, options)
|
||||
this.name = 'RemotePromptCancelledError'
|
||||
}
|
||||
}
|
||||
|
||||
type ActivePrompt = {
|
||||
reportedQuestions?: Set<string>
|
||||
subagentProgress?: OpenCodeSubagentProgress
|
||||
@@ -1016,9 +1023,7 @@ export class AcpRemoteRuntime implements AgentRuntime {
|
||||
false
|
||||
).catch(() => undefined)
|
||||
if (
|
||||
result?.status === 'terminal' &&
|
||||
(result.processTree === 'empty' ||
|
||||
result.terminalState === 'completed')
|
||||
result?.status === 'terminal'
|
||||
) {
|
||||
const terminal = await this.persist(
|
||||
context,
|
||||
@@ -1310,6 +1315,7 @@ export class AcpRemoteRuntime implements AgentRuntime {
|
||||
return runtimeSessionBindingSchema.parse({
|
||||
bindingId,
|
||||
...this.options.identity,
|
||||
controllerGeneration: context.channel.generation,
|
||||
conversationId,
|
||||
runtimeId: this.options.runtimeId,
|
||||
acpSessionId: `opening-${randomUUID()}`,
|
||||
@@ -1353,6 +1359,15 @@ export class AcpRemoteRuntime implements AgentRuntime {
|
||||
'没有可安全附加的远端 Agent 请求,且恢复不会重放任务'
|
||||
)
|
||||
}
|
||||
if (
|
||||
request.remoteRecoveryOnly === true &&
|
||||
binding &&
|
||||
!this.bindingIdentityMatches(binding)
|
||||
) {
|
||||
throw new RemotePromptRecoveryUnavailableError(
|
||||
'原远端 Agent 或 Runtime 已变更,无法恢复原请求且不会重放任务'
|
||||
)
|
||||
}
|
||||
if (
|
||||
request.remoteRecoveryOnly !== true &&
|
||||
this.options.modelProfile !== undefined &&
|
||||
@@ -1741,6 +1756,11 @@ export class AcpRemoteRuntime implements AgentRuntime {
|
||||
current.context,
|
||||
current.binding
|
||||
)
|
||||
current.binding = await this.rotateBindingTransport(
|
||||
current.binding,
|
||||
current.context,
|
||||
signal
|
||||
)
|
||||
current.binding = await this.persist(
|
||||
current.context,
|
||||
current.binding,
|
||||
@@ -2685,9 +2705,10 @@ export class AcpRemoteRuntime implements AgentRuntime {
|
||||
)
|
||||
session.binding = binding
|
||||
if (terminal.state === 'cancelled') {
|
||||
throw signal.aborted
|
||||
? abortReason(signal)
|
||||
: new Error('远端 Runtime 请求已取消')
|
||||
throw new RemotePromptCancelledError(
|
||||
'远端 Runtime 请求已取消',
|
||||
signal.aborted ? { cause: abortReason(signal) } : undefined
|
||||
)
|
||||
}
|
||||
if (terminal.state === 'failed') {
|
||||
throw new Error(
|
||||
@@ -2810,6 +2831,14 @@ export class AcpRemoteRuntime implements AgentRuntime {
|
||||
signal,
|
||||
authorize
|
||||
)
|
||||
} catch (error) {
|
||||
if (signal.aborted && session.binding.state === 'closed') {
|
||||
throw new RemotePromptCancelledError(
|
||||
error instanceof Error ? error.message : '远端 Runtime 请求已取消',
|
||||
{ cause: error }
|
||||
)
|
||||
}
|
||||
throw error
|
||||
} finally {
|
||||
this.sessionReservations.delete(request.conversationId)
|
||||
this.notifyDrain()
|
||||
|
||||
Reference in New Issue
Block a user