Skip to content

join: expose transport during attach cold start - #541

Merged
joelteply merged 1 commit into
canaryfrom
codex/attach-startup-owner
May 6, 2026
Merged

joelteply merged 1 commit into
canaryfrom
codex/attach-startup-owner

Conversation

@joelteply

@joelteply joelteply commented May 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • write startup transport evidence (airc.pid) before slow discovery/bootstrap work
  • create messages.jsonl before attach so Monitor/log-tail can attach immediately
  • make attach stream tolerate pre-init config by falling back to a generic self name
  • add regression for slow attach cold-start before final host/join pidfile rewrite

Tests

  • bash -n airc lib/airc_bash/cmd_connect.sh test/integration.sh
  • ./test/integration.sh attach_starts_background_transport
  • ./test/integration.sh attach_spawn_strips_attach_flag
  • ./test/integration.sh attach_reports_starting_transport
  • ./test/integration.sh codex_join_detaches_transport
  • ./test/integration.sh codex_join_idempotent_when_healthy
  • ./test/integration.sh monitor_gone_gist_stops_respawn
  • ./test/integration.sh send_gone_gist_does_not_claim_delivery
  • ./test/integration.sh python_units

Copilot AI review requested due to automatic review settings May 6, 2026 19:17
@joelteply
joelteply merged commit 5da9c4c into canary May 6, 2026
8 checks passed
@joelteply
joelteply deleted the codex/attach-startup-owner branch May 6, 2026 19:18

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 improves airc join --attach cold-start behavior by making the background transport discoverable/attachable earlier (before slower discovery/bootstrap steps), primarily to avoid “not running” false negatives during startup (notably on Windows/WSL Monitor flows).

Changes:

  • Emit early “startup transport ownership” evidence (create messages log + write airc.pid) before discovery/bootstrap work begins.
  • Allow attach log-tail to run even when config/name is not yet initialized by using a precomputed tail name.
  • Add an integration regression scenario to ensure attach sessions can connect promptly during slow startup.

Reviewed changes

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

File Description
lib/airc_bash/cmd_connect.sh Writes early pidfile/messages evidence prior to slow bootstrap and adjusts attach log-tail naming behavior.
test/integration.sh Adds a regression scenario asserting attach can connect while transport is still in delayed startup.

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

_airc_startup_rc=$?
rm -f "$AIRC_WRITE_DIR/airc.pid" 2>/dev/null
exit $_airc_startup_rc
' EXIT INT TERM
Comment on lines +292 to +296
local _tail_name; _tail_name=$(get_name 2>/dev/null || echo "airc")
if [ -n "$_client_id" ]; then
AIRC_CLIENT_ID="$_client_id" exec "$AIRC_PYTHON" -u -m airc_core.log_tail --home "$AIRC_WRITE_DIR" --my-name "$(get_name)"
AIRC_CLIENT_ID="$_client_id" exec "$AIRC_PYTHON" -u -m airc_core.log_tail --home "$AIRC_WRITE_DIR" --my-name "$_tail_name"
else
exec "$AIRC_PYTHON" -u -m airc_core.log_tail --home "$AIRC_WRITE_DIR" --my-name "$(get_name)"
exec "$AIRC_PYTHON" -u -m airc_core.log_tail --home "$AIRC_WRITE_DIR" --my-name "$_tail_name"
exit $_airc_startup_rc
' EXIT INT TERM
if [ -n "${AIRC_TEST_STARTUP_DELAY_SEC:-}" ]; then
sleep "$AIRC_TEST_STARTUP_DELAY_SEC"
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 added a commit that referenced this pull request May 7, 2026
`wsl.exe sh -lc "<script>" airc %*` does NOT forward the positional
args to the inline script as $0, $1, $@. wsl.exe consumes them itself,
so `$@` inside the script was always empty and `airc.cmd join` ended
up running `exec airc` with no verb. airc fell through to the generic
help banner and exited 0; Claude Code's Monitor on Windows saw airc
print help and silently terminate before any transport spawned.

Symptom from Windows trace just now (`airc.cmd version`): printed
the help banner instead of `airc <sha> on canary`. Same shape was
hiding behind the post-takeover "no existing room — fresh start"
death window: the Monitor's airc.cmd → wsl.exe → sh -lc invocation
was never actually running `airc join`; it was running airc with
no args, which prints help and exits.

Fix:

1. Inline cmd's %* directly into the bash command string, so
   positional args are part of the script string before wsl.exe
   sees them — bypassing the silent arg-drop.
2. Use `bash -lc` (matches the airc script's #!/bin/bash shebang)
   instead of `sh -lc` (dash on Ubuntu). Avoids subtle sh/dash
   parser divergence on the same wire shape.

Verified locally:

  $ cmd /c airc.cmd version
    airc <sha> on canary
    Merge pull request #543 ...
    install: /home/joel/.airc-src

Pre-fix the same command printed help.

Related context for the Windows Monitor cold-start surface:
  #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 — Windows shim prefers WSL clone
  THIS: #543 made the WSL-routing path correct in shape but
        broke arg-forwarding in implementation.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
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