The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: the SSH remote marker judges share the TS judge's constants
Teknium7f37b9979342
diff --git a/apps/desktop/electron/remote-update-marker-programs.test.ts b/apps/desktop/electron/remote-update-marker-programs.test.tsindex 0663fa54b26..cd3d81d45ad 100644--- a/apps/desktop/electron/remote-update-marker-programs.test.ts+++ b/apps/desktop/electron/remote-update-marker-programs.test.ts@@ -7,7 +7,8 @@ import { promisify } from 'node:util'import { test } from 'vitest'-import { REMOTE_MARKER_GATE_PY, REMOTE_MARKER_JUDGE_PY } from './remote-update-marker-programs'+import { REMOTE_MARKER_GATE_PY, REMOTE_MARKER_JUDGE_PY, WINDOWS_MARKER_JUDGE_PS } from './remote-update-marker-programs'+import { parseUpdateMarker } from './update-marker-judge'const execFile = promisify(execFileCallback)const corpusPath = path.resolve(__dirname, '../../../tests/fixtures/update_marker_corpus.json')@@ -39,6 +40,51 @@ test.skipIf(process.platform === 'win32')('the remote marker judge agrees with eassert.deepEqual(JSON.parse(stdout), expected)})+// The same replay through the PowerShell judge Windows remotes run, with each+// case's live table and the corpus clock injected over its fact seams.+const PS_DRIVER = String.raw`+function Get-MarkerProcessFacts([int]$ownerId){if($script:live.ContainsKey([int64]$ownerId)){return @{Alive=$true;Ct=$script:live[[int64]$ownerId]}};return @{Alive=$false}}+function Get-MarkerNow{[int64]$script:corpus.now}+$script:corpus=Get-Content -LiteralPath $args[0] -Raw -Encoding UTF8 | ConvertFrom-Json+foreach($case in $script:corpus.judge){+$script:live=@{};foreach($p in $case.live.PSObject.Properties){$script:live[[int64]$p.Name]=if($null -eq $p.Value){$null}else{[double]$p.Value}}+[Console]::Out.WriteLine($case.name+[char]9+(Get-MarkerVerdict $case.text))+}+`++const powershell = ['pwsh', 'powershell'].find(shell => spawnSync(shell, ['-NoProfile', '-Command', 'exit 0']).status === 0)++test.skipIf(!powershell)('the Windows remote marker judge agrees with every corpus judge case', async () => {+ const corpus = JSON.parse(readFileSync(corpusPath, 'utf8'))+ const dir = mkdtempSync(path.join(os.tmpdir(), 'hermes-remote-ps-judge-'))+ const script = path.join(dir, 'replay.ps1')++ try {+ writeFileSync(script, `${WINDOWS_MARKER_JUDGE_PS}\n${PS_DRIVER}`)+ const { stdout } = await execFile(powershell!, ['-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', script, corpusPath])+ const verdicts = Object.fromEntries(stdout.trim().split(/\r?\n/).map(line => line.split('\t')))++ // Only the host shell is "us" to this judge (never a marker owner), so the+ // corpus cases about the reader's own pid do not apply.+ const cases = corpus.judge.filter((c: any) => {+ const marker = parseUpdateMarker(c.text)++ return ![marker?.pid, marker?.delegate?.pid].includes(c.our_pid ?? corpus.our_pid)+ })++ const verdict = (c: any) =>+ ({ malformed: 'UNCERTAIN', dead: 'CLEAR', live: `LIVE:${c.expect.owner}` })[c.expect.verdict as string]++ assert.ok(cases.length >= 40)+ assert.deepEqual(+ Object.fromEntries(cases.map((c: any) => [c.name, verdicts[c.name]])),+ Object.fromEntries(cases.map((c: any) => [c.name, verdict(c)]))+ )+ } finally {+ rmSync(dir, { recursive: true, force: true })+ }+})+// A dead claim whose checkout lock is still flocked (a killed updater's completion// child) must be kept: the gate answers HELD instead of unlinking it (review G1).const HOLD_PY = String.raw`diff --git a/apps/desktop/electron/remote-update-marker-programs.ts b/apps/desktop/electron/remote-update-marker-programs.tsindex 5883347f97d..fcd2760e5c4 100644--- a/apps/desktop/electron/remote-update-marker-programs.ts+++ b/apps/desktop/electron/remote-update-marker-programs.ts@@ -1,10 +1,11 @@/*** The update-marker judge as programs that run ON an SSH remote.*- * Same contract as `update-marker-judge.ts` (`tests/fixtures/update_marker_corpus.json`):- * an identity (pid, ct) is live when the pid is alive and its creation time is- * within 2 s of the recorded `ct:`; with no recorded/readable ct it is live only- * while `now - started_at <= 1200`. Owner or delegate live => LIVE, both dead =>+ * Same contract as `update-marker-judge.ts` (`tests/fixtures/update_marker_corpus.json`),+ * with its constants interpolated so no copy can drift: an identity (pid, ct)+ * is live when the pid is alive and its creation time is within+ * CREATE_TIME_TOLERANCE_S of the recorded `ct:`; with no recorded/readable ct it+ * is live only while `now - started_at <= V1_MAX_AGE_S`. Owner or delegate live => LIVE, both dead =>* CLEAR, malformed => UNCERTAIN. Only the host's system Python (POSIX) or* PowerShell/.NET (Windows relaunch/spawn) runs these: nothing imports the* checkout an updater may be replacing.@@ -13,6 +14,8 @@* as a PowerShell native argument, and PowerShell 5.1 does not escape them.*/+import { CREATE_TIME_TOLERANCE_S, OWN_CT_EPSILON_S, V1_MAX_AGE_S } from './update-marker-judge'+/** Defines `marker_judge(text, env)` (corpus-shaped, injectable facts) and `marker_verdict(raw_bytes_or_None)`. */export const REMOTE_MARKER_JUDGE_PY = String.raw`import os,re,sys,time@@ -29,11 +32,11 @@ def marker_identity_state(pid,ct,started,env):if pid==0:return 'dead'if pid==env['our_pid']:own=env['our_ct']()- return 'ours' if ct is not None and own is not None and abs(ct-own)<=0.005 else 'dead'+ return 'ours' if ct is not None and own is not None and abs(ct-own)<=${OWN_CT_EPSILON_S} else 'dead'if not env['alive'](pid):return 'dead'actual=None if ct is None else env['ct'](pid)- if ct is None or actual is None:return 'unknown' if env['now']-started<=1200 else 'dead'- return 'match' if abs(ct-actual)<=2.0 else 'dead'+ if ct is None or actual is None:return 'unknown' if env['now']-started<=${V1_MAX_AGE_S} else 'dead'+ return 'match' if abs(ct-actual)<=${CREATE_TIME_TOLERANCE_S} else 'dead'def marker_judge(text,env):if text.startswith('\ufeff'):text=text[1:]@@ -190,16 +193,23 @@ sys.exit(subprocess.run(['sh','-c',payload,'hermes-update-mutex',str(fd)],pass_f* same rule via .NET process facts (Process.StartTime = psutil create_time on* Windows; a process we may not query is alive with no ct). Windows runs this* instead of the venv python so a probe never holds the runtime's python.exe- * open while an updater replaces it. Our own pid is never a remote owner.+ * open while an updater replaces it. The process facts and clock sit in+ * `Get-MarkerProcessFacts` / `Get-MarkerNow` so the corpus replay can inject them.*/export const WINDOWS_MARKER_JUDGE_PS = [+ 'function Get-MarkerProcessFacts([int]$ownerId){',+ // Our own pid is never a remote owner.+ 'if($ownerId -eq $PID){return @{Alive=$false}}',+ 'try{$proc=[Diagnostics.Process]::GetProcessById($ownerId)}catch [ArgumentException]{return @{Alive=$false}}',+ 'try{if($proc.HasExited){return @{Alive=$false}};return @{Alive=$true;Ct=([DateTimeOffset]$proc.StartTime).ToUnixTimeMilliseconds()/1000.0}}catch{return @{Alive=$true}}finally{$proc.Dispose()}',+ '}',+ 'function Get-MarkerNow{[DateTimeOffset]::UtcNow.ToUnixTimeSeconds()}','function Test-MarkerIdentity($ownerId,$ct,$started,$now){',- 'if($ownerId -eq 0 -or $ownerId -eq $PID -or $ownerId -gt [int]::MaxValue){return $false}',- 'try{$proc=[Diagnostics.Process]::GetProcessById([int]$ownerId)}catch [ArgumentException]{return $false}',- '$actual=$null',- 'try{if($proc.HasExited){return $false};if($null -ne $ct){$actual=([DateTimeOffset]$proc.StartTime).ToUnixTimeMilliseconds()/1000.0}}catch{}finally{$proc.Dispose()}',- 'if($null -eq $ct -or $null -eq $actual){return ($now-[double]$started) -le 1200}',- 'return [Math]::Abs($ct-$actual) -le 2.0',+ 'if($ownerId -eq 0 -or $ownerId -gt [int]::MaxValue){return $false}',+ '$facts=Get-MarkerProcessFacts $ownerId',+ 'if(-not $facts.Alive){return $false}',+ `if($null -eq $ct -or $null -eq $facts.Ct){return ($now-[double]$started) -le ${V1_MAX_AGE_S}}`,+ `return [Math]::Abs($ct-$facts.Ct) -le ${CREATE_TIME_TOLERANCE_S}`,'}','function Get-MarkerCt([string]$digits){$value=0.0;if([double]::TryParse($digits,[Globalization.NumberStyles]::AllowDecimalPoint,[Globalization.CultureInfo]::InvariantCulture,[ref]$value)){return $value};return [double]::PositiveInfinity}','function Get-MarkerVerdict([string]$text){',@@ -209,7 +219,7 @@ export const WINDOWS_MARKER_JUDGE_PS = ['$ct=$null;if($lines.Count -gt 2 -and $lines[2] -cmatch "^ct:([0-9]+(\\.[0-9]+)?)$"){$ct=Get-MarkerCt $Matches[1]}','$ids=@(,@($ownerId,$ct))','foreach($line in @($lines | Select-Object -Skip 3)){[uint32]$delegateId=0;if($line -cmatch "^delegate:([0-9]+) ct:([0-9]+(\\.[0-9]+)?)$" -and [uint32]::TryParse($Matches[1],$style,$culture,[ref]$delegateId)){$ids+=,@($delegateId,(Get-MarkerCt $Matches[2]));break}}',- '$now=[DateTimeOffset]::UtcNow.ToUnixTimeSeconds()',+ '$now=Get-MarkerNow','foreach($id in $ids){if(Test-MarkerIdentity $id[0] $id[1] $started $now){return "LIVE:$($id[0])"}}','return "CLEAR"','}'