Skip to content

Protect attach startup grace - #516

Merged
joelteply merged 1 commit into
canaryfrom
codex/protect-attach-startup-grace
May 5, 2026
Merged

joelteply merged 1 commit into
canaryfrom
codex/protect-attach-startup-grace

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Summary

  • stop airc join --attach calls from killing each other while a live transport is still starting
  • if transport health is degraded only with starting; no heartbeat yet and the pidfile is within AIRC_STARTUP_GRACE_SEC (default 45s), treat the process as startup-in-progress and attach instead of restarting
  • still restart true stale cases (stale heartbeat, stale bearer pid, or outside the grace window)

Observed after #514/#515 Mac destructive validation: multiple Claude attach tabs could race. One starts a valid background transport, another sees DEGRADED ... starting; no heartbeat yet and restarts the scope, producing Terminated: 15 loops and killing the Monitor foreground. This patch makes startup idempotent.

Tests

  • bash -n lib/airc_bash/cmd_connect.sh airc test/integration.sh
  • git diff --check
  • bash test/integration.sh attach_starts_background_transport

Follow-up from #511/#514/#515 validation.

Copilot AI review requested due to automatic review settings May 5, 2026 05:49
@joelteply
joelteply merged commit 33dc6a7 into canary May 5, 2026
8 checks passed
@joelteply
joelteply deleted the codex/protect-attach-startup-grace branch May 5, 2026 05:51

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 makes airc join --attach startup idempotent by preventing concurrent attach invocations from restarting (and killing) a scope’s background transport while it is still in the “starting; no heartbeat yet” window. It does this by treating a degraded transport-health result as “startup-in-progress” if the scope pidfile is sufficiently fresh (within AIRC_STARTUP_GRACE_SEC, default 45s), while still restarting truly stale cases.

Changes:

  • Add _join_transport_in_startup_grace to detect “startup-in-progress” based on pidfile mtime + transport_health output.
  • Replace the prior boolean --quiet health probe with a captured-output health check, enabling attach-vs-restart decisions and better diagnostics.

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

Comment on lines +513 to +517
if [ "$_health_rc" != "0" ] && _join_transport_in_startup_grace "$_health_out" "$_early_pidfile"; then
local _early_pids; _early_pids=$(cat "$_early_pidfile" 2>/dev/null | tr '\n' ' ')
echo " airc join: AIRC process is still starting in this scope (AIRC PIDs: $_early_pids)."
printf '%s\n' "$_health_out" | sed 's/^/ /' || true
_join_show_status_and_inbox
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