Repository navigation
mesh m3c: edge-router attach protocol + self-healing failover - #23
Conversation
aphelps-claude-bot
left a comment
There was a problem hiding this comment.
What was done. Routers advertise a hop/cost metric; nodes bind to the best (hops, load, deviceId) with a hold-down, and hold it with attach keepalives against a membership lease. Failover = route drop on heartbeat timeout + leader re-election + lease expiry; relaying never stops, so keyframeMs covers the state gap. Deferred RSSI question resolved as (b), the RSSI-free heuristic — no WLED core patch, so no fork divergence to re-apply on upstream bumps. Pure logic in esp-now-router/src/router_attach.h, host-tested; shared header carries only the wire format. Hardware failover + coexistence tests remain (## Testing Required).
What's needed from you. Review the PR — code, tests, and the disposition of any self-review findings.
Links.
plan: todo_plans/mesh-m3c-edge-router-attach-protocol-self-healing-failover.md
PR: #23
aphelps-claude-bot
left a comment
There was a problem hiding this comment.
Self-review (bot) of the M3c change set — anchor summary. This PR's own diff is the two gitlink bumps (WLED → 56d4c56, esp-now-router → eaec2df), both pointing at the submodule PR heads as of this review, so the substantive findings are posted where the code lives:
- aphelps/esp-now-router#2 — attach protocol + failover: 2 medium, 3 minor, 1 suggested test.
- aphelps/WLED#13 — shared wire-format reservation: 1 medium (scope/doc).
What was verified and holds:
- State machine — all liveness / hold-down / lease comparisons are wrap-safe unsigned interval arithmetic with
nowinjected (nomillis()wrap hazard, no absolute-time comparisons); selection is a strict total order (hopCost, memberCount, deviceId) so nodes converge without negotiating; the incumbent's metric is refreshed in place (best-not-latest); a just-rebooted router's empty-table load advantage is only a tiebreak and is gated by the hold-down; everysend()result is checked and logged, with periodic timers as the retry path. - Wire-format discipline — the shared header gains only msgType numbers,
SS_HOP_UNREACHABLE, and the packed payload structs both sides parse; no router logic leaked in; msgType 2/3/4 collide with nothing and edges reject all non-snapshot types viass_parse_header(confirmed at head).ss_router_is_relayablecorrectly narrows the relay rule so the new control frames cannot flood. - Tests — the failure paths are real, not happy-path: timeout at exactly the boundary vs boundary+1, lease-edge expiry, hold-down suppression plus shorter-path preemption, unreachable-upstream drop, both loop guards, stale/foreign acks, and the re-election deviceId tiebreak.
Findings by severity (details inline on the submodule PRs):
- Medium — (1)
RouterAdvert.leaderTermis documented as a "stale-advert guard" but never consulted by selection, so post-failover stale adverts rank equal to fresh ones; (2) the loop guards only cover 2-cycles — a >=3-node stale-advert cycle after a mid-tier router death goes undetected and heals only via cost saturation (~250 s) or an external shorter-path advert, a bound that should be documented or poisoned away; (3) the edge side of the attach protocol is not implemented in WLED (edges reject msgType 2–4), so the "edge announces itself" subtask is exercised router-to-router only — the docs should say so explicitly. - Minor —
AttachAck.leaseMsis transmitted but ignored by the receiver; therouterId == 0any-router wildcard is dead code that would multi-admit if ever used; BACKBONE_ROUTER.md's "failover window is dimensioned below keyframeMs" claim is numerically false (route timeout 3.5 s > keyframe 3 s) though harmless since delivery is flood-based. - Suggested test — wrap-around time base (near
UINT32_MAX) for the failover/hold-down/lease sequences, and the >=3-node cycle scenario.
None of these block the merge. Merge-order note from the task stands: land #13 and #2 first, then re-point this PR at the merged commits before merging it, and close superseded #22 once this lands.
aphelps-claude-bot
left a comment
There was a problem hiding this comment.
Re-review (bot) of 4897fbf..775c95f — anchor summary. This PR's own diff is the two gitlink bumps only, so as before the substantive findings live on the submodule PRs:
- Gitlinks verified:
WLED → 627ea13andesp-now-router → 64dc581are exactly the re-reviewed submodule heads, both onm3c-attach-failoverand descendants of the previously reviewed commits (56d4c56,eaec2df). All host suites pass locally at these pins (make -C esp-now-router/tests test). - Prior findings — all addressed by the bumped commits:
- Medium (1)
leaderTermunconsulted → route selection now gates on it via wrap-safess_seq_newer; verified the gate cannot strand a node (unattached adoption is term-blind, and a node holding an orphaned newer term self-heals via the 3.5 s route timeout or the incumbent's own term update). Pinned by new term-gate + 0xFFFF-wrap tests. - Medium (2) >=3-node cycle undetected → addressed as a documented bound (comment now states 2-cycle scope; longer cycles bounded by hop-cost saturation) plus a pinning test.
- Medium (3) edge side unimplemented but undocumented → SENSOR_SYNC.md now states this repo reserves the wire format only; claim verified against
ss_parse_headerat head. - Minor:
leaseMsignored → keepalive cadence now derives from the quoted lease, floored byROUTER_ATTACH_MIN_MS; verified the derived interval ≤ lease/3 for any lease ≥ 750 ms (a residual sub-750 ms edge is a new minor on #2). Minor:routerId == 0wildcard removed. Minor: BACKBONE_ROUTER.md keyframe claim corrected. - Suggested tests (uint32 time wrap, 3-node cycle) → both added, plus the re-election deviceId tiebreak.
- Medium (1)
- New findings, none blocking (inline on the submodule re-reviews):
- esp-now-router#2 (aphelps/esp-now-router#2 (review)): 2 minor (keepalive floor can exceed a sub-250 ms quoted lease; stale
routerLeaseMssurvives route drop/switch until the next ack) + 1 suggested test (the 3-node-cycle test's middle loop restatesra_advert_costsaturation on one struct instead of simulating the three-node advert exchange). - WLED#13 (aphelps/WLED#13 (review)): 1 minor (the shared header's
NodeAttach.routerIdcomment still documents the removed0 = any routerwildcard — now-contradicted wire semantics; suggestion attached).
- esp-now-router#2 (aphelps/esp-now-router#2 (review)): 2 minor (keepalive floor can exceed a sub-250 ms quoted lease; stale
Merge-order note from the task stands: land #13 and #2 first, re-point this PR at the merged commits before merging it, and close superseded #22 once this lands.
aphelps-claude-bot
left a comment
There was a problem hiding this comment.
Re-review (bot) of 775c95f..f17b9aa — anchor summary. This PR's own diff is the two gitlink bumps only; the substantive verification lives on the submodule re-reviews.
- Gitlinks verified:
WLED → c88a3c46andesp-now-router → 08bd6e2are exactly the current submodule PR heads (both are them3c-attach-failoverbranch tips, single-commit descendants of the previously reviewed627ea13/64dc581). All router host suites pass locally at these pins (make -C esp-now-router/tests test). - Prior residual findings — all addressed by the bumped commits (verified in detail on the submodule re-reviews):
- esp-now-router#2 (aphelps/esp-now-router#2 (review)): a sub-750 ms lease is now rejected at ack time, so the keepalive interval is provably ≤ lease/3 for every accepted lease and rejection cannot strand a node (cost is logged membership flap only);
attachIntervalMs()now gates onroute.attached, and every route-change/drop path was verified to clear that flag, so a lease only ever applies to the router that quoted it; the 3-node-cycle test now genuinely simulates the three-node advert exchange (collapses at lap 169 of the 512 bound; the assertion fails if the unreachable-drop rule regresses). One non-blocking observational note inline there. - WLED#13 (aphelps/WLED#13 (review)): the
NodeAttach.routerIdwire comment now matches the no-wildcard router behaviour on both send and receive paths; clean.
- esp-now-router#2 (aphelps/esp-now-router#2 (review)): a sub-750 ms lease is now rejected at ack time, so the keepalive interval is provably ≤ lease/3 for every accepted lease and rejection cannot strand a node (cost is logged membership flap only);
- No new findings on this PR itself.
Merge-order note from the task stands: land #13 and #2 first, re-point this PR at the merged commits before merging it, and close superseded #22 once this lands.
Now conflicting — the
|
WLED |
|
|---|---|
| merge base | 467c222 |
main now |
cdfef9c0 — receive-path fixes (#25) |
| this branch | c88a3c4 |
That gitlink is the entire conflict. Nothing textual clashes: aphelps/WLED#13 still merges onto the updated base-wled-16.0.1 with zero conflicts, verified locally with git merge-tree. The RS485 changes (packed socket header, receive-path fixes) and the attach-protocol work touch different files.
Resolution order:
- merge reserve the attach-protocol wire format for the sensor-sync bus WLED#13 into
base-wled-16.0.1— it now contains the RS485 work, and Move todo-handler skill to user-level claude-skills repo #13 applies cleanly on top - re-point this branch's
WLEDgitlink at the resulting merge sha esp-now-routeris unaffected — both sides agree at8090318
Step 1 is why I have not just resolved this: merging #13 is a call for whoever owns the mesh work, not something to do as a side effect of unblocking a pointer refresh.
For reference, the RS485 side is finished and merged: socket-header packing (7 B on every target — previously 8 on ESP32 vs 7 on AVR, which misparsed every frame in both directions), four receive-path defects, and the bench tooling. make test now covers four suites where it covered two.
aphelps
left a comment
There was a problem hiding this comment.
Merge this. I can't do the testing currently so please add a task to walk me through comprehensive testing.
Refreshed against current
|
WLED -> 586c6136 (the attach-protocol wire format) and esp-now-router -> d4154389 (the router firmware, attach protocol and failover). main still pinned esp-now-router at its initial README commit, so the router's test suites were being skipped rather than run. Also correct CLAUDE.md: custom work now branches from main, since base-wled-16.0.1 was renamed to main and the pre-v16 line kept as main-pre-v16.
1566fb8 to
11059a0
Compare
Summary
Mesh M3c — the edge↔router attach protocol and self-healing failover. Advances both submodule pointers; there is no super-repo source change.
Relaying alone cannot notice that a router went away, so the mesh had no way to re-form around a failure. Routers now advertise how far they are from the elected timebase leader, nodes bind to the router they rank best, and heartbeat timeouts drop dead routes so the tree re-roots on its own.
The deferred RSSI decision landed on (b), the RSSI-free heuristic. WLED's
onEspNowMessage(sender, payload, len)hook does not forward per-frame RSSI (espNowReceiveCBdrops it before the hook), so ranking by signal strength would mean patching WLED core and re-applying that divergence on every upstream bump. Instead the router advertises a hop/cost metric and every node selects on it — hop count to the leader, then load, thendeviceId— which needs no core change and is fully host-testable.Failover rests on three independent timers (route drop on heartbeat timeout, leader re-election, membership lease expiry). Relaying continues throughout, so what a node loses during the churn is state rather than delivery, and the edge's
keyframeMsre-sync covers that gap.Submodule PRs
WLED: reserve the attach-protocol wire format for the sensor-sync bus WLED#13 — the shared wire format (msgType numbers + attach payload structs). Additive; wire version stays 5.esp-now-router: add the attach protocol and self-healing failover esp-now-router#2 — the router-side implementation, pure logic + host tests.Test plan
Automated:
make test— super-repo host suites across both submodulescd esp-now-router && pio test -e nativecd esp-now-router && pio run -e wt32-eth01cd WLED && pio run -e ampworksManual:
keyframeMs. Measure recovery time.Note on ordering
PR #22 (
m3b-submodule-pointers) also advances these pointers. This branch is based onorigin/main, so whichever lands second just re-advances them; the gitlink conflict resolves in favour of this branch's newer tips.