Skip to content

fix(connect): SIGPIPE-trap + heartbeat so silent-deafness launches fail loud - #32

Merged
joelteply merged 1 commit into
mainfrom
fix/connect-fail-on-silent-notification-loss
Apr 23, 2026
Merged

joelteply merged 1 commit into
mainfrom
fix/connect-fail-on-silent-notification-loss

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Summary

When airc connect <invite> is launched in a way that closes stdout
without anyone reading it (one-shot Bash exec, nohup, background &,
detached shell), the pairing succeeds, the python formatter and ssh
tail spawn correctly, and the host's messages.jsonl fills as
expected — but every inbound peer message goes to a closed stdout and
silently disappears. The pairing looks alive in airc peers, but the
agent never sees a single notification.

This is the worst possible failure mode for a relay protocol: looks
healthy from the outside, totally deaf in practice.

Fix

  1. SIGPIPE trap installed at the top of cmd_connect. When any write
    to stdout fails (closed pipe), the trap prints a loud, specific
    error to stderr (which usually survives the closed-stdout case)
    pointing at the right launch patterns, then exits with code 3.
  2. 60-second-period heartbeat to stdout, spawned in a background
    subshell. With a live reader (Monitor, interactive TTY) the
    heartbeats are harmless filler. With no reader, the next heartbeat
    triggers SIGPIPE → trap fires → loud death within 60s.
  3. AIRC_BACKGROUND_OK=1 env var skips the heartbeat for legitimate
    background launches (systemd unit + dedicated tail -f consumer,
    test harnesses).

Worst-case latency from "stdout closed" to "airc dies loudly" is 60s —
the price of catching the failure mode at all. Heartbeat interval
could become an env knob in a follow-up if anyone needs faster
detection.

Why this matters

This bug surfaced today (2026-04-23) when a peer paired into a host
via Claude Code's Bash tool instead of via the /connect skill (which
wraps in Monitor(persistent=true)). The peer's airc peers showed
the host. The host's airc peers showed the peer. The host sent three
messages. None reached the peer. Both sides debugged for hours before
the launch pattern came up.

The relevant principle: a protocol whose entire purpose is "stream
inbound messages to the agent" must NOT silently succeed when the
stream has no reader.
It is allowed to fail at startup, allowed to
fail loudly later, but is not allowed to look fine while being
functionally deaf.

Test plan

  • Manually reproduced original failure mode (one-shot bash exec,
    no reader) — confirmed inbound messages were silently dropped on
    main.
  • After this PR: same launch → SIGPIPE trap fires within 60s with
    clear error pointing at correct launch patterns.
  • Monitor(persistent=true, command="airc connect <invite>") →
    heartbeats appear as benign Monitor events, no false-fail.
  • Interactive TTY launch (airc connect <invite> typed at shell)
    → heartbeats visible inline, no false-fail.
  • AIRC_BACKGROUND_OK=1 nohup airc connect ... & → heartbeat
    suppressed, runs normally for legitimate background use.

…il loud

The bug a real user surfaced today:

A peer ran `airc connect <invite>` via Claude Code's one-shot Bash tool
(not via the /connect skill, which wraps in Monitor). The pairing
succeeded, the python formatter + ssh tail spawned, messages.jsonl on
the host filled correctly — but stdout had no reader because the bash
that exec'd `airc connect` had already exited and closed the pipe.
Result: airc was paired and "looked alive" in `airc peers`, but every
inbound message went to a closed stdout and silently disappeared. The
peer never saw any reply. Hours of debugging from both sides before
anyone noticed the launch pattern was the cause.

This is exactly the silent-failure-mode airc has no business shipping.
A protocol whose whole purpose is "stream inbound messages to the
agent" must NOT silently succeed when the stream has no reader.

Fix:
1. Install a SIGPIPE trap in cmd_connect that prints a clear error to
   stderr (which usually survives even when stdout is dead) explaining
   the cause AND the right launch patterns, then exits non-zero.
2. Spawn a 60s-period heartbeat to stdout. If a reader is consuming
   stdout (Monitor / interactive TTY), the heartbeats are harmless
   filler. If stdout is closed (one-shot bash, nohup, '&' background,
   detached shell), the next heartbeat write triggers SIGPIPE → trap
   fires → loud death instead of silent deafness.
3. AIRC_BACKGROUND_OK=1 env var skips the heartbeat for the rare
   legitimate background launch (systemd unit + dedicated tail
   consumer, test harness with its own monitoring).

Worst-case latency from "stdout closed" to "airc dies loudly" is 60s
which is the price of catching the failure mode at all. Tunable later
if anyone needs faster (heartbeat interval as env var).

Triggered by: 2026-04-23 incident where continuum-6cae paired into
continuum-a25c via /airc:connect <invite> launched as a Bash one-shot.
Symptom: continuum-a25c sent 3 messages, none reached continuum-6cae's
notification stream. Continuum-6cae's diagnosis (over the mesh) matched
ours. Joel: "take every bug you encounter, especially for NEW users on
like a NEW machine or OS as an OPPORTUNITY so do NOT hack it. You fix
it. Look at it as a freaking gift."
@joelteply
joelteply merged commit 3c4092b into main Apr 23, 2026
1 check passed
@joelteply
joelteply deleted the fix/connect-fail-on-silent-notification-loss branch April 25, 2026 03:18
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