The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(install): name the marker owner as the Desktop hand-off pid
elvindu013e94b38a05
diff --git a/scripts/desktop-update/posix.sh b/scripts/desktop-update/posix.shindex 7a54fe71994..007a3b13a22 100755--- a/scripts/desktop-update/posix.sh+++ b/scripts/desktop-update/posix.sh@@ -1159,7 +1159,14 @@ export PYTHONUNBUFFERED=1# absent and the helper no-ops.export HERMES_UPDATE_STATUS_FILE="$STATUS"# `hermes update` runs under OUR marker claim (contract C1 rule 4/6).-export HERMES_UPDATE_HANDOFF_PID="$$"+# The claim's owner is not this script. marker_refresher_start hands line 1 to a custodian+# subshell that outlives us, so the owner is a *sibling* of this script: never our own pid,+# and never an ancestor of the `hermes update` we spawn. update_lock._is_partner can only+# match it through this variable, so exporting `$$` left the custodian unrecognisable and+# every desktop-initiated update refused its own claim with exit code 2+# ("Another Hermes update is already running (started Ns ago, process <custodian>)").+# $MY_PID is the custodian once the handover succeeded, and our own pid when it did not.+export HERMES_UPDATE_HANDOFF_PID="$MY_PID"# The update's receipt carries this id (update_receipt._launcher_correlation_id),# which is how update_committed_after_exit finds THIS run's receipt.export HERMES_UPDATE_CORRELATION_ID="$UPDATE_CORRELATION"diff --git a/tests/scripts/desktop_update/test_posix_handoff_pid_export.py b/tests/scripts/desktop_update/test_posix_handoff_pid_export.pynew file mode 100644index 00000000000..40a20597791--- /dev/null+++ b/tests/scripts/desktop_update/test_posix_handoff_pid_export.py@@ -0,0 +1,47 @@+"""posix.sh must export the marker's OWNER as HERMES_UPDATE_HANDOFF_PID, not its own pid.++`hermes update` adopts an existing claim only when the live owner is its own pid, the+``HERMES_UPDATE_HANDOFF_PID`` value, or one of its ancestors+(``update_lock.UpdateLock._is_partner``). The posix hand-off hands marker line 1 to a+*custodian* subshell (``marker_refresher_start``) that outlives the hand-off script, so the+owner is a **sibling** of that script: never its own pid, and never an ancestor of the+``hermes update`` it spawns. Exporting ``$$`` therefore left the custodian unrecognisable and+every desktop-initiated update refused its own claim with exit code 2 --+``Another Hermes update is already running (started Ns ago, process <custodian>)``.++The runtime hand-off protocol suite (``test_desktop_update_posix_handoff_protocol.py``) is+``platforms("linux")`` because it decides liveness through ``/proc``; these assertions pin the+same invariant on every platform.+"""+from __future__ import annotations++from pathlib import Path++import pytest++POSIX = Path(__file__).resolve().parents[3] / "scripts" / "desktop-update" / "posix.sh"+EXPORT = "export HERMES_UPDATE_HANDOFF_PID="++[email protected](scope="module")+def body() -> str:+ return POSIX.read_text(encoding="utf-8-sig")+++def test_handoff_pid_names_the_marker_owner_not_the_script(body):+ """Line 1 of the marker carries $MY_PID, so that is what the update child must be told."""+ assert f'{EXPORT}"$MY_PID"' in body+ assert f'{EXPORT}"$$"' not in body+++def test_custodian_handover_precedes_the_export(body):+ """$MY_PID only becomes the custodian when marker_refresher_start runs; an export placed+ before that call site would still name the hand-off script itself."""+ call_site = body.index("\nmarker_refresher_start\n") # the call, not the definition+ assert call_site < body.index(EXPORT)+++def test_the_owner_the_marker_names_is_what_my_pid_is_set_to(body):+ """marker.sh writes line 1 from "$MY_PID" (marker_custody_take_locked / marker_canonical),+ and the handover is what re-points it at the custodian."""+ assert 'MY_PID="$MARKER_REFRESHER"' in body