Skip to content

feat(relay): self-election trigger — isolated node auto-becomes a relay (#1247 slice 4b) - #1252

Merged
joelteply merged 1 commit into
canaryfrom
feat/relay-self-election-trigger
Jun 18, 2026
Merged

joelteply merged 1 commit into
canaryfrom
feat/relay-self-election-trigger

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Completes self-election (#1247 slice 4). Slice 4a (#1251) gave a node the mechanism to be a relay; this is the daemon trigger that decides when. With both, the fleet reconnects itself with zero ops — a reachable node self-elects, the rest discover it through the gist directory, and slices 1–3 carry the traffic.

Change

  • RouteDiscoverySnapshot::should_self_elect_as_relay(enrolled_peers) — the pure decision (unit-tested independent of the loop): become a relay when the node knows peers exist but can reach none of them — no live relay route AND no directly-connected LAN peer. Deliberately simple because slice 4a made reachability empirical: a wrong "yes" is harmless (an unreachable self-elected relay gets no connections, its gist entry goes stale), so we never predict our own reachability.
  • The daemon's 60s route-refresh loop evaluates it each tick and calls become_relay(0.0.0.0:0) when true — all interfaces (LAN + Tailscale reachable, not loopback), OS-assigned port (the gist advertises the actual port, so the durable pointer survives restarts). Idempotent → re-evaluating "yes" just re-advertises. Election logged loudly; a bind failure logs + retries next tick (self-heal). The next publish_account_registry carries the advertised endpoint into the gist automatically (it already includes route_endpoints()).

Tests

4 decision cases: isolated-with-peers elects; a connected LAN peer or a live relay suppresses it; grid-of-one (no enrolled peers) never elects. clippy -D warnings + fmt clean; existing relay tests still green.

Where this leaves the backbone

Self-election is complete. A node that can't reach anyone becomes a relay and advertises itself; reachable peers find it through the gist and route through it. So for the fleet: once these land and daemons refresh, an isolated-but-reachable node (e.g. a Mac that accepts inbound) will self-elect, and BigMama↔M5↔IntelMac can re-form over the relay — and continuum's grid with them (same transport). Remaining polish: slice 8 (relay↔relay federation), 9 (relay durable mailbox), 10 (gist room directory).

🤖 Generated with Claude Code

…ay (#1247 slice 4b)

Completes self-election: slice 4a gave a node the MECHANISM to be a relay;
this is the daemon TRIGGER that decides when. With both, the fleet reconnects
itself with zero ops — a reachable node self-elects, the rest find it through
the gist directory (slices 1-3 carry the traffic).

- `RouteDiscoverySnapshot::should_self_elect_as_relay(enrolled_peers)` — the
  pure decision (unit-tested independent of the daemon loop): a node should
  become a relay when it knows peers exist but can reach NONE of them right now
  — no live relay route AND no directly-connected LAN peer. Deliberately simple
  because slice 4a made reachability EMPIRICAL: a wrong "yes" is harmless (an
  unreachable self-elected relay accumulates no connections, its gist entry goes
  stale), so we never try to predict our own reachability.
- The daemon's 60s route-refresh loop (`refresh_routes_once`) evaluates it each
  tick and calls `become_relay(0.0.0.0:0)` when true — all interfaces (LAN +
  Tailscale reachable, not loopback), OS-assigned port (the gist advertises
  whatever port the OS gave, so the durable pointer survives restarts).
  Idempotent → re-evaluating "yes" just re-advertises. Election is logged loudly
  ("self-elected as a relay on <addr>"); a bind failure logs + retries next tick
  (self-heal). The next account-registry publish carries the advertised endpoint
  into the gist automatically (publish_account_registry already includes
  route_endpoints).

Tests: 4 decision cases — isolated-with-peers elects; a connected LAN peer or a
live relay suppresses it; grid-of-one (no enrolled peers) never elects. clippy
-D warnings + fmt clean; existing relay tests still green.

Slice 4 (self-election) complete. Next: slice 8 (relay↔relay federation),
slice 9 (relay durable mailbox), slice 10 (gist room directory).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@joelteply
joelteply merged commit 319e24b into canary Jun 18, 2026
10 of 11 checks passed
@joelteply
joelteply deleted the feat/relay-self-election-trigger branch June 18, 2026 07:55
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