Repository navigation
fix(monitor): don't override cmd_connect trap — fixes #21 orphaned SSH tail + Python formatter - #22
Merged
Merged
Conversation
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
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.
2 of 3 tasks
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.
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.
Summary
monitor()was overriding the EXIT/INT/TERM trap thatcmd_connecthad set up to clean upairc.pidand reap every child viapgrep -P \$\$. The override only killedreminder_pidandflush_pid, leaving the SSH tail and Pythonmonitor_formatteras orphans whenever the outer shell exited. Tools wrappingairc 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
trapoverride insidemonitor(). The trap installed bycmd_connect(resume, join, host branches all set it) already reapsreminder_pid/flush_pidtransitively viapgrep -P \$\$, so no replacement is needed. Keeps the invariant that the outer shell owns all cleanup.Test plan
bash -n airc— syntax OKairc connect(resume) in an active session, fix is narrow (7 lines, comment + removed trap line)./test-two-instance.shhost/join roundtrip — requires port 7547 free; can't run while the active session holds it./test/integration.sh tabs— sameShipping 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