Skip to content

fix(tailscale): set -e was silently aborting the logged-out prompt - #113

Merged
joelteply merged 1 commit into
canaryfrom
fix/tailscale-prompt-set-e-abort
Apr 26, 2026
Merged

joelteply merged 1 commit into
canaryfrom
fix/tailscale-prompt-set-e-abort

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Three sites where local out; out=$(tailscale status) was aborting under set -e because logged-out tailscale exits 1 — exactly the case we wanted to detect. Verified live by mocking tailscale-status: prompt now fires, 'Opening Tailscale.app' line confirms code path is reached.

I shipped tailscale_login_check_or_prompt + advise_tailscale_if_down
status checks using:
  local out; out=$("$ts_bin" status 2>&1)

`tailscale status` exits 1 when the node is Logged out — exactly the
state we want to detect. But `set -euo pipefail` at the top of airc
aborts on a failing $() assignment, so the function silently exited
BEFORE reaching the case-match that would have fired the prompt.
Detection passed unit-style tests because those used signed-in
Tailscale (rc=0, no abort) — the bug only manifested in the actual
target case.

Caught when Joel asked "you should just run it" and I mocked
tailscale to return Logged out — airc connect produced empty output
instead of the expected prompt. Verified the fix by re-running with
the same mock: the "⚠ Tailscale is installed but you're not signed
in" message now prints, plus "Opening Tailscale.app — sign in there",
and airc proceeds to host normally.

Three sites fixed:
- tailscale_login_check_or_prompt (the new startup nudge)
- advise_tailscale_if_down (the per-SSH joiner gate; same shape)
- host_address_set's tailscale-entry probe (same shape)

The pattern: wrap in if/else when rc matters
  (`if out=$(cmd 2>&1); then rc=0; else rc=$?; fi`)
or `|| true` when only the output matters.

Saving the lesson: `set -e` + `local x=$(failing-cmd)` is the
silent-abort that masks the entire reason you wrote the function.
Test the failure case explicitly, not just the success case.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings April 26, 2026 15:00
@joelteply
joelteply merged commit b09eadf into canary Apr 26, 2026
@joelteply
joelteply deleted the fix/tailscale-prompt-set-e-abort branch April 26, 2026 15:00

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

Fixes airc Tailscale detection/prompt logic so that set -e doesn’t prematurely exit when tailscale status returns a non-zero code in the “logged out” state.

Changes:

  • Wraps tailscale status capture in advise_tailscale_if_down with an if/else to preserve output and exit code under set -e.
  • Appends || true to tailscale status command substitutions in other call sites to prevent set -e aborts.
  • Adds inline comments documenting the set -e/non-zero-exit interaction and intent.

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

Comment thread airc
Comment on lines 413 to +417
local ts_bin; ts_bin=$(resolve_tailscale_bin)
local ts_status_out=""
local ts_status_rc=1
if [ -n "$ts_bin" ]; then
ts_status_out=$("$ts_bin" status 2>&1)
ts_status_rc=$?
# `set -e` aborts on `out=$(...)` if the command exits non-zero.

Copilot AI Apr 26, 2026

Copy link

Choose a reason for hiding this comment

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

resolve_tailscale_bin returns 1 when Tailscale isn't installed; with set -e a failing command substitution in ts_bin=$(resolve_tailscale_bin) can still abort the script before the later -z "$ts_bin" logic runs. Make this assignment non-fatal (e.g., append || true / redirect stderr like other callsites) so the "Tailscale is not installed" message can be reached.

Copilot uses AI. Check for mistakes.
Comment thread airc
Comment on lines +631 to 635
# set -e + non-zero exit on `tailscale status` (logged out) would
# abort. `|| true` is fine here — we only use the output.
local ts_out; ts_out=$("$ts_bin" status 2>&1) || true
case "$ts_out" in
*"Logged out"*|*"NeedsLogin"*) ;; # not signed in → no entry

Copilot AI Apr 26, 2026

Copy link

Choose a reason for hiding this comment

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

In host_address_set, tailscale status is allowed to fail via || true, but the rc is then ignored; if the daemon is down, the error output likely won't match Logged out/NeedsLogin, so the *) branch runs and the later tailscale ip -4 command substitution can still abort under set -euo pipefail. Capture/check the tailscale status exit code (like advise_tailscale_if_down) or ensure subsequent tailscale ip -4 is also made non-fatal and gated on a successful status.

Copilot uses AI. Check for mistakes.
Comment thread airc
local out; out=$("$ts_bin" status 2>&1)
# `set -e` at the top of airc aborts on a failed $() assignment.
# `tailscale status` exits 1 when logged out — exactly the case we
# WANT to detect. Trail with `|| true` so the rc doesn't kill us.

Copilot AI Apr 26, 2026

Copy link

Choose a reason for hiding this comment

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

Typo/wording: "Trail with || true" reads like a misspelling/grammar error; consider "Append || true" (or similar) to make the intent clearer.

