Skip to content

The agent that grows with you

fix(desktop-update): add the gateway hint only when the follow-up blames gateways

kshitijk4poor3c23e52ae3a2
diff --git a/scripts/desktop-update/posix.sh b/scripts/desktop-update/posix.sh
index 007a3b13a22..5147ff4cf4a 100755
--- a/scripts/desktop-update/posix.sh
+++ b/scripts/desktop-update/posix.sh
@@ -1278,7 +1278,14 @@ if [ "$CODE" -eq 0 ]; then FINAL_CODE=0 FINAL_MSG="Update complete." UPDATE_COMM
# end as a plain "Update complete." (review regression 1).
OWED_STEPS="$(owed_followup_steps)"
if [ -n "$OWED_STEPS" ]; then
+ # A gateway_restart owed only for serve/dashboard units (the reason then starts with
+ # "serve/dashboard") names their own command in the log; every other gateway_restart reason,
+ # including a raw restart-phase error, keeps the gateway hint (#141071).
case " $OWED_STEPS " in *" gateway_restart "*) OWED_HINT=" Run hermes gateway restart to move the messaging gateway onto the new code now." ;; *) OWED_HINT="" ;; esac
+ if printf '%s\n' "$OUT" | grep -Eq "Update follow-up 'gateway_restart' did not finish: serve/dashboard " \
+ && ! printf '%s\n' "$OUT" | grep -Eq "Update follow-up 'gateway_restart' did not finish: .*hermes gateway restart"; then
+ OWED_HINT=""
+ fi
if [ -n "$DONE_NOTE" ]; then DONE_NOTE="$DONE_NOTE Follow-up steps still owed: $OWED_STEPS.$OWED_HINT"
else DONE_NOTE="Hermes was updated, but some follow-up steps did not finish ($OWED_STEPS). The next launch or hermes update retries them; the update log has the details.$OWED_HINT"; fi
add_warning "followup" "owed by the committed update: $OWED_STEPS"
diff --git a/scripts/desktop-update/windows.ps1 b/scripts/desktop-update/windows.ps1
index 16b30249575..131e0df7ad7 100644
--- a/scripts/desktop-update/windows.ps1
+++ b/scripts/desktop-update/windows.ps1
@@ -1685,7 +1685,12 @@ try {
$owedSteps = @([regex]::Matches(($res.Output -join "`n"), "Update follow-up '([A-Za-z0-9_]+)' did not finish: ") |
ForEach-Object { $_.Groups[1].Value } | Select-Object -Unique)
if ($owedSteps.Count -gt 0) {
- $owedHint = if ($owedSteps -contains 'gateway_restart') { " Run 'hermes gateway restart' to move the messaging gateway onto the new code now." } else { '' }
+ # A gateway_restart owed only for serve/dashboard units (the reason then starts with
+ # "serve/dashboard") names their own command in the log; every other gateway_restart reason,
+ # including a raw restart-phase error, keeps the gateway hint (#141071).
+ $owedText = $res.Output -join "`n"
+ $serveOnly = ($owedText -match "Update follow-up 'gateway_restart' did not finish: serve/dashboard ") -and -not ($owedText -match "Update follow-up 'gateway_restart' did not finish: .*hermes gateway restart")
+ $owedHint = if (($owedSteps -contains 'gateway_restart') -and -not $serveOnly) { " Run 'hermes gateway restart' to move the messaging gateway onto the new code now." } else { '' }
Add-Followup ("followup: owed by the committed update: " + ($owedSteps -join ', ')) ("some follow-up steps did not finish (" + ($owedSteps -join ', ') + "). The next launch or 'hermes update' retries them; the update log has the details." + $owedHint) -Manual
}
diff --git a/tests/hermes_cli/test_update_system_dashboard_unit.py b/tests/hermes_cli/test_update_system_dashboard_unit.py
index 8518f6e0ed9..9136a48b4f0 100644
--- a/tests/hermes_cli/test_update_system_dashboard_unit.py
+++ b/tests/hermes_cli/test_update_system_dashboard_unit.py
@@ -13,6 +13,8 @@ the manual command. Three things then went wrong after it:
from __future__ import annotations
+import os
+import subprocess
import sys
from types import SimpleNamespace
from unittest.mock import patch
@@ -303,3 +305,32 @@ def test_next_run_carries_a_unit_row_forward_from_the_previous_receipt(monkeypat
update_receipt.begin_update_receipt()
carried = update_receipt._current.get().data["carried_manual_serves"]
assert [row["pid"] for row in carried] == [DASH_PID]
+
+
[email protected]("reason, hinted", [
+ ("serve/dashboard unit(s) hermes-dashboard were not restarted onto the new code; see the systemctl advice above", False),
+ ("gateways may still run pre-update code or were stopped without a successor; recover with `hermes gateway restart`", True),
+ ("gateways may still run pre-update code or were stopped without a successor; recover with `hermes gateway restart`;"
+ " serve/dashboard unit(s) hermes-dashboard were not restarted onto the new code", True),
+ # update_finish owes gateway_restart with the raw exception when the restart phase itself crashes.
+ ("RuntimeError: systemctl list-units timed out", True),
+])
+def test_desktop_handoffs_add_the_gateway_hint_only_when_gateways_are_blamed(capsys, reason, hinted):
+ """#141071: both Desktop hand-offs keyed the "Run hermes gateway restart" hint on the step id alone.
+ Now only a serve/dashboard-only reason drops it; every other gateway_restart reason keeps it. Pin
+ each script's predicate against the line the producer prints."""
+ import re
+ from pathlib import Path
+
+ update_receipt.record_followup("gateway_restart", reason)
+ out = capsys.readouterr().out
+ scripts = Path(__file__).resolve().parents[2] / "scripts/desktop-update"
+ posix = (scripts / "posix.sh").read_text(encoding="utf-8")
+ serve_re, gw_re = re.findall(r'grep -Eq "(Update follow-up .gateway_restart[^"]+)"', posix)
+ sh = f'printf "%s\\n" "$OUT" | grep -Eq "{serve_re}" && ! printf "%s\\n" "$OUT" | grep -Eq "{gw_re}"'
+ serve_only = subprocess.run(["bash", "-c", sh], env={**os.environ, "OUT": out},
+ capture_output=True, text=True, encoding="utf-8", check=False).returncode == 0
+ assert (not serve_only) is hinted
+ ps = (scripts / "windows.ps1").read_text(encoding="utf-8")
+ ps_serve, ps_gw = re.findall(r'-match "(Update follow-up .gateway_restart[^"]+)"', ps)
+ assert (not (bool(re.search(ps_serve, out)) and not re.search(ps_gw, out))) is hinted
diff --git a/tests/scripts/desktop_update/test_desktop_update_gateway_flag.py b/tests/scripts/desktop_update/test_desktop_update_gateway_flag.py
index 3905d819b6b..2cf984cb0fa 100644
--- a/tests/scripts/desktop_update/test_desktop_update_gateway_flag.py
+++ b/tests/scripts/desktop_update/test_desktop_update_gateway_flag.py
@@ -126,6 +126,19 @@ def test_every_owed_followup_reaches_the_desktop_result(tmp_path, step):
assert ("hermes gateway restart" in result["message"]) is (step == "gateway_restart")
+@requires_posix_handoff
+def test_dashboard_only_gateway_restart_followup_gets_no_gateway_hint(tmp_path):
+ """#141071: the step id stays gateway_restart, but a restart owed only for a serve/dashboard unit
+ must not tell the user to run `hermes gateway restart`, which never touches that unit."""
+ line = (" ⚠ Update follow-up 'gateway_restart' did not finish: serve/dashboard unit(s) hermes-dashboard were not"
+ " restarted onto the new code; see the systemctl advice above (the next launch retries it)")
+ _run_handoff(tmp_path, [], f"{line}\n✓ Update complete!")
+
+ result = json.loads((tmp_path / ".hermes-update-result.json").read_text(encoding="utf-8-sig"))
+ assert result["manual"] is True and "gateway_restart" in result["message"]
+ assert "hermes gateway restart" not in result["message"]
+
+
@requires_posix_handoff
def test_a_clean_update_stays_plain_success(tmp_path):
_run_handoff(tmp_path, [], "✓ Update complete!")