pi-better-server 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/package.json +1 -1
- package/src/handshake.ts +1 -1
- package/src/remote-client/packages.ts +8 -2
- package/src/startup/activation.ts +27 -3
package/README.md
CHANGED
|
@@ -316,6 +316,12 @@ an explicit migration before automatic activation can proceed. The client leaves
|
|
|
316
316
|
the old daemon running and reports the reason instead of killing it.
|
|
317
317
|
|
|
318
318
|
Activation records live in `<serverDir>/activation.json` and `activation.log`.
|
|
319
|
+
When an older build remains staged after its daemon exits, a new activation can
|
|
320
|
+
retire that build's reservations under the exclusive activation lock. Cleanup
|
|
321
|
+
requires an absent listener, verified previous-owner exit, the same agent
|
|
322
|
+
directory, and compatible SDK/protocol versions. It preserves session files and
|
|
323
|
+
compatibility evidence; live or ambiguous owners and committed upgrades remain
|
|
324
|
+
blocked.
|
|
319
325
|
`recovery-required` preserves an ambiguous or adopted candidate for inspection;
|
|
320
326
|
it does not authorize another writer or a rollback. Automatic rollback is limited
|
|
321
327
|
to a proven candidate exit before adoption and restores code only, not settings,
|
package/package.json
CHANGED
package/src/handshake.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { ServerBuild } from "./startup/managed-types.ts";
|
|
|
4
4
|
import { PROTOCOL_VERSION, type HelloCommand, type HelloData } from "./protocol.ts";
|
|
5
5
|
|
|
6
6
|
/** Kept equal to package.json `version`; a test pins that. */
|
|
7
|
-
export const SERVER_VERSION = "0.1.
|
|
7
|
+
export const SERVER_VERSION = "0.1.2";
|
|
8
8
|
|
|
9
9
|
export const SERVER_EXTENSION_VERSIONS: Readonly<Record<string, string>> = { "pi-better-server": SERVER_VERSION };
|
|
10
10
|
|
|
@@ -2,7 +2,7 @@ import { execFile } from "node:child_process";
|
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
3
|
import { existsSync, lstatSync, mkdirSync, readFileSync, realpathSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
|
-
import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
5
|
+
import { delimiter, dirname, isAbsolute, join, resolve } from "node:path";
|
|
6
6
|
import { promisify } from "node:util";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
8
|
import { getAgentDir, ProjectTrustStore, SettingsManager } from "@earendil-works/pi-coding-agent";
|
|
@@ -313,7 +313,13 @@ export async function installPackageCatalog(packages: PackageSpec[], options: {
|
|
|
313
313
|
for (const item of approved) {
|
|
314
314
|
try {
|
|
315
315
|
await run(process.execPath, [cli, "install", item.source], {
|
|
316
|
-
cwd: agentDir,
|
|
316
|
+
cwd: agentDir,
|
|
317
|
+
env: {
|
|
318
|
+
...process.env,
|
|
319
|
+
// The managed runtime's npm and its Node shebang live beside this executable.
|
|
320
|
+
PATH: [dirname(process.execPath), process.env.PATH].filter(Boolean).join(delimiter),
|
|
321
|
+
PI_CODING_AGENT_DIR: agentDir,
|
|
322
|
+
},
|
|
317
323
|
encoding: "utf8", maxBuffer: 4 * 1024 * 1024,
|
|
318
324
|
});
|
|
319
325
|
} catch {
|
|
@@ -213,9 +213,10 @@ export async function activateStagedRuntime(options: ActivateOptions): Promise<A
|
|
|
213
213
|
const journal = readActivationJournal(serverDir);
|
|
214
214
|
if (journal && !freshRollbackRequest(journal, request)) {
|
|
215
215
|
if (journal.desiredBuild.contentId !== options.runtime.build.contentId) {
|
|
216
|
-
// The detached worker
|
|
217
|
-
// Keep
|
|
218
|
-
|
|
216
|
+
// The detached worker may still be replacing a ready journal or retiring
|
|
217
|
+
// a stale staged activation. Keep its caller reservation until it decides.
|
|
218
|
+
const awaitingWorker = journal.phase === "staged" && worker.exitCode === null && worker.signalCode === null;
|
|
219
|
+
if ((journal.phase !== "ready" && !awaitingWorker) || !reservedAgainst(request, journal.operationId)) { unreserve(); return conflict(journal); }
|
|
219
220
|
} else if (journal.phase === "ready") {
|
|
220
221
|
const probe = await defaultActivationPorts.probe(serverDir);
|
|
221
222
|
if (matches(probe, journal)) { unreserve(); return result(journal); }
|
|
@@ -323,6 +324,29 @@ export async function runActivationWorker(request: UpgradeRequest, ports: Activa
|
|
|
323
324
|
const probe = await ports.probe(serverDir);
|
|
324
325
|
if (probe.kind === "ready" && matches(probe, journal)) { clearReservations(journal); return result(journal); }
|
|
325
326
|
}
|
|
327
|
+
// A legacy daemon may have exited after deferring a staged build. Its durable
|
|
328
|
+
// reservation must not block every later build. Only the exclusive coordinator
|
|
329
|
+
// can retire it, after proving no writer remains and preserving compatibility.
|
|
330
|
+
if (journal?.phase === "staged" && journal.desiredBuild.contentId !== request.runtime.build.contentId
|
|
331
|
+
&& journal.rollbackPermit === undefined && !journal.candidateOwner
|
|
332
|
+
&& realpathSync(journal.agentDir) === realpathSync(request.agentDir)
|
|
333
|
+
&& reservedAgainst(request, journal.operationId)) {
|
|
334
|
+
const probe = await ports.probe(serverDir);
|
|
335
|
+
const owner = inspectDaemonOwner(serverDir);
|
|
336
|
+
const previous = journal.previousBuild ?? journal.previousCompatibility;
|
|
337
|
+
if (probe.kind === "absent" && (owner.status === "missing" || owner.status === "dead")
|
|
338
|
+
&& journal.previousOwner && !ownerIsAlive(journal.previousOwner)
|
|
339
|
+
&& previous && compatibleUpgrade(previous, request.runtime.build)
|
|
340
|
+
&& reservedAgainst(request, journal.operationId)) {
|
|
341
|
+
const retired = journal;
|
|
342
|
+
journal = { ...request, serverDir, version: 1, phase: "staged", desiredBuild: request.runtime.build,
|
|
343
|
+
previousBuild: retired.previousBuild, previousRuntime: retired.previousRuntime,
|
|
344
|
+
previousCompatibility: retired.previousCompatibility, previousOwner: retired.previousOwner,
|
|
345
|
+
emptyNamespace: retired.emptyNamespace };
|
|
346
|
+
save(journal);
|
|
347
|
+
clearReservations(retired);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
326
350
|
if (journal && journal.desiredBuild.contentId !== request.runtime.build.contentId && journal.phase !== "ready"
|
|
327
351
|
&& (committed(journal.phase) || hasActivationReservations(journal))) return conflict(journal);
|
|
328
352
|
if (journal?.phase === "recovery-required") {
|