From 39bb7ad0e35ef08d03408cdc48797a04e0f1306d Mon Sep 17 00:00:00 2001 From: Andre Brait Date: Wed, 18 Nov 2026 10:23:21 +0000 Subject: [PATCH 1/3] fix(windows): stop a failed host candidate that got the old daemon's pid A restarted instance is recorded in plan.current. Windows hands a freed pid to the next process, so the candidate can carry the pid the update inspected, with a different start time. assertPlan refused that as inconsistent, so rolling back could not stop the failed candidate ('Invalid upgrade process plan: current instance does not match the inspected process') and recovery was required. The inspected pid and identity describe a process that is gone after a restart; a stop acts on plan.current, which runningInstance checks against the live process, so a recycled pid is still refused. Drop the false invariant. --- CHANGELOG.md | 1 + lib/upgrade-process.test.mjs | 12 +++++++++++- lib/upgrade-process.ts | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 00ef9ec4d..6119ae333 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ All notable changes to **omp-web** (`@kahme247/ompweb`) are documented in this f - **In-app updates can replace an npm-global Windows install started by the tray.** The update stops the tray program in the package and any node or bun process still using that install, without ending the update itself, and runs the install from outside the package so Windows can rename it. When the tray started the server, it is started again in the logged-on session and starts the one server; otherwise the server is started directly and still told which install to serve. - **Windows updates no longer fail when the update status is read while it is written.** Host update state, the server worker's status and upgrade plans retry their atomic replacement for a moment when a concurrent reader holds the file, as the server's own update state already did. +- **A host update's failed candidate is stopped on Windows even when it got the old daemon's pid.** Windows hands a freed pid to the next process, so the restarted candidate could carry the pid the update had inspected; the stop then refused the plan as inconsistent ("Invalid upgrade process plan: current instance does not match the inspected process"), left the candidate running and required recovery instead of restoring the previous release. A stop checks the instance it acts on against the live process, so a recycled pid is still refused. - **GitHub workflow watches no longer regress to stale run states.** Workflow updates retain GitHub's run timestamp and ignore older snapshots for the same or an earlier attempt, so a delayed `queued` response cannot follow a newer `in_progress` delivery. - **Keep sidebar transcript results aligned with expandable hits on every linked host.** Each daemon now searches its own active conversations, ignoring abandoned branches and pre-compaction messages. diff --git a/lib/upgrade-process.test.mjs b/lib/upgrade-process.test.mjs index 8d059f765..5185cfb4e 100644 --- a/lib/upgrade-process.test.mjs +++ b/lib/upgrade-process.test.mjs @@ -238,10 +238,20 @@ test("inspection refuses the wrong role, installation or process, and stop refus await assert.rejects(upgrade.stopUpgradeProcess({ ...plan, platform: "plan9" }), /Invalid upgrade process plan/); await assert.rejects(upgrade.stopUpgradeProcess({ ...plan, supervisor: { kind: "systemd", unit: "../evil", user: false, configHash: "x" } }), /Invalid upgrade process plan/); await assert.rejects(upgrade.stopUpgradeProcess({ ...plan, supervisor: { kind: "launchd", label: "dev.ompweb.test", domain: "pid/1", plist: join(fixture.dir, "test.plist"), configHash: "x" } }), /Invalid upgrade process plan/); - await assert.rejects(upgrade.stopUpgradeProcess({ ...plan, identity: `${plan.identity}-other` }), /Invalid upgrade process plan/); assert.ok(running(fixture.pid), "none of the refused plans touched the process"); }); +test("an instance that took the inspected pid over after a restart is stopped, and a recycled pid is still refused", { timeout: 120_000 }, async () => { + const fixture = await orphanHost("restarted onto the inspected pid"); + const inspected = await inspect(fixture); + // Windows gives a just-freed pid to the very next process: the restarted instance has the inspected pid and a later start time. + const reused = { ...inspected, identity: `${inspected.identity}-previous-instance` }; + await assert.rejects(upgrade.stopUpgradeProcess({ ...reused, current: { pid: fixture.pid, identity: `${inspected.identity}-recycled` } }), /no longer the process that was inspected/); + assert.ok(running(fixture.pid), "an instance that is not the recorded one is never signalled"); + await upgrade.stopUpgradeProcess(reused); + assert.ok(!running(fixture.pid), "the recorded instance was stopped"); +}); + test("a shell restart loop is frozen while its daemon is replaced, then resumed to start the daemon again", { skip: windows && "POSIX shell loops only; Windows supervisors are tasks and services", timeout: 120_000 }, async () => { const { dir, host, pidFile } = install("loop with spaces"); const script = join(dir, "loop.sh"); diff --git a/lib/upgrade-process.ts b/lib/upgrade-process.ts index 4fc74c1c8..43f5ec82b 100644 --- a/lib/upgrade-process.ts +++ b/lib/upgrade-process.ts @@ -663,7 +663,7 @@ function assertPlan(plan: UpgradeProcess): void { if (typeof plan.installDir !== "string" || !isAbsolute(plan.installDir)) bad("installDir"); const current = plan.current; if (!current || typeof current !== "object" || (current.pid === null) !== (current.identity === null) || (current.pid !== null && (!Number.isSafeInteger(current.pid) || current.pid <= 1 || typeof current.identity !== "string"))) bad("current instance"); - if (current.pid === plan.pid && current.identity !== plan.identity) bad("current instance does not match the inspected process"); + // `current` follows restarts and is checked against the live process when a stop acts on it; Windows may give the restarted instance the inspected pid, so the pid alone says nothing about identity. const s = plan.supervisor; const text = (value: unknown) => typeof value === "string" && value.length > 0 && value.length <= 4096 && !/[\0-\x1f]/.test(value); if (!s || typeof s !== "object") bad("supervisor"); From 3af570b6a270663109bd0b0d5945b0f00d251c7a Mon Sep 17 00:00:00 2001 From: Andre Brait Date: Wed, 18 Nov 2026 10:27:50 +0000 Subject: [PATCH 2/3] test(hosts): wait for the fixture daemon to finish writing its pid main failed "binary release verifies the official digest" with "Invalid process id": the ready file existed but was still empty. --- lib/hosts/update-worker.test.mjs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/hosts/update-worker.test.mjs b/lib/hosts/update-worker.test.mjs index ec7754668..ddda0a03d 100644 --- a/lib/hosts/update-worker.test.mjs +++ b/lib/hosts/update-worker.test.mjs @@ -101,7 +101,8 @@ async function fixture(id, { candidate = "ack", installKind = "ack", method = "n writeFileSync(starterScript, `require("node:fs").writeFileSync(${JSON.stringify(ready)},String(process.pid));\n` + (shutdownDelay ? `process.on("SIGTERM",()=>setTimeout(()=>process.exit(0),${shutdownDelay}));\n` : "") + (sessions ? sessionDaemonScript(join(install, "bin", "idle-web.js"), sessionPids, sessions === "orphan") : `require(${JSON.stringify(host)});`)); starter = await spawnNodeOutsideService(starterScript, launch.env, [host, ...layout.hostArgs]); assert.ok(starter, "the fixture requires a scope outside the suite's service"); - for (let tries = 0; !existsSync(ready) || (sessions && !existsSync(sessionPids)); tries++) { + // The starter writes its pid with writeFileSync, which can be seen empty before the write lands. + for (let tries = 0; !existsSync(ready) || !readFileSync(ready, "utf8").trim() || (sessions && !existsSync(sessionPids)); tries++) { assert.ok(tries < 100, "the scoped daemon never became ready"); await wait(100); } From b2aae4914fef37fae533e98122bc398833c1be84 Mon Sep 17 00:00:00 2001 From: Andre Brait Date: Wed, 18 Nov 2026 10:28:53 +0000 Subject: [PATCH 3/3] docs: describe Windows pid reuse as possible, not guaranteed --- CHANGELOG.md | 2 +- lib/upgrade-process.test.mjs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6119ae333..fb7606e77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,7 @@ All notable changes to **omp-web** (`@kahme247/ompweb`) are documented in this f - **In-app updates can replace an npm-global Windows install started by the tray.** The update stops the tray program in the package and any node or bun process still using that install, without ending the update itself, and runs the install from outside the package so Windows can rename it. When the tray started the server, it is started again in the logged-on session and starts the one server; otherwise the server is started directly and still told which install to serve. - **Windows updates no longer fail when the update status is read while it is written.** Host update state, the server worker's status and upgrade plans retry their atomic replacement for a moment when a concurrent reader holds the file, as the server's own update state already did. -- **A host update's failed candidate is stopped on Windows even when it got the old daemon's pid.** Windows hands a freed pid to the next process, so the restarted candidate could carry the pid the update had inspected; the stop then refused the plan as inconsistent ("Invalid upgrade process plan: current instance does not match the inspected process"), left the candidate running and required recovery instead of restoring the previous release. A stop checks the instance it acts on against the live process, so a recycled pid is still refused. +- **A host update's failed candidate is stopped on Windows even when it got the old daemon's pid.** Windows can reuse a freed pid, so the restarted candidate could receive the pid the update had inspected; the stop then refused the plan as inconsistent ("Invalid upgrade process plan: current instance does not match the inspected process"), left the candidate running and required recovery instead of restoring the previous release. A stop checks the instance it acts on against the live process, so a recycled pid is still refused. - **GitHub workflow watches no longer regress to stale run states.** Workflow updates retain GitHub's run timestamp and ignore older snapshots for the same or an earlier attempt, so a delayed `queued` response cannot follow a newer `in_progress` delivery. - **Keep sidebar transcript results aligned with expandable hits on every linked host.** Each daemon now searches its own active conversations, ignoring abandoned branches and pre-compaction messages. diff --git a/lib/upgrade-process.test.mjs b/lib/upgrade-process.test.mjs index 5185cfb4e..5215e1a9b 100644 --- a/lib/upgrade-process.test.mjs +++ b/lib/upgrade-process.test.mjs @@ -244,7 +244,7 @@ test("inspection refuses the wrong role, installation or process, and stop refus test("an instance that took the inspected pid over after a restart is stopped, and a recycled pid is still refused", { timeout: 120_000 }, async () => { const fixture = await orphanHost("restarted onto the inspected pid"); const inspected = await inspect(fixture); - // Windows gives a just-freed pid to the very next process: the restarted instance has the inspected pid and a later start time. + // Windows can reuse a freed pid, so a restarted instance may hold the inspected pid with a later start time; simulated here by changing the recorded identities. const reused = { ...inspected, identity: `${inspected.identity}-previous-instance` }; await assert.rejects(upgrade.stopUpgradeProcess({ ...reused, current: { pid: fixture.pid, identity: `${inspected.identity}-recycled` } }), /no longer the process that was inspected/); assert.ok(running(fixture.pid), "an instance that is not the recorded one is never signalled");