diff --git a/src/main/computer/sidecar-client.test.ts b/src/main/computer/sidecar-client.test.ts index c7041ca87..67e68278e 100644 --- a/src/main/computer/sidecar-client.test.ts +++ b/src/main/computer/sidecar-client.test.ts @@ -79,4 +79,28 @@ describe('computer sidecar client', () => { await expect(secondCall).resolves.toEqual({ supports: { screenshots: true } }) }) + + it('starts a replacement sidecar after the active child errors', async () => { + const firstCall = callComputerSidecarCapabilities() + const firstRejection = expect(firstCall).rejects.toThrow('active sidecar failed') + const firstChild = children[0]! + + firstChild.emit('error', new Error('active sidecar failed')) + await firstRejection + expect(firstChild.killed).toBe(true) + + const secondCall = callComputerSidecarCapabilities() + void secondCall.catch(() => undefined) + expect(children).toHaveLength(2) + const secondChild = children[1]! + const secondRequest = secondChild.sent[0]! + + secondChild.emit('message', { + id: secondRequest.id, + ok: true, + result: { supports: { screenshots: true } } + }) + + await expect(secondCall).resolves.toEqual({ supports: { screenshots: true } }) + }) }) diff --git a/src/main/computer/sidecar-client.ts b/src/main/computer/sidecar-client.ts index d0b5e99bc..d9e94d6d3 100644 --- a/src/main/computer/sidecar-client.ts +++ b/src/main/computer/sidecar-client.ts @@ -222,6 +222,10 @@ class ComputerSidecarProcess { if (this.child !== child) { return } + // Why: an active process error makes the IPC sidecar unreliable; restart + // on the next call instead of reusing a broken helper. + this.child = null + child.kill('SIGTERM') const wrapped = new RuntimeClientError('accessibility_error', error.message) for (const [id, pending] of this.pending) { clearTimeout(pending.timer)