The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: the POSIX launcher counts the custodian its daemon forked as a started hand-off
Teknium299fcf1c69c8
diff --git a/scripts/desktop-update/marker.sh b/scripts/desktop-update/marker.shindex a61f18928f2..2a693353aec 100644--- a/scripts/desktop-update/marker.sh+++ b/scripts/desktop-update/marker.sh@@ -68,6 +68,16 @@ pid_parent() { # pid -> parent pid, or nothingps -o ppid= -p "$1" 2>/dev/null | tr -d '[:space:]'}+# The launcher's "hand-off started" proof (contract C2). Within moments of its+# claim the daemon hands line 1 to the custodian it forked (marker_refresher_start),+# so accepting only the daemon's pid lost that race on a slow host and reported a+# running update as a failed launch.+marker_names_handoff() { # daemon pid -> 0 iff line 1 names it or a process it forked+ local p+ p="$(head -1 "$MARKER" 2>/dev/null | tr -d '[:space:]')"+ [ -n "$p" ] && { [ "$p" = "$1" ] || [ "$(pid_parent "$p")" = "$1" ]; }+}+ct_close() { # a b tolerance -> 0 iff |a - b| <= toleranceawk -v a="$1" -v b="$2" -v t="$3" 'BEGIN{d=a-b; if (d<0) d=-d; exit !(d<=t)}'}diff --git a/scripts/desktop-update/posix.sh b/scripts/desktop-update/posix.shindex 574fda23a08..b39692d9957 100755--- a/scripts/desktop-update/posix.sh+++ b/scripts/desktop-update/posix.sh@@ -970,7 +970,7 @@ os.execve("/bin/bash", ["/bin/bash", sys.argv[1], *sys.argv[2:]], env)# the marker. Report a daemon that never got that far (no /usr/bin/python3,# a refused claim) as a failed launch so the Desktop stays up.for _ in $(seq 1 100); do- [ "$(head -1 "$MARKER" 2>/dev/null | tr -d '[:space:]')" = "$DAEMON_PID" ] && exit 0+ marker_names_handoff "$DAEMON_PID" && exit 0if ! kill -0 "$DAEMON_PID" 2>/dev/null; thenwait "$DAEMON_PID"; code=$?[ "$code" -ne 0 ] || code=70diff --git a/tests/scripts/desktop_update/test_desktop_update_posix_marker.py b/tests/scripts/desktop_update/test_desktop_update_posix_marker.pyindex 8f9287f6e9e..9cfe62fa675 100644--- a/tests/scripts/desktop_update/test_desktop_update_posix_marker.py+++ b/tests/scripts/desktop_update/test_desktop_update_posix_marker.py@@ -415,3 +415,26 @@ def test_desktop_that_exits_inside_the_ceiling_lets_the_update_run(tmp_path):assert result.returncode == 0, result.stdout + result.stderrassert any(c.startswith("update") for c in _calls(tmp_path))+++def test_launcher_counts_the_custodian_its_daemon_forked_as_a_started_handoff(tmp_path):+ """Contract C2: the launcher exits 0 once the marker names its hand-off. The daemon hands+ line 1 to the custodian it forked moments after the claim, so a launcher that waited for+ the daemon's own pid reported a running update as a failed launch (exit 70) whenever the+ handover beat its next poll. Only the daemon or its own fork counts."""+ marker = tmp_path / "marker"+ script = f"""+. {shlex.quote(str(POSIX.parent / "marker.sh"))}+MARKER={shlex.quote(str(marker))}+judge() {{ echo "$1" > "$MARKER"; marker_names_handoff $$ && echo "$2=yes" || echo "$2=no"; }}+sleep 30 & child=$!+( sleep 30 & echo $! > {shlex.quote(str(tmp_path / "gc"))}; wait ) & sub=$!+while [ ! -s {shlex.quote(str(tmp_path / "gc"))} ]; do sleep 0.05; done+judge "$child" custodian+judge "$$" daemon+judge "$(cat {shlex.quote(str(tmp_path / "gc"))})" grandchild+judge 1 unrelated+kill $child $sub $(cat {shlex.quote(str(tmp_path / "gc"))}) 2>/dev/null+"""+ out = subprocess.run(["/bin/bash", "-c", script], capture_output=True, text=True, timeout=30, check=True).stdout+ assert out.split() == ["custodian=yes", "daemon=yes", "grandchild=no", "unrelated=no"], out