Skip to content

The agent that grows with you

refactor(desktop): move update-gate helpers out of main.ts into topical siblings

Teknium73b813d018d8
diff --git a/apps/desktop/electron/bundle-swap.ts b/apps/desktop/electron/bundle-swap.ts
index 42188046dc6..2ed5f226622 100644
--- a/apps/desktop/electron/bundle-swap.ts
+++ b/apps/desktop/electron/bundle-swap.ts
@@ -72,3 +72,69 @@ export function detectBundleSwap(running: BundleSwapStamp | null, onDisk: Bundle
return running.builtAt !== onDisk.builtAt
}
+
+// One-shot guard for the automatic bundle-swap relaunch below: the relaunched
+// instance carries this flag so a stamp that still mismatches (unreadable
+// resources, exotic packaging) can never produce a relaunch loop.
+export const BUNDLE_SWAP_RELAUNCH_FLAG = '--hermes-bundle-swap-relaunched'
+
+// How long the parked instance waits for its own scheduled exit to land before
+// giving up and booting the stale build anyway. Better a torn renderer with a
+// banner than a window that never comes back.
+export const BUNDLE_SWAP_RELAUNCH_FAILSAFE_MS = 15_000
+
+export interface BundleSwapRelaunchHost {
+ isPackaged: boolean
+ argv: string[]
+ /** The stamp this process was built with. */
+ running: BundleSwapStamp | null
+ resourcesPath: string
+ /** Schedule a relaunch with these extra args (may throw). */
+ relaunch: (extraArgs: string[]) => void
+ /** Exit after shutting the backend down (the relaunch lands on exit). */
+ exit: () => void
+ log: (line: string) => void
+}
+
+// The detached updater swaps the packaged bundle on disk AFTER `hermes update`
+// exits (posix.sh mac_swap / windows.ps1). An instance reopened mid-update —
+// the #50238 gesture the boot update gate exists for — was launched from the
+// PRE-swap bundle, and the updater's `open` leg then merely focuses us (single
+// instance), so no process ever loads the new build. Letting boot proceed here
+// runs the new runtime under the old renderer: exactly the skew
+// detectRendererSkew() warns about, except the Updates card already says
+// "latest", so the warning's own remedy has nothing to run.
+//
+// waitForUpdateToFinish (main.ts) calls this at the earliest point where the
+// swap is PROVABLE — it happens while we are parked on the gate, so checking any sooner (at `ready`, before the gate)
+// only ever compares a stamp with itself. Relaunching here also keeps the
+// boot-progress window up for the whole wait instead of leaving the user with
+// no window at all.
+//
+// Returns true when the relaunch was scheduled; the caller must park rather
+// than continue booting, because the process exits underneath it.
+export function relaunchIntoSwappedBundle(host: BundleSwapRelaunchHost): boolean {
+ if (!host.isPackaged || host.argv.includes(BUNDLE_SWAP_RELAUNCH_FLAG)) {
+ return false
+ }
+
+ if (!detectBundleSwap(host.running, readBundleSwapStamp(host.resourcesPath))) {
+ return false
+ }
+
+ host.log('[updates] app bundle was swapped during the update; relaunching into the new build')
+
+ try {
+ host.relaunch([BUNDLE_SWAP_RELAUNCH_FLAG])
+ } catch (err) {
+ host.log(
+ `[updates] bundle-swap relaunch failed: ${(err as Error)?.message || err}; continuing with the current build`
+ )
+
+ return false
+ }
+
+ host.exit()
+
+ return true
+}
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.ts
index 9a7e30e1f91..7e8cc963e3e 100644
--- a/apps/desktop/electron/main.ts
+++ b/apps/desktop/electron/main.ts
@@ -119,7 +119,12 @@ import {
buildBrowserWindowUrl
} from './browser-windows'
import { createBundleSkewChecker } from './bundle-skew'
-import { detectBundleSwap, readBundleSwapStamp } from './bundle-swap'
+import {
+ BUNDLE_SWAP_RELAUNCH_FAILSAFE_MS,
+ detectBundleSwap,
+ readBundleSwapStamp,
+ relaunchIntoSwappedBundle
+} from './bundle-swap'
import { registerChatOnboardingWindow } from './chat-onboarding-window'
import { provisionCliLinks } from './cli-provision'
import { closeStopFailureMessage, finishWindowsCloseStop, type RuntimeLock } from './close-stop-kill'
@@ -281,7 +286,6 @@ import { probeGatewayWebSocket, spawnedBackendProbeOptions } from './gateway-ws-
import { windowsGitCandidates } from './git-binary-candidates'
import { registerGitIpc } from './git-ipc'
import { desktopBackendSpawnEnv, guestOnboardingEnabled } from './guest-onboarding'
-import { readAndConsumeHandoffResult } from './handoff-result'
import {
assertExistingPathForOpen,
ATTACHMENT_UPLOAD_DEFAULT_MAX_BYTES,
@@ -591,14 +595,21 @@ import {
windowOpacityFor,
windowOpacityOptions
} from './translucency'
-import { waitForUpdateClearance } from './update-gate'
+import {
+ UPDATE_HANDOFF_DWELL_MS,
+ UPDATE_WAIT_POLL_MS,
+ UPDATE_WAIT_TIMEOUT_MS,
+ waitForUpdateClearance
+} from './update-gate'
+import { reportHandoffResult } from './update-handoff-report'
import {
createUpdateHoldScreen,
holdGraceClock,
type MarkerGateCallbacks,
markerGateProbe,
registerUpdateHoldIpc,
- type UpdateHoldWire
+ type UpdateHoldWire,
+ waitForPoolUpdateClearance
} from './update-hold-wiring'
import { describeSkippedPrewrite, markerPath, updateHandoffConflict, writeUpdateMarker } from './update-marker'
import { type HeldState, heldWaitMessage } from './update-marker-gate'
@@ -611,6 +622,7 @@ import {
} from './updater'
import {
observeUpdaterHandoff,
+ repairMacUpdaterHelper,
resolveInstallationLauncher,
resolveStagedUpdaterBinary,
resolveVenvDir,
@@ -2977,21 +2989,6 @@ function directoryExists(filePath) {
// own relaunch hits our single-instance lock and quits). Marker parsing +
// staleness self-heal live in update-marker.ts (unit-tested).
-// How long the launch parks on an in-process update signal (in-flight /
-// hand-off) before starting the backend anyway. A LIVE marker owner is waited
-// out with no deadline (owner liveness, never age); past this the boot copy
-// says the update is still running.
-const UPDATE_WAIT_TIMEOUT_MS = 20 * 60 * 1000
-const UPDATE_WAIT_POLL_MS = 1000
-// How long the desktop lingers on the "updating, don't reopen" overlay after
-// spawning the detached updater, before it quits to release the venv shim. The
-// old 600ms was long enough to register the child process but far too short for
-// the user to READ the overlay — the window just vanished, looked like a crash,
-// and the user relaunched mid-update (the #50238 restart-loop trigger). A
-// couple of seconds lets the message land and bridges the gap until the
-// updater's own progress window appears. (#50419)
-const UPDATE_HANDOFF_DWELL_MS = 2500
-
// Gate deps shared by the primary-window boot path and the pool-backend
// spawn path. Consulting the on-disk marker, the in-process updateInFlight
// flag, AND the successful detached hand-off state is load-bearing (#73822):
@@ -3013,59 +3010,6 @@ function updateGateDeps(callbacks: MarkerGateCallbacks = {}) {
}
}
-// One-shot guard for the automatic bundle-swap relaunch below: the relaunched
-// instance carries this flag so a stamp that still mismatches (unreadable
-// resources, exotic packaging) can never produce a relaunch loop.
-const BUNDLE_SWAP_RELAUNCH_FLAG = '--hermes-bundle-swap-relaunched'
-
-// How long the parked instance waits for its own scheduled exit to land before
-// giving up and booting the stale build anyway. Better a torn renderer with a
-// banner than a window that never comes back.
-const BUNDLE_SWAP_RELAUNCH_FAILSAFE_MS = 15_000
-
-// The detached updater swaps the packaged bundle on disk AFTER `hermes update`
-// exits (posix.sh mac_swap / windows.ps1). An instance reopened mid-update —
-// the #50238 gesture the gate above exists for — was launched from the
-// PRE-swap bundle, and the updater's `open` leg then merely focuses us (single
-// instance), so no process ever loads the new build. Letting boot proceed here
-// runs the new runtime under the old renderer: exactly the skew
-// detectRendererSkew() warns about, except the Updates card already says
-// "latest", so the warning's own remedy has nothing to run.
-//
-// This is the earliest point where the swap is PROVABLE — it happens while we
-// are parked on the gate, so checking any sooner (at `ready`, before the gate)
-// only ever compares a stamp with itself. Relaunching here also keeps the
-// boot-progress window up for the whole wait instead of leaving the user with
-// no window at all.
-//
-// Returns true when the relaunch was scheduled; the caller must park rather
-// than continue booting, because the process exits underneath it.
-function relaunchIntoSwappedBundle() {
- if (!IS_PACKAGED || process.argv.includes(BUNDLE_SWAP_RELAUNCH_FLAG)) {
- return false
- }
-
- if (!detectBundleSwap(INSTALL_STAMP, readBundleSwapStamp(process.resourcesPath))) {
- return false
- }
-
- rememberLog('[updates] app bundle was swapped during the update; relaunching into the new build')
-
- try {
- app.relaunch({
- args: [...buildNoSandboxRelaunchArgs(process.argv.slice(1)), BUNDLE_SWAP_RELAUNCH_FLAG]
- })
- } catch (err) {
- rememberLog(`[updates] bundle-swap relaunch failed: ${err?.message || err}; continuing with the current build`)
-
- return false
- }
-
- void exitAfterBackendShutdown(0)
-
- return true
-}
-
// The blocked boot screen (R8 D3) every update wait publishes its hold on.
const updateHoldScreen = createUpdateHoldScreen({
hermesHome: HERMES_HOME,
@@ -3168,72 +3112,16 @@ async function waitForUpdateToFinish() {
clearUpdateHold()
- // The detached hand-off script (scripts/desktop-update/windows.ps1) runs hidden;
- // its result file is the ONLY way the user learns a detached update
- // failed. Consume it exactly once, here, right where boot passes the
- // update gate — success gets a log line, failure gets a real dialog
- // (previously a failed detached update was indistinguishable from
- // "nothing happened").
- try {
- const result = readAndConsumeHandoffResult(HERMES_HOME, {
- expectedStartedAt: parkedRunStartedAt,
- log: rememberLog
- })
-
- if (result && result.ok && result.warnings.length && !result.manual) {
- // Committed, but follow-up work failed (C2/C3): the user IS on the new
- // version, so this is a non-blocking notice, never "previous version".
- rememberLog(`[updates] detached update finished with warnings: ${result.warnings.join(' | ')}`)
- void dialog.showMessageBox({
- type: 'info',
- title: 'Hermes update',
- message: 'Hermes updated, but some follow-up steps need another try',
- detail: `${result.warnings.join('\n')}\n\nHermes retries them on the next launch or the next update.`
- })
- } else if (result && result.ok && result.manual) {
- // Update landed but the user must act (reopen/reinstall/sandbox). On
- // machines with no shim browser and no notifier this dialog is the
- // FIRST time the message is visible — it must not be a log line.
- rememberLog(`[updates] detached update finished with manual action (branch ${result.branch}): ${result.message}`)
- dialog.showMessageBox({
- type: 'warning',
- title: 'Hermes update',
- message: 'The update finished, but needs one more step',
- detail: result.message
- })
- } else if (result && result.ok) {
- rememberLog(`[updates] detached update finished OK (branch ${result.branch})`)
- } else if (result) {
- rememberLog(`[updates] detached update FAILED (exit ${result.exitCode}): ${result.message}`)
- const handoffLogPath = path.join(HERMES_HOME, 'logs', 'desktop-update-handoff.log')
-
- // Async so boot is not blocked behind the dialog; the response handlers
- // reuse the menu's open-updates path (queued until the renderer is ready)
- // and the same reveal primitive as 'hermes:logs:reveal'.
- void dialog
- .showMessageBox({
- type: 'error',
- title: 'Hermes update',
- message: "Hermes couldn't finish updating",
- detail:
- "You're still on the previous version and can keep using it. Try the update again, or open the update log to report the problem.\n\n" +
- `Details: ${result.message}`,
- buttons: ['Try again', 'Open log', 'Close'],
- defaultId: 0,
- cancelId: 2,
- noLink: true
- })
- .then(({ response }) => {
- if (response === 0) {
- sendOpenUpdatesRequested()
- } else if (response === 1) {
- shell.showItemInFolder(handoffLogPath)
- }
- })
- }
- } catch (err) {
- rememberLog(`[updates] could not read hand-off result: ${err.message}`)
- }
+ // A detached update's result file is the only way the user learns it
+ // failed: consumed once, here, where boot passes the update gate.
+ reportHandoffResult({
+ hermesHome: HERMES_HOME,
+ expectedStartedAt: parkedRunStartedAt,
+ log: rememberLog,
+ dialog,
+ shell,
+ openUpdates: sendOpenUpdatesRequested
+ })
if (outcome === 'cancelled') {
localBackendLifecycle.assertCanStart()
@@ -3247,7 +3135,18 @@ async function waitForUpdateToFinish() {
rememberLog('[updates] update still in progress after wait timeout; starting backend anyway')
} else if (overridden) {
rememberLog('[updates] proceeding with backend start over a held update (user chose Start anyway); no relaunch')
- } else if (relaunchIntoSwappedBundle()) {
+ } else if (
+ relaunchIntoSwappedBundle({
+ isPackaged: IS_PACKAGED,
+ argv: process.argv,
+ running: INSTALL_STAMP,
+ resourcesPath: process.resourcesPath,
+ relaunch: extraArgs =>
+ app.relaunch({ args: [...buildNoSandboxRelaunchArgs(process.argv.slice(1)), ...extraArgs] }),
+ exit: () => void exitAfterBackendShutdown(0),
+ log: rememberLog
+ })
+ ) {
await advanceBootProgress('backend.update-restart', 'Restarting Hermes to load the updated app…', 14)
// Park while the scheduled exit lands so this stale build never starts a
// backend; the failsafe below only runs if the exit somehow does not.
@@ -4053,7 +3952,7 @@ function resolveCheckoutUpdateStrategy(): UpdaterStrategy {
rememberLog,
startHermes,
stopBackendsForUpdate,
- repairMacUpdaterHelper,
+ repairMacUpdaterHelper: updater => repairMacUpdaterHelper(updater, { isMac: IS_MAC, log: rememberLog }),
preflightStateDb: async (home: string, log: (message: string) => void): Promise<void> => {
const root: string = resolveUpdateRoot()
@@ -4179,34 +4078,6 @@ function resolveUpdaterBinary() {
return resolveStagedUpdaterBinary(HERMES_HOME, { fileExists, isWindows: IS_WINDOWS })
}
-function repairMacUpdaterHelper(updater) {
- if (!IS_MAC || !updater) {
- return
- }
-
- try {
- execFileSync('/usr/bin/xattr', ['-cr', updater], { stdio: 'ignore' })
- } catch (err) {
- rememberLog(`[updates] macOS updater helper quarantine repair skipped: ${err.message}`)
- }
-
- try {
- execFileSync('/usr/bin/codesign', ['--verify', updater], { stdio: 'ignore' })
-
- return
- } catch {
- // Unsigned or invalid helper. Apply a local ad-hoc signature so Gatekeeper
- // does not block the staged updater before it can run.
- }
-
- try {
- execFileSync('/usr/bin/codesign', ['--force', '--sign', '-', updater], { stdio: 'ignore' })
- rememberLog('[updates] repaired macOS updater helper signature')
- } catch (err) {
- rememberLog(`[updates] macOS updater helper signature repair skipped: ${err.message}`)
- }
-}
-
// Path to the venv shim whose lock decides whether `hermes update` can write
// fresh entry points. On Windows this is the file the running backend
// `hermes.exe` holds open; on POSIX it's never mandatory-locked.
@@ -12362,59 +12233,18 @@ async function runPoolBackendStart(
// during applyUpdates' critical section starts a backend on the runtime
// being replaced. No boot-progress UI here — pool backends boot
// silently for background profiles — so we only log while parked.
- {
- let poolAnnounced = false
- let poolHoldLogged: string | null = null
- let poolHeld: HeldState | null = null
- const poolBlockedHold = holdGraceClock()
- const holdOwner = `pool:${poolKey}`
-
- // A blocking hold never ages out here either (R8 D3). Past the grace it is
- // published on the window's blocked screen like the primary's (R8 M6): a
- // remote primary, or one that booted before the hold appeared, never
- // shows one of its own. Check again / Start anyway act on its hold id.
- const poolGateDeps = updateGateDeps({
- onHeld: state => {
- poolHeld = state
-
- if (state.blocking && poolHoldLogged !== state.holdId) {
- poolHoldLogged = state.holdId
- rememberLog(
- `[updates] pool backend start for profile "${profile}" blocked: update marker ${state.verdict}, ` +
- `hold ${state.holdId}; waiting for the hold to end or a Start anyway on the blocked screen`
- )
- }
- }
- })
-
- try {
- await waitForUpdateClearance(poolGateDeps, {
- signal: localBackendLifecycle.signal,
- isCancelled: (): boolean => backendPool.get(poolKey) !== entry,
- onWaitTick: reason => {
- if (!poolAnnounced) {
- poolAnnounced = true
- rememberLog(
- `[updates] update in progress (${reason}); deferring pool backend start for profile "${profile}"`
- )
- }
-
- const blocked = poolBlockedHold(reason, poolHeld)
- poolHeld = null
-
- if (blocked) {
- showUpdateHold(blocked, holdOwner)
- } else {
- clearUpdateHold(holdOwner)
- }
- },
- pollMs: UPDATE_WAIT_POLL_MS,
- timeoutMs: UPDATE_WAIT_TIMEOUT_MS
- })
- } finally {
- clearUpdateHold(holdOwner)
- }
- }
+ await waitForPoolUpdateClearance({
+ profile,
+ poolKey,
+ gateDeps: updateGateDeps,
+ signal: localBackendLifecycle.signal,
+ isCancelled: (): boolean => backendPool.get(poolKey) !== entry,
+ log: rememberLog,
+ showHold: showUpdateHold,
+ clearHold: clearUpdateHold,
+ pollMs: UPDATE_WAIT_POLL_MS,
+ timeoutMs: UPDATE_WAIT_TIMEOUT_MS
+ })
profileDeletionGate.assertCanStart(profile)
diff --git a/apps/desktop/electron/update-gate.ts b/apps/desktop/electron/update-gate.ts
index 164a9bf1274..45cb6093626 100644
--- a/apps/desktop/electron/update-gate.ts
+++ b/apps/desktop/electron/update-gate.ts
@@ -33,6 +33,21 @@ import { runBackendStartStep } from './backend-start-cancellation'
* updater's marker reads dead and opens the gate by itself.
*/
+// How long the launch parks on an in-process update signal (in-flight /
+// hand-off) before starting the backend anyway. A LIVE marker owner is waited
+// out with no deadline (owner liveness, never age); past this the boot copy
+// says the update is still running.
+export const UPDATE_WAIT_TIMEOUT_MS = 20 * 60 * 1000
+export const UPDATE_WAIT_POLL_MS = 1000
+// How long the desktop lingers on the "updating, don't reopen" overlay after
+// spawning the detached updater, before it quits to release the venv shim. The
+// old 600ms was long enough to register the child process but far too short for
+// the user to READ the overlay — the window just vanished, looked like a crash,
+// and the user relaunched mid-update (the #50238 restart-loop trigger). A
+// couple of seconds lets the message land and bridges the gap until the
+// updater's own progress window appears. (#50419)
+export const UPDATE_HANDOFF_DWELL_MS = 2500
+
export type UpdateGateReason = 'marker' | 'update-in-flight' | 'handoff' | null
export interface UpdateGateDeps {
diff --git a/apps/desktop/electron/update-handoff-report.ts b/apps/desktop/electron/update-handoff-report.ts
new file mode 100644
index 00000000000..8018950e051
--- /dev/null
+++ b/apps/desktop/electron/update-handoff-report.ts
@@ -0,0 +1,89 @@
+// Report a detached update's result once, where boot passes the update gate.
+
+import path from 'node:path'
+
+import type { Dialog, Shell } from 'electron'
+
+import { readAndConsumeHandoffResult } from './handoff-result'
+
+export interface HandoffReportHost {
+ hermesHome: string
+ /** Marker line 2 of the run this boot parked on (C2 started_at match), else null. */
+ expectedStartedAt: number | null
+ log: (line: string) => void
+ dialog: Pick<Dialog, 'showMessageBox'>
+ shell: Pick<Shell, 'showItemInFolder'>
+ /** The menu's open-updates path (queued until the renderer is ready). */
+ openUpdates: () => void
+}
+
+/**
+ * The detached hand-off script (scripts/desktop-update/windows.ps1) runs hidden;
+ * its result file is the ONLY way the user learns a detached update
+ * failed. Consume it exactly once, here, right where boot passes the
+ * update gate — success gets a log line, failure gets a real dialog
+ * (previously a failed detached update was indistinguishable from
+ * "nothing happened").
+ */
+export function reportHandoffResult(host: HandoffReportHost): void {
+ try {
+ const result = readAndConsumeHandoffResult(host.hermesHome, {
+ expectedStartedAt: host.expectedStartedAt,
+ log: host.log
+ })
+
+ if (result && result.ok && result.warnings.length && !result.manual) {
+ // Committed, but follow-up work failed (C2/C3): the user IS on the new
+ // version, so this is a non-blocking notice, never "previous version".
+ host.log(`[updates] detached update finished with warnings: ${result.warnings.join(' | ')}`)
+ void host.dialog.showMessageBox({
+ type: 'info',
+ title: 'Hermes update',
+ message: 'Hermes updated, but some follow-up steps need another try',
+ detail: `${result.warnings.join('\n')}\n\nHermes retries them on the next launch or the next update.`
+ })
+ } else if (result && result.ok && result.manual) {
+ // Update landed but the user must act (reopen/reinstall/sandbox). On
+ // machines with no shim browser and no notifier this dialog is the
+ // FIRST time the message is visible — it must not be a log line.
+ host.log(`[updates] detached update finished with manual action (branch ${result.branch}): ${result.message}`)
+ host.dialog.showMessageBox({
+ type: 'warning',
+ title: 'Hermes update',
+ message: 'The update finished, but needs one more step',
+ detail: result.message
+ })
+ } else if (result && result.ok) {
+ host.log(`[updates] detached update finished OK (branch ${result.branch})`)
+ } else if (result) {
+ host.log(`[updates] detached update FAILED (exit ${result.exitCode}): ${result.message}`)
+ const handoffLogPath = path.join(host.hermesHome, 'logs', 'desktop-update-handoff.log')
+
+ // Async so boot is not blocked behind the dialog; the response handlers
+ // reuse the menu's open-updates path (queued until the renderer is ready)
+ // and the same reveal primitive as 'hermes:logs:reveal'.
+ void host.dialog
+ .showMessageBox({
+ type: 'error',
+ title: 'Hermes update',
+ message: "Hermes couldn't finish updating",
+ detail:
+ "You're still on the previous version and can keep using it. Try the update again, or open the update log to report the problem.\n\n" +
+ `Details: ${result.message}`,
+ buttons: ['Try again', 'Open log', 'Close'],
+ defaultId: 0,
+ cancelId: 2,
+ noLink: true
+ })
+ .then(({ response }) => {
+ if (response === 0) {
+ host.openUpdates()
+ } else if (response === 1) {
+ host.shell.showItemInFolder(handoffLogPath)
+ }
+ })
+ }
+ } catch (err) {
+ host.log(`[updates] could not read hand-off result: ${(err as Error).message}`)
+ }
+}
diff --git a/apps/desktop/electron/update-hold-wiring.ts b/apps/desktop/electron/update-hold-wiring.ts
index 798623d0cef..d5d11a120b3 100644
--- a/apps/desktop/electron/update-hold-wiring.ts
+++ b/apps/desktop/electron/update-hold-wiring.ts
@@ -7,6 +7,7 @@ import path from 'node:path'
import type { IpcMain, IpcMainInvokeEvent } from 'electron'
+import { type UpdateGateDeps, waitForUpdateClearance, type WaitForUpdateClearanceOptions } from './update-gate'
import { cachedCreateTimeProbe } from './update-marker'
import {
allowStartOverHold,
@@ -236,3 +237,74 @@ export function registerUpdateHoldIpc(ipc: IpcMain, host: UpdateHoldIpcHost) {
return { ok: true }
})
}
+
+export interface PoolUpdateWaitHost {
+ profile: string
+ poolKey: string
+ /** main.ts's `updateGateDeps`: the gate deps shared with the primary boot wait. */
+ gateDeps: (callbacks: MarkerGateCallbacks) => UpdateGateDeps
+ signal: WaitForUpdateClearanceOptions['signal']
+ isCancelled: () => boolean
+ log: (line: string) => void
+ showHold: (state: HeldState, owner: string) => void
+ clearHold: (owner: string) => void
+ pollMs: number
+ timeoutMs: number
+}
+
+/**
+ * A pool/profile backend's update wait. No boot-progress UI (pool backends
+ * boot silently for background profiles), so it only logs while parked. A
+ * blocking hold never ages out here either (R8 D3). Past the grace it is
+ * published on the window's blocked screen like the primary's (R8 M6): a
+ * remote primary, or one that booted before the hold appeared, never shows
+ * one of its own. Check again / Start anyway act on its hold id.
+ */
+export async function waitForPoolUpdateClearance(host: PoolUpdateWaitHost): Promise<void> {
+ const { profile } = host
+ let poolAnnounced = false
+ let poolHoldLogged: string | null = null
+ let poolHeld: HeldState | null = null
+ const poolBlockedHold = holdGraceClock()
+ const holdOwner = `pool:${host.poolKey}`
+
+ const poolGateDeps = host.gateDeps({
+ onHeld: state => {
+ poolHeld = state
+
+ if (state.blocking && poolHoldLogged !== state.holdId) {
+ poolHoldLogged = state.holdId
+ host.log(
+ `[updates] pool backend start for profile "${profile}" blocked: update marker ${state.verdict}, ` +
+ `hold ${state.holdId}; waiting for the hold to end or a Start anyway on the blocked screen`
+ )
+ }
+ }
+ })
+
+ try {
+ await waitForUpdateClearance(poolGateDeps, {
+ signal: host.signal,
+ isCancelled: host.isCancelled,
+ onWaitTick: reason => {
+ if (!poolAnnounced) {
+ poolAnnounced = true
+ host.log(`[updates] update in progress (${reason}); deferring pool backend start for profile "${profile}"`)
+ }
+
+ const blocked = poolBlockedHold(reason, poolHeld)
+ poolHeld = null
+
+ if (blocked) {
+ host.showHold(blocked, holdOwner)
+ } else {
+ host.clearHold(holdOwner)
+ }
+ },
+ pollMs: host.pollMs,
+ timeoutMs: host.timeoutMs
+ })
+ } finally {
+ host.clearHold(holdOwner)
+ }
+}
diff --git a/apps/desktop/electron/updater-process.ts b/apps/desktop/electron/updater-process.ts
index d51aa340c3b..92d50e9ae53 100644
--- a/apps/desktop/electron/updater-process.ts
+++ b/apps/desktop/electron/updater-process.ts
@@ -1,4 +1,4 @@
-import { spawn, type SpawnOptions, spawnSync, type SpawnSyncReturns } from 'node:child_process'
+import { execFileSync, spawn, type SpawnOptions, spawnSync, type SpawnSyncReturns } from 'node:child_process'
import { existsSync, realpathSync, statSync } from 'node:fs'
import os from 'node:os'
import path from 'node:path'
@@ -470,6 +470,41 @@ export function stagedUpdaterSupportsPrewrittenMarker(
return typeof mtimeMs === 'number' && Number.isFinite(mtimeMs) && mtimeMs >= MARKER_SELF_ADOPT_EPOCH_MS
}
+/**
+ * Clear the staged macOS updater helper's quarantine and, when its signature
+ * does not verify, ad-hoc sign it so Gatekeeper lets it run. Best effort.
+ */
+export function repairMacUpdaterHelper(
+ updater: string | null,
+ deps: { isMac: boolean; log: (line: string) => void }
+): void {
+ if (!deps.isMac || !updater) {
+ return
+ }
+
+ try {
+ execFileSync('/usr/bin/xattr', ['-cr', updater], { stdio: 'ignore' })
+ } catch (err) {
+ deps.log(`[updates] macOS updater helper quarantine repair skipped: ${(err as Error).message}`)
+ }
+
+ try {
+ execFileSync('/usr/bin/codesign', ['--verify', updater], { stdio: 'ignore' })
+
+ return
+ } catch {
+ // Unsigned or invalid helper. Apply a local ad-hoc signature so Gatekeeper
+ // does not block the staged updater before it can run.
+ }
+
+ try {
+ execFileSync('/usr/bin/codesign', ['--force', '--sign', '-', updater], { stdio: 'ignore' })
+ deps.log('[updates] repaired macOS updater helper signature')
+ } catch (err) {
+ deps.log(`[updates] macOS updater helper signature repair skipped: ${(err as Error).message}`)
+ }
+}
+
export interface SpawnUpdaterProcessDeps {
isWindows?: boolean
spawnProcess?: (command: string, args: string[], options: SpawnOptions) => UpdaterChild