diff --git a/CHANGELOG.md b/CHANGELOG.md index 224f37ab4..10460860c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - macOS menu: device list now uses `node.list` (devices only; no agent/tool presence entries). - macOS menu: device list now shows connected nodes only. - iOS node: fix ReplayKit screen recording crash caused by queue isolation assertions during capture. +- CLI: avoid spurious gateway close errors after successful request/response cycles. ## 2.0.0-beta4 — 2025-12-27 diff --git a/src/gateway/call.ts b/src/gateway/call.ts index 3ebdcd0dd..c2b14623b 100644 --- a/src/gateway/call.ts +++ b/src/gateway/call.ts @@ -25,6 +25,7 @@ export async function callGateway( const timeoutMs = opts.timeoutMs ?? 10_000; return await new Promise((resolve, reject) => { let settled = false; + let ignoreClose = false; const stop = (err?: Error, value?: T) => { if (settled) return; settled = true; @@ -49,19 +50,23 @@ export async function callGateway( const result = await client.request(opts.method, opts.params, { expectFinal: opts.expectFinal, }); - client.stop(); + ignoreClose = true; stop(undefined, result); + client.stop(); } catch (err) { + ignoreClose = true; client.stop(); stop(err as Error); } }, onClose: (code, reason) => { + if (settled || ignoreClose) return; stop(new Error(`gateway closed (${code}): ${reason}`)); }, }); const timer = setTimeout(() => { + ignoreClose = true; client.stop(); stop(new Error("gateway timeout")); }, timeoutMs);