Skip to content

Commit 23ae573

Browse files
fix(cli): compare t3 update against the installed service, not the executable
A newer t3 downloaded by hand and pointed at a home whose service still ran the old version reported "already on" and did nothing, because the already-on and downgrade checks compared the target against the executable's own version. The installed service version is what the machine runs, so it is now the baseline whenever a service is installed for the target home; the executable's version only stands in when there is no service. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent c3ffcff commit 23ae573

1 file changed

Lines changed: 33 additions & 23 deletions

File tree

‎apps/server/src/cli/update.ts‎

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,27 @@ const runUpdate = Effect.fn("cli.update.run")(function* (input: {
286286
const targetVersion = input.requestedVersion ?? (yield* resolveNewestVersion(channel));
287287
const targetChannel = cliReleaseChannelOf(targetVersion);
288288

289+
// Work out everything that will be touched before touching anything, so the
290+
// user sees one plan and one question rather than a surprise restart.
291+
const status = yield* service.status;
292+
// The unit name is per user, not per T3 home. Only touch the service when it
293+
// serves the home this update targets; otherwise it belongs to another
294+
// install on this machine and restarting it would take that server down.
295+
const servesThisHome =
296+
status.installedBaseDir !== undefined &&
297+
path.resolve(status.installedBaseDir) === path.resolve(input.baseDir);
298+
const serviceInstalled = status.supported && status.installed && servesThisHome;
299+
const foreground = yield* findForegroundServer({
300+
serverRuntimeStatePath: input.serverRuntimeStatePath,
301+
serviceInstalled,
302+
});
303+
// "Already on" is about what this machine runs, not what this executable
304+
// is: a newer t3 downloaded by hand and pointed at a home whose service
305+
// still runs the old version has an update to do, and the service's
306+
// version is the one the downgrade check has to protect.
307+
const serviceVersion = serviceInstalled ? status.installedVersion : undefined;
308+
const installedVersion = serviceVersion ?? currentVersion;
309+
289310
// Only archive-distributed versions install without Node and npm on the
290311
// machine. Until nightly and stable ship archives, updating onto them from
291312
// here would reintroduce the dependency this command exists to remove.
@@ -294,13 +315,17 @@ const runUpdate = Effect.fn("cli.update.run")(function* (input: {
294315
reason: `t3@${targetVersion} is published on npm only. Install it with \`npm install -g t3@${targetVersion}\`, or pick a version from the preview channel.`,
295316
});
296317
}
297-
if (targetVersion === currentVersion) {
298-
yield* Console.log(`t3 is already on ${currentVersion} (${targetChannel}).`);
318+
if (targetVersion === installedVersion) {
319+
yield* Console.log(
320+
serviceVersion !== undefined
321+
? `t3 and its background service are already on ${installedVersion} (${targetChannel}).`
322+
: `t3 is already on ${installedVersion} (${targetChannel}).`,
323+
);
299324
return;
300325
}
301-
if (!input.allowDowngrade && compareExactServiceVersions(targetVersion, currentVersion) < 0) {
326+
if (!input.allowDowngrade && compareExactServiceVersions(targetVersion, installedVersion) < 0) {
302327
return yield* new CliUpdateError({
303-
reason: `t3@${targetVersion} is older than the running ${currentVersion}. Pass --allow-downgrade to install it anyway.`,
328+
reason: `t3@${targetVersion} is older than the installed ${installedVersion}. Pass --allow-downgrade to install it anyway.`,
304329
});
305330
}
306331

@@ -311,25 +336,10 @@ const runUpdate = Effect.fn("cli.update.run")(function* (input: {
311336
Effect.orElseSucceed(() => false),
312337
);
313338

314-
// Work out everything that will be touched before touching anything, so the
315-
// user sees one plan and one question rather than a surprise restart.
316-
const status = yield* service.status;
317-
// The unit name is per user, not per T3 home. Only touch the service when it
318-
// serves the home this update targets; otherwise it belongs to another
319-
// install on this machine and restarting it would take that server down.
320-
const servesThisHome =
321-
status.installedBaseDir !== undefined &&
322-
path.resolve(status.installedBaseDir) === path.resolve(input.baseDir);
323-
const serviceInstalled = status.supported && status.installed && servesThisHome;
324-
const foreground = yield* findForegroundServer({
325-
serverRuntimeStatePath: input.serverRuntimeStatePath,
326-
serviceInstalled,
327-
});
328-
329339
yield* Console.log(
330340
alreadyOnDisk
331-
? `Switching t3 ${currentVersion} -> ${targetVersion} (${targetChannel}, already downloaded).`
332-
: `Updating t3 ${currentVersion} -> ${targetVersion} (${targetChannel}).`,
341+
? `Switching t3 ${installedVersion} -> ${targetVersion} (${targetChannel}, already downloaded).`
342+
: `Updating t3 ${installedVersion} -> ${targetVersion} (${targetChannel}).`,
333343
);
334344
let restartService = false;
335345
if (serviceInstalled) {
@@ -444,7 +454,7 @@ const runUpdate = Effect.fn("cli.update.run")(function* (input: {
444454
yield* Console.log(` Background service restarted on ${targetVersion}`);
445455
} else if (serviceInstalled) {
446456
yield* Console.log(
447-
` Background service still running ${status.installedVersion ?? currentVersion}. Run \`t3 service update\` when you are ready to restart it.`,
457+
` Background service still running ${installedVersion}. Run \`t3 service update\` when you are ready to restart it.`,
448458
);
449459
} else if (status.installed && !servesThisHome) {
450460
yield* Console.log(
@@ -453,7 +463,7 @@ const runUpdate = Effect.fn("cli.update.run")(function* (input: {
453463
}
454464
if (foreground !== undefined) {
455465
yield* Console.log(
456-
` A server started by hand is still running ${currentVersion} at ${foreground.origin} (pid ${foreground.pid}). Stop it and start it again to pick up ${targetVersion}.`,
466+
` A server started by hand is still running at ${foreground.origin} (pid ${foreground.pid}). Stop it and start it again to pick up ${targetVersion}.`,
457467
);
458468
}
459469
});

0 commit comments

Comments
 (0)