Repository navigation
fix(connect): _join_restart_scope_processes must not kill self - #546
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes a join/self-heal regression where _join_restart_scope_processes could SIGTERM the currently running airc process after _reexec_into host (because airc.pid may contain the current PID).
Changes:
- Add a PID self-filtering pass in
_join_restart_scope_processesto exclude$$and$PPIDbefore issuing kill signals.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+192
to
+196
| case "$_candidate" in | ||
| ''|*[!0-9]*) continue ;; | ||
| esac | ||
| [ "$_candidate" = "$$" ] && continue | ||
| [ "$_candidate" = "$PPID" ] && continue |
Comment on lines
+179
to
+188
| # Self-kill guard. After `_reexec_into host` the new airc inherits | ||
| # the same PID — `airc.pid` written by the pre-exec instance now | ||
| # names US. Without this filter, the kill loop below SIGTERM's its | ||
| # own shell and the running airc dies right after printing | ||
| # "AIRC process exists but transport is degraded; restarting this | ||
| # scope's AIRC process." Observed live during Windows Monitor | ||
| # post-takeover host-setup window: shim correctly routed to the | ||
| # canonical clone, airc detected stale prior heartbeat from a | ||
| # crashed predecessor, called this function — and exit 1'd because | ||
| # airc.pid contained $$. _join_scope_transport_pids already excludes |
Pre-fix this function was the last self-killer in the join cold-start
path. Three failure shapes combine — fixing only one was insufficient:
(1) Same-PID self-kill after re-exec. After `_reexec_into host`,
the new airc inherits the SAME pid as the pre-exec instance.
airc.pid (written early per #541) names US. Without filtering
$$/$PPID, the kill loop SIGTERM'd its own shell. Defensive
pattern already exists in _join_scope_transport_pids:211 — was
never propagated to airc.pid contents until now.
(2) OS PID recycling. The other PID sources (airc.pid contents from
a crashed predecessor, bearer_gist.*.pid stragglers) can name
a slot the kernel has since reassigned to an unrelated process
— including, on Windows WSL2, the parent wsl.exe / cmd.exe
shell in our launcher chain. Killing one of those takes Claude
Code's Monitor down with us. Joel hit this exact shape in #97 /
#446 in different code paths; the fix there ("verify cmdline
before treating PID as ours") was never propagated here.
(3) set -e + pipefail kills the whole airc on best-effort PID
assembly. The function uses `proc_airc_pids_matching` (pgrep)
which exits 1 when no matches. Pipefail propagates the 1
through `pgrep | tr`, the simple var assignment then triggers
set -e, and airc dies between debug-instrumented "step1" and
"step2" markers — never reaching the kill loop, never returning
from the function. This was the residual death point that
made my earlier $$ filter alone look ineffective. Joel's
"Codex and Claude usually miss the obvious" call applies.
Fix:
Layer 1 — drop $$ and $PPID from the candidate list.
Layer 2 — verify cmdline matches airc/airc_core before killing,
so an OS-recycled PID owned by an unrelated process is
never targeted.
Layer 3 — wrap each substitution in `|| true` so pipefail can't
propagate pgrep's empty-result-1 into a fatal var
assignment.
Verified end-to-end on Windows + WSL2 (with #544 + #545 also applied
locally). Monitor's `airc join` flow:
shim → wsl.exe → canonical airc → join → discover → take over
→ re-exec to host mode → trust-existing-monitor short-circuit
→ degraded transport detected → _join_restart_scope_processes
→ filters $$ (PID 57724) + dead bearer pids 80413/38943
→ all candidates dropped, kill loop empty, function returns
→ host setup completes through "Hosting #cambriantech (gh-account
substrate)" → "Monitoring for messages..." → broadcast contract
banner → mesh send confirmed bidirectional.
After: Windows Claude Code Monitor `airc join` finally completes
the cold-start path without Joel relay.
Related — Windows Monitor cold-start surface trail:
#533 SIGHUP cascade (transport detach via setsid -f)
#538 monitor 404-gone gist treated as terminal
#541 airc.pid + messages.jsonl created before slow bootstrap
#542 airc.cmd direct cmd→bash (drop PowerShell hop)
#543 dual-clone single-source (airc.cmd prefers WSL)
#544 airc.cmd args-forwarding (wsl.exe doesn't forward $@)
#545 polyglot shim for Windows-visible PATH (single source)
THIS three-layer self-protect on the supervisor restart path.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
joelteply
force-pushed
the
fix/restart-scope-no-self-kill
branch
from
May 6, 2026 22:22
890f73c to
8c48de3
Compare
This was referenced May 7, 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.
Summary
_join_restart_scope_processes(lib/airc_bash/cmd_connect.sh:167) read PIDs fromairc.pidand helpers and killed every one without filtering out$$/$PPID. After_reexec_into host, the new airc inherits the same pid as the pre-exec instance, soairc.pid(written by the pre-exec airc with$$) now names us. The kill loop SIGTERM'd its own shell and the running airc died exit 1, right after printing:How it surfaced
Observed live on Windows Monitor once #545's polyglot shim correctly routed Monitor's
airc jointo the canonical clone (same SHAairc versionalready reported, but Monitor was running stale code via Git Bash's PATH-resolved full-script copy). Fresh airc detected stale prior heartbeat from a crashed predecessor, called this function — and exit 1'd becauseairc.pidcontained$$.Note:
_join_scope_transport_pids(line ~199) already excludes$$/$PPID(line 211-212). Theairc.pidcontents path simply wasn't filtered in the same way until now.Fix
Add a self-filter pass before the kill loop:
Applied at the consolidated entry point so all four PID sources (
airc.pid,_airc_scope_monitor_formatter_pids,bearer_gist.*.pid,_join_scope_transport_pids) are protected uniformly.Verification
After deploying both #545 (polyglot shim) and this fix locally:
airc joinreaches the supervisor's restart-degraded-transport branch80413,38943) — not the running airc parentRelated — Windows Monitor cold-start surface trail
$@)After all of these, the Windows Monitor
airc joinflow finally completes:shim → wsl.exe → canonical airc → join → discover → take over → re-exec to host → detect stale prior state → restart scope (kills OLD pids, not us) → host setup → heartbeat loop → Monitor stays alive.🤖 Generated with Claude Code