The best way to control Claude Code, Codex and more from any computer or phone
fix(server): t3 service install no longer moves a --base-dir service onto an empty ~/.t3 (#23878)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
shivam committed
Nov 7, 2026 at 10:45 UTC
33f85846be8bc4bc592f0e621d6f0313e5abd4a4
7 files changed
+232
-40
apps/server/src/cli/service.test.ts
+26
-10
@@ -59,13 +59,33 @@ function makeTestService(
59
}
60
61
it.layer(Layer.mergeAll(NodeServices.layer, NetService.layer))("service commands", (it) => {
62
- it.effect.each(["install", "update"] as const)(
63
- "%s refuses a downgrade before changing the service",
64
- (command) =>
62
+ it.effect.each(
63
+ (["install", "update"] as const).flatMap((command) => [
64
+ {
65
+ command,
66
+ label: "a downgrade",
67
+ status: newerServiceStatus,
68
+ error: {
69
+ _tag: "BootServiceDowngradeRefusedError",
70
+ installedVersion: "999.0.0",
71
+ targetVersion: packageJson.version,
72
+ },
73
+ },
74
+ // This home's newer state must not ask for --allow-downgrade first.
75
+ {
76
+ command,
77
+ label: "another home's service",
78
+ status: { ...newerServiceStatus, otherBaseDir: "/srv/t3" },
79
+ error: { _tag: "BootServiceOtherBaseDirError", installedBaseDir: "/srv/t3" },
80
+ },
81
+ ]),
82
+ )(
83
+ "$command refuses $label before changing the service",
84
+ ({ command, status: serviceStatus, error: expected }) =>
85
Effect.gen(function* () {
86
const fs = yield* FileSystem.FileSystem;
87
const baseDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-service-cli-test-" });
68
- const { service, installOptions } = makeTestService(newerServiceStatus);
88
+ const { service, installOptions } = makeTestService(serviceStatus);
89
vi.spyOn(BootService, "layer").mockReturnValue(
90
Layer.succeed(BootService.BootService, service),
91
);
@@ -80,11 +100,7 @@ it.layer(Layer.mergeAll(NodeServices.layer, NetService.layer))("service commands
100
Effect.flip,
101
);
102
83
- expect(error).toMatchObject({
84
- _tag: "BootServiceDowngradeRefusedError",
85
- installedVersion: "999.0.0",
86
- targetVersion: packageJson.version,
87
- });
103
+ expect(error).toMatchObject(expected);
104
expect(installOptions).toEqual([]);
105
}),
106
);
@@ -239,7 +255,7 @@ it.layer(Layer.mergeAll(NodeServices.layer, NetService.layer))("service commands
255
),
256
);
257
expect(uninstalls).toEqual(input.removed);
242
- expect(output).toContain(input.otherHome ? "another T3 home" : "Removed");
258
+ expect(output).toContain(input.otherHome ? "--base-dir '/home/me/.t3'" : "Removed");
259
}),
260
);
261
});
apps/server/src/cli/service.ts
+19
-2
@@ -92,6 +92,13 @@ export const reconcileService = Effect.fn("cli.service.reconcile")(function* (op
92
const { baseDir } = yield* ServerConfig.ServerConfig;
93
const service = yield* BootService.BootService;
94
const status = yield* service.status;
95
+ // Before the downgrade check, which reads this home's state, not the service's.
96
+ if (status.otherBaseDir !== undefined) {
97
+ return yield* new BootService.BootServiceOtherBaseDirError({
98
+ installedBaseDir: status.otherBaseDir,
99
+ baseDir,
100
+ });
101
+ }
102
if (status.installed && status.current) {
103
return { changed: false, status } satisfies ServiceReconcileResult;
104
}
@@ -152,6 +159,14 @@ function formatServiceStatus(
159
if (!status.installed) {
160
return "T3 Code service\n Status: not installed\n Next: Run `t3 service install`.";
161
}
162
+ if (status.otherBaseDir !== undefined) {
163
+ return [
164
+ "T3 Code service",
165
+ " Status: installed for another T3 home",
166
+ ` Base dir: ${status.otherBaseDir}`,
167
+ ` Next: Pass \`${BootService.formatBootServiceBaseDirOption(status.otherBaseDir)}\` to manage it.`,
168
+ ].join("\n");
169
+ }
170
const installedVersion = status.installedVersion ?? cliVersion;
171
const problems = (status.problems ?? []).map(
172
(problem) => ` [${problem}] ${BootService.formatBootServiceProblem(problem)}`,
@@ -264,7 +279,9 @@ const serviceRestartCommand = Command.make("restart", projectLocationFlags).pipe
279
? `Restarted the T3 Code service${onVersion}.`
280
: outcome === "queued"
281
? `Queued a restart of the T3 Code service${onVersion}. This session runs inside the service and disconnects when it goes down.\nLogs: ${status.logPath}`
267
- : "T3 Code service is not installed.",
282
+ : status.otherBaseDir !== undefined
283
+ ? `The T3 Code service serves ${status.otherBaseDir}, so it was not restarted. Pass \`${BootService.formatBootServiceBaseDirOption(status.otherBaseDir)}\` to restart it.`
284
+ : "T3 Code service is not installed.",
285
);
286
}),
287
),
@@ -290,7 +307,7 @@ const serviceUninstallCommand = Command.make("uninstall", projectLocationFlags).
307
path.resolve(installedBaseDir) !== path.resolve(baseDir)
308
) {
309
yield* Console.log(
293
- "The installed service runs another T3 home, so it was not removed. Pass its --base-dir.",
310
+ `The T3 Code service serves ${installedBaseDir}, so it was not removed. Pass \`${BootService.formatBootServiceBaseDirOption(installedBaseDir)}\` to remove it.`,
311
);
312
return;
313
}
apps/server/src/cli/up.connect.test.ts
+50
@@ -126,5 +126,55 @@ it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer, NetService.layer))
126
expect(yield* fs.readFileString(`${baseDir}/service.env`)).toBe("T3CODE_LAN=false\n");
127
}),
128
);
129
+
130
+ it.effect("--connect signs in to nothing for another home's service", () =>
131
+ Effect.gen(function* () {
132
+ events.length = 0;
133
+ link.desired = false;
134
+ link.mode = "managed";
135
+ const fs = yield* FileSystem.FileSystem;
136
+ const baseDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-up-connect-test-" });
137
+ vi.spyOn(BootService, "layer").mockReturnValue(
138
+ Layer.succeed(
139
+ BootService.BootService,
140
+ BootService.BootService.of({
141
+ status: Effect.succeed({
142
+ supported: true,
143
+ installed: true,
144
+ current: false,
145
+ otherBaseDir: "/srv/t3",
146
+ unitPath: "/home/me/.config/systemd/user/t3code.service",
147
+ logPath: "/home/me/.t3/userdata/logs/boot-service.log",
148
+ }),
149
+ withStopped: (operation) => operation,
150
+ restart: Effect.sync(() => events.push("restart")).pipe(
151
+ Effect.as("skipped" as const),
152
+ ),
153
+ install: () => Effect.die("another home's service is not reinstalled"),
154
+ uninstall: Effect.succeed(false),
155
+ }),
156
+ ),
157
+ );
158
+
159
+ const error = yield* Command.runWith(upCommand, { version: packageJson.version })([
160
+ "--base-dir",
161
+ baseDir,
162
+ "--connect",
163
+ ]).pipe(
164
+ Effect.provideService(HostProcess.Environment, {}),
165
+ Effect.provide(
166
+ Layer.mergeAll(
167
+ ConfigProvider.layer(ConfigProvider.fromEnv({ env: {} })),
168
+ Layer.fresh(TestConsole.layer),
169
+ ),
170
+ ),
171
+ Effect.flip,
172
+ );
173
+
174
+ expect(error).toMatchObject({ _tag: "BootServiceOtherBaseDirError" });
175
+ expect(events).toEqual([]);
176
+ expect(link).toEqual({ desired: false, mode: "managed" });
177
+ }),
178
+ );
179
},
180
);
apps/server/src/cli/up.test.ts
+58
-19
@@ -18,7 +18,7 @@ import { afterEach, vi } from "vite-plus/test";
18
import packageJson from "../../package.json" with { type: "json" };
19
import * as BootService from "../cloud/bootService.ts";
20
import { upsertServiceEnv } from "./service.ts";
21
-import { connectEnabled, planRoutes, upCommand } from "./up.ts";
21
+import { connectEnabled, planRoutes, statusCommand, upCommand } from "./up.ts";
22
23
const none = Option.none<boolean>();
24
@@ -162,6 +162,8 @@ it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer, NetService.layer))
162
readonly status?: Partial<BootService.BootServiceStatus>;
163
readonly installFails?: boolean;
164
readonly restartFails?: boolean;
165
+ readonly fails?: boolean;
166
+ readonly reportStatus?: boolean;
167
/** Runs as if in a terminal, answering each question with this text. */
168
readonly answer?: string;
169
readonly prints?: string;
@@ -252,6 +254,29 @@ it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer, NetService.layer))
254
restarts: 0,
255
envAfter: "T3CODE_LAN=false\n",
256
},
257
+ {
258
+ label: "a service for another home is refused without a restart",
259
+ installed: true,
260
+ status: { current: false, otherBaseDir: "/srv/t3 home" },
261
+ fails: true,
262
+ answer: "y",
263
+ env: "T3CODE_LAN=false\n",
264
+ args: ["--lan"],
265
+ installs: 0,
266
+ restarts: 0,
267
+ envAfter: "T3CODE_LAN=false\n",
268
+ },
269
+ {
270
+ label: "another home's service supplies no local network default",
271
+ installed: true,
272
+ status: { current: false, otherBaseDir: "/srv/t3 home" },
273
+ reportStatus: true,
274
+ env: "",
275
+ args: ["--json"],
276
+ installs: 0,
277
+ restarts: 0,
278
+ envAfter: "",
279
+ },
280
{
281
label: "no service manager still records the choice",
282
installed: false,
@@ -271,7 +296,7 @@ it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer, NetService.layer))
296
restarts: 0,
297
envAfter: "T3CODE_LAN=true\n",
298
},
274
- ])("restarts the service only when it must: $label", (input) =>
299
+ ])("keeps service changes and access settings consistent: $label", (input) =>
300
Effect.gen(function* () {
301
const fs = yield* FileSystem.FileSystem;
302
const baseDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-up-test-" });
@@ -298,30 +323,36 @@ it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer, NetService.layer))
323
),
324
),
325
install: () =>
301
- input.installFails === true
326
+ status.otherBaseDir !== undefined
327
? Effect.fail(
303
- new BootService.BootServicePrerequisiteError({ problem: "linger-disabled" }),
304
- )
305
- : Effect.sync(() => {
306
- installs++;
307
- return {
308
- program: ["t3"],
328
+ new BootService.BootServiceOtherBaseDirError({
329
+ installedBaseDir: status.otherBaseDir,
330
baseDir,
310
- unitPath: status.unitPath,
311
- logPath: status.logPath,
312
- };
313
- }),
331
+ }),
332
+ )
333
+ : input.installFails === true
334
+ ? Effect.fail(
335
+ new BootService.BootServicePrerequisiteError({ problem: "linger-disabled" }),
336
+ )
337
+ : Effect.sync(() => {
338
+ installs++;
339
+ return {
340
+ program: ["t3"],
341
+ baseDir,
342
+ unitPath: status.unitPath,
343
+ logPath: status.logPath,
344
+ };
345
+ }),
346
uninstall: Effect.succeed(false),
347
}),
348
),
349
);
350
351
if (input.answer !== undefined) yield* asTerminal;
320
- const { exit, lines } = yield* Command.runWith(upCommand, { version: packageJson.version })([
321
- "--base-dir",
322
- baseDir,
323
- ...input.args,
324
- ]).pipe(
352
+ const run = input.reportStatus
353
+ ? Command.runWith(statusCommand, { version: packageJson.version })
354
+ : Command.runWith(upCommand, { version: packageJson.version });
355
+ const { exit, lines } = yield* run(["--base-dir", baseDir, ...input.args]).pipe(
356
Effect.provideService(HostProcess.Environment, {}),
357
input.answer === undefined
358
? (effect) => effect
@@ -340,7 +371,15 @@ it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer, NetService.layer))
371
if (input.prints !== undefined) {
372
expect(lines.join("\n")).toContain(input.prints.replace("<baseDir>", baseDir));
373
}
343
- expect(exit._tag).toBe(input.restartFails === true ? "Failure" : "Success");
374
+ if (input.reportStatus) {
375
+ expect(JSON.parse(lines.join("\n"))).toMatchObject({
376
+ service: { otherBaseDir: "/srv/t3 home" },
377
+ lan: { enabled: false, inheritedDefault: false },
378
+ });
379
+ }
380
+ expect(exit._tag).toBe(
381
+ input.restartFails === true || input.fails === true ? "Failure" : "Success",
382
+ );
383
expect({ installs, restarts }).toEqual({
384
installs: input.installs,
385
restarts: input.restarts,
apps/server/src/cli/up.ts
+24
-4
@@ -79,12 +79,14 @@ const readSetup = Effect.fn("cli.up.read_setup")(function* () {
79
revoked: connectRevoked,
80
})
81
: null;
82
+ // Another home's service doesn't read this home's service.env.
83
+ const servesThisHome = service.installed && service.otherBaseDir === undefined;
84
return {
85
service,
86
connect,
87
connectRevoked,
86
- lan: Option.getOrElse(lan, () => service.installed),
87
- lanFromOldDefault: Option.isNone(lan) && service.installed,
88
+ lan: Option.getOrElse(lan, () => servesThisHome),
89
+ lanFromOldDefault: Option.isNone(lan) && servesThisHome,
90
host: entries.T3CODE_HOST,
91
} satisfies Setup;
92
});
@@ -125,6 +127,14 @@ const CHOICES = {
127
128
const formatSetup = (setup: Setup) => {
129
const { service } = setup;
130
+ // This home's access settings reach no service, so only the service is shown.
131
+ if (service.otherBaseDir !== undefined) {
132
+ return [
133
+ ` ${"Service".padEnd(15)}installed for another T3 home · ${service.otherBaseDir}`,
134
+ "",
135
+ `Pass \`${BootService.formatBootServiceBaseDirOption(service.otherBaseDir)}\` to manage it.`,
136
+ ].join("\n");
137
+ }
138
const rows: ReadonlyArray<readonly [string, string]> = [
139
[
140
"Service",
@@ -203,6 +213,13 @@ const setUp = Effect.fn("cli.up")(function* (flags: {
213
});
214
const { command: pairCommand } = yield* resolveHostCliCommand("pair", baseDirArgs);
215
const before = yield* readSetup();
216
+ // Before any question or write: install would refuse only after both.
217
+ if (before.service.otherBaseDir !== undefined) {
218
+ return yield* new BootService.BootServiceOtherBaseDirError({
219
+ installedBaseDir: before.service.otherBaseDir,
220
+ baseDir,
221
+ });
222
+ }
223
if (before.connect === null && Option.getOrElse(flags.connect, () => false)) {
224
return yield* new CliError.UserError({
225
cause: "connect",
@@ -400,7 +417,7 @@ const setUp = Effect.fn("cli.up")(function* (flags: {
417
}
418
if (outcome === "skipped") {
419
yield* Console.log(
403
- "The installed service runs another T3 home, so it was not restarted. Pass its --base-dir.",
420
+ "The installed service was not restarted. Run `t3 service status` to see why.",
421
);
422
}
423
started = outcome === "restarted";
@@ -480,6 +497,7 @@ const setupJson = (setup: Setup) =>
497
supported: setup.service.supported,
498
installed: setup.service.installed,
499
installedVersion: setup.service.installedVersion ?? null,
500
+ otherBaseDir: setup.service.otherBaseDir ?? null,
501
},
502
connect:
503
setup.connect === null ? null : { enabled: setup.connect, revoked: setup.connectRevoked },
@@ -521,7 +539,9 @@ export const statusCommand = Command.make("status", {
539
yield* Console.log(
540
flags.json
541
? setupJson(setup)
524
- : `This machine\n${formatSetup(setup)}\n\nChange access: \`t3 up\`.`,
542
+ : setup.service.otherBaseDir !== undefined
543
+ ? `This machine\n${formatSetup(setup)}`
544
+ : `This machine\n${formatSetup(setup)}\n\nChange access: \`t3 up\`.`,
545
);
546
}),
547
),
apps/server/src/cloud/bootService.test.ts
+13
-5
@@ -7,6 +7,7 @@ import * as Effect from "effect/Effect";
7
import * as FileSystem from "effect/FileSystem";
8
import * as Layer from "effect/Layer";
9
import * as Path from "effect/Path";
10
+import { CliError } from "effect/cli";
11
import { HttpClient } from "effect/http";
12
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
13
@@ -679,17 +680,24 @@ it.layer(NodeServices.layer)("boot service install", (it) => {
680
}),
681
);
682
682
- it.effect("restart leaves a service that serves another T3 home alone", () =>
683
+ it.effect("restart and install leave a service that serves another T3 home alone", () =>
684
Effect.gen(function* () {
684
- const { service, fs, commands, makeService } = yield* makeHarness();
685
- yield* service.install();
686
- commands.length = 0;
685
+ const { service, fs, baseDir, commands, makeService } = yield* makeHarness();
686
+ const plan = yield* service.install();
687
+ const unit = yield* fs.readFileString(plan.unitPath);
688
const path = yield* Path.Path;
689
const otherHome = yield* fs.makeTempDirectoryScoped({ prefix: "t3-other-home-" });
690
691
const other = yield* makeService(undefined, "1.2.3", path.join(otherHome, ".t3"));
692
+ commands.length = 0;
693
expect(yield* other.restart).toBe("skipped");
692
- expect(commands.filter((command) => command.startsWith("systemctl "))).toEqual([]);
694
+ const refused = yield* other.install().pipe(Effect.flip);
695
+ expect(refused._tag).toBe("BootServiceOtherBaseDirError");
696
+ // The CLI prints a user message without a stack trace.
697
+ expect(CliError.getUserMessage(refused)).toBe(refused.message);
698
+ expect(yield* fs.readFileString(plan.unitPath)).toBe(unit);
699
+ expect(commands).toEqual([]);
700
+ expect((yield* other.status).otherBaseDir).toBe(baseDir);
701
}),
702
);
703
apps/server/src/cloud/bootService.ts
+42
@@ -9,6 +9,7 @@ import * as FileSystem from "effect/FileSystem";
9
import * as Layer from "effect/Layer";
10
import * as Option from "effect/Option";
11
import * as Path from "effect/Path";
12
+import { CliError } from "effect/cli";
13
import { HttpClient } from "effect/http";
14
import * as Schema from "effect/Schema";
15
@@ -514,8 +515,29 @@ export class BootServiceDowngradeRefusedError extends Schema.TaggedError<BootSer
515
}
516
}
517
518
+export const formatBootServiceBaseDirOption = (baseDir: string) =>
519
+ `--base-dir '${baseDir.replaceAll("'", `'"'"'`)}'`;
520
+
521
+export class BootServiceOtherBaseDirError extends Schema.TaggedError<BootServiceOtherBaseDirError>()(
522
+ "BootServiceOtherBaseDirError",
523
+ {
524
+ installedBaseDir: Schema.String,
525
+ baseDir: Schema.String,
526
+ },
527
+) {
528
+ override get message(): string {
529
+ return `The T3 Code service on this machine serves ${this.installedBaseDir}, not ${this.baseDir}. Pass ${formatBootServiceBaseDirOption(this.installedBaseDir)} to manage it, or run \`t3 service uninstall ${formatBootServiceBaseDirOption(this.installedBaseDir)}\` first to move it; both data directories are kept.`;
530
+ }
531
+
532
+ // A refusal the user fixes by rerunning, so the CLI prints the message, not a stack trace.
533
+ override get [CliError.userMessage]() {
534
+ return this.message;
535
+ }
536
+}
537
+
538
export type BootServiceError =
539
| BootServiceUnsupportedError
540
+ | BootServiceOtherBaseDirError
541
| BootServiceCommandError
542
| BootServiceInstallError
543
| BootServicePrerequisiteError
@@ -528,6 +550,8 @@ export interface BootServiceStatus {
550
readonly current: boolean;
551
readonly installedVersion?: string;
552
readonly installedBaseDir?: string;
553
+ /** Set when the installed unit serves a different T3 home than this CLI. */
554
+ readonly otherBaseDir?: string;
555
readonly problems?: ReadonlyArray<BootServiceProblem>;
556
readonly unitPath: string;
557
readonly logPath: string;
@@ -631,6 +655,13 @@ export const make = Effect.fn("cloud.boot_service.make")(function* (input: {
655
const logPath = path.join(input.logsDir, BOOT_SERVICE_LOG_FILE);
656
const statePath = path.join(input.baseDir, "runtime", SERVICE_STATE_FILE);
657
const restartPendingPath = path.join(input.baseDir, "runtime", SERVICE_RESTART_PENDING_FILE);
658
+ const otherBaseDirOf = (unit: string) => {
659
+ const installedBaseDir = bootServiceBaseDirOf(unit);
660
+ return installedBaseDir !== undefined &&
661
+ path.resolve(installedBaseDir) !== path.resolve(input.baseDir)
662
+ ? installedBaseDir
663
+ : undefined;
664
+ };
665
const writeDurably = (filePath: string, contents: string) =>
666
Effect.scoped(
667
Effect.gen(function* () {
@@ -773,6 +804,15 @@ export const make = Effect.fn("cloud.boot_service.make")(function* (input: {
804
readonly start?: boolean;
805
}) {
806
const manager = yield* requireManager;
807
+ // The unit is per user. Rewriting one that serves another home moves the
808
+ // service onto this home's data, which looks like every thread vanished.
809
+ const existingUnit = yield* fs.readFileString(unitPath).pipe(Effect.option);
810
+ const installedBaseDir = Option.isSome(existingUnit)
811
+ ? otherBaseDirOf(existingUnit.value)
812
+ : undefined;
813
+ if (installedBaseDir !== undefined) {
814
+ return yield* new BootServiceOtherBaseDirError({ installedBaseDir, baseDir: input.baseDir });
815
+ }
816
yield* fs
817
.makeDirectory(input.logsDir, { recursive: true })
818
.pipe(Effect.mapError((cause) => new BootServiceInstallError({ cause })));
@@ -1040,6 +1080,7 @@ export const make = Effect.fn("cloud.boot_service.make")(function* (input: {
1080
? serviceStateActiveVersion(stateText.value)
1081
: undefined;
1082
const installedBaseDir = bootServiceBaseDirOf(unit);
1083
+ const otherBaseDir = otherBaseDirOf(unit);
1084
const normalizeUnit = (contents: string) =>
1085
detectedManager.kind === "launchd"
1086
? contents.replace(/(<key>PATH<\/key>\n\s*<string>)[^<]*(<\/string>)/, "$1$2")
@@ -1052,6 +1093,7 @@ export const make = Effect.fn("cloud.boot_service.make")(function* (input: {
1093
installed: true,
1094
...(installedVersion === undefined ? {} : { installedVersion }),
1095
...(installedBaseDir === undefined ? {} : { installedBaseDir }),
1096
+ ...(otherBaseDir === undefined ? {} : { otherBaseDir }),
1097
problems,
1098
current:
1099
problems.length === 0 &&