The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(update): with no marker the Desktop gate still asks whether the checkout lock is held
Tekniume13fb204e94f
diff --git a/apps/desktop/electron/update-marker-gate.test.ts b/apps/desktop/electron/update-marker-gate.test.tsindex f750c19a35b..023bc3fe0e0 100644--- a/apps/desktop/electron/update-marker-gate.test.ts+++ b/apps/desktop/electron/update-marker-gate.test.ts@@ -309,16 +309,38 @@ describe.skipIf(process.platform === 'win32')('gate over a dead marker (R6)', ()assert.equal(helperCalls(home).length, 0, 'legacy capability absence remains unsupported')})- test('a live owner never reaches the helper; an absent marker neither', async () => {+ test('a live owner never reaches the helper', async () => {const { root, home } = fakeHelperCheckout()const hasLiveMarker = gate(root, home)- assert.equal(await hasLiveMarker(), false)const owner = await liveOwner()fs.writeFileSync(markerPath(home), `${owner.pid}\n${minutesAgo(1)}\n`)assert.equal(await hasLiveMarker(), true)assert.deepEqual(helperCalls(home), [])})++ // Review 5411223284: with no marker the gate opened without asking whether+ // the checkout lock was held (an update before its marker, or after it).+ test('no marker: only the helper `held` keeps the gate shut; any other answer opens it', async () => {+ const { root, home } = fakeHelperCheckout()+ const states: HeldState[] = []+ fs.writeFileSync(path.join(home, 'helper-verdict'), 'held')+ const hasLiveMarker = gate(root, home, undefined, { onHeld: s => states.push(s) })++ assert.equal(await hasLiveMarker(), true, 'no marker, checkout lock held: parked')+ assert.deepEqual(helperCalls(home), [`--marker-op reclaim --install-root ${root}`])+ assert.deepEqual([states[0]?.verdict, states[0]?.ownerPid, states[0]?.blocking], ['held', null, true])+ assert.equal(fs.existsSync(markerPath(home)), false, 'Desktop creates nothing')++ requestHoldRecheck()+ fs.writeFileSync(path.join(home, 'helper-verdict'), 'absent')+ assert.equal(await hasLiveMarker(), false, 'the lock was let go: the gate opens')++ for (const answer of ['garbage', 'busy']) {+ fs.writeFileSync(path.join(home, 'helper-verdict'), answer)+ assert.equal(await gate(root, home)(), false, `a helper that cannot answer (${answer}) never blocks a markerless boot`)+ }+ })})test("a pool/profile hold reaches the screen when the primary shows none; the primary's own clear never drops it (R8 M6)", () => {diff --git a/apps/desktop/electron/update-marker-gate.ts b/apps/desktop/electron/update-marker-gate.tsindex 3a97a86619c..96fdf15ffa1 100644--- a/apps/desktop/electron/update-marker-gate.ts+++ b/apps/desktop/electron/update-marker-gate.ts@@ -10,6 +10,9 @@** - `held` / `busy` / `live <pid>` => an update still owns the checkout: keep waiting;* - `reclaimed` / `absent` => nothing runs: proceed;+ * - no marker at all => the helper is asked too (it checks the checkout lock+ * under the same rule); only its `held` keeps the gate closed, any other+ * answer proceeds as before;* - `unsupported` (older checkout, no helper) => proceed without deleting* (dead = not running, as before minus the deletion) — unless this process* already saw the same body block: then the script is only missing or@@ -93,6 +96,13 @@ export interface LiveMarkerProbeOptions {const STILL_RUNNING = new Set(['held', 'busy', 'live', 'error'])+/**+ * The hold id of "no marker, but the helper says the checkout lock is held"+ * (an update that holds the lock before publishing, or after retiring, its+ * marker). There is no body to scope it to, so one id stands for that state.+ */+const ABSENT_HOLD_ID = markerHoldId(Buffer.from('\0no update marker\0'))+// First sighting of each held body, process-wide: a later gate wait (a pool// backend, a reconnect) reports the same "since".const firstHeldAt = new Map<string, number>()@@ -251,7 +261,8 @@ async function refreshVerdict(holdId: string,reclaim: () => Promise<MarkerHelperVerdict>,now: () => number,- log: ((line: string) => void) | undefined+ log: ((line: string) => void) | undefined,+ subject = 'dead update marker'): Promise<AskedEntry> {const generation = recheckGenerationlet verdict = await reclaim()@@ -264,7 +275,7 @@ async function refreshVerdict(if (!previous || STILL_RUNNING.has(previous.verdict.kind) !== STILL_RUNNING.has(verdict.kind)) {log?.(- `[updates] dead update marker: script helper says ${verdict.kind}${'pid' in verdict ? ` ${verdict.pid}` : ''}`+ `[updates] ${subject}: script helper says ${verdict.kind}${'pid' in verdict ? ` ${verdict.pid}` : ''}`)}@@ -358,11 +369,13 @@ export function liveMarkerProbe({return true}- if (inspection.state !== 'dead' || !reclaim) {+ const absent = inspection.state === 'absent'++ if ((inspection.state !== 'dead' && !absent) || !reclaim) {return false}- const holdId = markerHoldId(inspection.raw, statMarkerFile(hermesHome))+ const holdId = absent ? ABSENT_HOLD_ID : markerHoldId(inspection.raw, statMarkerFile(hermesHome))if (unanswerableHolds.has(holdId)) {return false@@ -372,19 +385,22 @@ export function liveMarkerProbe({let entry = previous!if (verdictDue(previous, now, reprobeMs)) {- entry = await refreshVerdict(previous, holdId, reclaim, now, log)+ entry = await refreshVerdict(previous, holdId, reclaim, now, log, absent ? 'no update marker' : undefined)asked.set(holdId, entry)}const { verdict } = entry- if (!STILL_RUNNING.has(verdict.kind) || helperUnanswerable(entry, holdId, log)) {+ // No marker: only the helper's positive `held` (a process holds the+ // checkout lock) closes the gate; a helper that cannot answer keeps the+ // old "no marker, nothing runs" so a broken script never blocks boot.+ if (!STILL_RUNNING.has(verdict.kind) || (absent && verdict.kind !== 'held') || helperUnanswerable(entry, holdId, log)) {return false}const state: HeldState = {verdict: verdict.kind as HeldState['verdict'],- ownerPid: inspection.marker?.pid ?? null,+ ownerPid: absent ? null : (inspection.marker?.pid ?? null),livePid: 'pid' in verdict ? verdict.pid : null,holdId,since: heldSince(holdId, now()),@@ -401,7 +417,7 @@ export function liveMarkerProbe({}onHeld?.(state)- onLiveMarker?.({ startedAt: inspection.marker?.startedAt ?? null, runId: inspection.marker?.run ?? null })+ onLiveMarker?.(absent ? { startedAt: null, runId: null } : { startedAt: inspection.marker?.startedAt ?? null, runId: inspection.marker?.run ?? null })return true}diff --git a/scripts/desktop-update/marker-claim.ps1 b/scripts/desktop-update/marker-claim.ps1index 352a5a9ed47..e25f9a99330 100644--- a/scripts/desktop-update/marker-claim.ps1+++ b/scripts/desktop-update/marker-claim.ps1@@ -288,7 +288,12 @@ function Invoke-MarkerOp([string]$Op, [int]$Desktop, [string]$Run) {try {$ctx = New-MarkerContext$read = Read-MarkerLocked $ctx- if ($read.State -eq 'absent') { return 'absent' }+ if ($read.State -eq 'absent') {+ # No marker is not proof nothing runs: an update can hold the checkout+ # lock before it publishes, or after it retires, its marker (R6).+ if ($Op -eq 'reclaim' -and (Test-CheckoutLockHeld)) { return 'held' }+ return 'absent'+ }if ($read.State -eq 'busy') { return 'busy' }$info = $read.Info$j = $read.Judgementdiff --git a/scripts/desktop-update/marker.sh b/scripts/desktop-update/marker.shindex 3c1ba2856e4..10cc9f02b4f 100644--- a/scripts/desktop-update/marker.sh+++ b/scripts/desktop-update/marker.sh@@ -542,7 +542,12 @@ marker_remove() { # 0 iff the marker is gone afterwards (rm -f exits 0 when it c}marker_op_reclaim_locked() {- marker_read || { echo absent; return 0; }+ # No marker is not proof nothing runs: an update can hold the checkout lock+ # before it publishes, or after it retires, its marker (R6, same rule).+ if ! marker_read; then+ if checkout_lock_held; then echo held; else echo absent; fi+ return 0+ fiif [ -z "$SEEN" ] && marker_young_empty; then echo busy; return 0; fimarker_judge "$SEEN"case "$J_VERDICT" in@@ -571,7 +576,7 @@ marker_op_withdraw_locked() {}marker_op() { # reclaim | withdraw -> one verdict line on stdout (same words as marker.ps1):- # reclaim absent | live <pid> | busy | held (dead, but the checkout lock is held) | reclaimed+ # reclaim absent | live <pid> | busy | held (dead or no marker, but the checkout lock is held) | reclaimed# withdraw absent | taken <pid> (a live adopter carries the run) | withdrawn (this Desktop's# own bridge, removed) | foreign (anything else, kept -- a dead adopter included)local rcdiff --git a/tests/scripts/desktop_update/test_desktop_update_posix_handoff_protocol.py b/tests/scripts/desktop_update/test_desktop_update_posix_handoff_protocol.pyindex c69d9cbc667..616d940a0fc 100644--- a/tests/scripts/desktop_update/test_desktop_update_posix_handoff_protocol.py+++ b/tests/scripts/desktop_update/test_desktop_update_posix_handoff_protocol.py@@ -322,6 +322,20 @@ def test_marker_outlives_a_survivor_that_still_holds_the_checkout_lock(tmp_path)assert not marker.exists()+def test_reclaim_without_a_marker_reports_held_while_the_checkout_lock_is_held(tmp_path):+ """Review 5411223284: `absent` was answered before the checkout lock was looked at, so a+ Desktop gate opened while an update that had not yet published (or had already retired)+ its marker still held the checkout."""+ home, install = _install(tmp_path, legacy=True)+ lock = install / ".hermes-update.lock"+ lock.touch()+ with open(lock, "rb") as held:+ fcntl.flock(held.fileno(), fcntl.LOCK_EX)+ assert _helper(tmp_path, home, install, "reclaim") == "held"+ assert not (home / ".hermes-update-in-progress").exists()+ assert _helper(tmp_path, home, install, "reclaim") == "absent"++def test_release_waits_for_the_survivor_then_removes_the_marker(tmp_path):home, install = _install(tmp_path, legacy=True)completion = tmp_path / "release-completion"diff --git a/tests/scripts/desktop_update/test_desktop_update_windows_marker_ops.py b/tests/scripts/desktop_update/test_desktop_update_windows_marker_ops.pyindex 32fa4b74a9b..df4fdd33478 100644--- a/tests/scripts/desktop_update/test_desktop_update_windows_marker_ops.py+++ b/tests/scripts/desktop_update/test_desktop_update_windows_marker_ops.py@@ -203,6 +203,27 @@ def test_marker_op_reclaim_reports_held_while_a_survivor_holds_the_checkout_lockassert not (tmp_path / MARKER).exists()[email protected]('windows')+def test_marker_op_reclaim_without_a_marker_reports_held_while_the_checkout_lock_is_held(tmp_path: Path) -> None:+ """Review 5411223284: `absent` was answered before the checkout lock was looked at, so a+ Desktop gate opened while an update with no marker (yet, or any more) held the checkout."""+ install = tmp_path / 'hermes-agent'+ install.mkdir()+ release = tmp_path / 'release-holder'+ holder = subprocess.Popen([sys.executable, '-c', _CHECKOUT_HOLDER, str(install / '.hermes-update.lock'), str(release)])+ try:+ deadline = time.monotonic() + 30+ while not Path(str(release) + '.ready').exists():+ assert time.monotonic() < deadline and holder.poll() is None+ time.sleep(0.05)+ assert _op(tmp_path, '-MarkerOp', 'reclaim')[:2] == (0, 'held\n')+ assert not (tmp_path / MARKER).exists()+ finally:+ release.touch()+ holder.wait(timeout=30)+ assert _op(tmp_path, '-MarkerOp', 'reclaim')[:2] == (0, 'absent\n')++@pytest.mark.platforms('windows')@pytest.mark.parametrize('lease', [1, 16])def test_marker_op_reclaim_reports_held_while_a_leased_child_outlives_its_owner(tmp_path: Path, lease: int) -> None: