Skip to content

fix(monitor): don't override cmd_connect trap — fixes #21 orphaned SSH tail + Python formatter - #22

Merged
joelteply merged 1 commit into
mainfrom
fix/resume-foreground-wait
Apr 19, 2026
Merged

joelteply merged 1 commit into
mainfrom
fix/resume-foreground-wait

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Summary

monitor() was overriding the EXIT/INT/TERM trap that cmd_connect had set up to clean up airc.pid and reap every child via pgrep -P \$\$. The override only killed reminder_pid and flush_pid, leaving the SSH tail and Python monitor_formatter as orphans whenever the outer shell exited. Tools wrapping airc connect (e.g. Claude Code's Monitor) lost visibility of the inbound event stream while the SSH session kept running on the remote.

Full repro + diagnosis in #21.

Fix

Remove the trap override inside monitor(). The trap installed by cmd_connect (resume, join, host branches all set it) already reaps reminder_pid / flush_pid transitively via pgrep -P \$\$, so no replacement is needed. Keeps the invariant that the outer shell owns all cleanup.

Test plan

  • bash -n airc — syntax OK
  • Manual: currently running airc connect (resume) in an active session, fix is narrow (7 lines, comment + removed trap line)
  • ./test-two-instance.sh host/join roundtrip — requires port 7547 free; can't run while the active session holds it
  • ./test/integration.sh tabs — same

Shipping on the narrow diff. The semantics are a strict subset of the previous trap behaviour (pgrep -P \$\$ covers what the removed override covered, plus the SSH tail + formatter that were being leaked).

Fixes #21

monitor() was replacing the EXIT/INT/TERM trap that cmd_connect set up to
(a) remove $AIRC_WRITE_DIR/airc.pid and (b) reap ALL children via
pgrep -P \$\$. The override only killed reminder_pid + flush_pid, which
meant the SSH tail and Python monitor_formatter were leaked as orphans
whenever the outer shell exited — visible in ps as dangling subprocesses
with inbound events still flowing into the local messages.jsonl mirror
but no way for tools capturing airc's stdout to see them.

Reproduced via Claude Code's Monitor wrapper on 'airc connect' (resume
mode). Task tracker lost visibility of the event stream while the SSH
tail kept running on the host. Full writeup in #21.

The cmd_connect trap already handles everything — reminder_pid and
flush_pid are direct children of the shell, so pgrep -P \$\$ reaps them
transitively. No replacement needed inside monitor(); just preserve the
outer trap.

Fixes #21
@joelteply
joelteply merged commit 52dc388 into main Apr 19, 2026
1 check passed
@joelteply
joelteply deleted the fix/resume-foreground-wait branch April 19, 2026 16:23
joelteply added a commit that referenced this pull request Apr 20, 2026
Symptom: airc status reports monitor "running" while last_recv climbs
into the minutes. Messages stop being delivered. Teardown + airc connect
restores flow. Observed repeatedly on 2026-04-20, multiple times per
multi-hour session.

Root cause: SSH's ServerAliveInterval / ServerAliveCountMax only detects
"no ACKs to keepalives" — but some middleboxes / sleeping hosts silently
drop the TCP payload channel while still ACKing keepalives at the TCP
layer. SSH thinks the connection is healthy and doesn't close; the
remote tail -F keeps running but its output never reaches the local
ssh pipe. The local monitor_formatter's Python `for line in sys.stdin:`
blocks on read forever. Pipeline stays open, bash while-loop never
iterates, status check sees a live PID and reports "running."

Fix: application-level inactivity watchdog inside monitor_formatter.
If no line arrives in WATCHDOG_SEC (180s — longer than normal chat
idle, shorter than anyone's frustration threshold), Python exits
non-zero. The pipeline closes, ssh exits, the while-loop's `|| true`
catches it, sleep 3, reconnect. Clean restart.

Normal traffic resets the alarm on every inbound line — zero penalty
for healthy channels. A stderr line surfaces the event so operators
can see why the tail restarted, instead of the previous invisible
silent hang.

Pairs with #22 (trap preservation) as the two fixes needed to make
monitor_formatter robust across the long-tail of connection failures
that do NOT trigger SSH's built-in detection.
joelteply added a commit that referenced this pull request Apr 20, 2026
Symptom: airc status reports monitor "running" while last_recv climbs
into the minutes. Messages stop being delivered. Teardown + airc connect
restores flow. Observed repeatedly on 2026-04-20, multiple times per
multi-hour session.

Root cause: SSH's ServerAliveInterval / ServerAliveCountMax only detects
"no ACKs to keepalives" — but some middleboxes / sleeping hosts silently
drop the TCP payload channel while still ACKing keepalives at the TCP
layer. SSH thinks the connection is healthy and doesn't close; the
remote tail -F keeps running but its output never reaches the local
ssh pipe. The local monitor_formatter's Python `for line in sys.stdin:`
blocks on read forever. Pipeline stays open, bash while-loop never
iterates, status check sees a live PID and reports "running."

Fix: application-level inactivity watchdog inside monitor_formatter.
If no line arrives in WATCHDOG_SEC (180s — longer than normal chat
idle, shorter than anyone's frustration threshold), Python exits
non-zero. The pipeline closes, ssh exits, the while-loop's `|| true`
catches it, sleep 3, reconnect. Clean restart.

Normal traffic resets the alarm on every inbound line — zero penalty
for healthy channels. A stderr line surfaces the event so operators
can see why the tail restarted, instead of the previous invisible
silent hang.

Pairs with #22 (trap preservation) as the two fixes needed to make
monitor_formatter robust across the long-tail of connection failures
that do NOT trigger SSH's built-in detection.
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.

airc connect --resume: Monitor task exits silently, inbound notifications stop streaming while subprocesses live on

1 participant