Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
42 changes: 42 additions & 0 deletions src/cli/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 7 additions & 1 deletion src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -245,7 +246,12 @@ class AutoLaunchIpcConnector implements IpcConnector {
await new Promise<void>((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)}`,
{},
);
}
}

Expand Down
Loading