Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.
fix(desktop): keep tailscale spawn defects from breaking advertised endpoints (#7116)
Rishet11d9c1732b2791
diff --git a/packages/tailscale/src/tailscale.test.ts b/packages/tailscale/src/tailscale.test.tsindex 24c22454d..09d9def21 100644--- a/packages/tailscale/src/tailscale.test.ts+++ b/packages/tailscale/src/tailscale.test.ts@@ -212,6 +212,45 @@ describe("tailscale", () => {});});+ it.effect("turns spawn defects into typed spawn failures", () => {+ // A non-directory entry on PATH makes node's spawn throw ENOTDIR+ // synchronously. The platform spawner calls `NodeChildProcess.spawn` from+ // inside an `Effect.callback` registration, so that throw arrives as a+ // defect rather than a typed error - the shape reproduced here.+ const defect = Object.assign(new Error("spawn tailscale ENOTDIR"), { code: "ENOTDIR" });+ const layer = Layer.succeed(+ ChildProcessSpawner.ChildProcessSpawner,+ ChildProcessSpawner.make(() =>+ Effect.callback<never, never>(() => {+ throw defect;+ }),+ ),+ );++ return Effect.gen(function* () {+ const statusError = yield* readTailscaleStatus.pipe(Effect.flip, Effect.provide(layer));+ assert.instanceOf(statusError, TailscaleCommandSpawnError);+ assert.equal(statusError.subcommand, "status");+ assert.strictEqual(statusError.cause, defect);++ const serveError = yield* ensureTailscaleServe({ localPort: 13773, servePort: 8443 }).pipe(+ Effect.flip,+ Effect.provide(layer),+ );+ assert.instanceOf(serveError, TailscaleCommandSpawnError);+ assert.equal(serveError.subcommand, "serve");+ assert.strictEqual(serveError.cause, defect);++ // What callers actually rely on: the desktop endpoint providers recover+ // with `Effect.orElseSucceed`, which only sees the typed error channel.+ const degraded = yield* readTailscaleStatus.pipe(+ Effect.orElseSucceed(() => null),+ Effect.provide(layer),+ );+ assert.equal(degraded, null);+ });+ });+it.effect("keeps nonzero exit diagnostics structured", () => {const layer = mockSpawnerLayer(() => ({code: 7,diff --git a/packages/tailscale/src/tailscale.ts b/packages/tailscale/src/tailscale.tsindex 7260a9de1..fedde02ee 100644--- a/packages/tailscale/src/tailscale.ts+++ b/packages/tailscale/src/tailscale.ts@@ -228,11 +228,15 @@ export const readTailscaleStatus = Effect.gen(function* () {argumentCount: args.length,};return yield* Effect.gen(function* () {- const child = yield* spawner- .spawn(ChildProcess.make(executable, args))- .pipe(- Effect.mapError((cause) => new TailscaleCommandSpawnError({ ...commandContext, cause })),- );+ const child = yield* spawner.spawn(ChildProcess.make(executable, args)).pipe(+ Effect.mapError((cause) => new TailscaleCommandSpawnError({ ...commandContext, cause })),+ // Spawning can also fail as a defect rather than a typed error - a+ // non-directory entry on PATH makes node throw ENOTDIR synchronously.+ // `mapError` never sees that, so it would escape as an uncaught error.+ Effect.catchDefect((cause) =>+ Effect.fail(new TailscaleCommandSpawnError({ ...commandContext, cause })),+ ),+ );const [stdout, stderr, exitCode] = yield* Effect.all([collectStdout(child.stdout),@@ -299,11 +303,12 @@ const runTailscaleCommand = (};const timeout = Duration.fromInputUnsafe(timeoutInput);return yield* Effect.gen(function* () {- const child = yield* spawner- .spawn(ChildProcess.make(executable, args))- .pipe(- Effect.mapError((cause) => new TailscaleCommandSpawnError({ ...commandContext, cause })),- );+ const child = yield* spawner.spawn(ChildProcess.make(executable, args)).pipe(+ Effect.mapError((cause) => new TailscaleCommandSpawnError({ ...commandContext, cause })),+ Effect.catchDefect((cause) =>+ Effect.fail(new TailscaleCommandSpawnError({ ...commandContext, cause })),+ ),+ );const [stderr, exitCode] = yield* Effect.all([collectStderr(child.stderr), child.exitCode.pipe(Effect.map(Number))],{ concurrency: "unbounded" },