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:
@@ -510,6 +510,44 @@ describe('SelectedRuntimeManager', () => {
|
||||
await manager.dispose()
|
||||
})
|
||||
|
||||
it('answers owned questions after settings reset while rejecting new work', async () => {
|
||||
const active = runtime()
|
||||
active.value.respondToQuestion = vi.fn(async () => undefined)
|
||||
active.value.run = async function* (request) {
|
||||
yield {
|
||||
requestId: request.requestId, type: 'question', questionId: 'retained-question',
|
||||
questions: [{ header: 'Choice', question: 'Continue?', options: [], multiple: false, custom: true }]
|
||||
}
|
||||
yield { requestId: request.requestId, type: 'done' }
|
||||
}
|
||||
const manager = new SelectedRuntimeManager(async () => active.value)
|
||||
const controller = await manager.getRuntime({ provider: 'opencode' }, executionSpace('project-one'))
|
||||
const stream = controller.run({
|
||||
requestId: 'retained-request', conversationId: 'retained-conversation',
|
||||
prompt: 'Ask a question', workMode: 'execute'
|
||||
}, new AbortController().signal)
|
||||
try {
|
||||
expect((await stream.next()).value?.type).toBe('question')
|
||||
await manager.reset()
|
||||
expect(active.dispose).not.toHaveBeenCalled()
|
||||
await expect(controller.respondToQuestion('unknown-question', [['Yes']]))
|
||||
.rejects.toThrow('正在关闭')
|
||||
await expect(controller.respondToQuestion('retained-question', [['Yes']]))
|
||||
.resolves.toBeUndefined()
|
||||
expect(active.value.respondToQuestion).toHaveBeenCalledWith('retained-question', [['Yes']])
|
||||
await expect(controller.run({
|
||||
requestId: 'new-request', conversationId: 'new-conversation',
|
||||
prompt: 'New work', workMode: 'execute'
|
||||
}, new AbortController().signal).next()).rejects.toThrow('正在关闭')
|
||||
expect((await stream.next()).value?.type).toBe('done')
|
||||
await stream.next()
|
||||
await vi.waitFor(() => expect(active.dispose).toHaveBeenCalledOnce())
|
||||
} finally {
|
||||
await stream.return()
|
||||
await manager.dispose()
|
||||
}
|
||||
})
|
||||
|
||||
it('routes application exit through cached runtime controllers without ordinary disposal', async () => {
|
||||
const active = runtime()
|
||||
const detachForApplicationExit = vi.fn(() => undefined)
|
||||
@@ -595,7 +633,8 @@ describe('SelectedRuntimeManager', () => {
|
||||
await expect(
|
||||
manager.getRuntime(selection('43'))
|
||||
).rejects.toThrow(/退役容量/iu)
|
||||
expect(create).toHaveBeenCalledTimes(2)
|
||||
expect(create).toHaveBeenCalledTimes(3)
|
||||
expect(created[2]!.dispose).toHaveBeenCalledOnce()
|
||||
await manager.dispose()
|
||||
expect(created[0]!.dispose).toHaveBeenCalledOnce()
|
||||
expect(created[1]!.dispose).toHaveBeenCalledOnce()
|
||||
@@ -607,7 +646,10 @@ describe('SelectedRuntimeManager', () => {
|
||||
finishCreate = resolve
|
||||
})
|
||||
const created = runtime()
|
||||
const create = vi.fn(async () => await pendingCreate)
|
||||
const rejected = runtime()
|
||||
const create = vi.fn()
|
||||
.mockReturnValueOnce(pendingCreate)
|
||||
.mockResolvedValueOnce(rejected.value)
|
||||
const manager = new SelectedRuntimeManager(create, 1, 1)
|
||||
const selection = (suffix: string) => ({
|
||||
provider: 'model' as const,
|
||||
@@ -622,7 +664,8 @@ describe('SelectedRuntimeManager', () => {
|
||||
await expect(
|
||||
manager.getRuntime(selection('52'))
|
||||
).rejects.toThrow(/退役容量/iu)
|
||||
expect(create).toHaveBeenCalledOnce()
|
||||
expect(create).toHaveBeenCalledTimes(2)
|
||||
expect(rejected.dispose).toHaveBeenCalledOnce()
|
||||
|
||||
finishCreate(created.value)
|
||||
await expect(firstRuntime).resolves.toEqual(
|
||||
|
||||
Reference in New Issue
Block a user