The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: a dead marker whose helper can never run no longer parks boot
Teknium80fd4bb3e222
diff --git a/apps/desktop/electron/update-marker-gate.test.ts b/apps/desktop/electron/update-marker-gate.test.tsindex b01d099fb5d..8058c16f179 100644--- a/apps/desktop/electron/update-marker-gate.test.ts+++ b/apps/desktop/electron/update-marker-gate.test.ts@@ -14,8 +14,10 @@ import { afterEach, describe, test } from 'vitest'import { markerPath } from './update-marker'import {allowStartOverHold,+ HELD_REPROBE_MS,type HeldState,heldWaitMessage,+ HELPER_ERROR_ATTEMPTS,HOLD_SCREEN_GRACE_MS,holdTicker,liveMarkerProbe,@@ -187,6 +189,50 @@ describe.skipIf(process.platform === 'win32')('gate over a dead marker (R6)', ()assert.equal(await probe(), false)})+ // Review K132345 (helper failure on a dead marker blocks boot): a helper that+ // can never run (bash / PowerShell blocked) must not park every boot after a+ // crashed update; main proceeded over a dead marker.+ test('a helper that never answers for a dead marker is retried, then the gate proceeds for every wait', async () => {+ const { root, home } = fakeHelperCheckout()+ const body = `${await deadPid()}\n${minutesAgo(1)}\nct:1.000\n`+ fs.writeFileSync(markerPath(home), body)+ fs.writeFileSync(path.join(home, 'helper-exit'), '1')+ let clock = Date.now()+ const states: HeldState[] = []+ const probe = gate(root, home, () => clock, { onHeld: s => states.push(s) })++ for (let attempt = 1; attempt < HELPER_ERROR_ATTEMPTS; attempt++) {+ assert.equal(await probe(), true, `error ${attempt}: still retrying`)+ clock += HELD_REPROBE_MS+ }++ assert.ok(states.every(s => s.verdict === 'error' && !s.blocking), 'retries are not a hold: no blocked screen')+ assert.equal(await probe(), false, 'retries used up: proceed as for any dead marker')+ assert.equal(helperCalls(home).length, HELPER_ERROR_ATTEMPTS)+ assert.equal(await gate(root, home, () => clock)(), false, 'a later wait (pool backend) proceeds at once')+ assert.equal(helperCalls(home).length, HELPER_ERROR_ATTEMPTS, 'without re-running the retries')+ assert.equal(fs.readFileSync(markerPath(home), 'utf8'), body, 'the marker is left in place')+ })++ test('once the helper has answered for a body, its later errors keep the gate parked (R8 M5)', async () => {+ const { root, home } = fakeHelperCheckout()+ fs.writeFileSync(markerPath(home), `${await deadPid()}\n${minutesAgo(1)}\nct:1.000\n`)+ fs.writeFileSync(path.join(home, 'helper-verdict'), 'held')+ let clock = Date.now()+ const states: HeldState[] = []+ const probe = gate(root, home, () => clock, { onHeld: s => states.push(s) })++ assert.equal(await probe(), true)+ fs.writeFileSync(path.join(home, 'helper-exit'), '1')++ for (let attempt = 0; attempt < 2 * HELPER_ERROR_ATTEMPTS; attempt++) {+ clock += HELD_REPROBE_MS+ assert.equal(await probe(), true, 'a working helper that fails for a moment never opens the gate')+ }++ assert.deepEqual([states.at(-1)!.verdict, states.at(-1)!.blocking], ['error', true])+ })+test('sidecar contention over an old marker is indeterminate, not an expired held checkout', async () => {const { root, home } = fakeHelperCheckout()fs.writeFileSync(markerPath(home), `${await deadPid()}\n${minutesAgo(180)}\nct:1.000\n`)diff --git a/apps/desktop/electron/update-marker-gate.ts b/apps/desktop/electron/update-marker-gate.tsindex 3709a46b6cf..c9e9f73a853 100644--- a/apps/desktop/electron/update-marker-gate.ts+++ b/apps/desktop/electron/update-marker-gate.ts@@ -21,11 +21,17 @@* the next poll after a Retry, because only the script can see the lock being* released.*- * No verdict has a ceiling (review R8 D3). `held` means no owner identity is- * alive but some process still holds the checkout lock; it may be a leaked- * long-lived one, and it may still be writing the install. `busy` / `error`- * mean the helper could not establish ownership at all. None of them ever- * opens the gate by itself: past a short grace the caller shows a blocked+ * No positive answer has a ceiling (review R8 D3). `held` means no owner+ * identity is alive but some process still holds the checkout lock; it may be+ * a leaked long-lived one, and it may still be writing the install. `busy` /+ * `error` mean the helper could not establish ownership at all. The one+ * bounded case is a helper that has never answered for this body: after+ * HELPER_ERROR_ATTEMPTS consecutive `error`s (bash / PowerShell blocked, a+ * broken script) the gate proceeds as main did for a dead marker, minus the+ * deletion — otherwise such a machine would park every boot after every+ * crashed update. Once the helper has answered for a body, a later `error` is+ * a transient failure of a working helper (R8 M5) and keeps waiting. Nothing+ * else ever opens the gate by itself: past a short grace the caller shows a blocked* boot screen (what holds the install, Retry, Quit) whose only way through* while the hold lasts is an explicit, confirmed, logged "Start anyway"* (`allowStartOverHold`), scoped to the exact marker body the user saw. The@@ -41,6 +47,13 @@ import type { MarkerHelperVerdict } from './updater/marker-helper'export const HELD_REPROBE_MS = 5_000+/**+ * Consecutive `error` answers about a body the helper never answered for+ * before the gate proceeds anyway (~10 s at HELD_REPROBE_MS): a helper that+ * cannot run at all must not park boot behind every dead marker.+ */+export const HELPER_ERROR_ATTEMPTS = 3+/** How long a blocking verdict must last in one wait before the boot shows the blocked screen. */export const HOLD_SCREEN_GRACE_MS = 5_000@@ -99,6 +112,10 @@ function heldSince(key: string, at: number): number {// update, a new owner) blocks again.const startAnywayHolds = new Set<string>()+// Bodies whose helper never answered within HELPER_ERROR_ATTEMPTS, process-wide+// so a later wait (a pool backend) proceeds without re-running the retries.+const unanswerableHolds = new Set<string>()+// Bumped by an explicit Retry: every probe re-asks the helper on its next poll.let recheckGeneration = 0@@ -194,6 +211,7 @@ export function requestHoldRecheck(): void {export function resetHoldStateForTests(): void {firstHeldAt.clear()startAnywayHolds.clear()+ unanswerableHolds.clear()recheckGeneration = 0}@@ -202,6 +220,10 @@ interface AskedEntry {at: numbergeneration: numberoverrideLogged?: boolean+ /** Consecutive `error` answers. */+ errors?: number+ /** The helper gave a real verdict (anything but `error`) for this body at least once. */+ answered?: boolean}function statMarkerFile(hermesHome: string): fs.Stats | null {@@ -244,7 +266,24 @@ async function refreshVerdict()}- return { ...previous, verdict, at: now(), generation }+ const errors = verdict.kind === 'error' ? (previous?.errors ?? 0) + 1 : 0++ return { ...previous, verdict, at: now(), generation, errors, answered: previous?.answered || verdict.kind !== 'error' }+}++/** The helper never answered for this body and has used its retries: proceed as main did for a dead marker. */+function helperUnanswerable(entry: AskedEntry, holdId: string, log: ((line: string) => void) | undefined): boolean {+ if (entry.verdict.kind !== 'error' || entry.answered || (entry.errors ?? 0) < HELPER_ERROR_ATTEMPTS) {+ return false+ }++ unanswerableHolds.add(holdId)+ log?.(+ `[updates] dead update marker (hold ${holdId}): the script helper failed ${entry.errors} times and never ` ++ 'answered; starting as for any dead marker. The marker is left in place.'+ )++ return true}function logOverrideOnce(entry: AskedEntry, state: HeldState, log: ((line: string) => void) | undefined): void {@@ -287,6 +326,11 @@ export function liveMarkerProbe({}const holdId = markerHoldId(inspection.raw, statMarkerFile(hermesHome))++ if (unanswerableHolds.has(holdId)) {+ return false+ }+const previous = asked.get(holdId)let entry = previous!@@ -297,7 +341,7 @@ export function liveMarkerProbe({const { verdict } = entry- if (!STILL_RUNNING.has(verdict.kind)) {+ if (!STILL_RUNNING.has(verdict.kind) || helperUnanswerable(entry, holdId, log)) {return false}@@ -308,7 +352,8 @@ export function liveMarkerProbe({holdId,since: heldSince(holdId, now()),checkedAt: entry.at,- blocking: verdict.kind !== 'live'+ // An `error` still inside its retries is not a hold yet: no blocked screen.+ blocking: verdict.kind !== 'live' && (verdict.kind !== 'error' || Boolean(entry.answered))}if (state.blocking && startAnywayHolds.has(holdId)) {