Skip to content

daemon: per-peer path watchdog — heal a single dead peer path in place#401

Merged
TeoSlayer merged 1 commit into
mainfrom
feat/per-peer-path-watch
Jul 18, 2026
Merged

daemon: per-peer path watchdog — heal a single dead peer path in place#401
TeoSlayer merged 1 commit into
mainfrom
feat/per-peer-path-watch

Conversation

@TeoSlayer

Copy link
Copy Markdown
Collaborator

Problem (2026-07-17 incident)

One peer's NAT/relay session died (list-agents unreachable for hours) while 8 other peers stayed healthy. The global rx-watchdog never fires in this shape — any single live peer keeps PktsRecv moving — and nothing health-checks an individual peer mapping: the tunnel keepalive is fire-and-forget (receiver silently swallows it; it warms the NAT mapping but verifies nothing). The only remedy was a full daemon restart — which drops every session and costs minutes of re-establishment on a NAT'd link (measured: mechanical restart 4s, functional recovery to service agents 4-15+ min).

Fix

New pathwatch.go (L4), per-peer feedback loop:

  • Detect: every Ready peer refreshes lastInboundDecrypt ≤~30s via bidirectional keepalives (all daemon versions). Silent > 55s → up to 3 pong-soliciting probes (one per 10s tick).
  • Heal: still silent → reset that ONE peer's path in place via the exact pilotctl prefer-direct sequence, now extracted as the shared resetPeerPath (drop cached resolve + tunnel, preserve relay-active / clear pin, clear rekey cooldowns, proactively push fresh PILA). Healthy sessions untouched. Worst-case detection ≈ 85s; recovery ~1 RTT.
  • Guard rails: 2-min per-peer reset cooldown; -no-path-watch to disable; events tunnel.path_suspect / tunnel.path_recovered; panic boundary per tick.

Backward compatibility (the hard requirement)

Zero wire changes. The probe is a plain ProtoControl/PortPing frame with a non-empty payload:

  • Verified against the v1.10.0, v1.10.0-rc5 and v1.10.0-rc7 trees (the deployed fleet runs rc6-dev, between the two): their isTunnelKeepalive only swallows empty frames, so the probe passes the filter, reaches handleControlPacket, and gets a pong (present in all three trees).
  • Old peers' own 25s keepalives independently refresh our liveness signal — an old peer that never pongs but is alive is never falsely reset.
  • The compat invariant is pinned by TestPathProbeIsNotSwallowedByOldKeepaliveFilter as a tripwire.

Tests

State machine (healthy/probe/reset/cooldown/prune), relay-state preservation in resetPeerPath, keepalive-filter compat. New tests green under -race; full pkg/daemon/... green under the -short CI gate. (TestIPCServer_MaxClientsCap / TestWriteLoopExitsOnWriteDeadline fail locally on clean main and v1.12.7 too — pre-existing non-short-only, unrelated.)

Post-merge validation plan

Release, update this laptop, then reproduce the original failure live (wifi→hotspot switch mid-session) and confirm list-agents reachability self-heals within ~85s with zero manual restarts.

🤖 Generated with Claude Code

2026-07-17 incident: one peer's NAT/relay session died (list-agents
unreachable for hours) while 8 other peers stayed healthy — so the
global rx-watchdog never fired (any live peer keeps PktsRecv moving),
and the only remedy was a full daemon restart, which drops EVERY
session and costs minutes of re-establishment on a NAT'd link. Nothing
health-checks an individual peer mapping: the tunnel keepalive is
fire-and-forget (the receiver silently swallows it), so it keeps NAT
mappings warm but verifies nothing.

Add pathwatch.go (L4): every Ready peer already refreshes
lastInboundDecrypt at least every ~30s via bidirectional keepalives.
A peer silent past 55s gets up to 3 pong-soliciting probes; still
silent → that ONE peer's path is reset in place via the same sequence
as `pilotctl prefer-direct` (drop cached resolve + tunnel, preserve
relay-active, clear rekey cooldowns, proactively push a fresh PILA) —
extracted from the IPC handler into the shared resetPeerPath. Worst-
case detection ≈85s, recovery ~1 RTT, healthy sessions untouched.
Reset is rate-limited per peer (2min cooldown); disable with
-no-path-watch. Events: tunnel.path_suspect / tunnel.path_recovered.

Backward compatible with the whole deployed fleet — no wire changes:
the probe is a plain PortPing control frame with a non-empty payload.
Verified against the v1.10.0, v1.10.0-rc5 and -rc7 trees (the fleet
runs rc6-dev): their isTunnelKeepalive only swallows EMPTY frames, so
the probe reaches handleControlPacket and gets a pong; old peers'
own keepalives independently keep refreshing our liveness signal, so
an old peer is never falsely reset. The compat invariant is pinned by
TestPathProbeIsNotSwallowedByOldKeepaliveFilter.

Tests: probe/reset/recovery/cooldown/prune state machine, relay-state
preservation in resetPeerPath, keepalive-filter compat. pkg/daemon
green under -race for the new tests and under the -short CI gate.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@TeoSlayer
TeoSlayer merged commit e30aafe into main Jul 18, 2026
14 checks passed
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