Repository navigation
fix(teardown): reap scope parent chain when pidfile is stale - #446
Merged
Merged
Conversation
Contributor
Author
|
LGTM from airc-8a5e (review only — shared gh account blocks formal approve). Diagnosis confirmed: scope-path pgrep catches Python children (--state-file/--peers-dir in argv) but misses bash Walk logic is safe:
Test is real: spawns gh-backed host, corrupts pidfile to 999999, calls teardown, asserts both parent_pid dead AND zero scope-path-tagged procs remain. Good regression. One minor non-blocker: Safe to merge to canary. |
joelteply
added a commit
that referenced
this pull request
May 3, 2026
…closes Task #97 (airc-bios) (#447) fix(self-heal): verify PID cmdline before treating as live monitor — closes Task #97 (airc-bios self-heal) Joel hit this 2026-05-03: laptop slept, airc Monitor died, OS later reused those PIDs for unrelated bash/python procs. `airc status` then reported "monitor: not running" while `airc connect` still refused to self-heal because bare `kill -0 $pid` returned true against the zombie PIDs (which were live, just not airc anymore). Mesh effectively partitioned. Joel had to manually `teardown && connect` through Monitor to reform the bus — explicit "airc went down and must be remedied" → "you don't investigate" frustration. Per the airc-bios memory rule: "Self-healing is mandatory life- support, NOT an optimization." Bare `kill -0` after sleep/wake is the single biggest false-positive that prevents self-heal from working in practice. ## Two call sites fixed 1. `airc::_monitor_alive_with_bearer_fallback` (Phase 1 of the shared liveness probe used by cmd_status, cmd_send, cmd_connect's early short-circuit). Previously: any `kill -0` true → "yes". Now: also requires cmdline regex match. PID-reused-by-OS path falls through to Phase 2 bearer-state freshness check (which is the truth — bearer-recv only updates that file when actually reading from the wire). 2. `cmd_connect.sh` canonical pidfile-cleanup block (line ~488). Previously: any `kill -0` true → refuse to start, "monitor already running" message pointing at zombie PIDs. Now: same cmdline verification → PID-reuse case treats pidfile as stale → `rm -f stale_pidfile` → proceed with normal connect flow → mesh reforms. ## Cmdline regex shape Identical to cmd_teardown's parent-chain reaper (#446). Three alternatives cover: - absolute-path airc connect|join (`/usr/local/bin/airc connect`) - bare airc connect|join (`airc connect` on PATH) - eval-wrapped airc connect|join (some daemon launchers) Keeps the codebase consistent on what counts as "an airc process." ## What it does NOT change - Live monitor in same scope: still detected, still respected (cmdline regex matches an actual airc connect|join). - Sibling shells running airc: unaffected; we still refuse to stomp a real live monitor (#292's original concern). - Bearer-state Phase 2 fallback: unchanged. Codex sandbox path (kill -0 blind) still works because bearer-state freshness is authoritative there. ## Verification - `bash -n airc lib/airc_bash/cmd_connect.sh` clean. - `bash test/integration_smoke.sh round_trip` 2 pass / 0 fail. - The two test/integration_smoke.sh "Killed: 9" lines at end are expected scenario teardown SIGKILLs, not regressions. Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Merged
6 tasks done
joelteply
added a commit
that referenced
this pull request
May 6, 2026
Pre-fix this function was the last self-killer in the join cold-start
path. Three failure shapes combine — fixing only one was insufficient:
(1) Same-PID self-kill after re-exec. After `_reexec_into host`,
the new airc inherits the SAME pid as the pre-exec instance.
airc.pid (written early per #541) names US. Without filtering
$$/$PPID, the kill loop SIGTERM'd its own shell. Defensive
pattern already exists in _join_scope_transport_pids:211 — was
never propagated to airc.pid contents until now.
(2) OS PID recycling. The other PID sources (airc.pid contents from
a crashed predecessor, bearer_gist.*.pid stragglers) can name
a slot the kernel has since reassigned to an unrelated process
— including, on Windows WSL2, the parent wsl.exe / cmd.exe
shell in our launcher chain. Killing one of those takes Claude
Code's Monitor down with us. Joel hit this exact shape in #97 /
#446 in different code paths; the fix there ("verify cmdline
before treating PID as ours") was never propagated here.
(3) set -e + pipefail kills the whole airc on best-effort PID
assembly. The function uses `proc_airc_pids_matching` (pgrep)
which exits 1 when no matches. Pipefail propagates the 1
through `pgrep | tr`, the simple var assignment then triggers
set -e, and airc dies between debug-instrumented "step1" and
"step2" markers — never reaching the kill loop, never returning
from the function. This was the residual death point that
made my earlier $$ filter alone look ineffective. Joel's
"Codex and Claude usually miss the obvious" call applies.
Fix:
Layer 1 — drop $$ and $PPID from the candidate list.
Layer 2 — verify cmdline matches airc/airc_core before killing,
so an OS-recycled PID owned by an unrelated process is
never targeted.
Layer 3 — wrap each substitution in `|| true` so pipefail can't
propagate pgrep's empty-result-1 into a fatal var
assignment.
Verified end-to-end on Windows + WSL2 (with #544 + #545 also applied
locally). Monitor's `airc join` flow:
shim → wsl.exe → canonical airc → join → discover → take over
→ re-exec to host mode → trust-existing-monitor short-circuit
→ degraded transport detected → _join_restart_scope_processes
→ filters $$ (PID 57724) + dead bearer pids 80413/38943
→ all candidates dropped, kill loop empty, function returns
→ host setup completes through "Hosting #cambriantech (gh-account
substrate)" → "Monitoring for messages..." → broadcast contract
banner → mesh send confirmed bidirectional.
After: Windows Claude Code Monitor `airc join` finally completes
the cold-start path without Joel relay.
Related — Windows Monitor cold-start surface trail:
#533 SIGHUP cascade (transport detach via setsid -f)
#538 monitor 404-gone gist treated as terminal
#541 airc.pid + messages.jsonl created before slow bootstrap
#542 airc.cmd direct cmd→bash (drop PowerShell hop)
#543 dual-clone single-source (airc.cmd prefers WSL)
#544 airc.cmd args-forwarding (wsl.exe doesn't forward $@)
#545 polyglot shim for Windows-visible PATH (single source)
THIS three-layer self-protect on the supervisor restart path.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Verification