Skip to content

fix(monitor-liveness): centralize via _monitor_alive_with_bearer_fallback (generalizes #371 to cmd_send + cmd_connect) - #374

Merged
joelteply merged 1 commit into
canaryfrom
fix/centralize-monitor-liveness-bearer-fallback
Apr 30, 2026
Merged

joelteply merged 1 commit into
canaryfrom
fix/centralize-monitor-liveness-bearer-fallback

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Generalizes #371 to fix Codex's broken `airc msg` and trust-existing-monitor short-circuit.

What broke

Joel had Codex (continuum-2c54, hosting #cambriantech, bearer_state.general 60s fresh) try `airc msg "hello mesh"`:

```
Send NOT delivered — this scope's monitor isn't running.
ERROR: monitor down — refusing to silently broadcast into a void
```

…while the bearer was provably alive. Then Codex tried `airc connect` to "fix" it, which didn't trust the existing monitor either (#369's short-circuit also kill-0 blind), proceeded to gh-auth preflight, hit the same Forbidden wall as before.

Root cause: kill -0 across process trees is broken inside Codex's sandbox. #371 patched ONE site (cmd_status); cmd_send and cmd_connect's #369 short-circuit had the SAME blindness in the SAME way.

Fix

Centralize: extract `_monitor_alive_with_bearer_fallback(pidfile)` at airc top-level. Phase 1 = kill-0; phase 2 = bearer-state freshness fallback (`bearer_state..json` last_recv_ts within 2x reminder interval). Pure read; doesn't mutate pidfile.

Three sites updated to call it:

  1. cmd_send.sh — monitor-liveness gate before "Send NOT delivered" refusal. Codex can broadcast now.
  2. cmd_connect.sh fix(connect+skill): trust running monitor over gh-auth-probe noise (closes #367) #369 short-circuit — trust-existing-monitor early-return now fires for Codex too.
  3. cmd_status.sh — switched from inline fix(status): fall back to bearer-state freshness when kill -0 is blind (closes #370) #371 fallback to the shared helper. Same behavior, single source of truth.

`prune_pidfile_and_count` retained for explicit cleanup paths (teardown) where pruning IS desired. The new helper is for liveness checks only.

What it unblocks

  • Codex (and any other sandboxed agent) can use `airc msg` without the false "monitor isn't running" refusal
  • Codex's `airc connect` short-circuits cleanly when its monitor is alive (no gh-auth preflight cascade)
  • `airc status` still reports correctly + retains the diagnostic split between "running (PID X)" and "likely-alive (Ns via #ch; kill -0 blind ...)"

Test plan

  • Syntax check all 4 files
  • `airc status` from no-pidfile scope → "not running" (correct; helper returns no on missing pidfile)
  • Live in Codex: from continuum-2c54 scope post-merge, `airc msg "hello"` succeeds; `airc status` reports likely-alive; `airc connect` short-circuits
  • Live in genuine-dead-monitor scope: kill monitor SIGKILL, wait > 2x reminder → cmd_send refuses correctly (bearer-state went stale); cmd_status reports stale pidfile

Closes operational half of #372

Codex can now send + connect + status correctly. The agent-side event-surfacing question (auto-receive into reasoning loop) remains as the broader UX fix tracked in #372.

🤖 Generated with Claude Code

…back (cmd_send + cmd_status + cmd_connect short-circuit) — generalizes #371

#371 fixed cmd_status to fall back to bearer-state freshness when
kill -0 was sandbox-blind (Codex). But cmd_send and cmd_connect's
#369 short-circuit had the SAME blindness in the SAME way, and #371
only patched one site. Joel hit this immediately when Codex
(continuum-2c54, hosting #cambriantech with bearer_state.general
fresh 60s ago) tried `airc msg "hello mesh"` — got "Send NOT
delivered — this scope's monitor isn't running" while the bearer
was provably alive. Then `airc connect` didn't trust-existing-monitor
either (#369 short-circuit also kill -0 blind), tried gh auth login,
hit the same Forbidden wall.

Root cause for all three: kill -0 across process trees is broken
inside Codex's sandbox. Fix: extract a centralized helper at airc
top-level + use everywhere.

New helper: _monitor_alive_with_bearer_fallback(pidfile)
  Phase 1: kill -0 against PIDs in pidfile (canonical, fast)
  Phase 2: bearer-state freshness fallback when phase 1 returns no
           live PIDs but pidfile exists. If any bearer_state.<ch>.json
           in scope has last_recv_ts within 2x reminder interval
           (default 600s), bearer-recv child is provably alive.

Pure read — does NOT mutate the pidfile (the older
prune_pidfile_and_count would actively delete a "no live PIDs"
pidfile, silently corrupting state when phase 1 was wrong about
death). prune_pidfile_and_count remains for explicit cleanup paths
where pruning IS desired (teardown).

Three call sites updated to use the helper:

1. cmd_send.sh: monitor-liveness gate before "Send NOT delivered"
   refusal. Codex can now broadcast even though kill -0 is blind.

2. cmd_connect.sh #369 short-circuit: trust-existing-monitor early
   return now fires for Codex too (was kill -0 inline, missed
   sandbox-blind case).

3. cmd_status.sh: switched from inline #371 fallback to the shared
   helper. Same behavior, less duplicated code, single source of
   truth for liveness semantics.

cmd_status retains the diagnostic split between "running (PID X)"
(verified via kill -0) and "likely-alive (Ns via #channel; kill -0
blind ...)" (verified via bearer-state only) so the user can tell
which path confirmed liveness.

Tested locally: airc status from a no-pidfile scope still reports
"not running" (helper returns no on missing pidfile — correct).
Live-test path: Joel runs airc msg from Codex's continuum-2c54 scope
post-merge — expect successful broadcast instead of "monitor isn't
running" refusal.

Closes the operational half of #372 (Codex can now send + status
correctly). The agent-side event surfacing (auto-receive for Codex)
is still tracked there as the broader UX fix.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@joelteply
joelteply merged commit ebdeacb into canary Apr 30, 2026
6 checks passed
@joelteply
joelteply deleted the fix/centralize-monitor-liveness-bearer-fallback branch April 30, 2026 04:02
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