Suggested change
# WANT to detect. Trail with `|| true` so the rc doesn't kill us.
# WANT to detect. Append `|| true` so the rc doesn't kill us.

Copilot uses AI. Check for mistakes.
joelteply added a commit that referenced this pull request Apr 26, 2026
fix(tailscale): just run `tailscale up` synchronously (cross-platform)

PR #112 used `open -a Tailscale` on Mac to surface the sign-in flow,
which brings up the GUI app's "Login Required" window with an extra
"Log In..." click before the actual auth URL appears. Joel: "I think
it could be simpler and more powershell friendly to do differently."

Pattern continuum already uses: just run `tailscale up`. The CLI prints
the auth URL straight to the user's terminal — where they're already
looking — and blocks until they authorize via the URL. Modern macOS
Terminal auto-links HTTPS URLs (cmd-click). Linux/Windows terminals
the same. No GUI middleman, no extra click.

Implementation:
- Bash tailscale_login_check_or_prompt and PS Test-TailscaleLoginOrPrompt
  drop the `open -a Tailscale` / "open browser to URL" code path.
- They run `tailscale up` synchronously, with `|| true` (bash) /
  try-catch (PS) so if the user cancels (Ctrl-C), airc continues.
- airc proceeds to host/join with whatever address set is currently
  reachable (same-machine and same-LAN paths still work even if user
  abandons Tailscale auth).
- Identical shape across both leaves. No bg jobs, no log-tailing, no
  URL extraction, no platform-specific browser launchers.

Verified locally with mock tailscale: prompt fires, mock-`tailscale up`
prints the URL, airc continues. Real mac+real Tailscale e2e was
verified by the prior fix #113; this just trims the surface.

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
joelteply added a commit that referenced this pull request Jul 2, 2026
…r door

The account-mesh rendezvous is now SELECTED, not hardcoded. `resolve_account_registry_store(choice, gist)` picks the AccountRegistryStore
for a RendezvousChoice and pairs it with the RegistryRefreshGate that
matches it — gist → GhAuth (hermetic + `gh auth status` probe), folder →
Always (no external auth to gate on). The daemon refresh loop runs against
the boxed store and never learns which door won.

