Skip to content

fix(install): single-source polyglot shim for Windows PATH - #545

Merged
joelteply merged 1 commit into
canaryfrom
fix/single-source-windows-shims
May 7, 2026
Merged

joelteply merged 1 commit into
canaryfrom
fix/single-source-windows-shims

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Summary

install.sh was symlinking the full canonical airc bash script to $BIN_DIR/airc. On real Linux/macOS the kernel resolves the symlink each invocation, so airc update propagates instantly. On Git Bash for Windows, ln -sf is silently a literal copy (Developer Mode is off by default), so the Windows PATH copy goes stale the moment airc update (run from WSL) refreshes the canonical clone.

That's how a 112KB May-5 copy of the full airc bash script sat at C:\Users\<user>\.local\bin\airc for weeks, while airc version (going through the .cmd shim) reported the up-to-date SHA. Claude Code's Monitor on Windows resolves airc via Git Bash's which, found the stale copy first, and silently ran months-old code — masking #538 / #541 / #542 / #543 entirely on the Monitor cold-start path.

Fix

Per Joel's directive (#543 follow-up):

Any Windows-visible airc on PATH must be a shim, not a copied full bash script. The shim should route to the canonical WSL install when WSL ~/.airc-src/airc exists. Native Windows fallback remains only when no WSL or AIRC_WINDOWS_NATIVE=1.

New file airc.shim — polyglot bash routing shim:

Step Condition Action
1 AIRC_DIR set + has airc exec that
2 We're in WSL ourselves (/proc/version says microsoft/wsl) exec $HOME/.airc-src/airc directly (no wsl.exe round-trip)
3 AIRC_WINDOWS_NATIVE=1 skip WSL branch
4 wsl.exe present + WSL canonical exists route via wsl.exe bash -lc "exec ... $quoted_args"
5 Native Windows clone at %USERPROFILE%\.airc-src exec that
6 otherwise loud failure with all attempted paths

