Skip to content

Commit d45a887

Browse files
playcationsclaude
andcommitted
fix(server): t3 run from a T3 terminal no longer trips on the service's launcher context
The background service passes T3_SERVICE_LAUNCHER_CONTEXT to its server, and every terminal and agent shell inherits it. Running `t3 serve` there failed with "invalid startup context" or "started a different t3 version". The launcher always spawns its child with an IPC channel that Node does not pass on, so the context is now only honored when that channel exists. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent d2c9281 commit d45a887

2 files changed

Lines changed: 23 additions & 10 deletions

File tree

‎apps/server/src/cloud/serviceLauncherClient.test.ts‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ import {
1212
import * as ServiceLauncherClient from "./serviceLauncherClient.ts";
1313

1414
class FakeLauncherProcess {
15-
readonly connected = true;
15+
readonly connected: boolean;
1616
readonly env: Record<string, string | undefined>;
1717
readonly sent: ServiceLauncherChildMessage[] = [];
1818
readonly #listeners = new Map<string, Set<(...args: ReadonlyArray<unknown>) => void>>();
1919

20-
constructor(context: unknown) {
20+
constructor(context: unknown, connected = true) {
21+
this.connected = connected;
2122
this.env = { [SERVICE_LAUNCHER_CONTEXT_ENV]: JSON.stringify(context) };
2223
}
2324

@@ -136,3 +137,18 @@ it.effect("rejects contradictory trial context instead of leaving activation clo
136137
expect(error.message).toBe("The service launcher supplied invalid startup context.");
137138
}),
138139
);
140+
141+
it.effect("ignores launcher context inherited without an IPC channel", () =>
142+
Effect.gen(function* () {
143+
const host = new FakeLauncherProcess(
144+
{ protocol: SERVICE_LAUNCHER_PROTOCOL, childVersion: "1.0.0" },
145+
false,
146+
);
147+
const client = yield* makeClient(host, "1.1.0");
148+
const error = yield* client
149+
.requestUpdate({ targetVersion: "1.2.0", dbPath: "/tmp/state.sqlite" })
150+
.pipe(Effect.flip);
151+
expect(error).toMatchObject({ _tag: "ServiceLauncherClientError", operation: "unmanaged" });
152+
expect(host.sent).toEqual([]);
153+
}),
154+
);

‎apps/server/src/cloud/serviceLauncherClient.ts‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ export class ServiceLauncherClientError extends Schema.TaggedError<ServiceLaunch
2020
operation: Schema.Literals([
2121
"decode-context",
2222
"version-mismatch",
23-
"ipc-unavailable",
2423
"unmanaged",
2524
"send",
2625
"disconnect",
@@ -35,8 +34,6 @@ export class ServiceLauncherClientError extends Schema.TaggedError<ServiceLaunch
3534
return "The service launcher supplied invalid startup context.";
3635
case "version-mismatch":
3736
return "The service launcher started a different t3 version.";
38-
case "ipc-unavailable":
39-
return "The service launcher IPC channel is unavailable.";
4037
case "unmanaged":
4138
return "This server is not managed by the launcher.";
4239
case "send":
@@ -116,7 +113,10 @@ const resolveStartup = Effect.fn("cloud.service_launcher_client.resolve_startup"
116113
const host = yield* ServiceLauncherHostProcess;
117114
const environment = yield* HostProcessEnvironment;
118115
const currentVersion = options?.currentVersion ?? packageJson.version;
119-
const rawContext = environment[SERVICE_LAUNCHER_CONTEXT_ENV];
116+
// The launcher always spawns its child with an IPC channel, and Node does
117+
// not pass that channel on. Without one, the context was inherited from an
118+
// ancestor (e.g. `t3 serve` run in a T3 terminal), so it describes someone else.
119+
const rawContext = host.connected ? environment[SERVICE_LAUNCHER_CONTEXT_ENV] : undefined;
120120
const context = rawContext === undefined ? undefined : decodeServiceLauncherContext(rawContext);
121121

122122
if (rawContext !== undefined && context === undefined) {
@@ -126,10 +126,7 @@ const resolveStartup = Effect.fn("cloud.service_launcher_client.resolve_startup"
126126
return yield* new ServiceLauncherClientError({ operation: "version-mismatch" });
127127
}
128128

129-
const managed = context !== undefined && host.connected;
130-
if (context !== undefined && !managed) {
131-
return yield* new ServiceLauncherClientError({ operation: "ipc-unavailable" });
132-
}
129+
const managed = context !== undefined;
133130

134131
return { host, context, managed };
135132
},

0 commit comments

Comments
 (0)