Skip to content

fix(self-heal): verify PID cmdline before treating as live monitor — closes Task #97 (airc-bios) - #447

Merged
joelteply merged 1 commit into
canaryfrom
fix/airc-self-heal-pid-reuse
May 3, 2026
Merged

joelteply merged 1 commit into
canaryfrom
fix/airc-self-heal-pid-reuse

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Summary

Closes Task #97 — the airc-bios self-heal gap Joel hit 2026-05-03 ("airc went down and must be remedied" → "you don't investigate").

Bug

After laptop sleep + wake, the OS reuses PIDs for unrelated processes (bash, python, etc.). Bare kill -0 $pid against the stale airc.pid returns true against those zombie PIDs → caller thinks the airc monitor is alive when it's actually long dead. Mesh effectively partitioned with no diagnosis path.

Per the airc-bios memory rule: "Self-healing is mandatory life-support, NOT an optimization." Bare kill-0 is the single biggest false-positive that prevents self-heal 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 (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 → proceed with normal connect flow → mesh reforms.

Cmdline regex shape

Identical to cmd_teardown's parent-chain reaper (#446). Three alternatives cover absolute-path / bare / eval-wrapped airc connect|join. Keeps the codebase consistent on what counts as "an airc process."

What it does NOT change

Verification

  • bash -n airc lib/airc_bash/cmd_connect.sh clean.
  • bash test/integration_smoke.sh round_trip 2 pass / 0 fail.

🤖 Generated with Claude Code

…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]>
Copilot AI review requested due to automatic review settings May 3, 2026 17:25
@joelteply

Copy link
Copy Markdown
Contributor Author

LGTM from codex-b741 (Mac-airc-side scope, original Task #97 filer).

Direct hit on the exact bug. The diagnosis quote from the comment matches what I observed and filed — laptop slept, airc Monitor died, OS reused PIDs for unrelated bash/python procs (which I confirmed via ps -p showing wildly-mismatched cmdlines), and airc connect then refused to self-heal because bare kill -0 returned true on the wrong-PID zombies.

Fix shape is correct and symmetric:

  • cmdline regex matches the same pattern cmd_teardown uses for parent-chain reap (fix(teardown): reap scope parent chain when pidfile is stale #446) — keeps the two paths in lockstep on what "an airc process" means. Touch the regex in one place, both paths update.
  • _monitor_alive_with_bearer_fallback covers the status-reporting path
  • cmd_connect covers the join-time refusal path
  • Phase 2 bearer-state freshness still wins as the truth when Phase 1 is inconclusive — fail-open on liveness rather than fail-closed

airc-bios alignment: this turns join into a self-healer instead of a refuser. Per Joel's airc-bios rule ("airc must self-heal from sleep/restart without human intervention") this is the systemic fix, not a bandaid.

Safe to merge to canary.

@joelteply

Copy link
Copy Markdown
Contributor Author

Codex review pass: no blocking findings. The fix addresses the PID-reuse false-positive directly: kill -0 is paired with the same airc connect/join cmdline shape used by teardown, and the stale-pidfile path only preserves real airc monitors. CI clean-install matrix is green. LGTM for canary.

@joelteply
joelteply merged commit 09edbec into canary May 3, 2026
10 checks passed
@joelteply
joelteply deleted the fix/airc-self-heal-pid-reuse branch May 3, 2026 17:34
@joelteply
joelteply removed the request for review from Copilot May 3, 2026 17:45
joelteply added a commit that referenced this pull request May 4, 2026
…irc-shaped fake PID, honest e2e skip (#456)

fix(test): scaffold_identity venv probe + send_dead_monitor airc-shaped fake + e2e_encryption honest skip

Three test fixes surfaced when canary→main CI ran the integration
suite. All three are about NOT swallowing errors (per Joel 2026-05-04
directive via Codex relay, mirroring CLAUDE.md "never swallow
errors"):

1. scaffold_identity walked `${AIRC_PYTHON:-python3}` and swallowed
   errors via `2>/dev/null`, so when system python3 lacked the
   `cryptography` module the bootstrap-ed25519 step silently failed
   to write private.pem. Downstream tests then errored with the
   opaque "ed25519 sign failed: [Errno 2] No such file or directory:
   '…/identity/private.pem'" — caller never told that cryptography
   was missing. Fix: probe candidate venvs (matching the same
   resolution airc itself walks for AIRC_PYTHON), let stderr through,
   fail loudly with explicit message if none have cryptography
   importable.

2. scenario_send_dead_monitor_dies's "live-pid" negative control
   wrote `$$` to airc.pid — the test harness's bash PID. Worked
   under bare `kill -0` semantics; broke under #447's hardened
   cmdline-shape verification (PID-reuse defense after sleep/wake).
   Fix: spawn an airc-SHAPED fake via `( exec -a "airc connect"
   sleep 60 ) &` — argv[0] now matches the
   /airc[[:space:]]+(connect|join)/ regex.
   _monitor_alive_with_bearer_fallback accepts it.

3. scenario_e2e_encryption gated on `$(dirname AIRC)/.venv-dev`,
   which install.sh does NOT create (install.sh creates `.venv`,
   inside its install dest — typically $HOME/.airc-src). Result:
   silently skipping every CI run despite the suite reporting "ran."
   Fixing the venv detection then surfaces the deeper issue: this
   scenario was written when SSH was a registered bearer; Phase E /
   post-3c removed it (`bearer_resolver.available_kinds` is gh +
   LocalBearer only), so the test's @peer-name send path errors with
   "no registered bearer can serve peer_meta=…" and the wire falls
   back to plaintext gh-substrate, defeating the "wire is ciphertext"
   assertion. Real fix is a rewrite via gh substrate; until then,
   skip with the actual reason in the message (loud skip, not silent
   pass-by-skip). Original test body preserved below `return` for
   the eventual rewriter's reference.

Local: send_dead_monitor_dies 8/8 pass; e2e_encryption skips with
explicit message; all other scenarios unaffected.

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant