Skip to content

Hold the first many-to-one route request until neighbors can accept it - #143

Closed
t3hk0d3 wants to merge 1 commit into
zigpy:devfrom
t3hk0d3:fix/hold-first-many-to-one
Closed

t3hk0d3 wants to merge 1 commit into
zigpy:devfrom
t3hk0d3:fix/hold-first-many-to-one

Conversation

@t3hk0d3

@t3hk0d3 t3hk0d3 commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Problem

After a coordinator restart, the first many-to-one route requests are lost on every Ziggurat router neighbor.

  • At startup the coordinator sends an empty link status. Each neighbor reads it as "the coordinator does not hear me" and sets its outgoing cost toward the coordinator to 0.
  • A Ziggurat router drops a route request from a neighbor at zero outgoing cost ("Path cost to neighbor is 0").
  • The startup gate in periodic_many_to_one_route_request_task waits for any_live_router_link(), which looks at the coordinator's own neighbor table. A restart keeps those costs, so the gate passes at once.

On a test network, the first two many-to-one route requests after a host restart went out within 10 s and every Ziggurat router dropped them. For about a minute, devices recorded routes around the coordinator's direct router links.

Change

  • Neighbors::any_router_link_confirmed_since(since) replaces any_live_router_link(). It counts only a router that sent a link status listing us with a nonzero cost after since, so costs kept across a restart do not count.
  • The first many-to-one route request now:
    1. waits one link status period, so every router neighbor gets to send its link status;
    2. once a router has confirmed the link, sends our own link status, so the neighbors learn their side;
    3. then advertises.
  • The ceiling of two link status periods stays, for a silent network.

Waiting only for the first router to answer is not enough: on the test network one router answered within 10 ms, and the others still dropped the request.

Testing

  • Unit tests in neighbors cover three cases:
    • a link heard before since is not confirmed;
    • a link status listing us after since confirms it;
    • a link status that does not list us does not.
  • cargo fmt --all --check
  • cargo clippy --workspace --all-targets --all-features -- -D warnings -Dclippy::all -Dclippy::nursery
  • cargo test --workspace
  • On the same test network, after a host restart, the first many-to-one route request went out at +15 s, and every Ziggurat router neighbor relayed it at cost 1.

🤖 Generated with Claude Code

A restarted coordinator sends an empty link status, which zeroes every neighbor's
outgoing cost toward it, and Ziggurat routers drop route requests from a sender at
zero cost. The startup gate checked our own outgoing costs, which a restart keeps, so
it passed at once: on the bench the first two many-to-one route requests after a host
restart went out within 10 s and every Ziggurat router dropped them, recording routes
around the coordinator's direct links for about a minute.

The first request now waits one link status period, so every router neighbor sends
its link status, then sends our own so they learn their side. Waiting only for the
first router to answer is not enough: one answered within 10 ms on the bench and the
others still dropped the request. Still bounded by two link status periods.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@zigpy-review-bot zigpy-review-bot added the bugfix This PR fixes a bug label Nov 16, 2026
@puddly

puddly commented Nov 16, 2026

Copy link
Copy Markdown
Member

I think the spec has a provision specifically to deal with this: an empty link status update should trigger an gratuitous link status from nearby routers.

If the link status field was empty, and a neighbor table entry corresponding to the transmitting device did not exist,
the receiver SHALL initiate a gratuitous Link Status command frame at a point in time randomly chosen within
nwkcMinRouterBootstrapJitter and nwkcMaxRouterBootstrapJitter.

@t3hk0d3

t3hk0d3 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor Author

@puddly

gratuitous link status

Good catch! I've overlooked these.
But are they supported yet? There is only TODO.

Also seems like it only fires when the receiver has no neighbor entry for the sender. After a coordinator restart every neighbor still has one, so spec-compliant routers stay quiet.

Another problem is that gratuitous link status tells us our link costs.

What breaks the many-to-one route request is the routers cost toward us, which our empty link status zeroed.

They only learn it from our next non-empty link status, so we have to send one before advertising anyway.

@puddly

puddly commented Nov 17, 2026

Copy link
Copy Markdown
Member

I looked into how a bunch of stacks behave when it comes to empty link statuses and route requests from unknown senders, etc.

Case Spec SiLabs Telink TI Z-Stack Espressif (ZBOSS) Ziggurat
Link status interval 15 s, random jitter recommended, more often allowed 15.4–18.9 s 15 s + 5–132 ms 15 s + 0–127 ms 15 s + up to about 64 ms 15 s, no jitter
Empty link status from a known router Cost set to 0, age reset Cost kept, age reset Cost kept, age reset Cost set to 0, age reset Ignored Cost set to 0, age reset
Non-empty link status that leaves the receiver out Cost set to 0 Ignored Cost kept Cost set to 0 Cost set to 0 Cost set to 0
No link status from a router: cost set to 0 after the last one When age exceeds 3: 4th period (45–60 s) About 51 s 3rd period (30–45 s) 5th period (60–75 s) 4th period (45–60 s) 60 s
Answers an empty link status from an unknown router Yes, after 0.5–1 s Yes, after about 2.2 s No No No No
Answers an empty link status from a known router Not required Yes, after 0.25–2.75 s No No No No
Route request from a router at cost 0 Dropped Dropped Relayed, hop counted at cost 7 Dropped Dropped Dropped
Route request from an unknown sender Dropped Dropped Many-to-one dropped, others relayed at cost 7 Relayed at cost 7 Dropped Dropped

At least on my network, most routers are SiLabs and a few are Telink.

@puddly

puddly commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Try out #144 and #145. I think some of our behavior (e.g. setting cost to 0) was not correct, especially compared to other stacks.

@t3hk0d3

t3hk0d3 commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

Try out #144 and #145. I think some of our behavior (e.g. setting cost to 0) was not correct, especially compared to other stacks.

Yeah, seems like #144 also solves this issue. I am closing this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix This PR fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants