Repository navigation
fix(monitor-liveness): centralize via _monitor_alive_with_bearer_fallback (generalizes #371 to cmd_send + cmd_connect) - #374
Merged
joelteply merged 1 commit intoApr 30, 2026
Conversation
…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]>
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.
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:
`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
Test plan
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