Skip to content

The agent that grows with you

fix: a failed update's live-looking v1 marker no longer parks boot 20 min

Teknium2f31792e824f
diff --git a/apps/desktop/electron/update-gate.test.ts b/apps/desktop/electron/update-gate.test.ts
index 4912629e1eb..6f5a68babad 100644
--- a/apps/desktop/electron/update-gate.test.ts
+++ b/apps/desktop/electron/update-gate.test.ts
@@ -201,12 +201,3 @@ test('a live marker keeps parking past the deadline until its owner finishes', a
assert.equal(outcome, 'finished')
assert.equal(ticks, 50, 'parked ten times past the deadline')
})
-
-// A failed receipt never outranks a live marker (desktop V2): latest.json is
-// written only at finalize, so a retry after a failed update still reads
-// "failed" while the new update runs.
-test('a failed receipt does not open the gate while a live marker exists', async () => {
- const withFailedReceipt = { ...deps(true, false), hasFailedReceipt: () => true }
-
- assert.equal(await updateGateReason(withFailedReceipt), 'marker')
-})
diff --git a/apps/desktop/electron/update-marker-gate.test.ts b/apps/desktop/electron/update-marker-gate.test.ts
index 8058c16f179..f750c19a35b 100644
--- a/apps/desktop/electron/update-marker-gate.test.ts
+++ b/apps/desktop/electron/update-marker-gate.test.ts
@@ -11,7 +11,7 @@ import path from 'path'
import { afterEach, describe, test } from 'vitest'
-import { markerPath } from './update-marker'
+import { formatCreateTime, markerPath, processCreateTimeSync } from './update-marker'
import {
allowStartOverHold,
HELD_REPROBE_MS,
@@ -344,6 +344,52 @@ test("a pool/profile hold reaches the screen when the primary shows none; the pr
assert.equal(board.shown(), null)
})
+// Review K132345 (#122206 fast exit): until the lock PR lands, `hermes update`
+// writes v1 markers, which read live on a bare alive (possibly recycled) pid for
+// 20 minutes. A failed receipt finished after the marker started ends the wait.
+describe('a live v1 marker and the latest failed receipt', () => {
+ function receipt(home: string, outcome: string, finishedS: number) {
+ fs.mkdirSync(path.join(home, 'logs', 'update_receipts'), { recursive: true })
+ fs.writeFileSync(
+ path.join(home, 'logs', 'update_receipts', 'latest.json'),
+ JSON.stringify({ outcome, finished_at: new Date(finishedS * 1000).toISOString().replace('Z', '+00:00') })
+ )
+ }
+
+ test('a failure recorded after the marker started opens the gate and leaves the marker', async () => {
+ const home = tmpHome('gate-v1-failed')
+ const owner = await liveOwner()
+ const body = `${owner.pid}\n${minutesAgo(10)}\n`
+ fs.writeFileSync(markerPath(home), body)
+ receipt(home, 'failed', minutesAgo(1))
+ const logs: string[] = []
+
+ assert.equal(await liveMarkerProbe({ hermesHome: home, reclaim: null, log: l => logs.push(l) })(), false)
+ assert.equal(fs.readFileSync(markerPath(home), 'utf8'), body)
+ assert.equal(logs.length, 1)
+ })
+
+ test('a retry (marker newer than the failure), a success, or a v2 owner still waits', async () => {
+ const home = tmpHome('gate-v1-retry')
+ const owner = await liveOwner()
+ const probe = () => liveMarkerProbe({ hermesHome: home, reclaim: null })()
+
+ fs.writeFileSync(markerPath(home), `${owner.pid}\n${minutesAgo(1)}\n`)
+ receipt(home, 'failed', minutesAgo(10))
+ assert.equal(await probe(), true, 'the retry started after the old failure: it is the running update')
+
+ fs.writeFileSync(markerPath(home), `${owner.pid}\n${minutesAgo(10)}\n`)
+ receipt(home, 'success', minutesAgo(1))
+ assert.equal(await probe(), true, 'only a failure ends the wait')
+
+ const ct = processCreateTimeSync(owner.pid)
+ assert.ok(ct !== null)
+ fs.writeFileSync(markerPath(home), `${owner.pid}\n${minutesAgo(10)}\nct:${formatCreateTime(ct)}\n`)
+ receipt(home, 'failed', minutesAgo(1))
+ assert.equal(await probe(), true, 'a v2 owner whose creation time matches is the running update')
+ })
+})
+
test('without a protocol-2 script the gate judges dead = not running and deletes nothing', async () => {
const home = tmpHome('gate-legacy')
const body = `${await deadPid()}\n${minutesAgo(1)}\n`
diff --git a/apps/desktop/electron/update-marker-gate.ts b/apps/desktop/electron/update-marker-gate.ts
index c9e9f73a853..4d22f10a6e5 100644
--- a/apps/desktop/electron/update-marker-gate.ts
+++ b/apps/desktop/electron/update-marker-gate.ts
@@ -41,8 +41,10 @@
import { createHash } from 'node:crypto'
import fs from 'node:fs'
+import path from 'node:path'
import { type CreateTimeProbe, inspectUpdateMarker, markerPath } from './update-marker'
+import type { UpdateMarker } from './update-marker-judge'
import type { MarkerHelperVerdict } from './updater/marker-helper'
export const HELD_REPROBE_MS = 5_000
@@ -298,6 +300,31 @@ function logOverrideOnce(entry: AskedEntry, state: HeldState, log: ((line: strin
)
}
+/**
+ * A v1 marker (no `ct:`, no delegate) reads live on a bare alive pid for up to
+ * V1_MAX_AGE_S, so a recycled pid (Windows, #122206) parks boot ~20 min. A
+ * failed receipt that finished after the marker started says that update is
+ * over. Only v1: a v2 owner's creation time already tells a reused pid apart,
+ * and a retry's marker starts after the old receipt, so a retry still waits
+ * (V2: `latest.json` keeps reading `failed` until the retry finalizes).
+ */
+async function failedAfterV1Start(hermesHome: string, marker: UpdateMarker | null): Promise<boolean> {
+ if (!marker || marker.ct !== null || marker.delegate !== null) {
+ return false
+ }
+
+ try {
+ const text = await fs.promises.readFile(path.join(hermesHome, 'logs', 'update_receipts', 'latest.json'), 'utf8')
+ const receipt = JSON.parse(text.replace(/^\uFEFF/, ''))
+ const finishedS = Date.parse(receipt?.finished_at) / 1000
+
+ // Line 2 is whole seconds: a receipt from the marker's own start second is ambiguous, so it waits.
+ return receipt?.outcome === 'failed' && finishedS >= marker.startedAt + 1
+ } catch {
+ return false
+ }
+}
+
/** `hasLiveMarker` for one gate wait (create it per wait, never module-wide). */
export function liveMarkerProbe({
hermesHome,
@@ -311,11 +338,21 @@ export function liveMarkerProbe({
reprobeMs = HELD_REPROBE_MS
}: LiveMarkerProbeOptions): () => Promise<boolean> {
const asked = new Map<string, AskedEntry>()
+ let finishedLogged = false
return async () => {
const inspection = await inspectUpdateMarker(hermesHome, { createTime, now })
if (inspection.state === 'live') {
+ if (await failedAfterV1Start(hermesHome, inspection.marker)) {
+ if (!finishedLogged) {
+ finishedLogged = true
+ log?.('[updates] latest update receipt records a failure after this v1 marker started; not parking the boot on it')
+ }
+
+ return false
+ }
+
onLiveMarker?.({ startedAt: inspection.marker?.startedAt ?? null })
return true