Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): recover stale cua-driver sessions
Dash9defa10bafd1
diff --git a/apps/desktop/src/main/mcp-integrations/__tests__/computer.test.ts b/apps/desktop/src/main/mcp-integrations/__tests__/computer.test.tsindex 97f237ce30..76e765ad93 100644--- a/apps/desktop/src/main/mcp-integrations/__tests__/computer.test.ts+++ b/apps/desktop/src/main/mcp-integrations/__tests__/computer.test.ts@@ -1363,6 +1363,51 @@ describe('computer mcp integration', () => {);});+ it('rotates and retries when cua-driver rejects a call because the named session has ended', async () => {+ mcpCallToolMock.mockImplementation((call: { name: string; arguments: Record<string, unknown> }) => {+ if (call.name === 'end_session') {+ return { content: [{ type: 'text', text: '{"ok":true}' }] };+ }+ if (call.name === 'list_windows') {+ const generation = driverSessionGeneration(+ String(call.arguments.session),+ 'session-ended-rejected',+ );+ if (generation === 0) {+ return {+ isError: true,+ content: [{+ type: 'text',+ text: `session '${String(call.arguments.session)}' has ended; tool call '${call.name}' was rejected`,+ }],+ };+ }+ return {+ content: [{ type: 'text', text: '{"ok":true,"windows":[{"window_id":9}]}' }],+ };+ }+ throw new Error(`unexpected call ${call.name}`);+ });++ await expect(callComputerDriverTool('list_windows', {+ session: 'caller-supplied',+ }, { sessionId: 'session-ended-rejected' })).resolves.toEqual({+ ok: true,+ windows: [{ window_id: 9 }],+ });++ expect(mcpConnectMock).toHaveBeenCalledTimes(2);+ expect(mcpCloseMock).toHaveBeenCalledTimes(1);+ const listCalls = mcpCallToolMock.mock.calls+ .map((call) => call[0])+ .filter((call) => call?.name === 'list_windows');+ expectDriverSessionGenerations(+ listCalls.map((call) => (call?.arguments as { session: string }).session),+ 'session-ended-rejected',+ [0, 1],+ );+ });+it('rotates the driver session and retries once when cua-driver reports not connected', async () => {mcpCallToolMock.mockRejectedValueOnce(new Error('Not connected'))diff --git a/apps/desktop/src/main/mcp-integrations/computer.ts b/apps/desktop/src/main/mcp-integrations/computer.tsindex 6bfcddeb7d..421fc930a9 100644--- a/apps/desktop/src/main/mcp-integrations/computer.ts+++ b/apps/desktop/src/main/mcp-integrations/computer.ts@@ -1987,12 +1987,16 @@ function splitTypeTextChunks(text: string): string[] {* `callCuaMcpTool` 和 `shouldRetryWithFreshCuaSession` 使用,避免某种* plain text 结果被提升成错误后却没有进入一次性重试分支。*/-const STALE_CUA_SESSION_MARKER_RE = /session ended; tool call ignored|not connected/i;+const STALE_CUA_SESSION_MARKER_RE =+ /session(?:\s+['"`][^'"`\r\n]+['"`])?\s+(?:has\s+)?ended\b|not connected/i;function shouldCleanupCuaMcpSessionAfterError(err: unknown): boolean {const message = err instanceof Error ? err.message : String(err);if (/timed out after/.test(message)) return true;- return /transport (?:closed|error)|read ECONNRESET|write EPIPE|connection closed|stream closed|session ended|not connected/i.test(message);+ return (+ STALE_CUA_SESSION_MARKER_RE.test(message) ||+ /transport (?:closed|error)|read ECONNRESET|write EPIPE|connection closed|stream closed/i.test(message)+ );}function shouldRetryWithFreshCuaSession(name: ComputerMcpToolName, err: unknown): boolean {