Skip to content

feat(sos): airc sos verb — out-of-band coordination channel of last resort (#7) - #1289

Merged
joelteply merged 1 commit into
canaryfrom
08ee47a4/self-heal-7-airc-sos-verb-send-watch-sta
Aug 13, 2026
Merged

joelteply merged 1 commit into
canaryfrom
08ee47a4/self-heal-7-airc-sos-verb-send-watch-sta

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

What

Formalizes the improvised GitHub-gist-comment backup channel (used all through the self-healing work when the wire couldn't route) into a first-class verb. One account-scoped gist's comment thread; works whenever gh works — exactly when the airc wire is down.

  • airc sos send <msg> — post [LABEL] msg; find-or-create the gist (marker airc-account-sos, seeded protocol doc), sentinel-cached.
  • airc sos watch [--follow] — surface new PEER comments, self-filtering our own label (+ id cursor). Agent mode: poll-print-exit; --follow: stream.
  • airc sos status — gist id + url + recent comments.

Reuse / discipline

Shares the machine-wide gh governor (gh_state), mirrors account_registry's find-or-create-by-marker + sentinel, and the filter.rs self-echo concept. Fails LOUD (every gh failure → specific Err; the sole exception is --follow tolerating a transient blip). Discovery paginates so a 100+-gist account can't spawn a duplicate.

Validation

Build + both clippy gates + 9 unit tests green on windows-msvc AND Linux. Live-tested: sos send created the account gist + posted [BIGMAMA], sos status renders the channel. Functional validation is the joint wire-down dogfood with the M5 node (in progress).

🤖 Generated with Claude Code

…esort (#7)

Formalizes the improvised GitHub-gist-comment backup channel into a first-class
verb. When the airc wire can't route (blind rooms, stale peers, dead dials) but
`gh` still works — exactly when we need it — agents coordinate recovery over ONE
account-scoped gist's comment thread.

- `airc sos send <msg>`  — post a `[LABEL] msg` comment; finds-or-creates the
  gist (marker `airc-account-sos`, seeded with a self-describing protocol doc),
  cached via a local sentinel.
- `airc sos watch [--follow]` — surface new PEER comments, self-filtering our own
  label (+ an id cursor) so we never echo our own posts. Agent mode: one poll,
  print, exit (harness re-invokes); `--follow`: stream for a human.
- `airc sos status` — gist id + url + recent comments.

Reuse (one-source-of-truth): shares the machine-wide gh governor
(`gh_state::reserve_guarded_request`/`record_backoff`), mirrors
`account_registry`'s find-or-create-by-marker + sentinel shape, and the
`filter.rs` self-echo CONCEPT (label-prefix predicate). Fails LOUD — every gh
failure returns a specific Err (a broken backup channel must be visible); the one
exception is the `--follow` loop tolerating a transient blip. Machine label from
COMPUTERNAME/HOSTNAME/hostname → normalized, fallback `<os>-<peerid8>`. Discovery
paginates so a 100+-gist account can't spawn a duplicate.

Validated build + clippy (both gates) + 9 unit tests on windows-msvc AND Linux.
Functional validation is the joint wire-down dogfood with the M5 node.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc
@joelteply
joelteply force-pushed the 08ee47a4/self-heal-7-airc-sos-verb-send-watch-sta branch from 6053f13 to ff681f4 Compare July 24, 2026 01:04
joelteply added a commit that referenced this pull request Jul 24, 2026
* feat(self-heal): atomic stamped endpoint replace — a fresher advertisement fully replaces, a staler one is refused

M5↔bigmama live repro #2: a registry re-sync took a peer's new IP but
kept its stale port, dialing a dead endpoint forever. Root cause: the
stored endpoint set had no freshness, so nothing could order an old
advertisement against a new one, and merge-backfilled stale endpoints
could ride a fresh presence into the store.

- peer_trust gains endpoints_advertised_at_ms (additive nullable
  migration; NULL floors to 0 so any stamped ad outranks legacy rows).
- set_peer_trust_endpoints now writes endpoints + stamp atomically and
  replaces monotonically: staler stamp = whole write refused.
- AccountPeerBeacon carries endpoints_advertised_at_ms (serde-default,
  old documents keep decoding); publishers stamp at generation; the
  reader-side merge backfill keeps the CARRIER's stamp so stale
  endpoints never masquerade as fresh; import clamps the peer-asserted
  stamp to now (same doctrine as the last_seen security clamp).

Tests:
- sqlite: fresher_advertisement_atomically_replaces_endpoints_and_staler_is_refused
- sqlite: replace_peer_trust_preserves_stored_endpoints now pins the stamp too
- account_registry: import_fresher_advertisement_fully_replaces_endpoint_and_stale_is_refused
  (the exact (ip1,port1)->(ip2,port2) regression + stale replay + fresh-presence/stale-endpoints composite)
- account_registry: merge_retains_endpoints_when_fresher_beacon_is_endpointless now pins carrier-stamp backfill

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

* feat(self-heal): refresh-on-failure — a failed dial re-reads the rendezvous before any blind retry

M5↔bigmama live repro #1: after a daemon restart, the remote peer kept
dialing the dead port (.249:58842 vs live .249:57958) forever, never
re-reading the rendezvous.

- Airc::heal_failed_dials(store, failures): record the failed peers'
  stored endpoint sets, do ONE rendezvous re-read + import (atomic +
  monotonic per the item-1 stamp, so it can never make things worse),
  and re-dial ONLY when a failed peer's endpoints actually changed —
  through the one pinned dial path (cost order, quarantine skips, stop
  on first success). No fresher endpoint = no extra dial pass: the
  dial-quarantine backoff (15s→120s) keeps owning the dead endpoint's
  retry cadence, so this is bounded by construction.
- Daemon wiring: the registry task shares its ONE resolved rendezvous
  (store + gate) via an Arc<OnceLock> slot; refresh_routes_once heals
  after emitting dial-failure diagnostics, honoring the same gh/hermetic
  gate as registry ticks, and the healed snapshot feeds the connected
  count + relay self-election.
- New Arc<dyn AccountRegistryStore> delegating impl (mirrors Box) so
  one resolved door serves both loops without a second resolution.

Test: stored_endpoint_dial::heal_failed_dials_rereads_rendezvous_and_dials_fresh_endpoint
(stub AccountRegistryStore rendezvous — unchanged rendezvous heals
nothing; fresh advertisement is imported, replaces the corpse, and the
live endpoint is dialed immediately).

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

* feat(self-heal): publish-on-bind — a freshly bound listener propagates to the rendezvous immediately

M5↔bigmama live repro #1 (the propagation half): a daemon restart that
lands on a new port only advertised it at the refresh loop's first
cadence tick, leaving every peer dialing the dead port meanwhile.

- Registry task nudges endpoint_resync the moment listen_lan_advertising
  binds; Notify stores the permit, so the refresh loop's biased select
  publishes IMMEDIATELY on start instead of waiting out first_tick.
  Idempotent: an unchanged advertisement republishes the same document.
- Relay self-election (become_relay binds a listener too) now nudges the
  same resync so the new relay endpoint propagates without waiting up to
  a full 120s cadence.
- (IP-move rebinds were already edge-triggered via
  refresh_advertised_endpoints Ok(true) — this closes the two bind
  sites that were not.)

Test: registry_refresh::pre_loop_resync_permit_publishes_immediately_not_at_first_tick
(first_tick/cadence at 3600s — only the stored permit can publish in
time; pins the Notify-permit-before-loop-start contract).

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

* feat(self-heal): advertise hygiene — never-correct addresses and known-peer collisions are refused (and withdrawn)

M5↔bigmama live repro decay modes #3 and #4: Docker containers
advertised internal bridge IPs (172.x) as reachable endpoints — dozens
of 3s dial timeouts per refresh across every peer — and one peer record
carried the reader's OWN Tailscale IP as another machine's endpoint.

- ONE hygiene predicate pair in airc-lib (lan_advertise_rejection /
  tailscale_advertise_rejection): loopback, unspecified, link-local
  169.254/16, the 172.16/12 docker/bridge band, and CGNAT-on-the-LAN-
  rung are never advertised; the Tailscale rung only carries 100.64/10.
  RFC1918 10/8 + 192.168/16 (en0-style) and public addresses pass. The
  172.16/12 refusal is by RANGE (the UDP source-address detection has
  no ifname) — per the live evidence that band is never correct on
  this mesh, and such a host still advertises its Tailscale rung.
- Known-peer collision guard: an endpoint equal to a KNOWN other
  peer's stored endpoint is refused loudly — advertising it would
  extend the corrupted-record chain onto the rendezvous.
- Applied at BOTH advertise seams (listen_lan_advertising and the
  per-tick refresh_advertised_endpoints): a rejected IP reads as None,
  so an already-poisoned advertised rung is WITHDRAWN on the next tick
  (self-heal), edge-triggering a corrected registry publish.
- CLI detection (detect_lan_ip / is_tailscale_ipv4) now delegates to
  the same one predicate — detection and advertisement can't drift.

Tests (lan.rs): advertise_hygiene_rejects_never_correct_classes_and_admits_real_lans,
refresh_withdraws_a_poisoned_advertised_bridge_ip,
refresh_refuses_to_advertise_a_known_peers_address.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

* feat(self-heal): failure-counted eviction — 5 consecutive dial failures mark an endpoint DEAD until a fresher advertisement

M5↔bigmama live repro decay mode #4 (the reader side): dozens of stored
172.x ghost endpoints burned a 3s timeout each on every discovery
refresh, forever — timed backoff alone caps at 120s and never gives up.

- DialQuarantine entries now carry a consecutive-failure streak and the
  endpoint-set freshness stamp the failures accrued under. New
  DialGate verdict: Dial / Backoff{remaining_ms} / Dead{count}.
  DEAD_AFTER_CONSECUTIVE_FAILURES = 5 (spans several backoff windows,
  so a flapping endpoint recovers long before eviction).
- Dead = evicted from the dial set (record kept, endpoint skipped even
  after every backoff window elapses). Revival: a STRICTLY fresher
  advertisement stamp (item 1's endpoints_advertised_at_ms, plumbed
  per-peer through dial_stored_peer_endpoints) lifts the eviction for
  ONE probe; a failure under the fresher stamp re-kills immediately —
  so a live-but-unreachable publisher costs at most one 3s dial per
  fresh advertisement, and a genuinely revived daemon (same stable
  port, fresh ad) reconnects on the first probe. The retention sweep
  (10min idle) stays the bounded second-chance horizon.
- Dead skips surface distinctly: PeerDialSkip.dead=true, and
  'airc transport health' prints 'endpoint dead: … evicted after 5
  consecutive failed dials; revived only by a fresher advertisement'
  instead of a misleading countdown.

Test: dial_quarantine::fifth_consecutive_failure_is_dead_until_a_fresher_advertisement
(dead after backoff expiry, not-dead below threshold, fresher-stamp
one-probe revival + immediate re-kill, success wipes the streak).
Also: peer_dials_lan_rung_and_skips_tailscale updated — the advertise
hygiene now rightly refuses loopback as a LAN advertisement, so the
dial-ladder test builds its imported endpoint set directly.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

* feat(self-heal): airc dial <host:port> — manual authenticated recovery dial

The hands-on override for a wedged mesh (M5↔bigmama live repro): one
authenticated dial both proves reachability AND teaches the REMOTE our
real source address via learn-live-address (#9), un-wedging its next
outbound dial when its stored endpoint for us is stale.

- New verb: airc dial HOST:PORT [--expected-peer <uuid>] [--timeout-ms N]
  (default 10s — a recovery verb watched by an operator, generous next
  to discovery's 3s sweep budget). Full mTLS-pinned handshake via the
  one existing connect_lan path; success stamps last_seen on the trust
  record (an authenticated dial IS fresh contact); success and failure
  both print LOUDLY with next-step hints; nonzero exit on failure.
- --expected-peer is inferred when omitted: stored-endpoint exact match
  first, else the identity-derived stable port (#8,
  airc_lib::stable_lan_port, now pub for exactly this). Zero or several
  candidates is a loud error naming them — never a guess.
- Flag named --expected-peer (not --peer) because --peer is the global
  volatile-peer-spec flag; same convention as lan-send.

Test: cli::dial_verb_parses_endpoint_and_optional_peer (parse contract).
Smoke-verified live: two temp homes, lan-listen + dial → 'CONNECTED:
authenticated handshake … succeeded'; dead endpoint + un-enrolled peer
both fail loudly with exit 1.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

* feat(self-heal): unknown_channel auto-rebind — a registry-known channel is re-bound, never silently store-and-dropped

M5↔bigmama live repro decay mode #5 (the blind room): a frame from a
connected peer landed durably in the store but no scope bound its
channel (#general → unknown_channel) — stored, never surfaced.

Investigation (root cause): scope↔channel binding = presence beacons in
the machine coordinator store; join/part/current_room already republish
the scope's FULL subscription set (publish_presence uses the whole
SubscriptionSet), so a joining scope does re-bind all its known rooms.
What a restart/wipe loses is the MACHINE-side beacon table (drained
stale rows, moved wire root, identity drift) — and nothing consulted
the account registry's known-channel list to recover.

The fix, at the one inbound seam (RouterInboundBridge):
- (a) the loud diagnostic with channel + peer already exists at the
  transport layer (FrameUndeliverable, persisted=true) — unchanged.
- (b) on an unbound channel, the bridge now consults the machine's
  LOCAL account-registry cache (SqliteAccountRegistryStore over the
  same events.sqlite, injected via with_account_registry): if the
  account KNOWS the channel (document channel union or any beacon's
  subscriptions derive to the frame's RoomId), the registry's
  subscribing beacons are republished into the coordinator store —
  restoring the durable binding — and the verdict is re-checked before
  claiming Delivered. New warn diagnostic UnknownChannelRebound
  (channel id + name + rebound beacon count). Channels the account
  does not know keep the honest unknown_channel verdict.

Test: daemon_lan_visibility::unknown_channel_auto_rebinds_from_account_registry_cache
(unknown stays unknown; known channel re-binds + delivers + is loud
exactly once; the binding persists — no per-frame patching).

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

* fix(identity): Windows-portable local fallback — never the degenerate local:unknown-host:unknown-user

Root cause of the M5<->bigmama blind room, receiver-side log: 24
unknown_channel frames all on channel eef18336-1424-5231-bcf9-5b6f8e04deb6,
which is exactly derive_room_id("local:unknown-host:unknown-user", "general").
On Windows every probe in local_fallback_identity() failed silently:
HOSTNAME and USER/LOGNAME env vars do not exist there, and Windows
hostname.exe rejects -s. Every gh-less Windows machine therefore
collapsed onto the SAME degenerate identity, silently forking its room
UUID derivation away from the account identity.

The fallback chain now consults COMPUTERNAME/USERNAME and falls through
to bare `hostname`, rejects empty/whitespace probe output, and is
injectable for hermetic tests. Deliberately NOT changed: the
keep-provisional-cache-on-gh-outage retention in resolve_with — churning
a cached identity would re-derive rooms out from under live
subscriptions; delivery for already-diverged machines is healed by the
channel-name reconvergence commit on this branch.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

* feat(self-heal): channel-NAME reconvergence — a diverged room UUID no longer makes a bound room blind

The M5<->bigmama fix, both directions. Channel UUIDs derive from
(mesh_identity, name); when one machine's identity resolution forks
(gh unreachable -> local:<host>:<user> fallback), its #general derives a
DIFFERENT UUID than its peers', and every room frame between them dies
as undeliverable{unknown_channel} while the room is bound and readable
on both sides. Live receipts: bigmama (identity forked to
local:unknown-host:unknown-user) sent #general frames to eef18336-...;
M5 binds 5eedf7b1-... under the gh login — 24 frames durably stored,
never surfaced, and the reverse direction refused symmetrically.

The heal, extending the existing seams:

- Senders stamp the human channel name on every room send
  (HEADER_AIRC_CHANNEL_NAME, stamped in send_frame_to_room +
  daemon_send_text/daemon_send_frame/daemon_publish via
  Room::stamp_name_header) — the cross-machine convergence key. It
  rides envelope headers, so the routed forwarder and multi-hop
  re-forwards carry it for free.
- RouterInboundBridge::deliver resolves the local binding BEFORE
  publish; when the addressed UUID binds no scope but the frame's name
  header derives — under THIS machine's identity — to a channel that is
  bound (directly, or after the existing account-registry rebind heal),
  the frame is published under the LOCAL channel and the verdict is the
  new DeliveredRemapped(local). A bound channel is never re-routed: the
  name is a heal hint from an authenticated enrolled peer, not
  addressing authority.
- Transport ack + handle fan-out follow the remapped channel
  (DeliveryOutcome::Delivered carries the receiver's local room), and
  the heal is LOUD: DiagnosticCode::ChannelNameReconverged names the
  addressed UUID, local UUID, room name, and sender so the operator
  sees the sending machine's identity is split.

Regression tests (daemon_lan_visibility): the literal field fingerprint
(eef18336 = derive("local:unknown-host:unknown-user","general"))
reconverging into the bound room at bridge level with all three
controls (no header / unbound name / bound-channel-never-rerouted), and
the full field scenario end-to-end over a real TLS LAN link — a remote
pinned to the degenerate identity joins #general, dials in, sends with
delivery ack, the ack says Delivered carrying the receiver's local
room, and the operator scope reads the message. Identity pinning is
hermetic via mesh_identity Operator-source entries
(Airc::coordinator_store_for_test, same pattern as the existing
_for_test seams).

Both machines must run this build for both directions to heal: the
sender stamps, the receiver reconverges.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

* fix(clippy): drop redundant closure on the endpoints stamp (unblock #1288 merge gate)

`cargo clippy -D warnings` (a merge gate) flagged `redundant_closure` at
account_registry.rs:577 — `.then(|| crate::time::now_ms())` wraps a fn that can
be passed directly. Pass `crate::time::now_ms` to `.then`. Semantically identical
(the `.transpose()?` still sees the Result); clears the only red check on #1288.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc

* fix(identity): stable machine-id fallback — never emit the colliding unknown-host sentinel (#6)

Root cause of the M5<->bigmama blind-room bug: when every host/user probe
failed (a bare daemon process with no HOSTNAME/USER/COMPUTERNAME/USERNAME and a
rejected `hostname`), local_fallback_identity() silently produced
`local:unknown-host:unknown-user` — the SAME degenerate identity on every such
machine. Two machines then derived divergent `#general` UUIDs and every frame
between them died as `unknown_channel`.

Fix: introduce a persisted, machine-wide `machine_id()` (`~/.airc/machine-id`,
one UUID per machine shared across scopes) and, on any probe failure, anchor the
degraded identity to it (`local:machine-<id>:...`) instead of the colliding
sentinel — so probe-blind machines stay DISTINCT — and shout loudly (never
silent) that identity degraded and will self-heal to gh. Same primitive is the
intended canonical key for the account-registry gist name (#5: one gist per
machine regardless of hostname resolution).

Tests: new `local_fallback_uses_machine_id_when_all_probes_fail` (asserts no
sentinel + distinct-per-machine); existing Windows-fallback tests updated for
the injected machine-id. 16/16 mesh_identity tests green on windows-msvc.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc

* fix(registry): prune stale beacons at the GH publish path (#4)

`airc network` kept reporting ~46 stale beacons because they were dropped from
the live reader-merge and the FS store but NEVER from the persisted GitHub gist:
the GH `publish()` serialized `document.peers` verbatim, so a machine's own gist
accumulated dead beacons forever (past sessions, dead containers).

Fix: apply the ONE canonical `prune_stale_peers` (the same primitive the
reader-merge and FS store already use, `DEFAULT_PEER_FRESHNESS_TTL_MS`) at the
missing write site, before serialization — clone because the trait hands us
`&document`. Emits the existing AccountRegistryStaleBeaconsPruned diagnostic when
it drops any. Now a republish self-cleans the gist instead of growing it.

27/27 account_registry tests green on windows-msvc.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc

* feat(self-heal): auto-reconnect after restart — boot dials stored live peers NOW, and a machine-vs-scope identity mismatch retries once pinned to the presented enrolled identity

Item 1 of the restart-reconnect heal (live two-machine evidence: every
daemon restart drops the transport sessions and reconnection never
converged unaided — a manual `airc dial` fixed it every time).

Two seams, no parallel dialers:

- FIRST_REFRESH_DELAY 5s → ZERO. run_daemon spawns the route-refresh
  loop only after identity/trust/router are built, so there is nothing
  to "settle": the first stored-peer dial pass runs at boot instead of
  waiting out a tick. The pass already honors ghost-freshness and the
  dial-quarantine gates (eviction/backoff respected), so an immediate
  tick cannot stampede dead endpoints.

- Identity-mismatch retry in the ONE pinned dial path (dial_one_peer):
  when a scope-pinned dial fails with the verifier's loud
  "server cert is for peer X, expected Y" naming a DIFFERENT identity,
  and X is ENROLLED, retry exactly once pinned to X — the same recovery
  a human performs with the error in hand. Strictness unchanged: an
  unenrolled presented identity is never retried, never accepted. The
  error format and its parser live side by side in the verifier
  (peer_identity_mismatch_error / presented_peer_from_mismatch_error)
  so they cannot drift.

Tests:
- route_refresh: boot_schedules_the_first_refresh_immediately (the
  restart-shaped regression), first_refresh_is_immediate_then_steady_interval,
  shutdown test updated for the boot-immediate tick.
- verifier: mismatch_error_round_trips_presented_peer_through_the_parser,
  wrong_peer_rejection_is_parseable_by_the_mismatch_parser.
- stored_endpoint_dial: identity_mismatch_dial_retries_once_pinning_the_presented_enrolled_identity,
  identity_mismatch_never_retries_an_unenrolled_identity.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

* feat(self-heal): receive-binding re-derive on identity heal — a healed mesh identity re-binds stale subscriptions to their converged rooms

Item 2 of the restart-reconnect heal (live sequel to d79843c): after
the Windows identity healed, sends derived CONVERGED channel UUIDs but
the scope's stored subscriptions kept the OLD diverged UUIDs — the
per-frame name reconvergence heals delivery TO a bound room, but a room
bound under a stale UUID must be REBOUND, or the scope keeps reading
(and attaching to) the dead room. Live evidence: only a manual
`airc stop && airc join` un-wedged it.

The heal: a subscription's channel NAME is its durable identity; the
room UUID is a derivation frozen at join time. SubscriptionSet::
rebind_diverged re-derives every subscription under the current mesh
identity and re-binds any that diverged (name/wire/joined_at preserved,
one loud old→new warning per move). Wired into the two join-shaped
touchpoints — Airc::join and Airc::ensure_join_context (bare `airc
join`, init re-runs, daemon-bounce recovery, monitor resume) — right
after mesh_identity() resolves, so the very next join after a heal
converges with zero manual steps. save + publish_presence on the same
paths persist the rebind and re-beacon the channel names under the
healed identity. Read cursors need no migration: runtime cursors are
keyed per consumer id over the owner-core's GLOBAL (epoch, counter)
order, not per room UUID.

Tests:
- subscriptions: rebind_diverged_moves_room_ids_to_the_current_identity_derivation
  (pure rule: re-derive, preserve, report, idempotent).
- daemon_lan_visibility: healed_identity_rebinds_stale_subscription_to_the_converged_room
  (end-to-end: diverged join → heal → rebind at join → a frame addressed
  to the converged UUID delivers AND the scope reads it; the old
  diverged UUID keeps delivering via the existing name-reconvergence
  remap).

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

* fix(registry): key the registry gist on the stable machine-id, not hostname (#5 part 1/2)

writer_key() was `<host>-<user>`, which STILL fragmented: `hostname` resolves
three ways on one Mac (joels-macbook-pro-local / joels-mbp-lan / macbookpro-lan),
minting THREE registry gists for a single machine (Joel's "47" was largely this).

Re-key to the canonical, persisted machine_id (`~/.airc/machine-id`, one value
per box shared across scopes, from #6) — stable regardless of hostname
resolution, so a box maps to exactly ONE registry gist even when its sentinel /
events.sqlite is wiped. Human-readable host/platform stays in the beacon content,
not the filename. Removed the now-dead host-resolution helpers
(first_nonempty_env / hostname_from_command / sanitize_writer_component) and their
test rather than leave dead code.

Part 2/2 (follow-up commit): teach the opt-in `airc registry gc` to reap gists
whose beacons are ALL stale, so the orphaned old `<host>-<user>` gists (which stop
receiving fresh beacons once a box adopts this key) get cleaned instead of
lingering. Reader-merge already ignores their stale beacons, so routing is correct
in the meantime.

26/26 account_registry tests green on windows-msvc.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc

* fix(registry): reap superseded/dead all-stale gists in the opt-in gc (#5 part 2/2)

Completes #5: with writer_key now on the stable machine-id (part 1), a box's old
`<host>-<user>` gists stop receiving fresh beacons and linger. Teach `airc
registry gc` to reap them.

The pure filename classifier stays untouched (still unit-testable); the freshness
dimension lives in the `gc()` I/O method: for each Kept, real machine-keyed gist
(never our own, never junk) it fetches the body and downgrades Keep->Delete when
`has_only_stale_beacons` — the doc carries beacons and EVERY one is past
DEFAULT_PEER_FRESHNESS_TTL_MS. Conservative: an EMPTY document is NOT reapable
(a just-created gist mid-first-write — never delete on ambiguity), and an
unreadable body leaves the gist Kept (never delete on a blind fetch). Reaping is
safe because the owner recreates a fresh gist on return via the sentinel; gc is
opt-in and dry-run by default, so the operator reviews the plan first.

New `has_only_stale_beacons_reaps_all_stale_but_never_fresh_or_empty` test
(fresh-keeps / all-stale-reaps / empty-keeps). Validated in a Linux container
(gh_stub is unix-gated): 40/40 account_registry tests green; windows-msvc clippy
+ non-gated tests green.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc

* feat(self-heal): machine-vs-scope cert identity — beacons carry the transport host, dialers pin it first time, whois joins the machine↔scope card

Item 3 of the restart-reconnect heal (live evidence: endpoints answer
TLS with the MACHINE identity e85a… while scopes send as SCOPE peers
ce8b…; every scope-pinned dial died in a loud mismatch until a human
redialed by machine id).

The model — one mapping, carried end to end with the endpoints it
describes (never a parallel table):

- AccountPeerBeacon.endpoints_peer_id (serde-default, skip-if-none —
  old documents decode, old readers see unchanged wire): the TLS cert
  identity that answers at the beacon's endpoints. DISTINCT from the
  mesh-identity machine-id (a registry rendezvous key string) — this is
  the daemon keypair identity, joinable with it in whois.
- Publisher: `registry sync` from a daemon-attached scope reads the
  daemon's endpoints back over IPC — it now also resolves the daemon's
  peer id (Status) and stamps it via Airc::set_advertised_endpoints_host,
  so the published self-beacon names WHO answers there. Handles that own
  their listener publish no mapping (endpoints answer as themselves).
- Merge: the endpoint-carrier backfill carries the CARRIER's mapping
  with its endpoints, exactly like the freshness stamp.
- Import: persisted on the trust record (new nullable peer_trust
  column endpoints_peer_id, migration m20260723_000020) atomically WITH
  the endpoint set under the same monotonic stamp; self-mappings are
  normalized away.
- Dial: resolve_dial_pin (pure) — pin the declared host ONLY when it is
  a different peer AND itself enrolled; unenrolled/self/absent mappings
  pin the record's own peer. Strictness unchanged: an unknown identity
  is never dialed-for, never accepted — a poisoned mapping can at worst
  redirect the pin to another already-trusted peer. A record hosted by
  an already-connected machine is skipped (route is up, no re-dial
  churn); item 1's one-shot mismatch retry remains the fallback for
  records that predate the mapping.
- Surfaces: `airc whois <peer>` shows the machine line (transport host)
  and, for a machine, the scope peers it hosts — one card; `airc peer
  list` adds host= (human) and endpoints_peer_id (JSON).

Tests:
- store: mapping written/refused/preserved atomically with endpoints
  (extended replace/rotation + monotonic-stamp tests).
- account_registry: merge_backfill_carries_the_carriers_endpoints_host_mapping
  (backfill + serde default/skip round-trip),
  import_stores_the_endpoints_host_mapping_normalized.
- discovery: dial_pin_honors_only_an_enrolled_foreign_host_mapping
  (strictness matrix).
- stored_endpoint_dial: stored_host_mapping_pins_the_machine_identity_and_connects
  (first-dial pin + steady-state no-churn); the unenrolled-identity
  loud-failure test from item 1 pins the never-accept-unknown gate.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

* style: cargo fmt the self-healing batch (unblock #1288 fmt gate)

`cargo fmt --check` was the one red check on #1288 — my registry changes went
through `cargo test` + `clippy` but not `cargo fmt`, so rustfmt's line-wrapping
of has_only_stale_beacons (gh/account_registry.rs) failed the gate. No logic
change; formatting only.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc

* feat(hooks): pre-push cargo fmt + clippy gate — catch CI-gate failures locally (cab380c0)

Recurring cost: pushing airc Rust changes without `cargo fmt` (or with clippy
warnings) fails the `cargo fmt --check` / `cargo clippy -D warnings` CI gates —
each a multi-minute round-trip plus a manual fixup commit (bit both #1288 and
#1289 in one session). This runs both LOCALLY at pre-push so the failure surfaces
in seconds, before the push leaves the machine.

- New worker `integrations/git-hooks/airc-cargo-gate.sh`: phase-aware (no-op
  except on pre-push — fmt+clippy on every commit is too slow), fail-open on a
  toolchain gap (no cargo / not the workspace → exit 0, never block), fail-closed
  on real fmt/clippy violations. Shares the one CARGO_TARGET_DIR so clippy reuses
  incremental artifacts. Escape hatches: AIRC_HOOK_SKIP / AIRC_CARGO_GATE_SKIP /
  AIRC_CARGO_GATE_CLIPPY=0.
- `_install_airc_git_hooks` wires it into the generated pre-commit/pre-push hooks
  alongside the existing fetch-staleness worker (the worker self-gates to push).

Completes the flywheel front-end: pre-push gate → CI → the board's merger daemon
auto-merges green Review cards. Validated: no-op on pre-commit, honors the skip,
fmt gate clean on canary.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc

---------

Co-authored-by: Claude Fable 5 <[email protected]>
@joelteply
joelteply merged commit fe0ab02 into canary Aug 13, 2026
11 of 12 checks passed
@joelteply
joelteply deleted the 08ee47a4/self-heal-7-airc-sos-verb-send-watch-sta branch August 13, 2026 01:14
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.

1 participant