Repository navigation
fix(attach): detach transport via setsid -f so Monitor exit does not kill it - #522
Merged
Merged
Conversation
…ill it Closes the third Windows blocker tracked on #511. After #518 (empty-value argparse) and #521 (--attach identity leak), Windows + Claude Code Monitor + `airc join --attach` still produced no working transport. `airc status` reported `airc process: not running` and `airc msg` refused with `monitor down` even though the canonical events ("Hosting as 'continuum-b69f'", "Found canonical gist") landed in the transport log. The transport-log mtime stops within a couple of seconds of the Monitor's `wsl bash -lc 'airc join --attach'` returning, exactly when SIGHUP would cascade through the launcher's pgroup. Root cause: `_join_spawn_transport_for_attach` started the transport as `( ... ) >>"$_log" 2>&1 &` — same session and pgroup as the launcher bash. On Windows, the launcher is the controlling-terminal session leader; when it returns, the kernel SIGHUPs the entire pgroup. The transport bash + airc_core.handshake accept_one + bearer_cli recv loops + reminder_timer_loop + _mesh_rediscover_loop all die before they ever write `airc.pid`. Foreground bash on Linux/Mac doesn't hit this because the user's interactive shell stays alive holding children open. (See the post-65adceb retest in #511 — transport-log frozen at "Found canonical gist", no fresh writes for 12+ hours.) Fix: detach the transport into a new session+pgroup with `setsid -f` on systems where it's available. The kernel-cascade SIGHUP from launcher exit no longer reaches the transport. Watchdog reworked to rely solely on the `airc.pid` file (written by airc itself once the transport reaches the bearer-spawn point); `setsid -f` returns 0 immediately after fork, so `$!` is no longer a useful liveness signal. Verified end-to-end on Windows 11 + WSL2 + Claude Code Monitor: $ airc join --attach (via Monitor) $ pgrep -af airc 30211 /bin/bash /home/joel/.airc-src/airc join 30584 ...handshake accept_one ... 30591 ...bearer_cli recv ... $ airc status airc process: AIRC background process running for scope (PID 30211) $ airc msg --channel general "..." → #general (broadcast) Pre-fix: same sequence produced zero airc processes after Monitor's bash returned. Fallback: AIRC_NO_DETACH=1 forces the inline `( ... ) &` form for harness tests that want to reap the transport via the parent process tree. macOS where setsid may be missing falls back to the inline form automatically (Mac doesn't hit the SIGHUP cascade because the launcher shell is foreground and stays alive). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR hardens airc join --attach so the scope-local transport can outlive the launcher shell, which targets the Windows/WSL Monitor failure reported in #511.
Changes:
- Reworks attach startup to prefer a detached
setsid -flaunch, with a HUP-ignoring fallback path. - Switches the attach watchdog to rely on
airc.pidreadiness instead of the launcher job PID when detaching. - Adds extra
--attachscrubbing so recursivejoincalls do not leak the flag into positional target/name parsing.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+272
to
+276
| if [ "${AIRC_NO_DETACH:-0}" != "1" ] && command -v setsid >/dev/null 2>&1; then | ||
| setsid -f env AIRC_NO_ATTACH=1 AIRC_BACKGROUND_OK=1 \ | ||
| "$AIRC_SELF" join \ | ||
| ${_spawn_args[@]+"${_spawn_args[@]}"} \ | ||
| >>"$_log" 2>&1 |
Comment on lines
+272
to
+276
| if [ "${AIRC_NO_DETACH:-0}" != "1" ] && command -v setsid >/dev/null 2>&1; then | ||
| setsid -f env AIRC_NO_ATTACH=1 AIRC_BACKGROUND_OK=1 \ | ||
| "$AIRC_SELF" join \ | ||
| ${_spawn_args[@]+"${_spawn_args[@]}"} \ | ||
| >>"$_log" 2>&1 |
Comment on lines
+233
to
+260
| # Approach: ignore SIGHUP in the subshell BEFORE exec'ing airc-self. | ||
| # POSIX semantics: a process started with SIGHUP set to SIG_IGN keeps | ||
| # SIG_IGN across exec() AND across fork() — every grandchild | ||
| # (handshake accept_one, bearer_cli recv loops, reminder timer, | ||
| # rediscover loop) inherits the same disposition unless it explicitly | ||
| # installs its own handler. Python's runtime resets SIG_DFL for many | ||
| # signals but PRESERVES SIG_IGN for SIGHUP unless code overrides it, | ||
| # so the python sidecars survive too. | ||
| # | ||
| # This keeps the watchdog at the bottom of the function intact: | ||
| # `kill -0 "$_transport_pid"` still tracks the wrapper subshell, and | ||
| # `_monitor_alive_with_bearer_fallback` reads airc.pid which airc | ||
| # writes after spawn. Both stay valid because the subshell does | ||
| # survive the parent shell's exit now. | ||
| # | ||
| # Mac's existing path doesn't hit this because Mac's launcher is a | ||
| # foreground bash that holds children alive until the user closes the | ||
| # tab — the subshell never receives SIGHUP. The trap is harmless | ||
| # there. | ||
| # Detach the transport into its own session+pgroup so SIGHUP from the | ||
| # launcher's session leader exit doesn't cascade. On Windows + Claude | ||
| # Code Monitor (`wsl bash -lc 'airc join --attach'`) the launcher | ||
| # bash is the controlling-terminal session leader; when it returns, | ||
| # kernel SIGHUPs the entire pgroup. `setsid -f` forks the transport | ||
| # into a new session AND a new pgroup AND disconnects it from the | ||
| # controlling terminal — the kill-all-on-launcher-exit semantics no | ||
| # longer apply. | ||
| # |
Contributor
Author
|
Codex review/update:
Local validation on Mac after the comment cleanup:
Waiting on CI rerun. If green, I think #522 is canary-mergeable. After canary merge, promotion validation should require named markers from Windows, Mac Claude tabs, and Codex, plus status/health output from each real scope. |
This was referenced May 5, 2026
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.
Closes the third Windows blocker on #511
After #518 cleared the empty-value argparse crash and #521 fixed the
--attachidentity leak, Windows + Claude Code Monitor +airc join --attachstill produced no live transport.airc statusreportedairc process: not running,airc msgrefused withmonitor down, and the transport log mtime froze at "Found canonical gist" — exactly when SIGHUP would cascade.Root cause
_join_spawn_transport_for_attachspawned via( ... ) >>"$_log" 2>&1 &— same session + pgroup as the launcher bash. On Windows, the Monitor'swsl bash -lc 'airc join --attach'is the controlling-terminal session leader; when it returns, the kernel SIGHUPs the entire pgroup. Every child in the join tree (handshake accept_one, bearer_cli recv loops, reminder_timer_loop, _mesh_rediscover_loop) dies beforeairc.pidis ever written. Foreground bash on Mac doesn't hit this because the user's interactive shell stays alive holding children open.Fix
Detach the transport into a new session + pgroup with
setsid -f. Kernel-cascade SIGHUP from the launcher's pgroup no longer reaches the transport. Watchdog reworked:setsid -freturns 0 immediately after fork so$!is no longer useful —airc.pidwritten by airc itself is the canonical liveness signal.Verified end-to-end on Windows 11 + WSL2 + Claude Code Monitor
Pre-fix: same sequence produced zero airc processes after Monitor's bash returned.
Test plan
airc join --attachkeeps working — setsid path used (transport still survives correctly), or AIRC_NO_DETACH=1 revertsbash -nalready passes; existing integration tests don't simulate launcher exit so they should be unaffected. A test for "transport survives parent exit" would need a separate harness — happy to add if codex points at where to plug in.🤖 Generated with Claude Code