Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ All notable changes to **omp-web** (`@kahme247/ompweb`) are documented in this f

### Fixed

- **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.
- **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.

Expand Down
12 changes: 11 additions & 1 deletion lib/hosts/update-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,17 @@ export function writeHostUpdateJson(path: string, value: unknown): void {
if (existsSync(path)) assertOwnedPath(path);
const temporary = `${path}.${randomUUID()}.tmp`;
writeFileSync(temporary, JSON.stringify(value), { mode: 0o600, flag: "wx" });
try { renameSync(temporary, path); } finally { rmSync(temporary, { force: true }); }
try { replaceFileSync(temporary, path); } finally { rmSync(temporary, { force: true }); }
}
/** Renames `temporary` over `path`. On Windows a concurrent reader of `path` can briefly refuse the replacement: retry, never unlink the previous complete file. */
export function replaceFileSync(temporary: string, path: string): void {
for (let attempt = 0; ; attempt++) {
try { return renameSync(temporary, path); }
catch (error) {
if (process.platform !== "win32" || !["EPERM", "EACCES", "EBUSY"].includes((error as NodeJS.ErrnoException).code ?? "") || attempt >= 20) throw error;
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 50);
}
}
}

export type HostUpdateDecision = "commit" | "cancel";
Expand Down
6 changes: 3 additions & 3 deletions lib/server-update-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
// never the Bun server or the hub. self-update.ts prepares everything the worker uses and verifies the result.
import { execFile } from "node:child_process";
import { randomUUID } from "node:crypto";
import { existsSync, lstatSync, readFileSync, realpathSync, renameSync, rmSync, writeFileSync } from "node:fs";
import { existsSync, lstatSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs";
import { homedir } from "node:os";
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
import { setTimeout as pause } from "node:timers/promises";
import { promisify } from "node:util";
import { requestHostControl, type HostControlStatus } from "./hosts/host-control";
import { assertOwnedPath, HOST_VERSION_PATTERN, hostLaunch, moveHostRelease, sharedHostInstallReason, validateApprovedReleasePin } from "./hosts/update-worker";
import { assertOwnedPath, HOST_VERSION_PATTERN, hostLaunch, moveHostRelease, replaceFileSync, sharedHostInstallReason, validateApprovedReleasePin } from "./hosts/update-worker";
import { getAgentDir } from "./omp/paths";
import { isProcessAlive } from "./process-identity";
import { atomicWrite, attemptPath, isActiveLease, leasePath, markerPath, patchStatus, readStateJson, removeSecureFile, renewLease, secureRegularFile, statusPath, type SelfUpdateStage, type StoredStatus } from "./self-update-state";
Expand Down Expand Up @@ -267,7 +267,7 @@ export function reportPlan(attemptId: string, participantId: string | null, stat
}
const temporary = `${file}.${process.pid}.${randomUUID()}.tmp`;
writeFileSync(temporary, JSON.stringify(plan), { mode: 0o600, flag: "wx" });
try { renameSync(temporary, file); } finally { rmSync(temporary, { force: true }); }
try { replaceFileSync(temporary, file); } finally { rmSync(temporary, { force: true }); }
} catch (error) {
console.error(`Could not record the server update plan's progress: ${message(error)}`);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/upgrade-plan.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createHash, randomUUID } from "node:crypto";
import { existsSync, mkdirSync, readFileSync, realpathSync, renameSync, rmdirSync, unlinkSync, writeFileSync } from "node:fs";
import { existsSync, mkdirSync, readFileSync, realpathSync, rmdirSync, unlinkSync, writeFileSync } from "node:fs";
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
import { setTimeout as pause } from "node:timers/promises";
import { getAgentDir } from "./omp/paths";
Expand All @@ -9,7 +9,7 @@ import { checkNpmUpdate, detectInstallMethod } from "./npm-update";
import { isUpdateDisabled } from "./update-policy";
import { requestHostControl } from "./hosts/host-control";
import { getHostSoftwareUpdates, getHostUpgradeInventory, updateHostSoftware, type HostUpgradeInventory } from "./hosts/hub";
import { assertOwnedPath, fetchHostUpdateBytes, HOST_VERSION_PATTERN, validateApprovedReleasePin } from "./hosts/update-worker";
import { assertOwnedPath, fetchHostUpdateBytes, HOST_VERSION_PATTERN, replaceFileSync, validateApprovedReleasePin } from "./hosts/update-worker";
import { HostOpError } from "./hosts/link-protocol";
import type { ApprovedReleasePin, HostUpdateCompatibility } from "./hosts/update-types";
import type { UpgradeApproval, UpgradeParticipant, UpgradePlan } from "./upgrade-types";
Expand Down Expand Up @@ -102,7 +102,7 @@ function writePlan(plan: UpgradePlan): void {
if (existsSync(path)) assertOwnedPath(path);
const temporary = `${path}.${randomUUID()}.tmp`;
writeFileSync(temporary, JSON.stringify(plan), { flag: "wx", mode: 0o600 });
try { renameSync(temporary, path); } finally { if (existsSync(temporary)) unlinkSync(temporary); }
try { replaceFileSync(temporary, path); } finally { if (existsSync(temporary)) unlinkSync(temporary); }
}

function validParticipant(value: unknown): value is UpgradeParticipant {
Expand Down
Loading