Skip to content

Commit 70b3f7d

Browse files
author
Stef
committed
fix(server): distinguish legacy runtime ownership
1 parent 0197d8e commit 70b3f7d

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

‎apps/server/src/serverSingleton.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,9 @@ layer("serverSingleton", (it) => {
245245
assert.strictEqual(failure.holderPid, process.pid);
246246
assert.strictEqual(failure.holderPort, 3775);
247247
assert.include(failure.message, SERVER_RUNTIME_STATE_FILENAME);
248+
assert.include(failure.message, "compatibility guard for this older");
249+
assert.include(failure.message, "Do not remove it while the recorded process is live");
250+
assert.notInclude(failure.message, "contains display metadata only");
248251
}
249252
// And it must not have claimed the directory it refused.
250253
assert.isFalse(yield* fs.exists(yield* serverLockPath(stateDir)));

‎apps/server/src/serverSingleton.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
*
1212
* A pre-lock server has no lock database, so the first upgraded process also
1313
* checks `server-runtime.json` and refuses while that recorded pid is live.
14+
* That compatibility check starts only after the old binary publishes its
15+
* runtime state; an unmodified old binary cannot participate in a lock that
16+
* did not exist when it shipped.
1417
*/
1518
import * as Data from "effect/Data";
1619
import * as Crypto from "effect/Crypto";
@@ -50,6 +53,7 @@ export class ServerAlreadyRunningError extends Schema.TaggedErrorClass<ServerAlr
5053
holderPid: Schema.optional(Schema.Int),
5154
holderPort: Schema.optional(Schema.Int),
5255
holderStartedAt: Schema.optional(Schema.String),
56+
legacyRuntimeStatePath: Schema.optional(Schema.String),
5357
},
5458
) {
5559
override get message(): string {
@@ -59,7 +63,7 @@ export class ServerAlreadyRunningError extends Schema.TaggedErrorClass<ServerAlr
5963
: this.holderPort === undefined
6064
? `pid ${this.holderPid}`
6165
: `pid ${this.holderPid}, listening on port ${this.holderPort}`;
62-
return [
66+
const common = [
6367
"Another T3 Code server is already using this data directory.",
6468
"",
6569
` data directory: ${this.stateDir}`,
@@ -69,6 +73,17 @@ export class ServerAlreadyRunningError extends Schema.TaggedErrorClass<ServerAlr
6973
"Two servers sharing one data directory overwrite each other's state.sqlite",
7074
"and settings.json. Connect to the running server, stop it cleanly, or use",
7175
"a different --base-dir.",
76+
];
77+
if (this.legacyRuntimeStatePath !== undefined) {
78+
return [
79+
...common,
80+
"",
81+
`${this.legacyRuntimeStatePath} is the compatibility guard for this older`,
82+
"server. Do not remove it while the recorded process is live.",
83+
].join("\n");
84+
}
85+
return [
86+
...common,
7287
"",
7388
`Ownership is released automatically when the process exits. ${this.lockPath}`,
7489
"contains display metadata only; removing it does not release a live owner.",
@@ -314,6 +329,7 @@ export const acquireServerSingleton = Effect.fn("serverSingleton.acquire")(funct
314329
holderPid: legacy.state.pid,
315330
holderPort: legacy.state.port,
316331
holderStartedAt: legacy.state.startedAt,
332+
legacyRuntimeStatePath,
317333
}),
318334
),
319335
}),

0 commit comments

Comments
 (0)