The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: a normal boot with no update marker spawns no marker helper
Teknium3d6f53aadc0a
diff --git a/apps/desktop/electron/update-hold-wiring.ts b/apps/desktop/electron/update-hold-wiring.tsindex 0e423655a09..143f0c2479d 100644--- a/apps/desktop/electron/update-hold-wiring.ts+++ b/apps/desktop/electron/update-hold-wiring.ts@@ -21,7 +21,7 @@ import {startAnywayLogLine,UpdateHoldBoard} from './update-marker-gate'-import { runMarkerHelper } from './updater/marker-helper'+import { checkoutLockMayBeHeld, runMarkerHelper } from './updater/marker-helper'export interface MarkerGateCallbacks {onLiveMarker?: (marker: { startedAt: number | null; runId: string | null }) => void@@ -54,6 +54,7 @@ export function markerGateProbe(host: MarkerGateHost, { onLiveMarker, onHeld, ononHeld,onOverride,log: host.log,+ checkoutLockMayBeHeld: () => checkoutLockMayBeHeld(host.updateRoot(), host.isWindows),// A missing or pre-protocol-2 script answers `unsupported`; one that// exists but cannot be read answers `error` (R8 M5).reclaim: () =>diff --git a/apps/desktop/electron/update-marker-gate.test.ts b/apps/desktop/electron/update-marker-gate.test.tsindex 023bc3fe0e0..9af8d793f5b 100644--- a/apps/desktop/electron/update-marker-gate.test.ts+++ b/apps/desktop/electron/update-marker-gate.test.ts@@ -27,7 +27,7 @@ import {UpdateHoldBoard} from './update-marker-gate'import { cleanupMarkerFixtures, deadPid, liveOwner, minutesAgo, tmpHome } from './update-marker.test-helpers'-import { runMarkerHelper } from './updater/marker-helper'+import { checkoutLockMayBeHeld, runMarkerHelper } from './updater/marker-helper'import { cleanupFakeCheckouts, fakeHelperCheckout } from './updater/marker-helper.test-helpers'// The old held ceiling (scripts' RELEASE_WAIT_S); the gate must not honour it.@@ -319,6 +319,26 @@ describe.skipIf(process.platform === 'win32')('gate over a dead marker (R6)', ()assert.deepEqual(helperCalls(home), [])})+ // Review K132354 (helper always spawned): no marker and no checkout lock file+ // is the script's own "not held", so the normal boot spawns nothing.+ test('no marker and no checkout lock file: the helper is never spawned; a lock file asks it', async () => {+ const { root, home } = fakeHelperCheckout()+ fs.writeFileSync(path.join(home, 'helper-verdict'), 'held')++ const probe = () =>+ liveMarkerProbe({+ hermesHome: home,+ reclaim: () => runMarkerHelper('reclaim', { updateRoot: root, hermesHome: home, isWindows: false }),+ checkoutLockMayBeHeld: () => checkoutLockMayBeHeld(root, false)+ })()++ assert.equal(await probe(), false)+ assert.deepEqual(helperCalls(home), [], 'nothing to ask: the boot path spawns no helper')+ fs.writeFileSync(path.join(root, '.hermes-update.lock'), '')+ assert.equal(await probe(), true, 'the lock file exists: only the script can tell whether it is held')+ assert.equal(helperCalls(home).length, 1)+ })+// 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 () => {diff --git a/apps/desktop/electron/update-marker-gate.ts b/apps/desktop/electron/update-marker-gate.tsindex d28a0fae7cf..77661968642 100644--- a/apps/desktop/electron/update-marker-gate.ts+++ b/apps/desktop/electron/update-marker-gate.ts@@ -11,7 +11,8 @@* - `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+ * under the same rule) unless no checkout lock file exists, which is the+ * script's own "not held"; 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@@ -83,6 +84,12 @@ export interface LiveMarkerProbeOptions {hermesHome: string/** The script helper `reclaim`, or null when the checkout's script predates protocol 2. */reclaim: (() => Promise<MarkerHelperVerdict>) | null+ /**+ * False when the script would answer "not held" for a missing checkout+ * lock: with no marker the helper is then not spawned (on Windows a+ * powershell.exe load on every boot's critical path).+ */+ checkoutLockMayBeHeld?: () => booleancreateTime?: CreateTimeProbeonLiveMarker?: (marker: { startedAt: number | null; runId: string | null }) => void/** Every answer that comes from a running helper verdict (boot progress, the blocked screen). */@@ -320,8 +327,17 @@ interface HelperSubject {run: { startedAt: number | null; runId: string | null }}-function helperSubject(inspection: MarkerInspection, hermesHome: string): HelperSubject | null {+function helperSubject(+ inspection: MarkerInspection,+ hermesHome: string,+ checkoutLockMayBeHeld: (() => boolean) | undefined+): HelperSubject | null {if (inspection.state === 'absent') {+ // No lock file is the script's own "not held": nothing to ask.+ if (checkoutLockMayBeHeld?.() === false) {+ return null+ }+return { holdId: ABSENT_HOLD_ID, absent: true, label: 'no update marker', ownerPid: null, run: { startedAt: null, runId: null } }}@@ -376,6 +392,7 @@ async function failedAfterV1Start(hermesHome: string, marker: UpdateMarker | nulexport function liveMarkerProbe({hermesHome,reclaim,+ checkoutLockMayBeHeld,createTime,onLiveMarker,onHeld,@@ -405,7 +422,7 @@ export function liveMarkerProbe({return true}- const subject = reclaim ? helperSubject(inspection, hermesHome) : null+ const subject = reclaim ? helperSubject(inspection, hermesHome, checkoutLockMayBeHeld) : nullif (!subject || !reclaim) {return falsediff --git a/apps/desktop/electron/updater/marker-helper.test.ts b/apps/desktop/electron/updater/marker-helper.test.tsindex 4d2ee652083..10d8478728a 100644--- a/apps/desktop/electron/updater/marker-helper.test.ts+++ b/apps/desktop/electron/updater/marker-helper.test.ts@@ -7,12 +7,15 @@import fs from 'fs'import assert from 'node:assert/strict'+import { execFileSync } from 'node:child_process'import os from 'os'import path from 'path'import { afterEach, describe, test } from 'vitest'import {+ checkoutLockMayBeHeld,+ checkoutLockPath,type HelperSpawn,markerHelperCommand,parseMarkerHelperVerdict,@@ -224,3 +227,62 @@ test('the Windows command line: powershell -File windows.ps1 -MarkerOp ... (hiddroot])})++// Review K132354 (helper always spawned): with no marker the gate skips the+// helper only when the script would answer "not held" for a missing checkout+// lock, so the TS path must be the script's own.+describe.skipIf(process.platform === 'win32')('checkout lock path mirrors marker.sh', () => {+ const markerSh = path.resolve(__dirname, '../../../../scripts/desktop-update/marker.sh')++ const scriptPath = (root: string) =>+ execFileSync('bash', ['-c', 'source "$0"; checkout_lock_path', markerSh], {+ env: { ...process.env, INSTALL_ROOT: root },+ encoding: 'utf8'+ }).trim()++ const layouts: Record<string, (root: string, other: string) => void> = {+ 'no .git (ZIP install)': () => {},+ '.git directory': root => fs.mkdirSync(path.join(root, '.git')),+ 'linked worktree: BOM, CRLF, relative gitdir, relative commondir': root => {+ fs.mkdirSync(path.join(root, 'wt', 'admin'), { recursive: true })+ fs.writeFileSync(path.join(root, '.git'), '\uFEFFgitdir: wt/admin \r\n')+ fs.writeFileSync(path.join(root, 'wt', 'admin', 'commondir'), '../common\n')+ },+ 'absolute gitdir and commondir': (root, other) => {+ fs.writeFileSync(path.join(root, '.git'), `gitdir:${other}\n`)+ fs.writeFileSync(path.join(other, 'commondir'), `\t${path.join(other, 'main')}\n`)+ },+ '.git file that is not a gitdir pointer': root => fs.writeFileSync(path.join(root, '.git'), 'GITDIR: x\n'),+ 'empty .git file': root => fs.writeFileSync(path.join(root, '.git'), ''),+ 'empty commondir': root => {+ fs.mkdirSync(path.join(root, '.git'))+ fs.writeFileSync(path.join(root, '.git', 'commondir'), '\n')+ }+ }++ test.each(Object.keys(layouts))('%s', name => {+ const root = scratchRoot('lock-path')+ const other = scratchRoot('lock-path-other')+ layouts[name](root, other)++ const expected = scriptPath(root)+ assert.equal(path.resolve(checkoutLockPath(root, false)), path.resolve(expected))+ assert.equal(checkoutLockMayBeHeld(root, false), false, 'no lock file: the script answers not held')+ fs.mkdirSync(path.dirname(expected), { recursive: true })+ fs.writeFileSync(expected, '')+ assert.equal(checkoutLockMayBeHeld(root, false), true, 'a lock file: only the script can tell')+ })++ test('an unreadable .git pointer asks the script', () => {+ const root = scratchRoot('lock-path-unreadable')+ fs.mkdirSync(path.join(root, '.git', 'x'), { recursive: true })+ fs.rmSync(path.join(root, '.git'), { recursive: true })+ fs.writeFileSync(path.join(root, '.git'), 'gitdir: elsewhere\n', { mode: 0o000 })++ if (process.getuid?.() === 0) {+ return // root reads it anyway+ }++ assert.equal(checkoutLockMayBeHeld(root, false), true)+ })+})diff --git a/apps/desktop/electron/updater/marker-helper.ts b/apps/desktop/electron/updater/marker-helper.tsindex 19940e8cddf..c0ce06be1c7 100644--- a/apps/desktop/electron/updater/marker-helper.ts+++ b/apps/desktop/electron/updater/marker-helper.ts@@ -18,7 +18,7 @@*/import { type ChildProcess, spawn } from 'node:child_process'-import { existsSync, readFileSync } from 'node:fs'+import { existsSync, readFileSync, statSync } from 'node:fs'import * as path from 'node:path'import { resolveUpdateScriptHandoff } from '../updater-process'@@ -218,6 +218,69 @@ export function markerHelperCommand(}}+/** First line as the scripts clean it: marker.sh `marker_line` (one CR, spaces/tabs); marker.ps1 `.Trim()`. */+function scriptLine(text: string, isWindows: boolean): string {+ const line = text.replace(/^\uFEFF/, '').split('\n')[0]++ return isWindows ? line.trim() : line.replace(/\r$/, '').replace(/^[ \t]+|[ \t]+$/g, '')+}++/**+ * The checkout lock exactly as marker.sh `checkout_lock_path` / marker.ps1+ * `Get-CheckoutLockPath` resolve it (hermes_cli/update_lock.py::checkout_lock_path):+ * `<git common dir>/hermes-update.lock`, else `<root>/.hermes-update.lock`.+ * Throws when `.git` or `commondir` exists but cannot be read.+ */+export function checkoutLockPath(updateRoot: string, isWindows: boolean): string {+ const dot = path.join(updateRoot, '.git')+ const plain = path.join(updateRoot, '.hermes-update.lock')+ const kind = statSync(dot, { throwIfNoEntry: false })+ let gitdir = dot++ if (kind?.isFile()) {+ const line = scriptLine(readFileSync(dot, 'utf8'), isWindows)++ // bash `case gitdir:*` is case-sensitive; PowerShell `-like` is not.+ if (!(isWindows ? /^gitdir:/i : /^gitdir:/).test(line)) {+ return plain+ }++ const named = scriptLine(line.slice(7), isWindows)++ // marker.ps1 treats an empty `gitdir:` as no git dir; bash resolves it to the root.+ if (isWindows && !named) {+ return plain+ }++ gitdir = path.resolve(updateRoot, named)+ } else if (!kind?.isDirectory()) {+ return plain+ }++ const commondir = path.join(gitdir, 'commondir')++ if (statSync(commondir, { throwIfNoEntry: false })?.isFile()) {+ const common = scriptLine(readFileSync(commondir, 'utf8'), isWindows)+ gitdir = common ? path.resolve(gitdir, common) : gitdir+ }++ return path.join(gitdir, 'hermes-update.lock')+}++/**+ * False only when the scripts' `checkout_lock_held` would answer "not held"+ * without trying the lock: no regular file at the checkout lock path+ * (`[ -f ]` / `[IO.File]::Exists`). Anything it cannot settle (an unreadable+ * `.git`, a stat error other than "missing") asks the script.+ */+export function checkoutLockMayBeHeld(updateRoot: string, isWindows: boolean): boolean {+ try {+ return statSync(checkoutLockPath(updateRoot, isWindows), { throwIfNoEntry: false })?.isFile() ?? false+ } catch (error) {+ return (error as NodeJS.ErrnoException)?.code !== 'ENOTDIR'+ }+}+/** Run one marker op through the checkout's script under its sidecar lock. */export async function runMarkerHelper(op: MarkerHelperOp, options: MarkerHelperOptions): Promise<MarkerHelperVerdict> {const scriptPath = handoffScriptPath(options.updateRoot, options.isWindows)