The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(update): hand-off results carry the real finish time after the R6 release wait
Teknium98d6720885a4
diff --git a/scripts/desktop-update/marker-claim.ps1 b/scripts/desktop-update/marker-claim.ps1index 181208456d9..352a5a9ed47 100644--- a/scripts/desktop-update/marker-claim.ps1+++ b/scripts/desktop-update/marker-claim.ps1@@ -225,6 +225,7 @@ function Invoke-MarkerRelease {$waited = 0while (Test-CheckoutLockHeld) {if ($waited -eq 0) { Write-HandoffLog "a process still holds the checkout update lock; keeping the update marker until it exits" }+ $script:MarkerReleaseWaited = $trueif ($waited -ge $script:MarkerReleaseWaitSeconds) {Write-HandoffLog "checkout update lock still held after $($waited)s; leaving the update marker"returndiff --git a/scripts/desktop-update/marker.ps1 b/scripts/desktop-update/marker.ps1index a6f4f1c4109..f7bdd86924c 100644--- a/scripts/desktop-update/marker.ps1+++ b/scripts/desktop-update/marker.ps1@@ -35,6 +35,7 @@ $script:MarkerClaim = "none" # claimed | adopted | refused$script:MarkerBlocker = 0$script:MarkerOwnCtText = $null$script:MarkerLastHeartbeat = $null+$script:MarkerReleaseWaited = $false # the R6 wait ran (windows.ps1 re-stamps the result after it)$script:StartedAt = $null$script:MarkerRunPattern = '\A[A-Za-z0-9._-]{1,128}\z'diff --git a/scripts/desktop-update/posix.sh b/scripts/desktop-update/posix.shindex d6bda569a91..caf60052a0e 100755--- a/scripts/desktop-update/posix.sh+++ b/scripts/desktop-update/posix.sh@@ -138,6 +138,7 @@ marker_release() { # A7 rule 5, under the lock. Never while a survivor of the[ "$MARKER_CLAIMED" -eq 1 ] && [ "$NO_MARKER_CLEANUP" -eq 0 ] || { marker_refresher_stop; return 0; }while checkout_lock_held; do[ "$waited" -gt 0 ] || log "a process still holds the checkout update lock; keeping the update marker until it exits"+ RELEASE_WAITED=1if [ "$waited" -ge "$RELEASE_WAIT_S" ]; thenlog "WARNING: checkout update lock still held after ${waited}s; leaving the update marker"marker_refresher_stop@@ -150,6 +151,7 @@ marker_release() { # A7 rule 5, under the lock. Never while a survivor of theMARKER_CLAIMED=0}RELEASE_WAIT_S=7200+RELEASE_WAITED=0 # the R6 wait ran: the result written before it carries a stale finished_at# An older packaged Desktop judges a marker by line 2 alone and deletes it 20# minutes in, live owner or not. From the claim until the release is decided@@ -664,6 +666,10 @@ finish() {write_resultmarker_release+ # The R6 wait can last hours, and the Desktop drops a non-manual result whose+ # finished_at is 30 minutes old: publish it again with the real finish time+ # (unless something already consumed it).+ if [ "$RELEASE_WAITED" -eq 1 ] && [ -f "$RESULT" ]; then write_result; fiif [ "$FINAL_CODE" -ne 0 ]; thenpublish "error" "$FINAL_MSG"; stop_ui leave-windowdiff --git a/scripts/desktop-update/windows.ps1 b/scripts/desktop-update/windows.ps1index 74a9f219bc4..288f995c26c 100644--- a/scripts/desktop-update/windows.ps1+++ b/scripts/desktop-update/windows.ps1@@ -1704,6 +1704,12 @@ try {$manualAction = $finalCode -eq 0 -and $script:ManualFollowupWrite-Result ($finalCode -eq 0) $finalCode $finalMsg $manualActionInvoke-MarkerRelease+ # The R6 wait can last hours, and the Desktop drops a non-manual result+ # whose finished_at is 30 minutes old: publish it again with the real+ # finish time (unless something already consumed it).+ if ($script:MarkerReleaseWaited -and [System.IO.File]::Exists($ResultPath)) {+ Write-Result ($finalCode -eq 0) $finalCode $finalMsg $manualAction+ }if ($finalCode -ne 0) {Show-ErrorFinale $finalMsgClose-ProgressWindowdiff --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 16405320fd9..8a73206eeec 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@@ -340,6 +340,31 @@ def test_release_waits_for_the_survivor_then_removes_the_marker(tmp_path):assert not (home / ".hermes-update-in-progress").exists()+def test_result_finished_at_is_stamped_after_the_r6_release_wait(tmp_path):+ """The relaunched Desktop has no expected run id and drops a non-manual result whose+ finished_at is 30 minutes old. The R6 wait lasts up to 2 h, so a result stamped before it+ went stale unread: finished_at must be the time the hand-off actually finished."""+ home, install = _install(tmp_path, legacy=True)+ completion = tmp_path / "release-completion"+ env = _env(tmp_path, home, HANDOFF_COMPLETION=str(completion), HANDOFF_CHECKOUT_LOCK=str(install / ".hermes-update.lock"))+ script = subprocess.Popen(["bash", str(POSIX), "--daemonized", "--no-ui", "--install-root", str(install)], env=env, cwd=tmp_path,+ stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)+ log = home / "logs" / "desktop-update-handoff.log"+ try:+ deadline = time.monotonic() + 60+ while "keeping the update marker" not in (log.read_text(encoding="utf-8-sig") if log.exists() else ""):+ assert time.monotonic() < deadline and script.poll() is None+ time.sleep(0.05)+ time.sleep(3.0)+ released = int(time.time())+ finally:+ completion.touch()+ assert script.wait(timeout=30) == 0+ result = json.loads((home / ".hermes-update-result.json").read_text(encoding="utf-8-sig"))+ assert result["ok"] is True and result["finished_at"] >= released, (result, released)+ assert not list(home.glob(".hermes-update-result.json.*.tmp"))++def test_line_two_stays_young_through_the_r6_release_wait(tmp_path):"""An old packaged Desktop deletes a marker whose line 2 is 20 minutes old, live owner ornot. The release wait can last hours, so the refresher must outlive `hermes update`."""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 ac6d31160de..d8fed633549 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@@ -12,6 +12,7 @@ import jsonimport osfrom pathlib import Pathimport subprocess+import sysimport timeimport pytest@@ -123,6 +124,35 @@ def test_a_result_that_cannot_be_published_leaves_no_tmp_file(tmp_path: Path) ->assert not list(home.glob('.hermes-update-result.json.*.tmp')), list(home.iterdir())+_TIMED_CHECKOUT_HOLDER = """+import msvcrt, os, sys, time+fd = os.open(sys.argv[1], os.O_RDWR | os.O_CREAT | os.O_BINARY, 0o644)+os.lseek(fd, 1 << 20, os.SEEK_SET)+msvcrt.locking(fd, msvcrt.LK_NBLCK, 1) # hermes_cli/update_lock.py::_try_lock's byte+time.sleep(float(sys.argv[2]))+"""++[email protected]('windows')+def test_result_finished_at_is_stamped_after_the_r6_release_wait(tmp_path: Path) -> None:+ # The relaunched Desktop drops a non-manual result whose finished_at is 30 minutes old; the+ # R6 wait lasts up to 2 h. The result must carry the time the hand-off actually finished.+ holders = []++ def hold_checkout(_home: Path, install: Path) -> None:+ holders.append((subprocess.Popen([sys.executable, '-c', _TIMED_CHECKOUT_HOLDER,+ str(install / '.hermes-update.lock'), '25']), time.time() + 25))+ try:+ code, out, _, result, home = _handoff(tmp_path, '-NoGateway', prepare=hold_checkout)+ finally:+ for proc, _ in holders:+ proc.kill(); proc.wait()+ assert code == 0, out+ log = (home / 'logs/desktop-update-handoff.log').read_text(encoding='utf-8-sig')+ assert 'keeping the update marker' in log, log+ assert result['ok'] is True and result['finished_at'] >= int(holders[0][1]) - 1, result++@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