The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(update): our own pid is ours only at our exact creation time
Tekniume6be5991b87c
diff --git a/hermes_cli/update_lock.py b/hermes_cli/update_lock.pyindex 6c6a3522c24..f31b3504b14 100644--- a/hermes_cli/update_lock.py+++ b/hermes_cli/update_lock.py@@ -41,6 +41,9 @@ UPDATE_MARKER_MAX_AGE_SECONDS = 20 * 60# Clock skew allowed between a recorded and a probed process creation time (C1 rule 3).CREATE_TIME_TOLERANCE_SECONDS = 2.0+# Our own creation time re-probed by the same clock: only the marker's 3-decimal rounding differs,+# while two processes are at least one scheduler tick (10 ms) apart.+_OWN_CREATE_TIME_EPSILON = 0.005# A claim published by create-then-write (filesystems without hard links) is briefly empty; an# empty marker this young is a claim in flight, not a dead one (contract A3).@@ -233,7 +236,10 @@ def _identity_live(pid: int, create_time: float | None, age: float) -> bool:actual = None if create_time is None else process_create_time(pid)if actual is None:return age <= UPDATE_MARKER_MAX_AGE_SECONDS- return abs(actual - create_time) <= CREATE_TIME_TOLERANCE_SECONDS+ # Our own pid is us only at our exact creation time: a fresh pid namespace (container, bwrap)+ # hands a killed update's pid to the next launch well inside the cross-writer skew window.+ tolerance = _OWN_CREATE_TIME_EPSILON if pid == os.getpid() else CREATE_TIME_TOLERANCE_SECONDS+ return abs(actual - create_time) <= tolerancedef _identity_line(pid: int | None = None) -> str:diff --git a/tests/hermes_cli/test_update_lock.py b/tests/hermes_cli/test_update_lock.pyindex 38fb0e37b71..87aac3ee21c 100644--- a/tests/hermes_cli/test_update_lock.py+++ b/tests/hermes_cli/test_update_lock.py@@ -177,6 +177,20 @@ def test_marker_naming_our_own_pid_is_adopted(marker, monkeypatch):assert not marker.exists()+def test_v2_marker_naming_our_pid_at_a_nearby_creation_time_is_a_killed_update(marker):+ """A fresh pid namespace (bwrap, a container) gives the next launch the killed updater's pid+ about a second after it started: inside the 2 s cross-writer skew, but not our creation time.+ Read as ours, the launch adopted a dead claim and silently skipped the tail the kill owed."""+ _claim_v2(marker, os.getpid(), ct_offset=-1.5)++ assert read_live_update(path=marker) is None, "a dead update's claim reads as a live one"+ _claim_v2(marker, os.getpid(), ct_offset=-1.5)+ lock = UpdateLock(path=marker)+ assert lock.acquire() is True and lock.acquired is True, "adopted a killed update's claim"+ assert marker.read_text(encoding="utf-8-sig").splitlines()[2] == f"ct:{process_create_time():.3f}"+ lock.release()++def test_release_leaves_a_marker_a_handoff_partner_now_owns(marker):"""The desktop writes the marker, then the Tauri updater takes ownership.