`AIRC_RENDEZVOUS_DIR` set → the no-GitHub shared-folder door (on-prem /
behind-firewall); unset → the default gist door. Set-but-empty / non-UTF-8
fail loud rather than silently defaulting to gist (which would hide an
operator's misconfiguration). This is the substrate half of #18 — a fresh
clone auto-picks a working rendezvous with zero manual network ops.

Reuses RegistryRefreshGate::Always (no new gate variant needed) and the
FsAccountRegistryStore from #1284. Adds one delegating
`impl AccountRegistryStore for Box<dyn AccountRegistryStore>` so a boxed
store satisfies run_loop's generic `S: AccountRegistryStore` bound — SELECTION happens once at the seam. Rendezvous initiates the exchange; it
does not supply security (that stays E2E in the data plane), so a shared
folder is a legitimate peer of a gist. ORM-abstracted throughout: the
local cache rides SqliteEventStore, the folder door is plain JSON files —
zero raw SQL.

Tests (rendezvous.rs, one mod): env→choice contract (unset=gist,
path=folder, empty=fail-loud, no env mutation); folder door pairs Always +
the boxed store really writes a file into the share; gist door pairs GhAuth
carrying the given scope_home.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
joelteply added a commit that referenced this pull request Jul 2, 2026
… (auto-pick gist vs folder) (#1284)

* feat(account-registry): FsAccountRegistryStore — no-GitHub shared-folder rendezvous

Second, maximally-different AccountRegistryStore impl (outlier B) proving the
rendezvous seam is genuinely swappable: a shared folder (iCloud / Syncthing /
NFS mount) that N machines of one account see, needing no gh CLI, no token, no
network. This is the concrete "other means if gist went away" and the
on-prem/behind-firewall grid rendezvous (a hospital deploy can't reach GitHub).

Rendezvous initiates the exchange, it does not supply the security — that lives
in the E2E data plane (paired peer keys, trust tiers) regardless of which door a
node came through, exactly the Tailscale coordination-server shape.

Fidelity: byte-identical convergence to the gist store. Each machine writes ITS
document to a per-writer file (<dir>/<identity>/<writer_file>) so two machines
never clobber, and refresh reads every writer file and folds through the SAME
merge_registry_documents + prune_stale_peers core — the merge/freshness logic
stays in exactly one place.

- publish: validate → pretty JSON → atomic pid-temp write + rename (a concurrent
  refresh on another machine never reads a half-written doc)
- refresh: read every .json writer file (skips .tmp staging + OS cruft like
  .DS_Store/.icloud), fail loud on a corrupt writer file, merge, prune stale
- unpublished identity → Ok(None), not an error (mirrors gh's no-gist → None)

Tests (one mod, // what this catches): round-trip; the keystone
two_machines_sharing_a_folder_converge_via_merge (two writers, one shared dir,
distinct writer files → both peers merged, zero GitHub); unknown-identity → None.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

* feat(rendezvous): #113 selector seam — auto-pick gist vs shared-folder door

The account-mesh rendezvous is now SELECTED, not hardcoded. `resolve_account_registry_store(choice, gist)` picks the AccountRegistryStore
for a RendezvousChoice and pairs it with the RegistryRefreshGate that
matches it — gist → GhAuth (hermetic + `gh auth status` probe), folder →
Always (no external auth to gate on). The daemon refresh loop runs against
the boxed store and never learns which door won.

`AIRC_RENDEZVOUS_DIR` set → the no-GitHub shared-folder door (on-prem /
behind-firewall); unset → the default gist door. Set-but-empty / non-UTF-8
fail loud rather than silently defaulting to gist (which would hide an
operator's misconfiguration). This is the substrate half of #18 — a fresh
clone auto-picks a working rendezvous with zero manual network ops.

Reuses RegistryRefreshGate::Always (no new gate variant needed) and the
FsAccountRegistryStore from #1284. Adds one delegating
`impl AccountRegistryStore for Box<dyn AccountRegistryStore>` so a boxed
store satisfies run_loop's generic `S: AccountRegistryStore` bound — SELECTION happens once at the seam. Rendezvous initiates the exchange; it
does not supply security (that stays E2E in the data plane), so a shared
folder is a legitimate peer of a gist. ORM-abstracted throughout: the
local cache rides SqliteEventStore, the folder door is plain JSON files —
zero raw SQL.

Tests (rendezvous.rs, one mod): env→choice contract (unset=gist,
path=folder, empty=fail-loud, no env mutation); folder door pairs Always +
the boxed store really writes a file into the share; gist door pairs GhAuth
carrying the given scope_home.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

* feat(account-registry): #18 auto-trust — same-account beacons enrol OwnAccount

Import-time trust elevation (the "both, staged" model — get the simple
version working now, harden to handshake-gated after positron desktop).

When `import_account_registry_document` enrols a peer beacon carried in
OUR OWN account registry, it now routes the peer through `detect_tier`
and applies the result — same-mesh peers land `OwnAccount` instead of the
default `Untrusted`. That is the difference between "join to Asha across
machines just works" and an unusable peer that needs a manual `set-tier`.
Closes the auto-trust half of #18 (the enrolment/key-pinning half already
existed); `detect_tier` was built (card 34942ec1) but had zero callers.

Security: the elevation consults our REAL resolved mesh identity
(`self.mesh_identity()`), never the document's self-asserted
`mesh_identity` — a document vouching for its own identity would be
circular and let any imported document mint account trust for its peers.
A foreign-mesh document therefore leaves its peers `Untrusted` (key still
pinned, trust withheld). Vanished-row-after-add fails loud, matching the
endpoint-store guard directly below it.

Staged follow-up (#18 handshake-gate): keep this enrol at Untrusted and
elevate to OwnAccount only once the peer ALSO proves possession of the
pinned key in a live session — defense-in-depth so a compromised
rendezvous alone can't mint account trust.

Test `import_elevates_same_account_peer_but_not_a_foreign_document` covers
both the positive elevation and the foreign-mesh negative. 34 account-
registry tests pass; the 2 gh_stub failures are pre-existing/env-dependent
on the branch base, unrelated to this change.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

* fix(gh): isolate the gh governor per-test — kill gh_stub suite flakiness

The gh_stub store tests built their `GhAccountRegistryStore` via `store_at`,
which never called `.with_budget(...)` — so every store fell through to
`GhBudget::account_default()` = the REAL machine-wide `~/.airc/gh/` governor
state. Two consequences, both flaky under `cargo test` parallelism:

  1. A live `backoff-until` armed by a background airc daemon (or by real
     gh rate-limiting during CI pushes) denied every gh call in these tests
     with "shared gh backoff active for Ns" — 7 of 8 gh_stub tests failing
     on machines with an active governor, passing on a clean one.
  2. A gh_stub test that itself arms a backoff (rate-limit simulation)
     poisoned its siblings within the same run — hence the 8-pass-then-
     7-fail flip on consecutive runs.

Fix routes `store_at` through the isolation seam that already exists for
exactly this (`GhBudget::at`, doc'd "Used by tests for isolation"): root
the governor at the StubGh's per-test state dir. Rooted at the STUB (not
`db_dir`) so the multiple store instances one test builds — sentinel_loss's
first/reborn — coordinate on ONE governor, exactly as one machine would;
db_dir is per-store and would split them.

gh_stub suite now 8/8 across 5 consecutive runs (was flaky 1-8 passing);
full account_registry suite 39/39 (was 34 pass / 2 env-flaky fail). No
production path touched — this is test isolation only.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

---------

Co-authored-by: Claude Opus 4.8 (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