The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(update): every owed follow-up reaches the Desktop hand-off result
Teknium260cef995a06
diff --git a/hermes_cli/update_receipt.py b/hermes_cli/update_receipt.pyindex e4b595f8fd7..6f6c10078e0 100644--- a/hermes_cli/update_receipt.py+++ b/hermes_cli/update_receipt.py@@ -353,7 +353,9 @@ def record_followup(step: str, reason: str, *, retry: str = "the next launch orThe code already committed, so the update does not fail; the step's own obligation (thesource tail, the fleet restart, the launch-time bytecode sweep) stays armed and the next- launch or ``hermes update`` retries it. Never raises.+ launch or ``hermes update`` retries it. Never raises. The printed line is a protocol: the+ Desktop hand-offs (scripts/desktop-update/posix.sh, windows.ps1) parse ``Update follow-up+ '<step>' did not finish:`` to report every owed step, so keep it one whole line."""reason = " ".join(str(reason).split())[:500] or "failed"print(f" ⚠ Update follow-up '{step}' did not finish: {reason} ({retry})", flush=True)diff --git a/scripts/desktop-update/posix.sh b/scripts/desktop-update/posix.shindex aad25662d0a..76e7cc8f311 100755--- a/scripts/desktop-update/posix.sh+++ b/scripts/desktop-update/posix.sh@@ -93,6 +93,12 @@ APP_REBUILD_FAILED=0 # 1 = the code committed but the Desktop app build is an olog() { echo "$(date +%Y-%m-%dT%H:%M:%S%z) $1" | tee -a "$LOG" 2>/dev/null; }+owed_followup_steps() { # $OUT -> the distinct owed steps, space-separated, in print order+ # hermes_cli/update_receipt.record_followup prints each as one whole line.+ printf '%s\n' "$OUT" | sed -n "s/^.*Update follow-up '\([A-Za-z0-9_]*\)' did not finish: .*$/\1/p" \+ | awk '!seen[$0]++' | tr '\n' ' ' | sed 's/ *$//'+}+# Keep a durable signal breadcrumb. A detached hand-off used to leave only the# generic FINAL_MSG when it was terminated while the updater child was running,# which erased the one fact needed to diagnose the failure.@@ -899,6 +905,17 @@ if [ "$CODE" -eq 0 ]; then FINAL_CODE=0 FINAL_MSG="Update complete."DONE_NOTE="Hermes was updated, but the Desktop app could not be rebuilt, so it still runs its old build. Run hermes desktop --force-build in a terminal to rebuild it; the update log has the build error."log "desktop app build is an owed follow-up of the committed update"fi+ # Every other owed follow-up (a gateway still on the old code, a Windows+ # resume, a lost completion, channel adoption, maintenance...) prints one+ # whole "Update follow-up '<step>' did not finish:" line. None of them may+ # end as a plain "Update complete." (review regression 1).+ OWED_STEPS="$(owed_followup_steps)"+ if [ -n "$OWED_STEPS" ]; then+ 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 [ -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+ log "owed follow-ups of the committed update: $OWED_STEPS"+ fielseFINAL_CODE="$CODE" FINAL_MSG="Update failed (exit $CODE). Run hermes debug share in a terminal to send a report."# The bricked-venv class is fixable and must not read as a generic exit 1:diff --git a/scripts/desktop-update/windows.ps1 b/scripts/desktop-update/windows.ps1index 6b97693f5d5..e50f058f1d0 100644--- a/scripts/desktop-update/windows.ps1+++ b/scripts/desktop-update/windows.ps1@@ -1740,6 +1740,18 @@ try {Write-HandoffLog $manualMsg}+ # Every other owed follow-up of the committed update (a gateway still on the old code, a+ # Windows resume, a lost completion...) prints one whole "Update follow-up '<step>' did not+ # finish:" line (hermes_cli/update_receipt.record_followup): never a plain success either.+ $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 ($res.Code -eq 0 -and -not $desktopBuildFailed -and $owedSteps.Count -gt 0) {+ $manualAction = $true+ $owedHint = if ($owedSteps -contains 'gateway_restart') { ' Run `hermes gateway restart` to move the messaging gateway onto the new code now.' } else { '' }+ $manualMsg = ($manualMsg + " Hermes was updated, but some follow-up steps did not finish (" + ($owedSteps -join ', ') + "). The next launch or ``hermes update`` retries them; the update log has the details." + $owedHint).Trim()+ Write-HandoffLog $manualMsg+ }+if ($res.Code -eq 0 -and -not $desktopBuildFailed) {$finalCode = 0$finalMsg = "Update complete."diff --git a/tests/hermes_cli/test_update_post_commit_followups.py b/tests/hermes_cli/test_update_post_commit_followups.pyindex f07ed21e03b..daee3ea287f 100644--- a/tests/hermes_cli/test_update_post_commit_followups.py+++ b/tests/hermes_cli/test_update_post_commit_followups.py@@ -197,3 +197,24 @@ def test_owed_restart_rearms_a_settled_obligation_and_a_later_run_keeps_owing_it# A later verify with nothing live to restart still owes the named gateway (and keeps it armed).assert fleet_verify._named_gateways_still_owed()assert fleet._fleet_restart_obligation_armed()+++def test_followup_line_is_the_one_both_desktop_handoffs_parse(tmp_path, monkeypatch, capsys):+ """The hand-offs read owed follow-ups from this printed line (review regression 1): pin the+ producer against the exact parsers in posix.sh (sed) and windows.ps1 (.NET regex)."""+ import re+ from pathlib import Path++ monkeypatch.setenv("HERMES_HOME", str(tmp_path))+ update_receipt.record_followup("gateway_restart", "x" * 900)+ update_receipt.record_followup("windows_resume", "Windows gateway recovery failed: 'quoted' reason")+ out = capsys.readouterr().out+ scripts = Path(__file__).resolve().parents[2] / "scripts/desktop-update"+ posix = (scripts / "posix.sh").read_text(encoding="utf-8")+ function = re.search(r"^owed_followup_steps\(\) \{.*?^\}", posix, re.S | re.M).group(0)+ steps = subprocess.run(["bash", "-c", f"{function}\nowed_followup_steps"], env={**os.environ, "OUT": out},+ capture_output=True, text=True, encoding="utf-8", check=True).stdout.strip()+ assert steps == "gateway_restart windows_resume"+ pattern = re.search(r"\[regex\]::Matches\(\(\$res\.Output -join \"`n\"\), \"([^\"]+)\"\)",+ (scripts / "windows.ps1").read_text(encoding="utf-8")).group(1)+ assert [m.group(1) for m in re.finditer(pattern, out)] == ["gateway_restart", "windows_resume"]diff --git a/tests/scripts/desktop_update/test_desktop_update_gateway_flag.py b/tests/scripts/desktop_update/test_desktop_update_gateway_flag.pyindex 8f3d05b9185..3905d819b6b 100644--- a/tests/scripts/desktop_update/test_desktop_update_gateway_flag.py+++ b/tests/scripts/desktop_update/test_desktop_update_gateway_flag.py@@ -108,3 +108,28 @@ def test_owed_desktop_build_is_a_manual_outcome_even_when_the_followup_is_truncaassert result["exit_code"] == 0assert result["manual"] is Trueassert "could not be rebuilt" in result["message"]+++@requires_posix_handoff[email protected]("step", ["gateway_restart", "windows_resume", "channel_adoption", "completion"])+def test_every_owed_followup_reaches_the_desktop_result(tmp_path, step):+ """Contract C3 (review regression 1): a committed update exits 0, but a follow-up it still owes+ (a gateway proven to run old code, a refused resume, a lost completion) must never end as a+ plain "Update complete." -- the result names the owed step."""+ line = f" ⚠ Update follow-up '{step}' did not finish: old code still serving (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["exit_code"] == 0 and result["ok"] is True+ assert result["manual"] is True+ assert step in result["message"]+ assert ("hermes gateway restart" in result["message"]) is (step == "gateway_restart")+++@requires_posix_handoff+def test_a_clean_update_stays_plain_success(tmp_path):+ _run_handoff(tmp_path, [], "✓ Update complete!")++ result = json.loads((tmp_path / ".hermes-update-result.json").read_text(encoding="utf-8-sig"))+ assert result["exit_code"] == 0 and result["manual"] is False+ assert result["message"] == "Update complete."