From 60a086c4f846ecf9a0839203eecf680cf2213e68 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Sun, 18 Oct 2026 16:17:25 +0200 Subject: [PATCH 1/2] test: report the auto-launch startup timeout under the contract's DAEMON_STARTUP_FAILED code (#672) --- src/cli/index.test.ts | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/cli/index.test.ts b/src/cli/index.test.ts index 0ecd52580..3356fae0b 100644 --- a/src/cli/index.test.ts +++ b/src/cli/index.test.ts @@ -1378,6 +1378,48 @@ describe("CLI: auto-launch's startup deadline (#663)", () => { }); }); +describe("CLI: auto-launch's failed start (#672)", () => { + it("reports a daemon it launched but never reached as DAEMON_STARTUP_FAILED, exit 1", async () => { + // why: nothing ever claims the socket, which is what a daemon still booting past the + // deadline looks like to the CLI. The run goes well past any deadline the loop could hold, + // so the code asserted here is the one the CLI chose for giving up, never one a clock reached. + const clock = new FakeClock(0); + const launcher = new FakeDaemonLauncher(); + const output = outputCapture({ + filesystem: new MemoryFilesystem(), + clock, + systemStats: new FakeSystemStats({ cpuCount: 8, totalRamBytes: 32 * gibibyte }), + ipc: new MemoryIpcTransport(), + launcher, + dataDirectory: "/simlock", + }); + let settled = false; + const exitCode = runCli(["daemon", "start", "--json"], output.environmentWith()).then( + (code) => { + settled = true; + return code; + }, + ); + for (let tick = 0; tick < 700 && !settled; tick += 1) { + clock.advance(50); + await settle(); + await settle(); + } + expect(settled, `simlock daemon start still had not settled at ${String(clock.now())}ms`).toBe( + true, + ); + expect(await exitCode).toBe(1); + expect(output.stdout).toBe(""); + expect(JSON.parse(output.stderr)).toMatchObject({ + error: { + code: "DAEMON_STARTUP_FAILED", + message: expect.stringContaining("Timed out starting simlock daemon"), + }, + }); + expect(launcher.launches).toBe(1); + }); +}); + describe("CLI: daemon status (ADR 0003 §11)", () => { it("reports stopped when the socket cannot be reached at all", async () => { const output = outputCapture(); From 2412e38207f4bf56c290958f9328cffbd38d69e6 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Sun, 18 Oct 2026 16:19:40 +0200 Subject: [PATCH 2/2] fix(cli): auto-launch timeout throws DAEMON_STARTUP_FAILED 1 failing -> 0 failing --- docs/CLI.md | 1 + src/cli/index.ts | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/CLI.md b/docs/CLI.md index d04e6e63b..9ad1e0b80 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -78,6 +78,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 | | 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 | | 2 | `USAGE` | usage error (bad flags, missing required args, unknown command) | | 2 | `BAD_FRAME` | malformed request frame sent to the daemon | diff --git a/src/cli/index.ts b/src/cli/index.ts index 504c4449a..511f0b7fb 100644 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -33,6 +33,7 @@ import { resolveRequesterId } from "../agent-identity/index.js"; import { connectSimlockAdmin } from "../admin/index.js"; import { isSimlockError, + SimlockError, type CatalogGetOutput, type AnySimlockError, type DoctorReport, @@ -245,7 +246,12 @@ class AutoLaunchIpcConnector implements IpcConnector { await new Promise((resolve) => this.clock.setTimer(50, resolve)); } } - throw new Error(`Timed out starting simlock daemon: ${errorMessage(lastError)}`); + throw new SimlockError( + "DAEMON_STARTUP_FAILED", + "transport", + `Timed out starting simlock daemon: ${errorMessage(lastError)}`, + {}, + ); } }