From 39b047ba96eeb9b0bac7547138c127972ad86c3d Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Wed, 21 Oct 2026 11:33:48 +0200 Subject: [PATCH 1/5] =?UTF-8?q?test:=20reproduce=20#790=20=E2=80=94=20daem?= =?UTF-8?q?on=20start=20never=20settles=20when=20the=20launched=20daemon?= =?UTF-8?q?=20closes=20the=20socket=20before=20hello?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cli/index.test.ts | 58 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/cli/index.test.ts b/src/cli/index.test.ts index 7a8a4f074..702e78dcc 100644 --- a/src/cli/index.test.ts +++ b/src/cli/index.test.ts @@ -1774,6 +1774,64 @@ describe("CLI: auto-launch's handshake cut short by the launched daemon (#684)", } }); + it("fails a start with DAEMON_STARTUP_FAILED, exit 1, when the daemon it launched closes the socket before the CLI's hello", async () => { + const directory = await mkdtemp(join(tmpdir(), "simlock-closed-")); + temporaryDirectories.push(directory); + const socketPath = join(directory, "daemon.sock"); + let accepted = 0; + // why: the daemon that refuses its history accepts the CLI's connection, then stops and + // closes it; the CLI is still reading `admin.token` then, so the close lands before `hello`. + const server = createServer((socket) => { + accepted += 1; + socket.destroy(); + }); + await new Promise((resolve) => server.listen(socketPath, resolve)); + try { + const real = new NodeIpcTransport(); + let launched = false; + const clock = new FakeClock(0); + const launcher = new FakeDaemonLauncher( + () => { + launched = true; + }, + { exit: { code: 1, signal: null } }, + ); + const ipc: IpcConnector = { + connect: async () => { + if (!launched) throw new IpcError("endpoint-not-found", "not yet", undefined); + const connection = await real.connect(socketPath); + await expect.poll(() => connection.closed).toBe(true); + return connection; + }, + }; + const output = outputCapture({ ...realCliEnvironmentPorts(), ipc, clock, launcher }); + let settled = false; + const run = runCli(["daemon", "start", "--token", "probe"], output.environmentWith()).then( + (code) => { + settled = true; + return code; + }, + ); + for (let tick = 0; tick < 100 && !settled; tick += 1) { + clock.advance(50); + await new Promise((resolve) => setTimeout(resolve, 5)); + } + expect(launcher.launches).toBe(1); + expect(accepted).toBe(1); + expect( + settled, + `simlock daemon start still had not settled at ${String(clock.now())}ms`, + ).toBe(true); + expect(await run).toBe(1); + expect(output.stdout).toBe(""); + expect(JSON.parse(output.stderr.trim().split("\n").at(-1)!)).toMatchObject({ + error: { code: "DAEMON_STARTUP_FAILED" }, + }); + } finally { + await new Promise((resolve) => server.close(() => resolve())); + } + }); + it.each([ { operation: "pending lease", health: "running" }, { operation: "pending lease", health: "starting" }, From 6f5fa1f52ce3ac0fc6c9df066f12dcf55ca3abf8 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Wed, 21 Oct 2026 11:53:21 +0200 Subject: [PATCH 2/5] fix(cli): reject sockets closed before the startup handshake (#790) --- src/cli/AGENTS.md | 2 +- src/cli/environment.ts | 52 ++++++++++++++++++++++---------------- src/simlock-client/wire.ts | 7 ++++- 3 files changed, 37 insertions(+), 24 deletions(-) diff --git a/src/cli/AGENTS.md b/src/cli/AGENTS.md index 305dbd7c3..ad500c53f 100644 --- a/src/cli/AGENTS.md +++ b/src/cli/AGENTS.md @@ -65,7 +65,7 @@ Surface: [CLI.md](../../docs/CLI.md) — every command, flag and exit code. first (a bad one fails on this stderr), launch the daemon detached, retry every 50 ms for `DAEMON_STARTUP_TIMEOUT_MS`; a launched daemon that exits fails the command at once with `startErrorFrom`'s text, unless another daemon answers a last connect. After a launch, `status.get` probes the connection - before handing it to a command, within that same deadline. A connection loss during this + before handing it to a command, within that same deadline. A connection loss during the handshake or this probe becomes `DAEMON_STARTUP_FAILED`; a silent probe times out with that code and starts closing its client without waiting for the daemon to end its side. An answered probe ends the window, including a `starting` status: subsequent command failures retain their original codes even while a lease queues or boots. diff --git a/src/cli/environment.ts b/src/cli/environment.ts index 8bf6171cf..476369262 100644 --- a/src/cli/environment.ts +++ b/src/cli/environment.ts @@ -35,7 +35,7 @@ class AutoLaunchAdminConnector { async connect(resolveCredential: () => Promise): Promise { try { - return await this.finishConnection(await this.connectClient(resolveCredential)); + return await this.finishConnection(this.connectClient(resolveCredential)); } catch (error: unknown) { if (!(await isUnavailable(error))) throw error; } @@ -52,7 +52,7 @@ class AutoLaunchAdminConnector { let lastError: unknown; while (this.clock.now() < deadline) { try { - return await this.finishConnection(await this.connectClient(resolveCredential)); + return await this.finishConnection(this.connectClient(resolveCredential)); } catch (error: unknown) { if (!(await isUnavailable(error))) throw error; lastError = error; @@ -77,7 +77,7 @@ class AutoLaunchAdminConnector { ): Promise { const output = await launched.readOutput().catch(() => ""); try { - return await this.finishConnection(await this.connectClient(resolveCredential)); + return await this.finishConnection(this.connectClient(resolveCredential)); } catch (error: unknown) { if (!(await isUnavailable(error))) throw error; } @@ -86,35 +86,43 @@ class AutoLaunchAdminConnector { throw new SimlockError("DAEMON_STARTUP_FAILED", "transport", startErrorFrom(exit, output), {}); } - private async finishConnection(client: SimlockAdminClient): Promise { - if (this.startupDeadline === undefined) return client; + private async finishConnection( + connecting: Promise, + ): Promise { const { isSimlockError, SimlockError } = await import("../contract/index.js"); - const remainingMs = Math.max(0, this.startupDeadline - this.clock.now()); + let client: SimlockAdminClient | undefined; let timer: ReturnType | undefined; let timedOut = false; - const timeout = new Promise((_resolve, reject) => { - timer = this.clock.setTimer(remainingMs, () => { - timedOut = true; - reject( - new SimlockError( - "DAEMON_STARTUP_FAILED", - "transport", - "Timed out starting simlock daemon: the startup status probe was not answered", - {}, - ), - ); - }); - }); try { + client = await connecting; + if (this.startupDeadline === undefined) return client; + const remainingMs = Math.max(0, this.startupDeadline - this.clock.now()); + const timeout = new Promise((_resolve, reject) => { + timer = this.clock.setTimer(remainingMs, () => { + timedOut = true; + reject( + new SimlockError( + "DAEMON_STARTUP_FAILED", + "transport", + "Timed out starting simlock daemon: the startup status probe was not answered", + {}, + ), + ); + }); + }); await Promise.race([client.getStatus(), timeout]); this.startupDeadline = undefined; return client; } catch (error: unknown) { // why: a daemon that went silent after `hello` never ends its side, so awaiting the close // would hang the start this deadline bounds; other failures close against a live peer. - if (timedOut) void client.close().catch(() => undefined); - else await client.close(); - if (isSimlockError(error) && error.code === "DAEMON_CONNECTION_LOST") { + if (timedOut) void client?.close().catch(() => undefined); + else await client?.close(); + if ( + this.startupDeadline !== undefined && + isSimlockError(error) && + error.code === "DAEMON_CONNECTION_LOST" + ) { throw new SimlockError( "DAEMON_STARTUP_FAILED", "transport", diff --git a/src/simlock-client/wire.ts b/src/simlock-client/wire.ts index 166500cbd..da30a048a 100644 --- a/src/simlock-client/wire.ts +++ b/src/simlock-client/wire.ts @@ -134,6 +134,11 @@ export class SimlockWire { new SimlockError("DAEMON_CONNECTION_LOST", "transport", "Daemon connection closed", {}), ), ); + if (connection.closed) { + this.#die( + new SimlockError("DAEMON_CONNECTION_LOST", "transport", "Daemon connection closed", {}), + ); + } } /** Sends `hello` and returns its reply, or throws the contract's typed mismatch/auth error. @@ -205,7 +210,6 @@ export class SimlockWire { * `client.ts` is responsible for input/output schema validation; this only moves bytes and * correlates frame ids. */ call(type: string, payload: unknown, hooks: CallHooks = {}): Promise { - if (this.#dead !== undefined) return Promise.reject(this.#dead); return this.#send(type, payload, hooks); } @@ -233,6 +237,7 @@ export class SimlockWire { } #send(type: string, payload: unknown, hooks: CallHooks): Promise { + if (this.#dead !== undefined) return Promise.reject(this.#dead); const id = this.#nextId++; return new Promise((resolve, reject) => { this.#pending.set(id, { ...hooks, reject, resolve }); From 9d0e065c6e587f32304311e9e72e46a0f19b2ef1 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Wed, 21 Oct 2026 11:54:37 +0200 Subject: [PATCH 3/5] test: report a closed handshake as a failed start only after launch (#790) --- src/mcp/connect.test.ts | 51 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/src/mcp/connect.test.ts b/src/mcp/connect.test.ts index 2adb9679c..ba5725ff1 100644 --- a/src/mcp/connect.test.ts +++ b/src/mcp/connect.test.ts @@ -160,3 +160,54 @@ describe("MCP: auto-launch's daemon that exits while starting (#760)", () => { expect(result).toBe("The daemon exited with code 3 while starting; see `simlock daemon logs`"); }); }); + +// why: the stdio host mocks this connector; this seam can force a socket to close before hello +// both in the launch loop and in the final connection after the launched process exits. +describe("MCP: a socket closed before hello (#790)", () => { + it("reports a closed handshake as a failed start only after launching the daemon", async () => { + for (const scenario of [ + { launch: false, afterExit: false, code: "DAEMON_CONNECTION_LOST", connects: 1 }, + { launch: true, afterExit: false, code: "DAEMON_STARTUP_FAILED", connects: 2 }, + { launch: true, afterExit: true, code: "DAEMON_STARTUP_FAILED", connects: 3 }, + ]) { + const transport = new MemoryIpcTransport(); + const socketPath = "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/simlock/daemon.sock"; + let accepted = 0; + const listen = () => + transport.listen(socketPath, (connection) => { + accepted += 1; + void connection.close(); + }); + if (!scenario.launch) await listen(); + const launcher = new FakeDaemonLauncher( + async () => { + await listen(); + }, + { exit: { code: 1, signal: null } }, + ); + let connects = 0; + const result = await connectWithAutoLaunch({ + clock: new FakeClock(0), + ipc: { + connect: async (endpoint) => { + connects += 1; + if (scenario.afterExit && connects === 2) { + throw new IpcError("endpoint-not-found", "not yet listening", undefined); + } + return transport.connect(endpoint); + }, + }, + launcher, + principal: "agent-1", + socketPath, + }).then( + () => ({ code: "connected" }), + (error: unknown) => error, + ); + expect(result, JSON.stringify(scenario)).toMatchObject({ code: scenario.code }); + expect(launcher.launches).toBe(scenario.launch ? 1 : 0); + expect(connects).toBe(scenario.connects); + expect(accepted).toBe(1); + } + }); +}); From bed5a270404e1720cd4a44f279bd9f2dad673aef Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Wed, 21 Oct 2026 11:55:40 +0200 Subject: [PATCH 4/5] fix(mcp): classify handshake loss after launch as startup failure (#790) --- src/mcp/AGENTS.md | 3 ++- src/mcp/connect.ts | 22 ++++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/mcp/AGENTS.md b/src/mcp/AGENTS.md index addfc4d78..6880d4127 100644 --- a/src/mcp/AGENTS.md +++ b/src/mcp/AGENTS.md @@ -43,7 +43,8 @@ Surface: [CLI.md](../../docs/CLI.md#simlock-mcp). (`connection-refused`, `endpoint-not-found`), retries every 50 ms for `startupTimeoutMs` (default `DAEMON_STARTUP_TIMEOUT_MS`), else `DAEMON_STARTUP_FAILED`; a launched daemon that exits fails at once with `startErrorFrom`'s text, unless another - daemon answers a last connect; + daemon answers a last connect; a connection lost during the launched daemon's handshake + is `DAEMON_STARTUP_FAILED`, while a pre-existing daemon keeps `DAEMON_CONNECTION_LOST`; - the renew timer → `connectToRunningDaemon`: never launches. The lease survives either way: the daemon released nothing. 7. **End** — stdin EOF, `SIGINT`/`SIGTERM` or transport close → `McpSession.close`: stop diff --git a/src/mcp/connect.ts b/src/mcp/connect.ts index 983b1e581..f3f75aa23 100644 --- a/src/mcp/connect.ts +++ b/src/mcp/connect.ts @@ -65,7 +65,7 @@ export async function connectWithAutoLaunch( let lastError: unknown; while (options.clock.now() < deadline) { try { - return await connectToRunningDaemon(options); + return await connectStartingDaemon(options); } catch (error: unknown) { if (!isUnavailable(error)) throw error; lastError = error; @@ -88,13 +88,31 @@ async function connectAfterExit( ): Promise { const output = await launched.readOutput().catch(() => ""); try { - return await connectToRunningDaemon(options); + return await connectStartingDaemon(options); } catch (error: unknown) { if (!isUnavailable(error)) throw error; } throw new SimlockError("DAEMON_STARTUP_FAILED", "transport", startErrorFrom(exit, output), {}); } +async function connectStartingDaemon( + options: ConnectToRunningDaemonOptions, +): Promise { + try { + return await connectToRunningDaemon(options); + } catch (error: unknown) { + if (isSimlockError(error) && error.code === "DAEMON_CONNECTION_LOST") { + throw new SimlockError( + "DAEMON_STARTUP_FAILED", + "transport", + "The daemon closed its connection while starting, before answering hello", + {}, + ); + } + throw error; + } +} + /** * Connects only to a daemon that is already listening, and never launches one -- which is * exactly `connectWithAutoLaunch` minus its one extra power, so the latter is written in terms From 40a3dc2c4d9b830c6b1bacf89367bf4dd73b4c9d Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Wed, 21 Oct 2026 12:10:17 +0200 Subject: [PATCH 5/5] test: close startup handshake audit gaps (#790) --- docs/CLI.md | 4 +- src/cli/index.test.ts | 133 +++++++++++++++++++++++----------------- src/mcp/connect.test.ts | 49 +++++++++++++-- 3 files changed, 124 insertions(+), 62 deletions(-) diff --git a/docs/CLI.md b/docs/CLI.md index b8f18c63b..dda575f7e 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -145,7 +145,7 @@ command starts it again) to bring the platform up. |---|---|---| | 0 | — | success (for a `lease` that stayed alive: the lease ended normally) | | 1 | `INTERNAL` | internal / unexpected error | -| 1 | `DAEMON_STARTUP_FAILED` | the daemon was started but did not accept connections before the startup timeout, or exited while starting (the message is the daemon's start error), or answered the handshake then closed before the CLI's startup status probe answered | +| 1 | `DAEMON_STARTUP_FAILED` | the daemon was started but did not accept connections before the startup timeout, or exited while starting (the message is the daemon's start error), or closed during the handshake or before the CLI's startup status probe answered | | 1 | `PROVISION_FAILED` | creating a device for the request failed twice; the message is the driver's error | | 1 | `HISTORY_UNAVAILABLE` | `stats` while `history.db` could not be opened, so the usage figures cannot be read; the daemon's log says why | | 1 | `WORKER_UNREACHABLE` | the gateway cannot reach the worker this lease or request lives on (its uplink is down), or a worker named with `component install --worker` cannot be asked | @@ -2528,7 +2528,7 @@ If a command auto-starts a daemon and that daemon exits before it accepts connections, the command fails at once with `DAEMON_STARTUP_FAILED` and the daemon's start error (`The daemon could not start: `, or the exit code when it logged none); a daemon that exits because another one holds the socket -is not a failure, and the command goes on with that one. If it answers the handshake but closes +is not a failure, and the command goes on with that one. If it closes during the handshake or before the CLI's startup status probe answers, the command reports `DAEMON_STARTUP_FAILED` (exit 1). The probe shares the launch timeout and runs before the command's operation, including after a rejected credential falls diff --git a/src/cli/index.test.ts b/src/cli/index.test.ts index 702e78dcc..e70a4b190 100644 --- a/src/cli/index.test.ts +++ b/src/cli/index.test.ts @@ -1743,10 +1743,19 @@ describe("CLI: auto-launch's handshake cut short by the launched daemon (#684)", const launcher = new FakeDaemonLauncher(() => { launched = true; }); + let probeSent = false; const ipc: IpcConnector = { connect: async () => { if (!launched) throw new IpcError("endpoint-not-found", "not yet", undefined); - return real.connect(socketPath); + const connection = await real.connect(socketPath); + const write = connection.write.bind(connection); + connection.write = async (contents) => { + await write(contents); + if ((JSON.parse(contents.trim()) as { type: string }).type === "status.get") { + probeSent = true; + } + }; + return connection; }, }; const output = outputCapture({ ...realCliEnvironmentPorts(), ipc, clock, launcher }); @@ -1762,6 +1771,9 @@ describe("CLI: auto-launch's handshake cut short by the launched daemon (#684)", await new Promise((resolve) => setTimeout(resolve, 5)); } expect(hellos).toBe(1); + // why: the server observing hello does not mean the client has read its reply and armed + // the probe deadline; advance the fake clock only after the client sends that probe. + await expect.poll(() => probeSent).toBe(true); clock.advance(20_000); await expect.poll(() => settled, { timeout: 2_000 }).toBe(true); expect(await run).toBe(1); @@ -1774,61 +1786,72 @@ describe("CLI: auto-launch's handshake cut short by the launched daemon (#684)", } }); - it("fails a start with DAEMON_STARTUP_FAILED, exit 1, when the daemon it launched closes the socket before the CLI's hello", async () => { - const directory = await mkdtemp(join(tmpdir(), "simlock-closed-")); - temporaryDirectories.push(directory); - const socketPath = join(directory, "daemon.sock"); - let accepted = 0; - // why: the daemon that refuses its history accepts the CLI's connection, then stops and - // closes it; the CLI is still reading `admin.token` then, so the close lands before `hello`. - const server = createServer((socket) => { - accepted += 1; - socket.destroy(); - }); - await new Promise((resolve) => server.listen(socketPath, resolve)); - try { - const real = new NodeIpcTransport(); - let launched = false; - const clock = new FakeClock(0); - const launcher = new FakeDaemonLauncher( - () => { - launched = true; - }, - { exit: { code: 1, signal: null } }, - ); - const ipc: IpcConnector = { - connect: async () => { - if (!launched) throw new IpcError("endpoint-not-found", "not yet", undefined); - const connection = await real.connect(socketPath); - await expect.poll(() => connection.closed).toBe(true); - return connection; - }, - }; - const output = outputCapture({ ...realCliEnvironmentPorts(), ipc, clock, launcher }); - let settled = false; - const run = runCli(["daemon", "start", "--token", "probe"], output.environmentWith()).then( - (code) => { - settled = true; - return code; - }, - ); - for (let tick = 0; tick < 100 && !settled; tick += 1) { - clock.advance(50); - await new Promise((resolve) => setTimeout(resolve, 5)); - } - expect(launcher.launches).toBe(1); - expect(accepted).toBe(1); - expect( - settled, - `simlock daemon start still had not settled at ${String(clock.now())}ms`, - ).toBe(true); - expect(await run).toBe(1); - expect(output.stdout).toBe(""); - expect(JSON.parse(output.stderr.trim().split("\n").at(-1)!)).toMatchObject({ - error: { code: "DAEMON_STARTUP_FAILED" }, + it("exits 1 for a socket closed before hello and reports DAEMON_STARTUP_FAILED only after launch", async () => { + for (const scenario of [ + { launch: false, afterExit: false, code: "DAEMON_CONNECTION_LOST", connects: 1 }, + { launch: true, afterExit: false, code: "DAEMON_STARTUP_FAILED", connects: 2 }, + { launch: true, afterExit: true, code: "DAEMON_STARTUP_FAILED", connects: 3 }, + ]) { + const directory = await mkdtemp(join(tmpdir(), "simlock-closed-")); + temporaryDirectories.push(directory); + const socketPath = join(directory, "daemon.sock"); + let accepted = 0; + // why: the daemon that refuses its history accepts the CLI's connection, then stops and + // closes it; the CLI is still reading `admin.token` then, so the close lands before `hello`. + const server = createServer((socket) => { + accepted += 1; + socket.destroy(); }); - } finally { - await new Promise((resolve) => server.close(() => resolve())); + await new Promise((resolve) => server.listen(socketPath, resolve)); + try { + const real = new NodeIpcTransport(); + let launched = !scenario.launch; + const clock = new FakeClock(0); + const launcher = new FakeDaemonLauncher( + () => { + launched = true; + }, + { exit: { code: 1, signal: null } }, + ); + let connects = 0; + const ipc: IpcConnector = { + connect: async () => { + connects += 1; + if (!launched || (scenario.afterExit && connects === 2)) { + throw new IpcError("endpoint-not-found", "not yet", undefined); + } + const connection = await real.connect(socketPath); + await expect.poll(() => connection.closed).toBe(true); + return connection; + }, + }; + const output = outputCapture({ ...realCliEnvironmentPorts(), ipc, clock, launcher }); + let settled = false; + const run = runCli(["daemon", "start", "--token", "probe"], output.environmentWith()).then( + (code) => { + settled = true; + return code; + }, + ); + for (let tick = 0; tick < 100 && !settled; tick += 1) { + clock.advance(50); + await new Promise((resolve) => setTimeout(resolve, 5)); + } + expect(launcher.launches).toBe(scenario.launch ? 1 : 0); + expect(accepted).toBe(1); + expect(connects).toBe(scenario.connects); + expect( + settled, + `simlock daemon start still had not settled at ${String(clock.now())}ms`, + ).toBe(true); + expect(await run).toBe(1); + expect(output.stdout).toBe(""); + expect(JSON.parse(output.stderr.trim().split("\n").at(-1)!)).toMatchObject({ + error: { code: scenario.code }, + }); + } finally { + await new Promise((resolve) => server.close(() => resolve())); + } } }); diff --git a/src/mcp/connect.test.ts b/src/mcp/connect.test.ts index ba5725ff1..51d5667cc 100644 --- a/src/mcp/connect.test.ts +++ b/src/mcp/connect.test.ts @@ -164,11 +164,37 @@ describe("MCP: auto-launch's daemon that exits while starting (#760)", () => { // why: the stdio host mocks this connector; this seam can force a socket to close before hello // both in the launch loop and in the final connection after the launched process exits. describe("MCP: a socket closed before hello (#790)", () => { - it("reports a closed handshake as a failed start only after launching the daemon", async () => { + it("reports only a closed handshake after launching the daemon as a failed start", async () => { for (const scenario of [ - { launch: false, afterExit: false, code: "DAEMON_CONNECTION_LOST", connects: 1 }, - { launch: true, afterExit: false, code: "DAEMON_STARTUP_FAILED", connects: 2 }, - { launch: true, afterExit: true, code: "DAEMON_STARTUP_FAILED", connects: 3 }, + { + launch: false, + afterExit: false, + refused: false, + code: "DAEMON_CONNECTION_LOST", + connects: 1, + }, + { + launch: true, + afterExit: false, + refused: false, + code: "DAEMON_STARTUP_FAILED", + connects: 2, + }, + { launch: true, afterExit: true, refused: false, code: "DAEMON_STARTUP_FAILED", connects: 3 }, + { + launch: true, + afterExit: false, + refused: true, + code: "ADMIN_AUTHENTICATION_FAILED", + connects: 2, + }, + { + launch: true, + afterExit: true, + refused: true, + code: "ADMIN_AUTHENTICATION_FAILED", + connects: 3, + }, ]) { const transport = new MemoryIpcTransport(); const socketPath = "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/simlock/daemon.sock"; @@ -176,7 +202,20 @@ describe("MCP: a socket closed before hello (#790)", () => { const listen = () => transport.listen(socketPath, (connection) => { accepted += 1; - void connection.close(); + if (scenario.refused) { + connection.onData((chunk) => { + const frame = JSON.parse(chunk.trim()) as { id: number }; + void connection.write( + `${JSON.stringify({ + id: frame.id, + ok: false, + error: { code: "ADMIN_AUTHENTICATION_FAILED", message: "refused" }, + })}\n`, + ); + }); + } else { + void connection.close(); + } }); if (!scenario.launch) await listen(); const launcher = new FakeDaemonLauncher(