Skip to content

After MAC_TRANSACTION_EXPIRED, a sleepy child is dropped from the association table and not restored (1.1.1) #296

Open

Description

@ptowalski

Versions: zigpy-znp 1.1.1, zigpy 2.3.0, zha 2.3.1, Home Assistant 2026.10.4; coordinator CC2652P (Sonoff Zigbee 3.0 USB Dongle Plus), Z-Stack 20240710. The end device: a sleepy end device (ZBOSS, nRF52840) polling its parent every ~5 s, its parent the coordinator.

What happens

send_packet() drops a working sleepy child after a single MAC_TRANSACTION_EXPIRED, and the restore path re-adds it, but from then on Z-Stack treats it as if it were not sleepy: polls are answered without frame pending, and every unicast to it goes out at once (up to 8 MAC tries) while its radio is off, so nearly all are lost. It lasts until the device itself rejoins or reboots: 37 and 45 hours on a battery-powered meter here, at ~3x its normal current (those two episodes were seen on the sniffer only; they also had a stale source route, and there only a reboot ended it).

ZHA debug log and a sniffer capture of one occurrence (two clocks, within ~0.1 s):

17:30:03.233 AF.DataRequestExt.Req(Dst=0xB625, ClusterId=1794, TSN=38, Options=ACK_REQUEST|SUPPRESS_ROUTE_DISC_NETWORK)
             (the Default Response to the device's attribute report)
[sniffer] 17:30:08.735 0xB625 -> 0x0000 Data Request, acked with frame pending
[sniffer] 17:30:08.750 0x0000 -> 0xB625 Default Response, MAC-acked by the device
[sniffer] 17:30:08.757 0xB625 -> 0x0000 APS Ack for it
[sniffer] 17:30:08.762 0x0000 -> 0xB625 the same MAC frame 6 more times, unacked
17:30:12.662 AF.DataConfirm.Callback(Status=MAC_TRANSACTION_EXPIRED, Endpoint=1, TSN=38)
17:30:12.991 UTIL.AssocGetWithAddress.Req -> Rsp(shortAddr=0xB625, nodeRelation=CHILD_RFD, devStatus=8, ...)
17:30:13.070 UTIL.AssocRemove.Req -> SUCCESS
17:30:13.084 ZDO.ExtRouteDisc.Req(Dst=0xB625)
17:30:14.404 AF.DataRequestExt.Req(Dst=0xB625, TSN=38) -> DataConfirm NWK_NO_ROUTE
17:30:15.930 UTIL.AssocAdd.Req(NWK=0xB625, NodeRelation=CHILD_RFD) -> SUCCESS
[sniffer] from 17:30:13.801 every Data Request from 0xB625 is acked without
          frame pending; unicasts to it go out directly, mostly unacked;
          then NWK_NO_ROUTE / APS_NO_ACK confirms.

Two points:

  1. The expiry does not mean the child is gone. Here it was reported for a frame the device received and APS-acked (Z-Stack apparently missed the device's MAC ack and retried until the transaction expired). In a second run (20:06, the device just paired as 0xA090) it came 133 ms after the request, and the frame (TSN 39, Read Attributes, Power Configuration) never appeared on air at all:

    20:06:37.784 AF.DataRequestExt.Req(Dst=0xA090, ClusterId=1, TSN=39, Options=SUPPRESS_ROUTE_DISC_NETWORK)
    20:06:37.917 AF.DataConfirm.Callback(Status=MAC_TRANSACTION_EXPIRED, TSN=39)
    20:06:37.942 UTIL.AssocRemove.Req -> SUCCESS
    20:06:39.591 retry -> AF.DataConfirm NWK_NO_ROUTE
    20:06:39.596 UTIL.AssocAdd.Req(NWK=0xA090, NodeRelation=CHILD_RFD)
    [sniffer] polls acked with frame pending until 20:06:41.39, without from 20:06:41.56 on
    

    In both runs no other request used the TSN at the time (so not AF.DataConfirm is matched by ZCL TSN only, so concurrent same-TSN requests to different devices get each other's delivery status #290).

  2. The re-added entry does not restore indirect delivery. Edit 2026-11-24: The restore never re-added the device: in 1.1.1 UTIL.AssocAdd sends its parameters in the wrong order, see the first comment. The device's own rejoin does restore it: after a reboot, and also after an NWK secure rejoin without a reboot (Rejoin Request to 0x0000, same short address), the next poll was acked with frame pending again and queued frames were handed over normally. While in the state, ZHA's interview of a newly paired device stalls; after the device's rejoin it completed.

How to reproduce: pair a sleepy end device directly to the coordinator (here forced with a parent allow list on the device).
In three runs the state came 4 s, 13 s and ~30 s after the join, during the interview and configuration, when ZHA sends the most frames to the new device.

Related: #285 (child aging), #286 ("a valid child is still removed on the first expiry", listed as not fixed), #290 (DataConfirm matched by TSN only). With child aging enabled (#287, on dev), is the remove/re-add still needed for devices whose association entry shows a recent poll?

Attachments: the zigpy-znp lines 17:29:40-17:30:30 (zha_1729-1730.log) and 20:06:30-20:07:00 (zha_2006.log), the per-frame sniffer summary (sniffer_spare_0xb625_1729-1735.txt), and the raw 802.15.4 frames 17:30:00-17:30:30 to/from 0xB625 plus all MAC acks (zipped sniffer_spare_0xb625_1730.pcap; NWK payloads encrypted, MAC layer readable).

zha_1729-1730.log

zha_2006.log

sniffer_spare_0xb625_1729-1735.txt

sniffer_spare_0xb625_1730.zip

Activity

  1. zigpy-review-bot commented on Nov 22, 2026

    @zigpy-review-bot
    Collaborator

    Thanks for the captures. In your logs, the restore doesn't actually put 0xB625 back. zigpy-znp 1.1.1 sends UTIL.AssocAdd with the short address before the IEEE address, but Koenkk's firmware reads the IEEE address first. Read the way the firmware reads it, the request at 17:30:15.930 adds a child 36:fe:5b:4e:5b:bd:b6:25 at 0xF4CE, and the one at 20:06:39.596 adds 36:fe:5b:4e:5b:bd:a0:90 at 0xF4CE. After the AssocRemove, your device is no longer in the association table at all. That matches the sniffer: no frame pending on its polls, unicasts sent to it directly, and only its own rejoin bringing it back.

    The parameter order is fixed on dev by #284 (merged 2026-10-21), but it isn't in a release yet. 1.1.1 is the latest release, and it's the version Home Assistant 2026.11 ships. The same goes for #287, which turns child aging on for builds from 20230507 (your 20240710 included). With 1.1.1, child aging is written off at every start, so it was off in your runs.

    What dev doesn't change:

    • The child is still dropped on the first MAC_TRANSACTION_EXPIRED (application.py L952-L957). This started with Zigpy application-level retries #260 (first released in 0.14.0). Before that, the first failure got a plain retry after 1.5 s, and AssocRemove only came on a later failure. zigbee-herdsman also removes the entry only from its second data request onwards (zStackAdapter.ts L606-L623).
    • In both of your runs, the retry after AssocRemove ended in NWK_NO_ROUTE. So for a child that never left, the recovery ended in the restore (L1015-L1023).
    • The restore passes back only the IEEE address, the short address and the node relation, and the firmware hands just those three to AssocAddNew. The rest of the original entry (devStatus=8, the end device timeout configuration) isn't carried over. Nobody has measured yet whether a correctly restored entry gets buffered delivery again; Fix UTIL.AssocAdd parameter order to match the firmware #284 lists that as open. For comparison, zigbee-herdsman's response-timeout recovery deliberately removes and re-adds the entry. Its comment says this sometimes fixes a missing frame-pending flag (zStackAdapter.ts L693).
    • The recovery runs whether child aging is on or off: its condition doesn't check the build or the aging setting.
    • Validate association lookups before dropping or restoring a child #286 (open) checks the association lookup before dropping or restoring a child. Even so, a child that is still at its own address and that the retry can't reach is dropped and restored there too. The PR lists the first-expiry removal as not fixed.

    If you can run zigpy-znp from dev with your sniffer setup, a capture of one expiry would show whether the corrected restore keeps buffered delivery. That would also tell whether the first-expiry removal still costs a sleepy child its buffered delivery.

    Verified (6 checks)
  2. changed the title [-]After `MAC_TRANSACTION_EXPIRED`, `AssocRemove` + `AssocAdd` leaves a sleepy child that Z-Stack no longer buffers frames for[/-] [+]After `MAC_TRANSACTION_EXPIRED`, a sleepy child is dropped from the association table and not restored (1.1.1)[/+] on Nov 24, 2026
  3. ptowalski commented on Nov 24, 2026

    @ptowalski
    Author

    Thanks, that's it. I checked it against the sources: the 1.1.1 request schema (NWK, IEEE, NodeRelation) and MT_UtilAssocAdd in Koenkk's firmware.patch at the commit that built 20240710 (85d2fc7), which reads the IEEE address first. Decoded that way, the two restores in my logs wrote 36:fe:5b:4e:5b:bd:b6:25 / …:a0:90 at 0xF4CE, and the device itself was no longer in the table. So my point 2 is wrong as written; I've corrected it in the description.

    Two observations that may help:

    • A third run (22:40) had an ordinary expiry: TSN 107, a Read Attributes during the interview, MAC_TRANSACTION_EXPIRED 7.7 s after it was sent, then the same remove, NWK_NO_ROUTE, misordered add. So across three runs the first expiry came from three different situations: a frame that was delivered but whose MAC ack was missed, a confirm 133 ms after the request with nothing on air, and a real expiry.
    • Two topology scans of the coordinator after the restores showed no neighbour at 0xF4CE and none with an IEEE 36:fe:…. I can't tell whether Z-Stack refused the entry, dropped it, or just doesn't report it.

    On the dev capture: this coordinator runs my production Home Assistant (HA OS), so I'd rather not run zigpy-znp from dev there. I'll capture it as soon as a release with #284 reaches Home Assistant; the sniffer setup stays in place.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Fields

    Priority

    None yet

    Size

    None yet

    Area

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions