Skip to content

fix(status): fall back to bearer-state freshness when kill -0 is blind (closes #370) - #371

Merged
joelteply merged 1 commit into
canaryfrom
fix/status-bearer-fallback-370
Apr 30, 2026
Merged

joelteply merged 1 commit into
canaryfrom
fix/status-bearer-fallback-370

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

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

  • Syntax check: `bash -n cmd_status.sh`
  • Local: scope with no pidfile (e.g. Claude Code shell from `/Users/joel/.airc-src/.airc`) → still reports `monitor: not running` (pidfile-present is the gate; correct behavior preserved)
  • Live in Codex: from continuum-2c54 scope, run `airc status` after merge → expect `monitor: likely-alive ( via #general; kill -0 blind ...)` instead of false `not running`
  • Live in genuine-dead-monitor scope: kill the monitor via SIGKILL, wait > reminder interval, run airc status → still reports `stale pidfile` (bearer-state went stale, fallback doesn't fire)
  • CI: 4 platforms

Related

🤖 Generated with Claude Code

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]>
@joelteply
joelteply merged commit 949018b into canary Apr 30, 2026
6 checks passed
@joelteply
joelteply deleted the fix/status-bearer-fallback-370 branch April 30, 2026 03:49
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]>
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