Repository navigation
fix(monitor,daemon): skip bearer-state fallback in daemon context — kills 10-min takeover blackout (#4) - #412
Merged
Conversation
…ills 10-min takeover blackout (#4 from b69f's daemon audit) ## Why Last bug from b69f's 2026-05-02 daemon audit. Repro: 1. Interactive `airc connect` running, writing bearer_state.json 2. Process dies (Claude session end, Ctrl-C, crash) 3. Daemon launcher (.bat / launchd / systemd) starts new airc connect 4. New airc connect calls _monitor_alive_with_bearer_fallback 5. Phase 1 (kill -0 on pidfile PIDs): all dead — falls through to Phase 2 6. Phase 2 (bearer_state freshness): last_recv_ts within 600s window → "yes" 7. New airc connect early-exits "monitor already running" 8. Launcher restarts every 5s, repeats until 600s window expires 9. **10-minute substrate blackout while daemon can't take over** Then daemon.err fills with hundreds of `airc connect exited. Restarting in 5s.` lines per minute. Joel observed exactly this pattern 2026-05-02 calling the daemon path "brittle as hell." Phase 2 was added (#370) for Codex sandbox blindness — kill -0 lies in some sandboxes about cross-process visibility. The fallback was supposed to disambiguate. But in daemon context (which sets `AIRC_BACKGROUND_OK=1`), kill -0 is reliable; the fallback only causes false positives. ## What Three-line skip at the top of Phase 2: when `AIRC_BACKGROUND_OK=1`, trust kill -0 and return "no" if all pidfile PIDs are dead. ```bash if [ "${AIRC_BACKGROUND_OK:-0}" = "1" ]; then echo "no" return 0 fi ``` Effect: daemon takeover is immediate (next .bat iteration after interactive death) instead of delayed 10 minutes. ## Why this is safe - Codex / sandbox sessions don't set `AIRC_BACKGROUND_OK=1` — they get the existing fallback behavior. Phase 2's purpose is preserved for them. - Daemon launcher (cmd_daemon.sh:233) explicitly sets `AIRC_BACKGROUND_OK=1` before spawning airc connect. That's the marker. - launchd plist (cmd_daemon.sh:160-162) and systemd unit (cmd_daemon.sh:331) also set it. Cross-platform consistent. - In daemon context the only thing populating bearer_state is the previously-running airc connect; that connect is now dead (Phase 1 confirmed), so there's no "real but blind" monitor — only a stale state file. ## Out of scope (follow-up) When daemon legitimately CAN'T take over because another airc connect IS running (user has both interactive + daemon, dual-monitor scenario), the launcher still spams 5s restart cycles. Distinct exit code from "monitor already running" → longer .bat sleep would be the polish. Filing as follow-up; this PR is the hot-path fix. ## Tests - bash -n passes - 11/11 monitor_formatter tests pass - Diff is 3 functional lines + comment; sandbox path unchanged - Smoke test scaffolding to repro the blackout requires a real Windows daemon install + interactive death; will rely on Mac dogfood + integration suite ## Closes b69f's daemon audit | Bug | PR | |-----|----| | #1 launcher absolute paths | #408 + #409 (Mac) | | #2 scope-aware install | #411 (b69f) | | #3 status honesty | #410 (Mac) | | **#4 daemon takeover blackout** | **THIS PR** | | #5 join-path tip | #410 (Mac) | 5/5 audit bugs in PRs. Daemon path on Windows should be substantially more honest after merge. Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR narrows the monitor liveness heuristic during daemon-launched airc connect runs so the daemon can immediately take over after an interactive monitor dies, instead of being blocked by a fresh bearer_state fallback window. It fits into the recent daemon reliability work by addressing the last reported blackout/crash-loop issue from the daemon audit.
Changes:
- Adds an early return in
_monitor_alive_with_bearer_fallback()whenAIRC_BACKGROUND_OK=1, skipping bearer-state freshness checks. - Documents why daemon contexts should trust
kill -0and how the prior fallback caused a 10-minute takeover blackout. - Leaves the existing fallback path unchanged for non-background contexts.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+539
to
+555
| # Skip when AIRC_BACKGROUND_OK=1 — that env var is set by the daemon | ||
| # launcher (cmd_daemon.sh's .bat / launchd plist / systemd unit), and | ||
| # in daemon context kill -0 is reliable (no Codex-style sandbox | ||
| # blindness). The fallback's 600s window otherwise creates a | ||
| # 10-minute "daemon can't take over" blackout after an interactive | ||
| # airc connect dies: the dying process leaves bearer_state with a | ||
| # fresh last_recv_ts, the daemon's next launch sees it as "monitor | ||
| # alive," early-exits, and the .bat retries every 5s for 10 minutes | ||
| # before the window expires. b69f filed as #4 in the 2026-05-02 | ||
| # daemon audit. Trust kill -0 in daemon context so takeover is | ||
| # immediate. Joel's BIOS-grade self-heal directive: substrate must | ||
| # work without a human in the loop, including across interactive | ||
| # process death. | ||
| if [ "${AIRC_BACKGROUND_OK:-0}" = "1" ]; then | ||
| echo "no" | ||
| return 0 | ||
| fi |
Comment on lines
+552
to
+554
| if [ "${AIRC_BACKGROUND_OK:-0}" = "1" ]; then | ||
| echo "no" | ||
| return 0 |
This was referenced May 2, 2026
joelteply
added a commit
that referenced
this pull request
May 2, 2026
…routing) (#418) Captures the architecture conversation Joel surfaced 2026-05-02 end of the 22-PR airc hardening session. Replaces "single transport at a time" with a reticulum-style fusion routing layer above pluggable interface drivers (loopback / LAN / Tailscale / gh / Reticulum-future). Core principles, all from Joel verbatim: - "airc is you as an agent's complex vocal learning trait" — substrate is constitutive of cognition, not infrastructure under it - "you never require these dependencies to exist" — every transport is optional, auto-detected, gracefully absent - "since we know it is a rate limited feature it should be used sparingly if possible. because when you do, gh suffers an outage and we are down" — gh as scarce resource, not default channel - "its like sensor fusion, if we lose accelerometer we dont lose position, it all works together" — fusion not failover; loss of one transport degrades the fused estimate gracefully, layer above sees one virtual channel Doc covers: - Layered structure (drivers → fusion → app) - Interface driver contract (is_available, addresses, connect, health, send, recv_iter) - Per-transport health vector (RTT EMA, success rate, budget, jitter) - Routing policy by traffic class (control_critical, control_routine, data, discovery, outsider) - Scenario matrix (TS-logout, TS-comeback, gh rate-limit, network partition, outsider, all-down) - 5-phase implementation plan (loopback+LAN → +TS → +health/routing → gh-as-control-only → Reticulum slot-in) - Pairs explicit with vuln-A (prompt injection), #412 daemon takeover, #414/#407 rediscover, #415 KEEP gist - 6 open questions for design ratification before code Companion to issue #417 (which holds the same content as the discussion surface). The repo doc is the durable artifact; the issue is the conversation lane. 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.
Why
Last bug from b69f's 2026-05-02 daemon audit. Repro:
airc connectrunning, writingbearer_state.jsonairc connect_monitor_alive_with_bearer_fallbackPhase 1 (kill -0): all dead — falls throughlast_recv_tswithin 600s window → "yes"airc connectearly-exits "monitor already running"daemon.errfills with hundreds ofairc connect exited. Restarting in 5s.lines per minute. Joel verbatim 2026-05-02: "brittle as hell."Phase 2 was added (#370) for Codex sandbox blindness —
kill -0lies in some sandboxes. The fallback disambiguates. But in daemon context (which setsAIRC_BACKGROUND_OK=1),kill -0is reliable; the fallback only causes false positives.What
3-line skip at the top of Phase 2: when
AIRC_BACKGROUND_OK=1, trustkill -0and return"no"if all pidfile PIDs are dead.Effect: daemon takeover is immediate (next .bat iteration after interactive death) instead of delayed 10 minutes.
Why this is safe
AIRC_BACKGROUND_OK. Behavior unchanged.cmd_daemon.sh:233(.bat),:160-162(plist),:331(systemd) all set it. Cross-platform consistent.bearer_stateis the previously-running airc connect. Phase 1 confirmed it's dead → no live monitor exists, fallback would only be lying.Out of scope (follow-up)
When daemon legitimately CAN'T take over because another airc connect IS running (user has both interactive + daemon), the launcher still spams 5s restart cycles. Distinct exit code from "monitor already running" → longer .bat sleep would be the polish. Filing as follow-up.
Closes b69f's daemon audit
5/5 audit bugs in PRs.
🤖 Generated with Claude Code