The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(update): the Windows hand-off removes its result tmp when publishing fails
Teknium6b97fee9c2d5
diff --git a/scripts/desktop-update/windows.ps1 b/scripts/desktop-update/windows.ps1index 35599783428..74a9f219bc4 100644--- a/scripts/desktop-update/windows.ps1+++ b/scripts/desktop-update/windows.ps1@@ -678,6 +678,8 @@ function Write-Result([bool]$Ok, [int]$Code, [string]$Message, [bool]$ManualActi# Atomic (tmp + rename over): a reader never sees a torn file, and the# previous result survives until this one is complete. run_id matches the# marker across heartbeat rewrites; started_at stays for older consumers.+ # A failed replace leaves no "<result>.<pid>.tmp" behind (finally).+ $tmp = "$ResultPath.$PID.tmp"try {$obj = @{ok = $Ok@@ -691,7 +693,6 @@ function Write-Result([bool]$Ok, [int]$Code, [string]$Message, [bool]$ManualActiwarnings = @($script:Warnings)finished_at = [DateTimeOffset]::UtcNow.ToUnixTimeSeconds()} | ConvertTo-Json -Compress- $tmp = "$ResultPath.$PID.tmp"[System.IO.File]::WriteAllText($tmp, $obj, (New-Object System.Text.UTF8Encoding $false))if ([System.IO.File]::Exists($ResultPath)) {[System.IO.File]::Replace($tmp, $ResultPath, [NullString]::Value)@@ -700,6 +701,8 @@ function Write-Result([bool]$Ok, [int]$Code, [string]$Message, [bool]$ManualActi}} catch {Write-HandoffLog "WARNING: could not write the update result: $($_.Exception.Message)"+ } finally {+ if ([System.IO.File]::Exists($tmp)) { Remove-Item -LiteralPath $tmp -Force -ErrorAction SilentlyContinue }}}diff --git a/tests/scripts/desktop_update/test_desktop_update_windows_commit_outcome.py b/tests/scripts/desktop_update/test_desktop_update_windows_commit_outcome.pyindex 43720df5047..ac6d31160de 100644--- a/tests/scripts/desktop_update/test_desktop_update_windows_commit_outcome.py+++ b/tests/scripts/desktop_update/test_desktop_update_windows_commit_outcome.py@@ -64,11 +64,13 @@ if __name__ == '__main__':"""-def _handoff(tmp_path: Path, *args: str, verify: str = 'pass\n', timeout: int = 150, **env: str):+def _handoff(tmp_path: Path, *args: str, verify: str = 'pass\n', timeout: int = 150, prepare=None, **env: str):install = tmp_path / 'checkout'publish_fixture_launcher(install, CLI)(install / 'hermes_cli/desktop_update_verify.py').write_text(verify, encoding='utf-8')home = tmp_path / 'home'; home.mkdir()+ if prepare is not None:+ prepare(home, install)calls = tmp_path / 'calls.jsonl'proc = subprocess.Popen(['powershell', '-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', str(SCRIPT),@@ -84,7 +86,8 @@ def _handoff(tmp_path: Path, *args: str, verify: str = 'pass\n', timeout: int =out, _ = proc.communicate()pytest.fail(f'hand-off did not finish within {timeout}s: {out}')argv = [json.loads(line) for line in calls.read_text(encoding='utf-8-sig').splitlines()] if calls.exists() else []- result = json.loads((home / '.hermes-update-result.json').read_text(encoding='utf-8-sig'))+ result_path = home / '.hermes-update-result.json'+ result = json.loads(result_path.read_text(encoding='utf-8-sig')) if result_path.is_file() else Nonereturn proc.returncode, out, argv, result, home@@ -109,6 +112,17 @@ def test_result_is_atomic_json_carrying_started_at_and_warnings(tmp_path: Path)assert not list(home.glob('.hermes-update-result.json.*.tmp'))[email protected]('windows')+def test_a_result_that_cannot_be_published_leaves_no_tmp_file(tmp_path: Path) -> None:+ # Write-Result's Move/Replace fail (the result path is a directory): its <result>.<pid>.tmp+ # must not be left beside it, one per hand-off, forever.+ code, out, _, result, home = _handoff(+ tmp_path, '-NoGateway', prepare=lambda home, _install: (home / '.hermes-update-result.json').mkdir())+ assert code == 0, out+ assert result is None+ assert not list(home.glob('.hermes-update-result.json.*.tmp')), list(home.iterdir())++@pytest.mark.platforms('windows')def test_marker_with_a_live_delegate_is_handed_to_it_at_finish(tmp_path: Path) -> None:# A7 release rule: the owner deletes its claim unless a delegate still runs; then that