Repository navigation
fix(status): fall back to bearer-state freshness when kill -0 is blind (closes #370) - #371
Merged
Merged
Conversation
closes #370) Inside Codex's sandbox, `kill -0 <pid>` for processes spawned outside the sandbox returns failure even when the process is alive. Result: prune_pidfile_and_count returns 0, status reports "monitor: not running" while the monitor IS running and visibly streaming events (Codex was hosting #cambriantech via continuum-2c54 with bearer events flowing, but airc status said the monitor was dead). Same root cause as openai/codex#10695 sandbox process isolation — also affects pgrep cross-tree (sysmon failure surfaced in the same session). airc isn't going to win against the sandbox boundary; it can route around it. Fix: when prune_pidfile_and_count returns 0 BUT a pidfile exists (implying a monitor was started here), look at the scope's bearer_state.<channel>.json files. If any has a last_recv_ts within 2x the reminder interval (default 600s), the bearer-recv child is provably alive — only a live monitor's bearer-recv loop updates that file. Report "likely-alive (<Ns> via #<channel>; kill -0 blind in this sandbox — see #370)" instead of the false "not running". Falls through to the existing "stale pidfile" message when bearer state is also stale (i.e., the monitor really IS dead, not just sandbox-invisible). So we don't lose the genuine-failure signal. Walks all bearer_state.*.json files in the scope (host's #general sidecar + any other subscribed channels). Picks the freshest. Hosts of project rooms don't have bearer_state for the project room itself (host writes locally), but the #general sidecar IS a recv path even for hosts — that's the key insight that makes this work for Codex's exact case (hosting #cambriantech, sidecar-recv'ing #general). Reads reminder interval from $AIRC_WRITE_DIR/reminder when present, defaulting to 300s if absent or invalid. Tested locally on a non-pidfile scope: still reports "not running" correctly (pidfile-present is the gate). Live-test path: Joel runs airc status from Codex's continuum-2c54 scope post-merge — expect "monitor: likely-alive (<Ns> via #general; kill -0 blind ...)" instead of "monitor: not running". Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
This was referenced Apr 30, 2026
joelteply
added a commit
that referenced
this pull request
Apr 30, 2026
…back (generalizes #371 to cmd_send + cmd_connect) (#374) fix(monitor-liveness): centralize via _monitor_alive_with_bearer_fallback (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: joel <[email protected]> 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.
Closes #370. Codex sandbox-friendly status reporting.
The bug
Inside Codex's sandbox, `kill -0 ` for processes spawned outside the sandbox returns failure even when the process is alive. `prune_pidfile_and_count` returns 0, status reports `monitor: not running` while the monitor IS running and visibly streaming events. Caught live during the Codex first-encounter QA — Codex was hosting `#cambriantech` as continuum-2c54 with bearer events flowing, but `airc status` claimed the monitor was dead.
Same root cause as openai/codex#10695 sandbox process isolation; also hits `pgrep` cross-tree (sysmon failure). airc isn't going to win against the sandbox boundary; it can route around it.
Fix
When `prune_pidfile_and_count` returns 0 BUT a pidfile exists (so a monitor was started here at some point), look at the scope's `bearer_state..json` files. If any has a `last_recv_ts` within 2x the reminder interval (default 600s), the bearer-recv child is provably alive — only a live monitor's bearer-recv loop updates that file. Report `likely-alive ( via #; kill -0 blind in this sandbox — see #370)` instead of the false `not running`.
Falls through to the existing `stale pidfile` message when bearer state is also stale (i.e., the monitor really IS dead, not just sandbox-invisible). So we don't lose the genuine-failure signal.
Why this works for Codex's specific case
Codex was hosting `#cambriantech` (host scope, no bearer_state for project room — host writes locally). BUT it was also subscribed to `#general` as a sidecar, and the `#general` bearer-recv loop DOES update `bearer_state.general.json` regardless of host status. Even host-of-X scopes have recv state for any sidecar they're subscribed to. That's the key insight.
Test plan
Related
🤖 Generated with Claude Code