The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop-update): the update window names the stage it is in, on Windows too
Tekniumc9b55ea26d23
diff --git a/hermes_cli/main_desktop.py b/hermes_cli/main_desktop.pyindex 537a84f0057..d3ffc065f8e 100644--- a/hermes_cli/main_desktop.py+++ b/hermes_cli/main_desktop.py@@ -1465,6 +1465,9 @@ def build_prepared_desktop(desktop_dir: Path, *, source_mode: bool, npm: str, entry:run_in_custody(desktop_dir.parents[1], build_cmd, f"Building desktop {build_label}", cwd=desktop_dir, env=build_env)if staging_dir is not None:+ from hermes_cli.update_stage import publish_stage++ publish_stage("Packaging the desktop app")run_in_custody(desktop_dir.parents[1], [npm, "run", "builder", "--", "--dir", "--publish", "never",f"-c.directories.output={staging_dir}"], "Packaging the desktop app",cwd=desktop_dir, env=build_env)diff --git a/hermes_cli/update_receipt.py b/hermes_cli/update_receipt.pyindex 97748b90366..c80a374f54d 100644--- a/hermes_cli/update_receipt.py+++ b/hermes_cli/update_receipt.py@@ -501,11 +501,26 @@ def record_skip(name: str, reason: str) -> None:_record("skip", f"update skip {name}", name, reason)+# The stage a pipeline mark hands over to, as the Desktop hand-off window names it. Without these+# the window read "Updating code and dependencies" for a whole 20-60 min run (#139952, #135363).+_NEXT_STAGE_LABEL = {+ "snapshot": "Downloading updates",+ "apply": "Updating dependencies",+ "deps": "Building the apps",+ "build": "Restarting Hermes services",+}++def record_stage(name: str, outcome: str, **facts: str) -> None:"""Mark the END of a pipeline stage (``success``/``failed``/``skipped``) with a timestamp."""_record("stage", f"update stage {name}", name, outcome, **facts)# Each stage boundary refreshes the durable running record (a kill names its last stage).persist_running_receipt()+ # A failed backup does not stop the update; any other failed stage ends it.+ if name in _NEXT_STAGE_LABEL and (outcome != "failed" or name == "snapshot"):+ from hermes_cli.update_stage import publish_stage++ publish_stage(_NEXT_STAGE_LABEL[name])def record_fact(key: str, value: Any) -> None:diff --git a/scripts/desktop-update/windows.ps1 b/scripts/desktop-update/windows.ps1index 48b11d656af..ef4febcdaa3 100644--- a/scripts/desktop-update/windows.ps1+++ b/scripts/desktop-update/windows.ps1@@ -216,6 +216,13 @@ $script:UiState = [hashtable]::Synchronized(@{acknowledged_receipt = $null})$script:UiServer = $null # @{ Listener; Runspace; PowerShell; Port; BrowserProc; Profile }+# `hermes update` publishes its own stages (hermes_cli/update_stage.py: downloading, dependencies,+# each app build, packaging) into this file, as it does under posix.sh. The step loop relays them+# to the window, which otherwise read "Updating code and dependencies" for a whole 20-60 minute+# run (#139952, #135363), and to the hand-off log, whose timestamps then name the slow stage.+$script:ChildStageFile = Join-Path ([IO.Path]::GetTempPath()) ("hermes-update-status.{0}" -f $PID)+$env:HERMES_UPDATE_STATUS_FILE = $script:ChildStageFile+$script:ChildStageSeen = $nullfunction Get-UiHtmlPath {# Lives next to this script in the checkout. Missing file = fall back to@@ -995,7 +1002,23 @@ function Step-PipeDrain($Reader, [ref]$Task, $Buffer, $Sink, [ref]$Moved) {return $false}+function Sync-ChildStage {+ # Best-effort: an unreadable or half-replaced file leaves the current stage on screen.+ try {+ $stream = [IO.File]::Open($script:ChildStageFile, 'Open', 'Read', 'ReadWrite, Delete')+ try { $text = (New-Object IO.StreamReader($stream)).ReadToEnd() } finally { $stream.Dispose() }+ $message = [string](ConvertFrom-Json $text).message+ } catch { return }+ if (-not $message -or $message -ceq $script:ChildStageSeen) { return }+ $script:ChildStageSeen = $message+ Write-HandoffLog ("stage: {0}" -f $message)+ Publish-UiProgress $message+}+function Invoke-HermesStep([string]$Exe, [string[]]$HermesArgs, [string]$Tag) {+ # A stage left by the previous step must not replace the one the orchestrator just published.+ Remove-Item -LiteralPath $script:ChildStageFile -Force -ErrorAction SilentlyContinue+ $script:ChildStageSeen = $null# The window does not stream child output, so no line-pump: both pipes# drain asynchronously (no deadlock however chatty the child) while a small# DoEvents loop keeps the marquee animating through long silent@@ -1075,6 +1098,7 @@ function Invoke-HermesStep([string]$Exe, [string[]]$HermesArgs, [string]$Tag) {$progressLogStamp = Get-StepProgressLogStamp$jobActivity = [HermesUpdateJob]::Activity($job)$stalled = $false+ $nextStageCheck = Get-Datewhile ($true) {$moved = $false$outDone = Step-PipeDrain $stdoutReader ([ref]$outTask) $outBuffer $outSink ([ref]$moved)@@ -1156,6 +1180,10 @@ function Invoke-HermesStep([string]$Exe, [string[]]$HermesArgs, [string]$Tag) {}if ($script:Ui) { [System.Windows.Forms.Application]::DoEvents() }Update-MarkerHeartbeat+ if ((Get-Date) -ge $nextStageCheck) {+ Sync-ChildStage+ $nextStageCheck = (Get-Date).AddSeconds(1)+ }}# Bounded overload deliberately: the argument-less overload also waits on# redirected streams, which is the very wait we just bounded. HasExited isdiff --git a/tests/hermes_cli/test_update_stage_relay.py b/tests/hermes_cli/test_update_stage_relay.pynew file mode 100644index 00000000000..7b04a57e88a--- /dev/null+++ b/tests/hermes_cli/test_update_stage_relay.py@@ -0,0 +1,21 @@+"""Each update pipeline stage mark names the next stage to a watching Desktop hand-off window."""+from __future__ import annotations++import json+++def test_stage_marks_publish_the_next_stage_to_the_handoff_window(tmp_path, monkeypatch):+ from hermes_cli import update_receipt++ status = tmp_path / "hermes-update-status.1"+ monkeypatch.setenv("HERMES_UPDATE_STATUS_FILE", str(status))++ def shown() -> str:+ return json.loads(status.read_text(encoding="utf-8"))["message"] if status.exists() else ""++ update_receipt.record_stage("snapshot", "failed") # a failed backup does not stop the update+ assert shown() == "Downloading updates"+ update_receipt.record_stage("apply", "success")+ assert shown() == "Updating dependencies"+ update_receipt.record_stage("deps", "failed") # the update ends here: nothing new to announce+ assert shown() == "Updating dependencies"diff --git a/tests/scripts/desktop_update/test_desktop_update_windows_child_stage.py b/tests/scripts/desktop_update/test_desktop_update_windows_child_stage.pynew file mode 100644index 00000000000..ba34b0764e1--- /dev/null+++ b/tests/scripts/desktop_update/test_desktop_update_windows_child_stage.py@@ -0,0 +1,70 @@+"""The Windows hand-off relays the stages `hermes update` publishes, instead of one static line.++The real ``windows.ps1`` runs a fixture ``hermes`` whose update publishes a stage through the real+``hermes_cli.update_stage.publish_stage`` and then waits to be released. On main the hand-off never+told the child where to publish, so the window (and the hand-off log) read "Updating code and+dependencies" for the whole 20-60 minute run (#139952, #135363).+"""+from __future__ import annotations++import os+from pathlib import Path+import subprocess+import time++import pytest++from tests.installation_launcher_fixture import publish_fixture_launcher+from tests.scripts.desktop_update.windows_handoff_support import _log++ROOT = Path(__file__).resolve().parent.parent.parent.parent+SCRIPT = ROOT / "scripts/desktop-update/windows.ps1"+STAGE_CLI = """+import os, sys, time+from pathlib import Path+def main():+ if '--version' in sys.argv:+ print('Install directory: ' + str(Path(__file__).resolve().parents[1])); return 0+ if '--help' in sys.argv:+ print('--keep-stash'); return 0+ if sys.argv[1:2] == ['update']:+ sys.path.insert(0, os.environ['HANDOFF_REPO'])+ from hermes_cli.update_stage import publish_stage+ publish_stage('Packaging the desktop app')+ hold = Path(os.environ['HANDOFF_HOLD'])+ deadline = time.monotonic() + 60+ while not hold.exists() and time.monotonic() < deadline:+ time.sleep(0.05)+ return 0+if __name__ == '__main__':+ sys.exit(main())+"""++[email protected]("windows")+def test_handoff_shows_the_stage_the_update_publishes(tmp_path: Path) -> None:+ install = tmp_path / "checkout"+ publish_fixture_launcher(install, STAGE_CLI)+ home = tmp_path / "home"+ home.mkdir()+ hold = tmp_path / "release-update"+ script = subprocess.Popen(+ ["powershell", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", str(SCRIPT),+ "-InstallRoot", str(install), "-NoUi"],+ cwd=tmp_path, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,+ env={**os.environ, "HERMES_HOME": str(home), "HERMES_RUNTIME_DIR": str(tmp_path / "empty-store"),+ "HANDOFF_HOLD": str(hold), "HANDOFF_REPO": str(ROOT)},+ )+ try:+ deadline = time.monotonic() + 90+ while "stage: Packaging the desktop app" not in _log(home):+ assert time.monotonic() < deadline and script.poll() is None, (+ "the hand-off never relayed the update's own stage:\n" + _log(home)[-3000:])+ time.sleep(0.2)+ finally:+ hold.write_text("", encoding="utf-8")+ try:+ script.wait(timeout=120)+ except subprocess.TimeoutExpired:+ subprocess.run(["taskkill", "/T", "/F", "/PID", str(script.pid)], capture_output=True, check=False)+ script.wait(timeout=30)