Skip to content

Commit d164cfa

Browse files
fix(server): reclaim the T3 home only after it stays free for a poll interval
A desktop app relaunching (auto-update, server exposure or WSL toggles, backend restarts) frees the home for a few seconds. A single free probe in that gap let the idle service take the lock, and the relaunched app then gave up waiting and quit. The launcher now needs two consecutive free probes, one interval apart, before it starts the server. AI-assisted; verified with the tests and tools listed above. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent c8b1c02 commit d164cfa

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

‎apps/server/src/serviceLauncher.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,7 @@ export class Launcher {
805805
readonly #serviceUnit: ServiceUnit | undefined;
806806
readonly #environment: Readonly<NodeJS.ProcessEnv>;
807807
readonly #stateDirOwnerPollMs: number;
808+
#stateDirFreeProbes = 0;
808809
readonly #output: number | undefined;
809810
readonly #lockPath: string | undefined;
810811
readonly #stopChildOverIpc: boolean;
@@ -1312,6 +1313,7 @@ export class Launcher {
13121313
this.#log(
13131314
"[service-launcher] Another T3 Code server owns this T3 home. This service starts again once it stops.\n",
13141315
);
1316+
this.#stateDirFreeProbes = 0;
13151317
// The interval also keeps Node alive: signal listeners alone do not.
13161318
this.#timer = setInterval(
13171319
() => this.#enqueue(() => this.#reclaimStateDir()),
@@ -1325,8 +1327,12 @@ export class Launcher {
13251327
return;
13261328
}
13271329
if (this.#timer === undefined || this.#child !== null) return;
1330+
const owned = await stateDirOwned(this.#baseDir);
13281331
// A stop during the probe clears the timer.
1329-
if ((await stateDirOwned(this.#baseDir)) || this.#timer === undefined) return;
1332+
if (this.#timer === undefined) return;
1333+
// A relaunching desktop app frees the home for a few seconds; leave it that gap.
1334+
this.#stateDirFreeProbes = owned ? 0 : this.#stateDirFreeProbes + 1;
1335+
if (this.#stateDirFreeProbes < 2) return;
13301336
this.#clearTimer();
13311337
this.#log("[service-launcher] The T3 home is free again. Starting the server.\n");
13321338
const update = this.#state.update;

0 commit comments

Comments
 (0)