@devries-cameron20 / t3code-1 / commits / f495217e92
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(server): Simlock open failures show what agent-device reported (#27564)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Nov 11, 2026 at 11:59 UTC f495217e928cafb7dc0563fc8c8a28dba718f64b
2 files changed +81 -14
apps/server/src/device/SimlockDeviceHost.test.ts
+47 -5
@@ -50,7 +50,8 @@ const CATALOG = {
50 /** The gateway's HTTP API and T3's agent-device CLI, recording what was asked of them. */
51 const fakePool = (
52 options: {
53 - readonly failOpen?: boolean;
53 + /** What the agent-device CLI prints before exiting 1 from `open`. */
54 + readonly failOpen?: unknown;
55 readonly holdOpen?: {
56 readonly entered: Deferred.Deferred<void>;
57 readonly proceed: Deferred.Deferred<void>;
@@ -93,9 +94,7 @@ const fakePool = (
94 if (command === "open") {
95 if (options.failOpen) {
96 return {
96 - stdout: JSON.stringify({
97 - error: { message: "No device matches.", hint: "Retry." },
98 - }),
97 + stdout: JSON.stringify(options.failOpen),
98 stderr: "",
99 code: ChildProcessSpawner.ExitCode(1),
100 timedOut: false,
@@ -394,7 +393,9 @@ describe("Simlock device host", () => {
393
394 it.effect("closes the session of a failed open so no lease is left behind", () =>
395 Effect.gen(function* () {
397 - const pool = yield* fakePool({ failOpen: true });
396 + const pool = yield* fakePool({
397 + failOpen: { error: { message: "No device matches.", hint: "Retry." } },
398 + });
399 const scope = yield* Scope.make();
400 const host = yield* makeHost(pool, config(), scope);
401 const ready = yield* host.ensureReady(() => Effect.void);
@@ -408,6 +409,47 @@ describe("Simlock device host", () => {
409 }).pipe(Effect.scoped, Effect.provide(layer)),
410 );
411
412 + it.effect("tells the user what agent-device reported when a device fails to open", () =>
413 + Effect.gen(function* () {
414 + const pool = yield* fakePool({
415 + failOpen: {
416 + success: false,
417 + error: {
418 + code: "COMMAND_FAILED",
419 + message: "Invalid daemon response",
420 + cause: {
421 + message: "Unexpected non-whitespace character after JSON at position 4",
422 + },
423 + hint: "Retry with --debug and inspect diagnostics log for details.",
424 + details: { requestId: "22a6bf10a567b2a1", line: "404 Not Found" },
425 + },
426 + },
427 + });
428 + const scope = yield* Scope.make();
429 + const host = yield* makeHost(pool, config(), scope);
430 + const ready = yield* host.ensureReady(() => Effect.void);
431 + const pixel = (yield* ready.devices.list).devices.find(({ name }) => name === "Pixel 9");
432 + const failure = yield* ready.devices.boot(pixel!).pipe(Effect.flip);
433 + expect(failure.message).not.toContain("The device host sent no details.");
434 + expect(failure.message).toContain("Invalid daemon response");
435 + expect(failure.message).toContain("404 Not Found");
436 + yield* Scope.close(scope, Exit.void);
437 +
438 + // A details bag without a usable response line still keeps agent-device's message.
439 + const oddPool = yield* fakePool({
440 + failOpen: { error: { message: "Invalid daemon response", details: { line: 17 } } },
441 + });
442 + const oddScope = yield* Scope.make();
443 + const oddReady = yield* (yield* makeHost(oddPool, config(), oddScope)).ensureReady(
444 + () => Effect.void,
445 + );
446 + const [oddDevice] = (yield* oddReady.devices.list).devices;
447 + const oddFailure = yield* oddReady.devices.boot(oddDevice!).pipe(Effect.flip);
448 + expect(oddFailure.message).toContain("Invalid daemon response");
449 + yield* Scope.close(oddScope, Exit.void);
450 + }).pipe(Effect.scoped, Effect.provide(layer)),
451 + );
452 +
453 it.effect("keeps a watched lease renewed and stops listing it once Simlock ends it", () =>
454 Effect.gen(function* () {
455 const pool = yield* fakePool();
apps/server/src/device/SimlockDeviceHost.ts
+34 -9
@@ -27,6 +27,7 @@ import * as Schema from "effect/Schema";
27 import * as Semaphore from "effect/Semaphore";
28 import { HttpClient, HttpClientError, HttpClientRequest, HttpClientResponse } from "effect/http";
29 import * as HostProcess from "@t3tools/shared/HostProcess";
30 +import { truncate } from "@t3tools/shared/String";
31 import type { NodeRuntimeUnavailableError } from "@t3tools/shared/nodeRuntime";
32
33 import * as SecretResolver from "@t3tools/secret-provider-core/server/SecretResolver";
@@ -61,13 +62,34 @@ const decodeCatalog = Schema.decodeUnknownEffect(Catalog);
62 const decodeSessionRecord = Schema.decodeUnknownEffect(
63 Schema.fromJsonString(Schema.Struct({ leaseId: Schema.String })),
64 );
64 -const decodeCliFailure = Schema.decodeUnknownOption(
65 - Schema.fromJsonString(
66 - Schema.Struct({
67 - error: Schema.Struct({ message: Schema.String, hint: Schema.optional(Schema.String) }),
68 - }),
69 - ),
70 -);
65 +const CliFailure = Schema.Struct({
66 + error: Schema.Struct({
67 + message: Schema.String,
68 + hint: Schema.optional(Schema.String),
69 + logPath: Schema.optional(Schema.String),
70 + // An open bag; `line` holds the daemon's raw response when agent-device could not parse it.
71 + details: Schema.optional(Schema.Unknown),
72 + }),
73 +});
74 +const responseLine = (details: unknown) =>
75 + typeof details === "object" &&
76 + details !== null &&
77 + "line" in details &&
78 + typeof details.line === "string"
79 + ? details.line
80 + : undefined;
81 +const decodeCliFailure = Schema.decodeUnknownOption(Schema.fromJsonString(CliFailure));
82 +const describeCliFailure = ({ error }: typeof CliFailure.Type) => {
83 + const line = responseLine(error.details);
84 + return [
85 + error.message,
86 + error.hint,
87 + line ? `The daemon answered: ${truncate(line, 300)}` : undefined,
88 + error.logPath ? `Log: ${error.logPath}` : undefined,
89 + ]
90 + .filter((part) => part !== undefined)
91 + .join(" ");
92 +};
93
94 interface Lease {
95 readonly leaseId: string;
@@ -295,7 +317,7 @@ export const make = Effect.fn("SimlockDeviceHost.make")(function* (
317 return yield* unavailable(
318 Option.match(failure, {
319 onNone: () => `agent-device ${args[0]} failed (exit code ${result.code ?? "none"}).`,
298 - onSome: ({ error }) => (error.hint ? `${error.message} ${error.hint}` : error.message),
320 + onSome: describeCliFailure,
321 }),
322 );
323 }
@@ -440,11 +462,13 @@ export const make = Effect.fn("SimlockDeviceHost.make")(function* (
462 ) {
463 const target = parseCatalogId(device.id);
464 if (!target) {
465 + const reason = "This Simlock device is no longer leased. Open it again from the list.";
466 return yield* new DeviceBootError({
467 hostId,
468 deviceId: device.id,
469 reason: "launch_failed",
447 - cause: new Error("This Simlock device is no longer leased. Open it again from the list."),
470 + diagnostics: reason,
471 + cause: new Error(reason),
472 });
473 }
474 const suffix = (yield* Random.nextIntBetween(0, 0xffffff)).toString(16).padStart(6, "0");
@@ -511,6 +535,7 @@ export const make = Effect.fn("SimlockDeviceHost.make")(function* (
535 hostId,
536 deviceId: device.id,
537 reason: "launch_failed",
538 + diagnostics: truncate(error.reason, 1_997),
539 cause: new Error(error.reason),
540 })
541 : error,