Step 4 uses printf %q to inline args into the bash command string — wsl.exe bash -lc "<cmd>" arg1 arg2 does NOT forward those args to the inline script (same root-cause as #544; wsl.exe consumes them).

install.sh updated: on MINGW/CYGWIN/MSYS hosts, drop the polyglot shim into $BIN_DIR/airc + $BIN_DIR/relay instead of ln -sf'ing the full bash script. Also clean any pre-existing full-script copy left by prior installs (best-effort rm -f). Real Linux/macOS keeps the symlink — right tool there.

Verification

Tested all three invocation contexts on Windows + WSL2:

$ cmd /c "C:\Users\green\.local\bin\airc.cmd" version
  airc 4305b8e (dirty) on fix/single-source-windows-shims
  install: /home/joel/.airc-src

$ "C:\Program Files\Git\bin\bash.exe" -lc "which airc; airc version"
/c/Users/green/.local/bin/airc          # the shim
  airc 4305b8e (dirty) on fix/single-source-windows-shims
  install: /home/joel/.airc-src

$ wsl bash -lc "/mnt/c/Users/green/.local/bin/airc version"
  airc 4305b8e (dirty) on fix/single-source-windows-shims
  install: /home/joel/.airc-src

All three resolve to the WSL canonical clone. No more dual-clone drift.

Follow-up (out of scope here)

  • install.ps1 should also drop the polyglot shim at %USERPROFILE%\.local\bin\airc so Git Bash users who installed via the Windows-native path get a shim there too. Deferred to a separate PR.
  • Add scenario_windows_install_no_full_script_in_path integration test that fails if any PATH entry has a full bash airc script (>10KB) instead of a shim. Deferred to a separate PR.
  • Reproduced a separate _join_restart_scope_processes self-kill bug while testing this PR — when stale heartbeat triggers a restart, the running airc parent gets killed alongside the stale ones. Filing separately; not blocking this PR.

Related

🤖 Generated with Claude Code

Pre-fix `install.sh` line 451 used `ln -sf "$CLONE_DIR/airc"
"$BIN_DIR/airc"`. On real Linux/macOS this is a real symlink that the
kernel resolves to the canonical airc each invocation — `airc update`
propagates instantly.

On Git Bash for Windows, `ln -sf` is silently a literal COPY (Developer
Mode is off by default; Git for Windows can't make NTFS symlinks).
That's why a 112KB May-5 copy of the full airc bash script sat at
`C:\Users\<user>\.local\bin\airc` for weeks: every `airc update` (run
from WSL) refreshed `~/.airc-src/` on the WSL side, but the Windows
PATH copy stayed frozen. Claude Code's Monitor on Windows resolves
`airc` via Git Bash's `which`, found the stale copy first, and silently
ran months-old code while `airc version` (which goes through the .cmd
shim) reported the new SHA. Diagnosed today during the post-#543
Monitor-cold-start investigation.

Fix per Joel's directive (#543 follow-up):
  > Any Windows-visible airc on PATH must be a shim, not a copied full
  > bash script. The shim should route to the canonical WSL install
  > when WSL ~/.airc-src/airc exists. Native Windows fallback remains
  > only when no WSL OR AIRC_WINDOWS_NATIVE=1.

New file `airc.shim` — polyglot bash routing shim:

  1. AIRC_DIR explicit  → exec that
  2. We're in WSL ourselves → exec $HOME/.airc-src/airc directly
     (handles "user invokes /mnt/c/.../bin/airc from WSL bash")
  3. AIRC_WINDOWS_NATIVE=1  → skip WSL branch
  4. wsl.exe present + WSL canonical exists → route via wsl.exe
     (uses printf %q to forward args correctly — wsl.exe doesn't
     forward positional args after `-lc`, so they must be inlined
     into the bash command string. Same root cause as #544.)
  5. Native Windows clone at %USERPROFILE%\.airc-src → exec that
  6. Loud failure with all attempted paths

`install.sh` updated: on MINGW/CYGWIN/MSYS hosts, drop the polyglot
shim into BIN_DIR/airc + BIN_DIR/relay instead of `ln -sf`'ing the full
bash script. Also clean any pre-existing full-script copy left by
prior installs (best-effort `rm -f` is enough). Real Linux/macOS keeps
the symlink — that's the right tool there.

Verified locally on Windows + WSL2 (canary tip + this branch):
  - cmd /c airc.cmd version             → routes via wsl.exe → canonical
  - "C:\Program Files\Git\bin\bash.exe" airc version  → shim → canonical
  - wsl bash -lc /mnt/c/.../bin/airc version  → shim detects WSL → canonical

All three contexts hit the same canonical SHA. No more dual-clone
drift.

Follow-up — install.ps1 should also drop the polyglot shim at
%USERPROFILE%\.local\bin\airc so Git Bash users who installed via
the Windows-native path also get a shim instead of nothing on Git
Bash's default PATH. Deferred to a separate PR for review-scope
hygiene.

Related context:
  #542: airc.cmd direct cmd→bash (drop PowerShell hop)
  #543: dual-clone single-source — airc.cmd prefers WSL clone
  #544: airc.cmd args-forwarding (wsl.exe doesn't forward $@)
  THIS: extend single-source to ALL Windows-visible PATH copies,
        not just airc.cmd.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings May 6, 2026 21:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR prevents Windows PATH installations from drifting stale by ensuring Windows-visible airc entries are shims (not full-script copies) that route to the canonical WSL install when available.

Changes:

  • Update install.sh to install airc.shim into $BIN_DIR/{airc,relay} on MINGW/MSYS/CYGWIN instead of ln -sf’ing (which can degrade into a copy on Windows).
  • Add airc.shim, a bash routing shim that prefers AIRC_DIR, then WSL ~/.airc-src/airc (direct or via wsl.exe), then a native Windows clone fallback.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
install.sh Installs the new shim on Windows-like shells and keeps symlinks on Linux/macOS.
airc.shim New polyglot bash shim to route invocations to the live canonical install (WSL-first).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread install.sh
Comment on lines +468 to +469
[ -f "$BIN_DIR/airc" ] && rm -f "$BIN_DIR/airc" 2>/dev/null || true
[ -f "$BIN_DIR/relay" ] && rm -f "$BIN_DIR/relay" 2>/dev/null || true
Comment thread airc.shim
Comment on lines +70 to +72
if wsl.exe bash -lc 'test -x "$HOME/.airc-src/airc"' >/dev/null 2>&1; then
_quoted=$(_airc_quote_args "$@")
exec wsl.exe bash -lc "exec \"\$HOME/.airc-src/airc\"$_quoted"
Comment thread install.sh
Comment on lines +470 to +471
cp -f "$CLONE_DIR/airc.shim" "$BIN_DIR/airc"
cp -f "$CLONE_DIR/airc.shim" "$BIN_DIR/relay"
Comment thread install.sh
Comment on lines +464 to +472
if [ -f "$CLONE_DIR/airc.shim" ]; then
# Replace any pre-existing full-script copy that earlier installs
# might have left in PATH. Failing soft is fine — best-effort
# cleanup is enough to fix dual-install drift.
[ -f "$BIN_DIR/airc" ] && rm -f "$BIN_DIR/airc" 2>/dev/null || true
[ -f "$BIN_DIR/relay" ] && rm -f "$BIN_DIR/relay" 2>/dev/null || true
cp -f "$CLONE_DIR/airc.shim" "$BIN_DIR/airc"
cp -f "$CLONE_DIR/airc.shim" "$BIN_DIR/relay"
chmod +x "$BIN_DIR/airc" "$BIN_DIR/relay" 2>/dev/null || true
joelteply added a commit that referenced this pull request May 6, 2026
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
joelteply merged commit 5a2c5b9 into canary May 7, 2026
10 checks passed
@joelteply
joelteply deleted the fix/single-source-windows-shims branch May 7, 2026 02:22
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.

2 participants