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:
@@ -615,6 +615,50 @@ describe('model bridge loopback helper', () => {
|
||||
describe('model bridge Unix broker', () => {
|
||||
const runOnUnix = process.platform === 'win32' ? it.skip : it
|
||||
|
||||
runOnUnix('routes shared Sessions concurrently and rejects queued work after its operation ends', async () => {
|
||||
let unblock!: () => void
|
||||
const blocked = new Promise<void>(resolve => { unblock = resolve })
|
||||
const dispatchOne = vi.fn(async () => { await blocked; return validResponse })
|
||||
const dispatchTwo = vi.fn(async () => validResponse)
|
||||
const brokers = [dispatchOne, dispatchTwo].map(dispatch => new ModelBridgeBrokerServer({
|
||||
scratchDirectory: privateTemporaryDirectory(), dispatch
|
||||
}))
|
||||
const fallback = vi.fn(async () => validResponse)
|
||||
const proxy = new ModelBridgeLoopbackProxy({ exchange: fallback, sharedSessions: true })
|
||||
await Promise.all(brokers.map(broker => broker.listen()))
|
||||
const origin = await proxy.listen()
|
||||
const route = (sessionId: string, operationId: string, index: number) => fetch(`${origin}/session`, {
|
||||
method: 'POST', body: JSON.stringify({ sessionId, operationId, socketPath: brokers[index]!.socketPath, workMode: 'execute' })
|
||||
})
|
||||
const prompt = (sessionId: string, operationId: string) => fetch(`${origin}/v1/messages`, {
|
||||
method: 'POST', headers: { 'content-type': 'application/json', 'x-goodbuddy-session': sessionId, 'x-goodbuddy-operation': operationId },
|
||||
body: '{"model":"fixture"}'
|
||||
})
|
||||
try {
|
||||
expect((await route('one', 'operation-1', 0)).ok).toBe(true)
|
||||
expect((await route('two', 'operation-2', 1)).ok).toBe(true)
|
||||
const first = prompt('one', 'operation-1')
|
||||
await vi.waitFor(() => expect(dispatchOne).toHaveBeenCalledOnce())
|
||||
const queued = prompt('one', 'operation-1')
|
||||
expect((await prompt('two', 'operation-2')).status).toBe(201)
|
||||
await route('one', 'next-operation', 0)
|
||||
unblock()
|
||||
expect((await first).status).toBe(201)
|
||||
expect((await queued).status).toBe(409)
|
||||
expect((await prompt('one', 'operation-1')).status).toBe(409)
|
||||
expect((await prompt('one', 'next-operation')).status).toBe(201)
|
||||
expect(dispatchOne).toHaveBeenCalledTimes(2)
|
||||
expect(fallback).not.toHaveBeenCalled()
|
||||
for (const dispatch of [dispatchOne, dispatchTwo]) {
|
||||
expect(dispatch.mock.calls[0]?.[0]).not.toHaveProperty('headers.x-goodbuddy-session')
|
||||
}
|
||||
} finally {
|
||||
unblock()
|
||||
await proxy.close()
|
||||
await Promise.all(brokers.map(broker => broker.close()))
|
||||
}
|
||||
})
|
||||
|
||||
it('allows a delayed connection with the default unlimited request timeout', async () => {
|
||||
const socket = new Duplex({
|
||||
read() {},
|
||||
|
||||
Reference in New Issue
Block a user