From 070576593c6143475f30bebca8aed5e6c15e5e63 Mon Sep 17 00:00:00 2001 From: Andre Brait Date: Thu, 19 Nov 2026 16:34:44 +0000 Subject: [PATCH 01/11] fix(hosts): report omp to the server once a runner fetched after start answers --- CHANGELOG.md | 2 ++ lib/hosts/daemon-link.ts | 3 +++ lib/hosts/daemon.test.mjs | 25 +++++++++++++++++++++++-- lib/hosts/daemon.ts | 18 +++++++++++++++++- 4 files changed, 45 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d4908cd3f..97d1be7cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ All notable changes to **omp-web** (`@kahme247/ompweb`) are documented in this f - **In-app updates work again on a Windows install without administrator rights.** The update looked for the service supervising the host daemon among its parent processes and skipped Task Scheduler's `svchost.exe` by its executable path, which Windows does not show to a non-administrator. It then took the daemon started by the `omp-web-host` scheduled task for the `Schedule` service, could not control that service and refused the update with `not_controllable` (#537). Service hosts are now recognized by process name, so the scheduled task is found. +- **A host no longer stays "omp not installed" once its runner is there.** The host daemon read the omp version once, at start, while the runner download it had just started in the background (or a fresh runner's first start, which Windows' antivirus can hold past the 30 s probe) was still running. Its server then showed **omp not installed** and refused every message until the daemon restarted, although Settings → Hosts listed the runner's version. A daemon that found no version now reads it again every 30 seconds and relinks to its servers as soon as omp answers. + ## [v0.7.3] - 2026-11-18 ### Fixed diff --git a/lib/hosts/daemon-link.ts b/lib/hosts/daemon-link.ts index e335bcfd8..c5de42077 100644 --- a/lib/hosts/daemon-link.ts +++ b/lib/hosts/daemon-link.ts @@ -75,6 +75,8 @@ export class DaemonLink { start(): void { this.runtime.start(); } stop(): Promise { return this.runtime.stop(); } rekey(token: string): void { this.runtime.rekey(token); } + /** Ends the current socket; the redial sends a fresh hello and resumes the link. */ + redial(why: string): void { this.runtime.redial(why); } isUp(): boolean { return this.runtime.isUp(); } busy(): boolean { return this.runtime.busy(); } /** An unsequenced report (`capacity`, `config_state`): sent now on an up link with room, never replayed. A @@ -495,5 +497,6 @@ function linkRuntime(owner: DaemonLink, deps: LinkDeps) { } return { queue, output, discard, result, report, busy: () => !mismatched && reliablePending > 0, ackedDown: () => down.acked, isUp: () => linked !== null && !stopped, rekey: (token: string) => { owner.login.token = token; authorization = "Bearer " + token; socket?.close(1001, "credentials changed"); }, + redial: (why: string) => { socket?.close(1001, why); }, start: () => { if (!started && !stopped) { started = true; loop = keepLinked(); } }, stop }; } diff --git a/lib/hosts/daemon.test.mjs b/lib/hosts/daemon.test.mjs index b6734c191..1fa821f47 100644 --- a/lib/hosts/daemon.test.mjs +++ b/lib/hosts/daemon.test.mjs @@ -1,6 +1,6 @@ import assert from "node:assert/strict"; import { execFileSync, spawnSync } from "node:child_process"; -import { existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, utimesSync, writeFileSync } from "node:fs"; +import { existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, renameSync, rmSync, utimesSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { dirname, join } from "node:path"; import test, { after } from "node:test"; @@ -123,7 +123,7 @@ globalThis.WebSocket = class SlowWebSocket extends globalThis.WebSocket { }; test.afterEach(() => Object.assign(uplink, { paused: false, bytesPerTick: Infinity, hideBuffer: false, maxBuffered: 0 })); -const { nextRedialDelay, runHostDaemon } = await import("./daemon.ts"); +const { nextRedialDelay, OMP_VERSION_RETRY_MS, runHostDaemon } = await import("./daemon.ts"); const { decodeBlobFrame, LINK_LIMITS, LINK_PROTOCOL_VERSION, PartJoiner } = await import("./link-protocol.ts"); const decoder = new TextDecoder(); @@ -536,6 +536,27 @@ test("an http:// loopback server links without --allow-http", async () => { } }); +test("a host whose omp was missing at start tells its server once the runner answers", async (t) => { + const log = captureLog(); + t.mock.timers.enable({ apis: ["setInterval"] }); + // Moved away rather than renamed in the env: earlier tests leave it cached as the binary. + renameSync(fakeOmp, `${fakeOmp}.missing`); + const server = scriptedServer(); + const daemon = start(server); + try { + await waitFor(() => server.hellos.length === 1, "the hello"); + assert.equal(server.hellos[0].ompVersion, null); + renameSync(`${fakeOmp}.missing`, fakeOmp); + t.mock.timers.tick(OMP_VERSION_RETRY_MS); + await waitFor(() => server.hellos.length === 2, "the redial"); + assert.equal(server.hellos[1].ompVersion, "14.0.0-fake"); + } finally { + if (existsSync(`${fakeOmp}.missing`)) renameSync(`${fakeOmp}.missing`, fakeOmp); + await daemon.stop(); + log.restore(); + } +}); + test("a running host deletes expired staged uploads every hour, not only when it starts or takes an upload", async (t) => { const log = captureLog(); t.mock.timers.enable({ apis: ["setInterval"] }); diff --git a/lib/hosts/daemon.ts b/lib/hosts/daemon.ts index 252f958fc..b6ea5b5bb 100644 --- a/lib/hosts/daemon.ts +++ b/lib/hosts/daemon.ts @@ -2,7 +2,7 @@ import { lstatSync, realpathSync, mkdirSync, watch } from "node:fs"; import { access, constants } from "node:fs/promises"; import { homedir } from "node:os"; import { basename, delimiter, dirname, isAbsolute, join, resolve, sep } from "node:path"; -import { getOmpVersion } from "../omp/omp-cli"; +import { getOmpVersion, resolveOmpBin } from "../omp/omp-cli"; import { getAgentDir, getSessionsDir } from "../omp/paths"; import { ProjectPathError } from "../project-registry"; import { isValidSessionId } from "../session-file-references-core"; @@ -98,6 +98,8 @@ export interface HostDaemon { } /** `hostSocket`: where omps started from a TUI attach (`hostSocketPath()`); unset, none can. */ type DaemonOptions = { allowHttp: boolean; url?: string; token?: string; links?: HostLink[]; hostSocket?: string }; +/** How often a daemon whose omp version read found nothing reads it again. */ +export const OMP_VERSION_RETRY_MS = 30_000; export function runHostDaemon(options: DaemonOptions): HostDaemon { const explicit = options.url !== undefined && options.token !== undefined ? [{ url: options.url, token: options.token }] : options.links; const initial = explicit ?? readHostLinks(); @@ -549,6 +551,20 @@ export function runHostDaemon(options: DaemonOptions): HostDaemon { operationsInFlight--; if (!stopped) for (const link of links.values()) link.start(); }); + // The hello is the only place a server reads the version, and a null one marks the host "omp not installed": a + // runner whose first fetch or (Windows antivirus) first start outlasted the startup read is retried until it answers, + // then every link redials to say so. + const versionRetry = setInterval(() => { + if (ompVersion !== null || stopped) { clearInterval(versionRetry); return; } + resolveOmpBin(true); + void getOmpVersion().then(version => { + if (version === null || ompVersion !== null || stopped) return; + ompVersion = version; + clearInterval(versionRetry); + for (const link of links.values()) link.redial("omp version changed"); + }).catch(error => log("could not read omp version: " + reason(error))); + }, OMP_VERSION_RETRY_MS); + versionRetry.unref?.(); const started = Promise.all([startupSweep, startupRecovery, versionRead, hostSocket]).then(() => {}); return { stop: () => shutdown(0), done, control, started }; } From dd6c2e156969849bf1acf1b4c335af576a2cdc69 Mon Sep 17 00:00:00 2001 From: Andre Brait Date: Thu, 19 Nov 2026 16:43:32 +0000 Subject: [PATCH 02/11] fix(hosts): report a late omp version as a link message instead of redialing --- CHANGELOG.md | 2 +- lib/hosts/daemon.test.mjs | 19 +++++++++------ lib/hosts/daemon.ts | 50 ++++++++++++++++++++++++-------------- lib/hosts/host-cli.ts | 2 +- lib/hosts/hub.test.mjs | 9 +++++++ lib/hosts/hub.ts | 4 +++ lib/hosts/link-protocol.ts | 7 +++++- lib/omp/omp-cli.ts | 4 ++- 8 files changed, 67 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 97d1be7cf..8aa431cfd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ All notable changes to **omp-web** (`@kahme247/ompweb`) are documented in this f - **In-app updates work again on a Windows install without administrator rights.** The update looked for the service supervising the host daemon among its parent processes and skipped Task Scheduler's `svchost.exe` by its executable path, which Windows does not show to a non-administrator. It then took the daemon started by the `omp-web-host` scheduled task for the `Schedule` service, could not control that service and refused the update with `not_controllable` (#537). Service hosts are now recognized by process name, so the scheduled task is found. -- **A host no longer stays "omp not installed" once its runner is there.** The host daemon read the omp version once, at start, while the runner download it had just started in the background (or a fresh runner's first start, which Windows' antivirus can hold past the 30 s probe) was still running. Its server then showed **omp not installed** and refused every message until the daemon restarted, although Settings → Hosts listed the runner's version. A daemon that found no version now reads it again every 30 seconds and relinks to its servers as soon as omp answers. +- **A host no longer stays "omp not installed" once its runner is there.** The host daemon read the omp version once, at start, while the runner download it had just started in the background (or a fresh runner's first start, which Windows' antivirus can hold past the 30 s probe) was still running. Its server then showed **omp not installed** and refused every message until the daemon restarted, although Settings → Hosts listed the runner's version. The daemon now reads the version again when the download finishes, and otherwise after 30 seconds, doubling up to 5 minutes, and tells its servers as soon as omp answers, without reconnecting. A server that predates this keeps the old behaviour until the daemon restarts. ## [v0.7.3] - 2026-11-18 diff --git a/lib/hosts/daemon.test.mjs b/lib/hosts/daemon.test.mjs index 1fa821f47..ee629bf3d 100644 --- a/lib/hosts/daemon.test.mjs +++ b/lib/hosts/daemon.test.mjs @@ -123,7 +123,7 @@ globalThis.WebSocket = class SlowWebSocket extends globalThis.WebSocket { }; test.afterEach(() => Object.assign(uplink, { paused: false, bytesPerTick: Infinity, hideBuffer: false, maxBuffered: 0 })); -const { nextRedialDelay, OMP_VERSION_RETRY_MS, runHostDaemon } = await import("./daemon.ts"); +const { nextRedialDelay, runHostDaemon } = await import("./daemon.ts"); const { decodeBlobFrame, LINK_LIMITS, LINK_PROTOCOL_VERSION, PartJoiner } = await import("./link-protocol.ts"); const decoder = new TextDecoder(); @@ -536,23 +536,26 @@ test("an http:// loopback server links without --allow-http", async () => { } }); -test("a host whose omp was missing at start tells its server once the runner answers", async (t) => { +test("a host whose omp was missing at start tells its server once the runner answers", async () => { const log = captureLog(); - t.mock.timers.enable({ apis: ["setInterval"] }); // Moved away rather than renamed in the env: earlier tests leave it cached as the binary. renameSync(fakeOmp, `${fakeOmp}.missing`); const server = scriptedServer(); - const daemon = start(server); + let daemon; try { + daemon = start(server); await waitFor(() => server.hellos.length === 1, "the hello"); assert.equal(server.hellos[0].ompVersion, null); + await daemon.refreshOmpVersion(); + assert.equal(server.up.some((m) => m.type === "omp_version"), false); renameSync(`${fakeOmp}.missing`, fakeOmp); - t.mock.timers.tick(OMP_VERSION_RETRY_MS); - await waitFor(() => server.hellos.length === 2, "the redial"); - assert.equal(server.hellos[1].ompVersion, "14.0.0-fake"); + await daemon.refreshOmpVersion(); + await waitFor(() => server.up.some((m) => m.type === "omp_version"), "the omp_version message"); + assert.equal(server.up.find((m) => m.type === "omp_version").ompVersion, "14.0.0-fake"); + assert.equal(server.hellos.length, 1, "the link is not redialed"); } finally { if (existsSync(`${fakeOmp}.missing`)) renameSync(`${fakeOmp}.missing`, fakeOmp); - await daemon.stop(); + await daemon?.stop(); log.restore(); } }); diff --git a/lib/hosts/daemon.ts b/lib/hosts/daemon.ts index b6ea5b5bb..6422ff711 100644 --- a/lib/hosts/daemon.ts +++ b/lib/hosts/daemon.ts @@ -2,7 +2,7 @@ import { lstatSync, realpathSync, mkdirSync, watch } from "node:fs"; import { access, constants } from "node:fs/promises"; import { homedir } from "node:os"; import { basename, delimiter, dirname, isAbsolute, join, resolve, sep } from "node:path"; -import { getOmpVersion, resolveOmpBin } from "../omp/omp-cli"; +import { getOmpVersion } from "../omp/omp-cli"; import { getAgentDir, getSessionsDir } from "../omp/paths"; import { ProjectPathError } from "../project-registry"; import { isValidSessionId } from "../session-file-references-core"; @@ -95,11 +95,14 @@ export interface HostDaemon { /** Settles once startup work (upload sweep, session recovery, omp version read) is done; until then drain reports busy. */ started: Promise; control(command: HostControlCommand): HostControlStatus; + /** Reads the omp version again while it is unknown (a runner fetched after start) and tells every server once found. */ + refreshOmpVersion(): Promise; } /** `hostSocket`: where omps started from a TUI attach (`hostSocketPath()`); unset, none can. */ type DaemonOptions = { allowHttp: boolean; url?: string; token?: string; links?: HostLink[]; hostSocket?: string }; -/** How often a daemon whose omp version read found nothing reads it again. */ +/** A daemon whose omp version read found nothing reads it again after this, doubling up to OMP_VERSION_RETRY_MAX_MS. */ export const OMP_VERSION_RETRY_MS = 30_000; +const OMP_VERSION_RETRY_MAX_MS = 5 * 60_000; export function runHostDaemon(options: DaemonOptions): HostDaemon { const explicit = options.url !== undefined && options.token !== undefined ? [{ url: options.url, token: options.token }] : options.links; const initial = explicit ?? readHostLinks(); @@ -117,6 +120,7 @@ export function runHostDaemon(options: DaemonOptions): HostDaemon { let stopping: Promise | undefined; let updateStateWarningLogged = false; let reloadTimer: NodeJS.Timeout | undefined; + let versionRetry: NodeJS.Timeout | undefined, versionRetryMs = OMP_VERSION_RETRY_MS; let drained = process.env.OMP_WEB_HOST_DRAINED === "1"; let preparationsInFlight = 0, operationsInFlight = 0, nativeUpdatesInFlight = 0; const executable = realpathSync(process.execPath); @@ -512,7 +516,7 @@ export function runHostDaemon(options: DaemonOptions): HostDaemon { } function shutdown(code: number): Promise { if (stopping) return stopping; - stopped = true; watcher.close(); clearTimeout(reloadTimer); clearInterval(sweepTimer); clearInterval(capacityTimer); uploadRetention.stop(); + stopped = true; watcher.close(); clearTimeout(reloadTimer); clearInterval(sweepTimer); clearInterval(capacityTimer); clearTimeout(versionRetry); uploadRetention.stop(); clearTimeout(recoveryTimer); // Freeze before exit handlers observe children stopping. resume.freeze(); @@ -551,20 +555,30 @@ export function runHostDaemon(options: DaemonOptions): HostDaemon { operationsInFlight--; if (!stopped) for (const link of links.values()) link.start(); }); - // The hello is the only place a server reads the version, and a null one marks the host "omp not installed": a - // runner whose first fetch or (Windows antivirus) first start outlasted the startup read is retried until it answers, - // then every link redials to say so. - const versionRetry = setInterval(() => { - if (ompVersion !== null || stopped) { clearInterval(versionRetry); return; } - resolveOmpBin(true); - void getOmpVersion().then(version => { - if (version === null || ompVersion !== null || stopped) return; - ompVersion = version; - clearInterval(versionRetry); - for (const link of links.values()) link.redial("omp version changed"); - }).catch(error => log("could not read omp version: " + reason(error))); - }, OMP_VERSION_RETRY_MS); - versionRetry.unref?.(); + // A null version in the hello marks this host "omp not installed" and its sessions refused. The runner's first fetch, + // or a first start Windows' antivirus holds past the probe, can outlast the startup read: read again until omp answers, + // then tell every server (a link made later says it in its hello). + async function refreshOmpVersion(): Promise { + await versionRead; + if (stopped || ompVersion !== null) return; + clearTimeout(versionRetry); versionRetry = undefined; + const version = await getOmpVersion(true); + if (stopped || ompVersion !== null) return; + if (version === null) { + clearTimeout(versionRetry); + versionRetry = setTimeout(() => void refreshOmpVersion(), versionRetryMs); + versionRetry.unref?.(); + versionRetryMs = Math.min(versionRetryMs * 2, OMP_VERSION_RETRY_MAX_MS); + return; + } + ompVersion = version; + for (const link of links.values()) link.queue({ type: "omp_version", ompVersion: version }, "omp_version"); + } + void versionRead.then(() => { + if (stopped || ompVersion !== null) return; + versionRetry = setTimeout(() => void refreshOmpVersion(), versionRetryMs); + versionRetry.unref?.(); + }); const started = Promise.all([startupSweep, startupRecovery, versionRead, hostSocket]).then(() => {}); - return { stop: () => shutdown(0), done, control, started }; + return { stop: () => shutdown(0), done, control, started, refreshOmpVersion }; } diff --git a/lib/hosts/host-cli.ts b/lib/hosts/host-cli.ts index 4f2b9c57d..0748c7d85 100644 --- a/lib/hosts/host-cli.ts +++ b/lib/hosts/host-cli.ts @@ -81,7 +81,7 @@ async function main(argv: string[]): Promise { // The runners of earlier "Update omp" installs: no session of this daemon is running from them any more. sweepOmpRunners(); // Sessions need the runner; until it is here they fail with OMP_NOT_FOUND and the next start retries. - void ensureOmpRunner().catch((error: unknown) => console.error(`ompweb host: ${error instanceof Error ? error.message : String(error)}`)); + void ensureOmpRunner().then(bin => { if (bin) return daemon?.refreshOmpVersion(); }).catch((error: unknown) => console.error(`ompweb host: ${error instanceof Error ? error.message : String(error)}`)); // Windows has no host socket yet (a current-user named pipe is open in the runner spec). daemon = runHostDaemon({ allowHttp: argv.includes("--allow-http"), hostSocket: process.platform === "win32" ? undefined : hostSocketPath() }); // Worker cutover starts fail-closed; ordinary hosts have no maintenance environment. diff --git a/lib/hosts/hub.test.mjs b/lib/hosts/hub.test.mjs index 7c79371c0..08f89de8e 100644 --- a/lib/hosts/hub.test.mjs +++ b/lib/hosts/hub.test.mjs @@ -307,6 +307,15 @@ test("hello without omp marks the host omp-missing and spawnRpc rejects", async await down.cancel(); }); +test("an omp_version after a hello without omp brings the host online", async () => { + const link = await linkedHost("Late omp", { ompVersion: null }); + assert.equal(link.remote.status(), "omp-missing"); + assert.deepEqual(linkPost(link, [{ type: "omp_version", seq: 1, ompVersion: "19.0.0" }]), [1]); + assert.equal(link.remote.status(), "online"); + assert.equal(hub.listHosts().find((h) => h.id === link.id).ompVersion, "19.0.0"); + await link.down.cancel(); +}); + test("a second link with the same token closes the first socket with 4409, and frames still arriving on it are ignored", async () => { const a = await linkedHost("Two daemons"); assert.deepEqual(linkPost(a, [{ type: "stdout", seq: 500, ch: "none", line: "x" }]), [500]); diff --git a/lib/hosts/hub.ts b/lib/hosts/hub.ts index c2cbc4e38..b7961acfe 100644 --- a/lib/hosts/hub.ts +++ b/lib/hosts/hub.ts @@ -1003,6 +1003,10 @@ function applyUp(link: Link, message: UpMessage | UnknownMessage, whole?: UpMess return link.channels.get(message.ch)?.deliverLine(message.line); case "stderr": return link.channels.get(message.ch)?.deliverStderr(message.chunk); + case "omp_version": + link.ompVersion = message.ompVersion; + if (link.status === "omp-missing") setStatus(link, "online"); + return; case "resync": return link.channels.get(message.ch)?.deliverResync(); case "exit": { diff --git a/lib/hosts/link-protocol.ts b/lib/hosts/link-protocol.ts index 49ec8133b..dd59a01ac 100644 --- a/lib/hosts/link-protocol.ts +++ b/lib/hosts/link-protocol.ts @@ -183,6 +183,9 @@ export type UpMessage = | { type: "resync"; seq: number; ch: string } | { type: "notifier"; seq: number; on: boolean } | { type: "sessions_changed"; seq: number } + /** The omp version found after the hello said none (the runner arrived or first answered later); a hub that predates + * it skips the type and keeps "omp not installed" until the next hello. */ + | { type: "omp_version"; seq: number; ompVersion: string } | { type: "channels_changed"; seq: number; channels: HelloChannel[] } /** The daemon's link samples, at most LINK_LIMITS.statsSamples; a hub that predates it skips the type. Advisory: the * receiver keeps the valid ones and counts the rest in `invalid` (decodeUp only; a sender leaves it out). */ @@ -305,7 +308,7 @@ export function isHostOp(name: string): name is HostOpName { } const DOWN_TYPES: readonly string[] = ["welcome", "stdin", "kill", "interest", "host_tools", "req", "ping", "pong", "ack"]; -const UP_TYPES: readonly string[] = ["hello", "stdout", "stderr", "exit", "resync", "notifier", "sessions_changed", "channels_changed", "stats", "capacity", "config_state", "res", "upload_ack", "workspace_file", "ping", "pong", "ack"]; +const UP_TYPES: readonly string[] = ["hello", "stdout", "stderr", "exit", "resync", "notifier", "sessions_changed", "omp_version", "channels_changed", "stats", "capacity", "config_state", "res", "upload_ack", "workspace_file", "ping", "pong", "ack"]; /** `otherDirection`: the types only the other direction decodes; one of those arrived on the wrong way. */ function unknownMessage(o: Obj, otherDirection: readonly string[]): UnknownMessage { @@ -524,6 +527,8 @@ export function decodeUp(line: string): UpMessage | UnknownMessage { return { type: "notifier", seq: seqNum(o, "seq"), on: bool(o, "on") }; case "sessions_changed": return { type: "sessions_changed", seq: seqNum(o, "seq") }; + case "omp_version": + return { type: "omp_version", seq: seqNum(o, "seq"), ompVersion: str(o, "ompVersion") }; case "channels_changed": return { type: "channels_changed", seq: seqNum(o, "seq"), channels: channels(o) }; case "stats": diff --git a/lib/omp/omp-cli.ts b/lib/omp/omp-cli.ts index 15589cfe9..d792182d9 100644 --- a/lib/omp/omp-cli.ts +++ b/lib/omp/omp-cli.ts @@ -177,7 +177,9 @@ export function resolveOmpBin(fresh = false): string | null { /** Return the installed CLI version, using file metadata to invalidate cached * results without launching omp on every visit. An expiry covers opaque * launchers; concurrent callers share a probe. */ -export function getOmpVersion(): Promise { +export function getOmpVersion(fresh = false): Promise { + // fresh: ignore the miss caches (the binary or its version not found within MISS_TTL_MS); a probe in flight is shared. + if (fresh) { binMissAt = 0; versionMiss = null; } versionProbe ??= probeOmpVersion().finally(() => { versionProbe = null; }); From 8ab50c02dafbfc8960ed0d36f493a30ef6fd6a8e Mon Sep 17 00:00:00 2001 From: Andre Brait Date: Thu, 19 Nov 2026 16:49:52 +0000 Subject: [PATCH 03/11] fix(hosts): rerun hello work when omp arrives, and read the version with a probe of its own --- CHANGELOG.md | 2 +- lib/hosts/daemon-link.ts | 3 --- lib/hosts/daemon.ts | 32 ++++++++++++++++++++------------ lib/hosts/host-cli.ts | 5 +++-- lib/hosts/hub.test.mjs | 4 ++++ lib/hosts/hub.ts | 6 ++++-- lib/omp/omp-cli.ts | 4 ++-- 7 files changed, 34 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8aa431cfd..eff00ea9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ All notable changes to **omp-web** (`@kahme247/ompweb`) are documented in this f - **In-app updates work again on a Windows install without administrator rights.** The update looked for the service supervising the host daemon among its parent processes and skipped Task Scheduler's `svchost.exe` by its executable path, which Windows does not show to a non-administrator. It then took the daemon started by the `omp-web-host` scheduled task for the `Schedule` service, could not control that service and refused the update with `not_controllable` (#537). Service hosts are now recognized by process name, so the scheduled task is found. -- **A host no longer stays "omp not installed" once its runner is there.** The host daemon read the omp version once, at start, while the runner download it had just started in the background (or a fresh runner's first start, which Windows' antivirus can hold past the 30 s probe) was still running. Its server then showed **omp not installed** and refused every message until the daemon restarted, although Settings → Hosts listed the runner's version. The daemon now reads the version again when the download finishes, and otherwise after 30 seconds, doubling up to 5 minutes, and tells its servers as soon as omp answers, without reconnecting. A server that predates this keeps the old behaviour until the daemon restarts. +- **A host no longer stays "omp not installed" once its runner is there.** The host daemon read the omp version once, at start, while the runner download it had just started in the background (or a fresh runner's first start, which Windows' antivirus can hold past the 30 s probe) was still running. Its server then showed **omp not installed** and refused every message until the daemon restarted, although Settings → Hosts listed the runner's version. The daemon now reads the version again when the download finishes, and otherwise after 30 seconds, doubling up to 5 minutes, and tells its servers as soon as omp answers, without reconnecting. A server that predates this learns the version the next time the daemon reconnects to it. ## [v0.7.3] - 2026-11-18 diff --git a/lib/hosts/daemon-link.ts b/lib/hosts/daemon-link.ts index c5de42077..e335bcfd8 100644 --- a/lib/hosts/daemon-link.ts +++ b/lib/hosts/daemon-link.ts @@ -75,8 +75,6 @@ export class DaemonLink { start(): void { this.runtime.start(); } stop(): Promise { return this.runtime.stop(); } rekey(token: string): void { this.runtime.rekey(token); } - /** Ends the current socket; the redial sends a fresh hello and resumes the link. */ - redial(why: string): void { this.runtime.redial(why); } isUp(): boolean { return this.runtime.isUp(); } busy(): boolean { return this.runtime.busy(); } /** An unsequenced report (`capacity`, `config_state`): sent now on an up link with room, never replayed. A @@ -497,6 +495,5 @@ function linkRuntime(owner: DaemonLink, deps: LinkDeps) { } return { queue, output, discard, result, report, busy: () => !mismatched && reliablePending > 0, ackedDown: () => down.acked, isUp: () => linked !== null && !stopped, rekey: (token: string) => { owner.login.token = token; authorization = "Bearer " + token; socket?.close(1001, "credentials changed"); }, - redial: (why: string) => { socket?.close(1001, why); }, start: () => { if (!started && !stopped) { started = true; loop = keepLinked(); } }, stop }; } diff --git a/lib/hosts/daemon.ts b/lib/hosts/daemon.ts index 6422ff711..674a1791b 100644 --- a/lib/hosts/daemon.ts +++ b/lib/hosts/daemon.ts @@ -101,7 +101,7 @@ export interface HostDaemon { /** `hostSocket`: where omps started from a TUI attach (`hostSocketPath()`); unset, none can. */ type DaemonOptions = { allowHttp: boolean; url?: string; token?: string; links?: HostLink[]; hostSocket?: string }; /** A daemon whose omp version read found nothing reads it again after this, doubling up to OMP_VERSION_RETRY_MAX_MS. */ -export const OMP_VERSION_RETRY_MS = 30_000; +const OMP_VERSION_RETRY_MS = 30_000; const OMP_VERSION_RETRY_MAX_MS = 5 * 60_000; export function runHostDaemon(options: DaemonOptions): HostDaemon { const explicit = options.url !== undefined && options.token !== undefined ? [{ url: options.url, token: options.token }] : options.links; @@ -554,31 +554,39 @@ export function runHostDaemon(options: DaemonOptions): HostDaemon { .finally(() => { operationsInFlight--; if (!stopped) for (const link of links.values()) link.start(); + if (!stopped && ompVersion === null) scheduleVersionRetry(); }); // A null version in the hello marks this host "omp not installed" and its sessions refused. The runner's first fetch, // or a first start Windows' antivirus holds past the probe, can outlast the startup read: read again until omp answers, - // then tell every server (a link made later says it in its hello). - async function refreshOmpVersion(): Promise { + // then tell every server (a link made later says it in its hello). One read at a time; a call during one reads again. + let refreshing: Promise | undefined, refreshAgain = false; + function scheduleVersionRetry(): void { + clearTimeout(versionRetry); + versionRetry = setTimeout(() => void refreshOmpVersion(), versionRetryMs); + versionRetry.unref?.(); + } + async function readVersionAgain(): Promise { await versionRead; if (stopped || ompVersion !== null) return; - clearTimeout(versionRetry); versionRetry = undefined; const version = await getOmpVersion(true); if (stopped || ompVersion !== null) return; if (version === null) { - clearTimeout(versionRetry); - versionRetry = setTimeout(() => void refreshOmpVersion(), versionRetryMs); - versionRetry.unref?.(); + scheduleVersionRetry(); versionRetryMs = Math.min(versionRetryMs * 2, OMP_VERSION_RETRY_MAX_MS); return; } + clearTimeout(versionRetry); ompVersion = version; for (const link of links.values()) link.queue({ type: "omp_version", ompVersion: version }, "omp_version"); } - void versionRead.then(() => { - if (stopped || ompVersion !== null) return; - versionRetry = setTimeout(() => void refreshOmpVersion(), versionRetryMs); - versionRetry.unref?.(); - }); + function refreshOmpVersion(): Promise { + if (refreshing) { refreshAgain = true; return refreshing; } + refreshing = readVersionAgain().finally(() => { + refreshing = undefined; + if (refreshAgain) { refreshAgain = false; void refreshOmpVersion(); } + }); + return refreshing; + } const started = Promise.all([startupSweep, startupRecovery, versionRead, hostSocket]).then(() => {}); return { stop: () => shutdown(0), done, control, started, refreshOmpVersion }; } diff --git a/lib/hosts/host-cli.ts b/lib/hosts/host-cli.ts index 0748c7d85..c1a948ad6 100644 --- a/lib/hosts/host-cli.ts +++ b/lib/hosts/host-cli.ts @@ -80,10 +80,11 @@ async function main(argv: string[]): Promise { try { // The runners of earlier "Update omp" installs: no session of this daemon is running from them any more. sweepOmpRunners(); - // Sessions need the runner; until it is here they fail with OMP_NOT_FOUND and the next start retries. - void ensureOmpRunner().then(bin => { if (bin) return daemon?.refreshOmpVersion(); }).catch((error: unknown) => console.error(`ompweb host: ${error instanceof Error ? error.message : String(error)}`)); // Windows has no host socket yet (a current-user named pipe is open in the runner spec). daemon = runHostDaemon({ allowHttp: argv.includes("--allow-http"), hostSocket: process.platform === "win32" ? undefined : hostSocketPath() }); + const started = daemon; + // Sessions need the runner; until it is here they fail with OMP_NOT_FOUND. Once fetched, the daemon tells its servers. + void ensureOmpRunner().then(bin => { if (bin) return started.refreshOmpVersion(); }).catch((error: unknown) => console.error(`ompweb host: ${error instanceof Error ? error.message : String(error)}`)); // Worker cutover starts fail-closed; ordinary hosts have no maintenance environment. if (process.env.OMP_WEB_HOST_DRAINED === "1") daemon.control("drain"); const stop = () => void daemon!.stop(); diff --git a/lib/hosts/hub.test.mjs b/lib/hosts/hub.test.mjs index 08f89de8e..ad071b220 100644 --- a/lib/hosts/hub.test.mjs +++ b/lib/hosts/hub.test.mjs @@ -310,8 +310,12 @@ test("hello without omp marks the host omp-missing and spawnRpc rejects", async test("an omp_version after a hello without omp brings the host online", async () => { const link = await linkedHost("Late omp", { ompVersion: null }); assert.equal(link.remote.status(), "omp-missing"); + const hellos = []; + const stop = hub.onHostHello((hostId) => hellos.push(hostId)); assert.deepEqual(linkPost(link, [{ type: "omp_version", seq: 1, ompVersion: "19.0.0" }]), [1]); + stop(); assert.equal(link.remote.status(), "online"); + assert.deepEqual(hellos, [link.id], "what waited for a hello with omp runs"); assert.equal(hub.listHosts().find((h) => h.id === link.id).ompVersion, "19.0.0"); await link.down.cancel(); }); diff --git a/lib/hosts/hub.ts b/lib/hosts/hub.ts index b7961acfe..3553648d9 100644 --- a/lib/hosts/hub.ts +++ b/lib/hosts/hub.ts @@ -1005,8 +1005,10 @@ function applyUp(link: Link, message: UpMessage | UnknownMessage, whole?: UpMess return link.channels.get(message.ch)?.deliverStderr(message.chunk); case "omp_version": link.ompVersion = message.ompVersion; - if (link.status === "omp-missing") setStatus(link, "online"); - return; + if (link.status !== "omp-missing") return notify(hub().changeListeners); + setStatus(link, "online"); + // What waited for a hello with omp (the outbox, resumes) runs now. + return notify(hub().helloListeners, link.id, link.recoveryInventory ?? []); case "resync": return link.channels.get(message.ch)?.deliverResync(); case "exit": { diff --git a/lib/omp/omp-cli.ts b/lib/omp/omp-cli.ts index d792182d9..44aea1009 100644 --- a/lib/omp/omp-cli.ts +++ b/lib/omp/omp-cli.ts @@ -178,8 +178,8 @@ export function resolveOmpBin(fresh = false): string | null { * results without launching omp on every visit. An expiry covers opaque * launchers; concurrent callers share a probe. */ export function getOmpVersion(fresh = false): Promise { - // fresh: ignore the miss caches (the binary or its version not found within MISS_TTL_MS); a probe in flight is shared. - if (fresh) { binMissAt = 0; versionMiss = null; } + // fresh: a probe of its own, past the miss caches; one in flight may have looked before the binary arrived. + if (fresh) { binMissAt = 0; versionMiss = null; return probeOmpVersion(); } versionProbe ??= probeOmpVersion().finally(() => { versionProbe = null; }); From 80b8889a3c958afb77cc0b29d4b14a84a7c2fd84 Mon Sep 17 00:00:00 2001 From: Andre Brait Date: Thu, 19 Nov 2026 16:53:44 +0000 Subject: [PATCH 04/11] test(hosts): cover the daemon's own omp version retry --- lib/hosts/daemon.test.mjs | 19 +++++++++++++++++++ lib/hosts/daemon.ts | 6 +++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/hosts/daemon.test.mjs b/lib/hosts/daemon.test.mjs index ee629bf3d..9f29549d9 100644 --- a/lib/hosts/daemon.test.mjs +++ b/lib/hosts/daemon.test.mjs @@ -560,6 +560,25 @@ test("a host whose omp was missing at start tells its server once the runner ans } }); +test("a host whose omp was missing at start reads it again on its own, without a server asking", async () => { + const log = captureLog(); + renameSync(fakeOmp, `${fakeOmp}.missing`); + const server = scriptedServer(); + let daemon; + try { + daemon = runHostDaemon({ url: server.url, token: "t", allowHttp: false, ompVersionRetryMs: 50 }); + await waitFor(() => server.hellos.length === 1, "the hello"); + assert.equal(server.hellos[0].ompVersion, null); + renameSync(`${fakeOmp}.missing`, fakeOmp); + await waitFor(() => server.up.some((m) => m.type === "omp_version"), "the retried omp_version"); + assert.equal(server.up.find((m) => m.type === "omp_version").ompVersion, "14.0.0-fake"); + } finally { + if (existsSync(`${fakeOmp}.missing`)) renameSync(`${fakeOmp}.missing`, fakeOmp); + await daemon?.stop(); + log.restore(); + } +}); + test("a running host deletes expired staged uploads every hour, not only when it starts or takes an upload", async (t) => { const log = captureLog(); t.mock.timers.enable({ apis: ["setInterval"] }); diff --git a/lib/hosts/daemon.ts b/lib/hosts/daemon.ts index 674a1791b..94b8ee782 100644 --- a/lib/hosts/daemon.ts +++ b/lib/hosts/daemon.ts @@ -99,7 +99,7 @@ export interface HostDaemon { refreshOmpVersion(): Promise; } /** `hostSocket`: where omps started from a TUI attach (`hostSocketPath()`); unset, none can. */ -type DaemonOptions = { allowHttp: boolean; url?: string; token?: string; links?: HostLink[]; hostSocket?: string }; +type DaemonOptions = { allowHttp: boolean; url?: string; token?: string; links?: HostLink[]; hostSocket?: string; /** Tests. */ ompVersionRetryMs?: number }; /** A daemon whose omp version read found nothing reads it again after this, doubling up to OMP_VERSION_RETRY_MAX_MS. */ const OMP_VERSION_RETRY_MS = 30_000; const OMP_VERSION_RETRY_MAX_MS = 5 * 60_000; @@ -120,7 +120,7 @@ export function runHostDaemon(options: DaemonOptions): HostDaemon { let stopping: Promise | undefined; let updateStateWarningLogged = false; let reloadTimer: NodeJS.Timeout | undefined; - let versionRetry: NodeJS.Timeout | undefined, versionRetryMs = OMP_VERSION_RETRY_MS; + let versionRetry: NodeJS.Timeout | undefined, versionRetryMs = options.ompVersionRetryMs ?? OMP_VERSION_RETRY_MS; let drained = process.env.OMP_WEB_HOST_DRAINED === "1"; let preparationsInFlight = 0, operationsInFlight = 0, nativeUpdatesInFlight = 0; const executable = realpathSync(process.execPath); @@ -562,7 +562,7 @@ export function runHostDaemon(options: DaemonOptions): HostDaemon { let refreshing: Promise | undefined, refreshAgain = false; function scheduleVersionRetry(): void { clearTimeout(versionRetry); - versionRetry = setTimeout(() => void refreshOmpVersion(), versionRetryMs); + versionRetry = setTimeout(() => void refreshOmpVersion().catch(error => log("could not read omp version: " + reason(error))), versionRetryMs); versionRetry.unref?.(); } async function readVersionAgain(): Promise { From fe354c902fb0a28a79a413530cb6fd94b383233d Mon Sep 17 00:00:00 2001 From: Andre Brait Date: Thu, 19 Nov 2026 16:58:50 +0000 Subject: [PATCH 05/11] fix(hosts): keep onHostHello to hellos and start the runner fetch before the daemon --- lib/hosts/daemon.test.mjs | 1 + lib/hosts/daemon.ts | 4 ++-- lib/hosts/host-cli.ts | 6 +++--- lib/hosts/hub.test.mjs | 4 ---- lib/hosts/hub.ts | 5 +---- 5 files changed, 7 insertions(+), 13 deletions(-) diff --git a/lib/hosts/daemon.test.mjs b/lib/hosts/daemon.test.mjs index 9f29549d9..6a43e933d 100644 --- a/lib/hosts/daemon.test.mjs +++ b/lib/hosts/daemon.test.mjs @@ -547,6 +547,7 @@ test("a host whose omp was missing at start tells its server once the runner ans await waitFor(() => server.hellos.length === 1, "the hello"); assert.equal(server.hellos[0].ompVersion, null); await daemon.refreshOmpVersion(); + await sleep(100); assert.equal(server.up.some((m) => m.type === "omp_version"), false); renameSync(`${fakeOmp}.missing`, fakeOmp); await daemon.refreshOmpVersion(); diff --git a/lib/hosts/daemon.ts b/lib/hosts/daemon.ts index 94b8ee782..fe364d186 100644 --- a/lib/hosts/daemon.ts +++ b/lib/hosts/daemon.ts @@ -564,6 +564,7 @@ export function runHostDaemon(options: DaemonOptions): HostDaemon { clearTimeout(versionRetry); versionRetry = setTimeout(() => void refreshOmpVersion().catch(error => log("could not read omp version: " + reason(error))), versionRetryMs); versionRetry.unref?.(); + versionRetryMs = Math.min(versionRetryMs * 2, OMP_VERSION_RETRY_MAX_MS); } async function readVersionAgain(): Promise { await versionRead; @@ -572,7 +573,6 @@ export function runHostDaemon(options: DaemonOptions): HostDaemon { if (stopped || ompVersion !== null) return; if (version === null) { scheduleVersionRetry(); - versionRetryMs = Math.min(versionRetryMs * 2, OMP_VERSION_RETRY_MAX_MS); return; } clearTimeout(versionRetry); @@ -583,7 +583,7 @@ export function runHostDaemon(options: DaemonOptions): HostDaemon { if (refreshing) { refreshAgain = true; return refreshing; } refreshing = readVersionAgain().finally(() => { refreshing = undefined; - if (refreshAgain) { refreshAgain = false; void refreshOmpVersion(); } + if (refreshAgain) { refreshAgain = false; void refreshOmpVersion().catch(error => log("could not read omp version: " + reason(error))); } }); return refreshing; } diff --git a/lib/hosts/host-cli.ts b/lib/hosts/host-cli.ts index c1a948ad6..4bbf29620 100644 --- a/lib/hosts/host-cli.ts +++ b/lib/hosts/host-cli.ts @@ -80,11 +80,11 @@ async function main(argv: string[]): Promise { try { // The runners of earlier "Update omp" installs: no session of this daemon is running from them any more. sweepOmpRunners(); + // Sessions need the runner; until it is here they fail with OMP_NOT_FOUND. Once fetched, the daemon tells its servers. + const runner = ensureOmpRunner().catch((error: unknown) => { console.error(`ompweb host: ${error instanceof Error ? error.message : String(error)}`); return null; }); // Windows has no host socket yet (a current-user named pipe is open in the runner spec). daemon = runHostDaemon({ allowHttp: argv.includes("--allow-http"), hostSocket: process.platform === "win32" ? undefined : hostSocketPath() }); - const started = daemon; - // Sessions need the runner; until it is here they fail with OMP_NOT_FOUND. Once fetched, the daemon tells its servers. - void ensureOmpRunner().then(bin => { if (bin) return started.refreshOmpVersion(); }).catch((error: unknown) => console.error(`ompweb host: ${error instanceof Error ? error.message : String(error)}`)); + void runner.then(bin => { if (bin) return daemon!.refreshOmpVersion(); }).catch((error: unknown) => console.error(`ompweb host: ${error instanceof Error ? error.message : String(error)}`)); // Worker cutover starts fail-closed; ordinary hosts have no maintenance environment. if (process.env.OMP_WEB_HOST_DRAINED === "1") daemon.control("drain"); const stop = () => void daemon!.stop(); diff --git a/lib/hosts/hub.test.mjs b/lib/hosts/hub.test.mjs index ad071b220..08f89de8e 100644 --- a/lib/hosts/hub.test.mjs +++ b/lib/hosts/hub.test.mjs @@ -310,12 +310,8 @@ test("hello without omp marks the host omp-missing and spawnRpc rejects", async test("an omp_version after a hello without omp brings the host online", async () => { const link = await linkedHost("Late omp", { ompVersion: null }); assert.equal(link.remote.status(), "omp-missing"); - const hellos = []; - const stop = hub.onHostHello((hostId) => hellos.push(hostId)); assert.deepEqual(linkPost(link, [{ type: "omp_version", seq: 1, ompVersion: "19.0.0" }]), [1]); - stop(); assert.equal(link.remote.status(), "online"); - assert.deepEqual(hellos, [link.id], "what waited for a hello with omp runs"); assert.equal(hub.listHosts().find((h) => h.id === link.id).ompVersion, "19.0.0"); await link.down.cancel(); }); diff --git a/lib/hosts/hub.ts b/lib/hosts/hub.ts index 3553648d9..279017aaa 100644 --- a/lib/hosts/hub.ts +++ b/lib/hosts/hub.ts @@ -1005,10 +1005,7 @@ function applyUp(link: Link, message: UpMessage | UnknownMessage, whole?: UpMess return link.channels.get(message.ch)?.deliverStderr(message.chunk); case "omp_version": link.ompVersion = message.ompVersion; - if (link.status !== "omp-missing") return notify(hub().changeListeners); - setStatus(link, "online"); - // What waited for a hello with omp (the outbox, resumes) runs now. - return notify(hub().helloListeners, link.id, link.recoveryInventory ?? []); + return setStatus(link, link.status === "omp-missing" ? "online" : link.status); case "resync": return link.channels.get(message.ch)?.deliverResync(); case "exit": { From 3a0dc317e4f7f2930548cd2d9b65d989bb65a94b Mon Sep 17 00:00:00 2001 From: Andre Brait Date: Thu, 19 Nov 2026 17:00:00 +0000 Subject: [PATCH 06/11] fix(hosts): a version read cancels the pending retry; test the retry past a second miss --- lib/hosts/daemon.test.mjs | 4 +++- lib/hosts/daemon.ts | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/hosts/daemon.test.mjs b/lib/hosts/daemon.test.mjs index 6a43e933d..a1aeb2138 100644 --- a/lib/hosts/daemon.test.mjs +++ b/lib/hosts/daemon.test.mjs @@ -567,9 +567,11 @@ test("a host whose omp was missing at start reads it again on its own, without a const server = scriptedServer(); let daemon; try { - daemon = runHostDaemon({ url: server.url, token: "t", allowHttp: false, ompVersionRetryMs: 50 }); + daemon = runHostDaemon({ url: server.url, token: "t", allowHttp: false, ompVersionRetryMs: 20 }); await waitFor(() => server.hellos.length === 1, "the hello"); assert.equal(server.hellos[0].ompVersion, null); + // Past the first retries (20, 40, 80 ms): each miss arms the next. + await sleep(200); renameSync(`${fakeOmp}.missing`, fakeOmp); await waitFor(() => server.up.some((m) => m.type === "omp_version"), "the retried omp_version"); assert.equal(server.up.find((m) => m.type === "omp_version").ompVersion, "14.0.0-fake"); diff --git a/lib/hosts/daemon.ts b/lib/hosts/daemon.ts index fe364d186..a5f579312 100644 --- a/lib/hosts/daemon.ts +++ b/lib/hosts/daemon.ts @@ -569,6 +569,7 @@ export function runHostDaemon(options: DaemonOptions): HostDaemon { async function readVersionAgain(): Promise { await versionRead; if (stopped || ompVersion !== null) return; + clearTimeout(versionRetry); // this read is the retry; a miss arms the next one const version = await getOmpVersion(true); if (stopped || ompVersion !== null) return; if (version === null) { From 1f790aaa1e0d1631ce8009c6da4d68f9df1d7670 Mon Sep 17 00:00:00 2001 From: Andre Brait Date: Thu, 19 Nov 2026 17:04:08 +0000 Subject: [PATCH 07/11] fix(hosts): a failed omp version read keeps retrying; refuse an empty omp_version --- lib/hosts/daemon.ts | 7 +++---- lib/hosts/link-protocol.ts | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/hosts/daemon.ts b/lib/hosts/daemon.ts index a5f579312..7651e8e18 100644 --- a/lib/hosts/daemon.ts +++ b/lib/hosts/daemon.ts @@ -562,7 +562,7 @@ export function runHostDaemon(options: DaemonOptions): HostDaemon { let refreshing: Promise | undefined, refreshAgain = false; function scheduleVersionRetry(): void { clearTimeout(versionRetry); - versionRetry = setTimeout(() => void refreshOmpVersion().catch(error => log("could not read omp version: " + reason(error))), versionRetryMs); + versionRetry = setTimeout(() => void refreshOmpVersion(), versionRetryMs); versionRetry.unref?.(); versionRetryMs = Math.min(versionRetryMs * 2, OMP_VERSION_RETRY_MAX_MS); } @@ -570,13 +570,12 @@ export function runHostDaemon(options: DaemonOptions): HostDaemon { await versionRead; if (stopped || ompVersion !== null) return; clearTimeout(versionRetry); // this read is the retry; a miss arms the next one - const version = await getOmpVersion(true); + const version = await getOmpVersion(true).catch(error => { log("could not read omp version: " + reason(error)); return null; }); if (stopped || ompVersion !== null) return; if (version === null) { scheduleVersionRetry(); return; } - clearTimeout(versionRetry); ompVersion = version; for (const link of links.values()) link.queue({ type: "omp_version", ompVersion: version }, "omp_version"); } @@ -584,7 +583,7 @@ export function runHostDaemon(options: DaemonOptions): HostDaemon { if (refreshing) { refreshAgain = true; return refreshing; } refreshing = readVersionAgain().finally(() => { refreshing = undefined; - if (refreshAgain) { refreshAgain = false; void refreshOmpVersion().catch(error => log("could not read omp version: " + reason(error))); } + if (refreshAgain) { refreshAgain = false; void refreshOmpVersion(); } }); return refreshing; } diff --git a/lib/hosts/link-protocol.ts b/lib/hosts/link-protocol.ts index dd59a01ac..7451fe9c1 100644 --- a/lib/hosts/link-protocol.ts +++ b/lib/hosts/link-protocol.ts @@ -528,6 +528,7 @@ export function decodeUp(line: string): UpMessage | UnknownMessage { case "sessions_changed": return { type: "sessions_changed", seq: seqNum(o, "seq") }; case "omp_version": + if (!str(o, "ompVersion")) fail("ompVersion must not be empty"); return { type: "omp_version", seq: seqNum(o, "seq"), ompVersion: str(o, "ompVersion") }; case "channels_changed": return { type: "channels_changed", seq: seqNum(o, "seq"), channels: channels(o) }; From aa5ece0af3b874a53e7e4afc996a475335693f97 Mon Sep 17 00:00:00 2001 From: Andre Brait Date: Thu, 19 Nov 2026 17:05:00 +0000 Subject: [PATCH 08/11] test(hosts): the hosts change event on omp_version; note the message in AGENTS.md --- AGENTS.md | 1 + lib/hosts/hub.test.mjs | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/AGENTS.md b/AGENTS.md index 560854798..ee2ebb27d 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -408,6 +408,7 @@ The table is static imports, not a runtime glob, so `bun build --compile` (`scri The daemon owns lifecycle, streaming snapshots and first-answer dialog settlement. Web callbacks choose the last-active eligible server and are not blindly retried. `channels_changed` discovers background runs; `sessions_changed` invalidates lists; + `omp_version` reports omp found after a hello that said none (the daemon retries the read, 30 s doubling to 5 min); one link is the automatic notification publisher. Cross-server fences live in the daemon: a history edit takes the acknowledged `editLease` op before preflight, and a `peer_message_command` marker makes another server's identical echo diff --git a/lib/hosts/hub.test.mjs b/lib/hosts/hub.test.mjs index 08f89de8e..e23577bab 100644 --- a/lib/hosts/hub.test.mjs +++ b/lib/hosts/hub.test.mjs @@ -310,8 +310,12 @@ test("hello without omp marks the host omp-missing and spawnRpc rejects", async test("an omp_version after a hello without omp brings the host online", async () => { const link = await linkedHost("Late omp", { ompVersion: null }); assert.equal(link.remote.status(), "omp-missing"); + let changes = 0; + const stop = hub.onHostsChange(() => changes++); assert.deepEqual(linkPost(link, [{ type: "omp_version", seq: 1, ompVersion: "19.0.0" }]), [1]); + stop(); assert.equal(link.remote.status(), "online"); + assert.ok(changes > 0, "Settings and the sidebar hear of it"); assert.equal(hub.listHosts().find((h) => h.id === link.id).ompVersion, "19.0.0"); await link.down.cancel(); }); From 48948f4bce74ea0ac4853bf87325244959fa3383 Mon Sep 17 00:00:00 2001 From: Andre Brait Date: Thu, 19 Nov 2026 17:10:11 +0000 Subject: [PATCH 09/11] fix(hosts): retry a failed runner fetch with the omp version read; accept the omp_version the hello accepts --- lib/hosts/daemon.test.mjs | 24 ++++++++++++++++++++++++ lib/hosts/daemon.ts | 10 ++++++++-- lib/hosts/host-cli.ts | 8 ++++---- lib/hosts/link-protocol.ts | 1 - 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/lib/hosts/daemon.test.mjs b/lib/hosts/daemon.test.mjs index a1aeb2138..f5cfc9fbe 100644 --- a/lib/hosts/daemon.test.mjs +++ b/lib/hosts/daemon.test.mjs @@ -582,6 +582,30 @@ test("a host whose omp was missing at start reads it again on its own, without a } }); +test("a host whose runner fetch finishes after start tells its server at once, and a failed fetch is tried again", async () => { + const log = captureLog(); + renameSync(fakeOmp, `${fakeOmp}.missing`); + const server = scriptedServer(); + let daemon, fetches = 0; + try { + // The first fetch fails (offline); the next one, from the retry, brings the runner. + const ensureRunner = async () => { + if (++fetches === 1) throw new Error("offline"); + await sleep(50); + renameSync(`${fakeOmp}.missing`, fakeOmp); + }; + daemon = runHostDaemon({ url: server.url, token: "t", allowHttp: false, ensureRunner, ompVersionRetryMs: 20 }); + await waitFor(() => server.up.some((m) => m.type === "omp_version"), "the omp_version message"); + assert.equal(server.hellos[0].ompVersion, null); + assert.equal(server.up.find((m) => m.type === "omp_version").ompVersion, "14.0.0-fake"); + assert.equal(fetches, 2); + } finally { + if (existsSync(`${fakeOmp}.missing`)) renameSync(`${fakeOmp}.missing`, fakeOmp); + await daemon?.stop(); + log.restore(); + } +}); + test("a running host deletes expired staged uploads every hour, not only when it starts or takes an upload", async (t) => { const log = captureLog(); t.mock.timers.enable({ apis: ["setInterval"] }); diff --git a/lib/hosts/daemon.ts b/lib/hosts/daemon.ts index 7651e8e18..898f1ebdb 100644 --- a/lib/hosts/daemon.ts +++ b/lib/hosts/daemon.ts @@ -99,7 +99,10 @@ export interface HostDaemon { refreshOmpVersion(): Promise; } /** `hostSocket`: where omps started from a TUI attach (`hostSocketPath()`); unset, none can. */ -type DaemonOptions = { allowHttp: boolean; url?: string; token?: string; links?: HostLink[]; hostSocket?: string; /** Tests. */ ompVersionRetryMs?: number }; +type DaemonOptions = { allowHttp: boolean; url?: string; token?: string; links?: HostLink[]; hostSocket?: string; + /** Fetches the omp runner when this install has none (`ensureOmpRunner`); each omp version retry runs it first. */ + ensureRunner?: () => Promise; + /** Tests. */ ompVersionRetryMs?: number }; /** A daemon whose omp version read found nothing reads it again after this, doubling up to OMP_VERSION_RETRY_MAX_MS. */ const OMP_VERSION_RETRY_MS = 30_000; const OMP_VERSION_RETRY_MAX_MS = 5 * 60_000; @@ -554,7 +557,7 @@ export function runHostDaemon(options: DaemonOptions): HostDaemon { .finally(() => { operationsInFlight--; if (!stopped) for (const link of links.values()) link.start(); - if (!stopped && ompVersion === null) scheduleVersionRetry(); + if (!stopped && ompVersion === null) void refreshOmpVersion(); }); // A null version in the hello marks this host "omp not installed" and its sessions refused. The runner's first fetch, // or a first start Windows' antivirus holds past the probe, can outlast the startup read: read again until omp answers, @@ -570,6 +573,9 @@ export function runHostDaemon(options: DaemonOptions): HostDaemon { await versionRead; if (stopped || ompVersion !== null) return; clearTimeout(versionRetry); // this read is the retry; a miss arms the next one + // A fetch that failed at start (offline) is tried again; one still running is joined. + await options.ensureRunner?.().catch(error => log("could not fetch the omp runner: " + reason(error))); + if (stopped || ompVersion !== null) return; const version = await getOmpVersion(true).catch(error => { log("could not read omp version: " + reason(error)); return null; }); if (stopped || ompVersion !== null) return; if (version === null) { diff --git a/lib/hosts/host-cli.ts b/lib/hosts/host-cli.ts index 4bbf29620..5655c9ade 100644 --- a/lib/hosts/host-cli.ts +++ b/lib/hosts/host-cli.ts @@ -80,11 +80,11 @@ async function main(argv: string[]): Promise { try { // The runners of earlier "Update omp" installs: no session of this daemon is running from them any more. sweepOmpRunners(); - // Sessions need the runner; until it is here they fail with OMP_NOT_FOUND. Once fetched, the daemon tells its servers. - const runner = ensureOmpRunner().catch((error: unknown) => { console.error(`ompweb host: ${error instanceof Error ? error.message : String(error)}`); return null; }); + // Sessions need the runner; until it is here they fail with OMP_NOT_FOUND. The daemon joins this fetch, tries it + // again while omp is missing and tells its servers once omp answers. + void ensureOmpRunner().catch((error: unknown) => console.error(`ompweb host: ${error instanceof Error ? error.message : String(error)}`)); // Windows has no host socket yet (a current-user named pipe is open in the runner spec). - daemon = runHostDaemon({ allowHttp: argv.includes("--allow-http"), hostSocket: process.platform === "win32" ? undefined : hostSocketPath() }); - void runner.then(bin => { if (bin) return daemon!.refreshOmpVersion(); }).catch((error: unknown) => console.error(`ompweb host: ${error instanceof Error ? error.message : String(error)}`)); + daemon = runHostDaemon({ allowHttp: argv.includes("--allow-http"), hostSocket: process.platform === "win32" ? undefined : hostSocketPath(), ensureRunner: ensureOmpRunner }); // Worker cutover starts fail-closed; ordinary hosts have no maintenance environment. if (process.env.OMP_WEB_HOST_DRAINED === "1") daemon.control("drain"); const stop = () => void daemon!.stop(); diff --git a/lib/hosts/link-protocol.ts b/lib/hosts/link-protocol.ts index 7451fe9c1..dd59a01ac 100644 --- a/lib/hosts/link-protocol.ts +++ b/lib/hosts/link-protocol.ts @@ -528,7 +528,6 @@ export function decodeUp(line: string): UpMessage | UnknownMessage { case "sessions_changed": return { type: "sessions_changed", seq: seqNum(o, "seq") }; case "omp_version": - if (!str(o, "ompVersion")) fail("ompVersion must not be empty"); return { type: "omp_version", seq: seqNum(o, "seq"), ompVersion: str(o, "ompVersion") }; case "channels_changed": return { type: "channels_changed", seq: seqNum(o, "seq"), channels: channels(o) }; From 083c38c95b37e2b31596566c1ebd86664c76f495 Mon Sep 17 00:00:00 2001 From: Andre Brait Date: Thu, 19 Nov 2026 17:10:41 +0000 Subject: [PATCH 10/11] docs(changelog): the omp version retry also retries the runner download --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eff00ea9e..8fa83be0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ All notable changes to **omp-web** (`@kahme247/ompweb`) are documented in this f - **In-app updates work again on a Windows install without administrator rights.** The update looked for the service supervising the host daemon among its parent processes and skipped Task Scheduler's `svchost.exe` by its executable path, which Windows does not show to a non-administrator. It then took the daemon started by the `omp-web-host` scheduled task for the `Schedule` service, could not control that service and refused the update with `not_controllable` (#537). Service hosts are now recognized by process name, so the scheduled task is found. -- **A host no longer stays "omp not installed" once its runner is there.** The host daemon read the omp version once, at start, while the runner download it had just started in the background (or a fresh runner's first start, which Windows' antivirus can hold past the 30 s probe) was still running. Its server then showed **omp not installed** and refused every message until the daemon restarted, although Settings → Hosts listed the runner's version. The daemon now reads the version again when the download finishes, and otherwise after 30 seconds, doubling up to 5 minutes, and tells its servers as soon as omp answers, without reconnecting. A server that predates this learns the version the next time the daemon reconnects to it. +- **A host no longer stays "omp not installed" once its runner is there.** The host daemon read the omp version once, at start, while the runner download it had just started in the background (or a fresh runner's first start, which Windows' antivirus can hold past the 30 s probe) was still running. Its server then showed **omp not installed** and refused every message until the daemon restarted, although Settings → Hosts listed the runner's version. The daemon now reads the version again as soon as the download finishes, and otherwise after 30 seconds, doubling up to 5 minutes; each try also downloads the runner again if the first download failed (a host started offline). It tells its servers as soon as omp answers, without reconnecting. A server that predates this learns the version the next time the daemon reconnects to it. ## [v0.7.3] - 2026-11-18 From a82936db23483ecf4b90f70daefdd80accf106fe Mon Sep 17 00:00:00 2001 From: Andre Brait Date: Thu, 19 Nov 2026 17:15:44 +0000 Subject: [PATCH 11/11] refactor(hosts): drop the unused refreshAgain and test-only refreshOmpVersion; log a failed fetch once --- AGENTS.md | 2 +- lib/hosts/daemon.test.mjs | 28 ++-------------------------- lib/hosts/daemon.ts | 15 ++++----------- lib/hosts/host-cli.ts | 2 +- 4 files changed, 8 insertions(+), 39 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index ee2ebb27d..a4e3bbe5e 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -408,7 +408,7 @@ The table is static imports, not a runtime glob, so `bun build --compile` (`scri The daemon owns lifecycle, streaming snapshots and first-answer dialog settlement. Web callbacks choose the last-active eligible server and are not blindly retried. `channels_changed` discovers background runs; `sessions_changed` invalidates lists; - `omp_version` reports omp found after a hello that said none (the daemon retries the read, 30 s doubling to 5 min); + `omp_version` reports omp found after a hello that said none (the daemon retries the runner fetch and the read, 30 s doubling to 5 min); one link is the automatic notification publisher. Cross-server fences live in the daemon: a history edit takes the acknowledged `editLease` op before preflight, and a `peer_message_command` marker makes another server's identical echo diff --git a/lib/hosts/daemon.test.mjs b/lib/hosts/daemon.test.mjs index f5cfc9fbe..ae664c59e 100644 --- a/lib/hosts/daemon.test.mjs +++ b/lib/hosts/daemon.test.mjs @@ -536,31 +536,6 @@ test("an http:// loopback server links without --allow-http", async () => { } }); -test("a host whose omp was missing at start tells its server once the runner answers", async () => { - const log = captureLog(); - // Moved away rather than renamed in the env: earlier tests leave it cached as the binary. - renameSync(fakeOmp, `${fakeOmp}.missing`); - const server = scriptedServer(); - let daemon; - try { - daemon = start(server); - await waitFor(() => server.hellos.length === 1, "the hello"); - assert.equal(server.hellos[0].ompVersion, null); - await daemon.refreshOmpVersion(); - await sleep(100); - assert.equal(server.up.some((m) => m.type === "omp_version"), false); - renameSync(`${fakeOmp}.missing`, fakeOmp); - await daemon.refreshOmpVersion(); - await waitFor(() => server.up.some((m) => m.type === "omp_version"), "the omp_version message"); - assert.equal(server.up.find((m) => m.type === "omp_version").ompVersion, "14.0.0-fake"); - assert.equal(server.hellos.length, 1, "the link is not redialed"); - } finally { - if (existsSync(`${fakeOmp}.missing`)) renameSync(`${fakeOmp}.missing`, fakeOmp); - await daemon?.stop(); - log.restore(); - } -}); - test("a host whose omp was missing at start reads it again on its own, without a server asking", async () => { const log = captureLog(); renameSync(fakeOmp, `${fakeOmp}.missing`); @@ -572,6 +547,7 @@ test("a host whose omp was missing at start reads it again on its own, without a assert.equal(server.hellos[0].ompVersion, null); // Past the first retries (20, 40, 80 ms): each miss arms the next. await sleep(200); + assert.equal(server.up.some((m) => m.type === "omp_version"), false, "nothing while omp is missing"); renameSync(`${fakeOmp}.missing`, fakeOmp); await waitFor(() => server.up.some((m) => m.type === "omp_version"), "the retried omp_version"); assert.equal(server.up.find((m) => m.type === "omp_version").ompVersion, "14.0.0-fake"); @@ -582,7 +558,7 @@ test("a host whose omp was missing at start reads it again on its own, without a } }); -test("a host whose runner fetch finishes after start tells its server at once, and a failed fetch is tried again", async () => { +test("a failed runner fetch is tried again with the omp version read, and its server is told once omp answers", async () => { const log = captureLog(); renameSync(fakeOmp, `${fakeOmp}.missing`); const server = scriptedServer(); diff --git a/lib/hosts/daemon.ts b/lib/hosts/daemon.ts index 898f1ebdb..1f25044f9 100644 --- a/lib/hosts/daemon.ts +++ b/lib/hosts/daemon.ts @@ -95,8 +95,6 @@ export interface HostDaemon { /** Settles once startup work (upload sweep, session recovery, omp version read) is done; until then drain reports busy. */ started: Promise; control(command: HostControlCommand): HostControlStatus; - /** Reads the omp version again while it is unknown (a runner fetched after start) and tells every server once found. */ - refreshOmpVersion(): Promise; } /** `hostSocket`: where omps started from a TUI attach (`hostSocketPath()`); unset, none can. */ type DaemonOptions = { allowHttp: boolean; url?: string; token?: string; links?: HostLink[]; hostSocket?: string; @@ -561,8 +559,8 @@ export function runHostDaemon(options: DaemonOptions): HostDaemon { }); // A null version in the hello marks this host "omp not installed" and its sessions refused. The runner's first fetch, // or a first start Windows' antivirus holds past the probe, can outlast the startup read: read again until omp answers, - // then tell every server (a link made later says it in its hello). One read at a time; a call during one reads again. - let refreshing: Promise | undefined, refreshAgain = false; + // then tell every server (a link made later says it in its hello). One read at a time. + let refreshing: Promise | undefined; function scheduleVersionRetry(): void { clearTimeout(versionRetry); versionRetry = setTimeout(() => void refreshOmpVersion(), versionRetryMs); @@ -586,13 +584,8 @@ export function runHostDaemon(options: DaemonOptions): HostDaemon { for (const link of links.values()) link.queue({ type: "omp_version", ompVersion: version }, "omp_version"); } function refreshOmpVersion(): Promise { - if (refreshing) { refreshAgain = true; return refreshing; } - refreshing = readVersionAgain().finally(() => { - refreshing = undefined; - if (refreshAgain) { refreshAgain = false; void refreshOmpVersion(); } - }); - return refreshing; + return refreshing ??= readVersionAgain().finally(() => { refreshing = undefined; }); } const started = Promise.all([startupSweep, startupRecovery, versionRead, hostSocket]).then(() => {}); - return { stop: () => shutdown(0), done, control, started, refreshOmpVersion }; + return { stop: () => shutdown(0), done, control, started }; } diff --git a/lib/hosts/host-cli.ts b/lib/hosts/host-cli.ts index 5655c9ade..b8456aa6f 100644 --- a/lib/hosts/host-cli.ts +++ b/lib/hosts/host-cli.ts @@ -82,7 +82,7 @@ async function main(argv: string[]): Promise { sweepOmpRunners(); // Sessions need the runner; until it is here they fail with OMP_NOT_FOUND. The daemon joins this fetch, tries it // again while omp is missing and tells its servers once omp answers. - void ensureOmpRunner().catch((error: unknown) => console.error(`ompweb host: ${error instanceof Error ? error.message : String(error)}`)); + void ensureOmpRunner().catch(() => {}); // the daemon joins it and logs a failure // Windows has no host socket yet (a current-user named pipe is open in the runner spec). daemon = runHostDaemon({ allowHttp: argv.includes("--allow-http"), hostSocket: process.platform === "win32" ? undefined : hostSocketPath(), ensureRunner: ensureOmpRunner }); // Worker cutover starts fail-closed; ordinary hosts have no maintenance environment.