AF.DataConfirm is matched by ZCL TSN only, so concurrent same-TSN requests to different devices get each other's delivery status
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 25/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 停滞
- 技術スタック
- python
- 領域
- backend, networking
調査の方向性
Start with zigpy_znp/zigbee/application.py around send_packet, _send_request_raw, and the AF.DataConfirm listener setup at lines 815–825; then read zigpy_znp/api.py around listener registration and frame_received. The open pull request #291 is already linked to this issue. Done means concurrent requests with the same ZCL TSN receive the confirm for their own frame, with regression coverage for overlapping requests.
索引モデルが issue の本文から書いたものです。
説明
Summary
zigpy-znp sends the ZCL TSN of the packet as the Z-Stack AF TransID and waits for AF.DataConfirm.Callback(partial=True, TSN=sequence). The confirm goes to the first registered listener with that TSN. zigpy keeps a separate TSN counter for each device, so requests to different devices often have the same TSN. If two or more such requests are in flight together, each confirm goes to the oldest waiting request, whichever device it actually belongs to. One device then gets another device's MAC_NO_ACK, and the device that really failed gets a SUCCESS and waits for a reply that never comes.
The overlap is most common just after Home Assistant starts. zigpy starts every device's counter at 1, so the ZHA startup refresh sends TSN 1, 2, 3... to about 25 devices at the same time.
Versions
- zigpy-znp 1.1.1, zigpy 2.3.0, zha 2.3.1, Home Assistant 2026.10.4 (Python 3.14)
- Z-Stack 3.x.0 coordinator (
SYS.VersionMajorRel 2, MinorRel 7, MaintRel 1) - The matching code is the same on
dev.
Reproduction
- Run a ZNP network with a few dozen mains-powered routers, at least one of them behind a weak link that sometimes returns
MAC_NO_ACK. - Restart Home Assistant with DEBUG logging for
zigpy_znpandzigpy. - In the first minute, ZHA reads attributes from every device. Each device's first request has TSN 1, the next one TSN 2, and so on. zigpy allows 4 requests at a time (
Max concurrency (4) reached), so several TSN-1 frames to different devices are in flight together.
You can also reproduce it without a radio: start two send_packet() calls with tsn=1 to different NWK addresses, then return AF.DataConfirm(Status=MAC_NO_ACK, TSN=1) followed by AF.DataConfirm(Status=SUCCESS, TSN=1). The first caller always gets MAC_NO_ACK, whichever destination failed.
Expected
Each request gets the confirm for its own frame.
Actual
Same-TSN requests to different destinations get their confirms in the order they were sent, not by the frame each confirm belongs to.
In one HA restart (about 4 minutes, 455 AF requests), there were 104 cases where a request was sent while another request with the same TSN to a different device was still waiting for its confirm. 101 of these were between 3 and 38 s after the coordinator started. In a 2-minute capture from normal running before the restart, there were none. A 52-minute capture from normal running on another day had 35 such cases in 6,222 requests, mostly clustered around slow (about 3 s) APS_NO_ACK confirms.
Example (11:38:58, all four requests use TSN 1)
The devices are mains-powered routers, labelled A–D. Each request is a Read Attributes (00 01 00 ...).
# condensed from zigpy_znp.api / zigpy.device DEBUG; NWK addresses replaced with A-D
11:38:58.591 AF.DataRequestExt.Req dst=A cluster=0x0006 TSN=1 (A: attempt 2 of 3)
11:38:58.633 AF.DataRequestExt.Req dst=B cluster=0x0006 TSN=1
11:38:58.658 AF.DataRequestExt.Req dst=C cluster=0x0006 TSN=1 (C: attempt 2 of 3)
11:38:58.697 AF.DataConfirm Status=SUCCESS TSN=1
11:38:58.697 AF.DataConfirm Status=SUCCESS TSN=1
11:38:58.739 AF.IncomingMsg src=B ReadAttributesResponse ZCL TSN 1 (106 ms)
11:38:58.742 AF.DataRequestExt.Req dst=D cluster=0x0702 TSN=1
11:38:58.752 AF.IncomingMsg src=C ReadAttributesResponse ZCL TSN 1 (94 ms, MacSrc=C)
11:38:58.977 AF.DataConfirm Status=MAC_NO_ACK TSN=1
11:38:59.037 zigpy.device Failed to send request, attempt 2 of 3
DeliveryError: Failed to send request: <Status.MAC_NO_ACK: 233> -> C
11:38:59.210 AF.DataConfirm Status=SUCCESS TSN=1
11:38:59.244 AF.IncomingMsg src=D ReadAttributesResponse ZCL TSN 1
11:38:59.493 AF.DataRequestExt.Req dst=C cluster=0x0006 TSN=1 (C: attempt 3)
11:38:59.563 AF.DataConfirm Status=SUCCESS TSN=1
11:38:59.564 AF.IncomingMsg src=C ReadAttributesResponse ZCL TSN 1
11:38:59.569 zigpy.device [C] Filtering duplicate packet
11:39:03.704 zigpy.device Failed to send request, attempt 2 of 3: TimeoutError -> A
11:39:04.577 zigpy.device Failed to send request, attempt 3 of 3: TimeoutError -> C
How we know which request got which result (the log shows no listener resolution, so this is inferred from what each request did next):
- C got the
MAC_NO_ACK. Its attempt failed withDeliveryErrorat 59.037, and its next attempt went out at 59.493. B and D were not charged with it: both sent their next request after this read (TSN 2). - The
MAC_NO_ACKwas almost certainly A's. C is a direct neighbour, and it answered this frame within 94 ms. A sent no reply. A's frames gotMAC_NO_ACKafter 230–390 ms throughout this capture, and this one came 386 ms after A's send. - A got a
SUCCESSthat was not its own. Its attempt did not fail fast. It ended with a reply timeout 5 s after the 58.697 confirms. - Result: C answered all three attempts but failed with
TimeoutError. The first reply was thrown away when the wrongMAC_NO_ACKarrived. The third reply was dropped by zigpy's duplicate filter (reported separately in zigpy). In HA, a service call that fails like this shows "device did not respond".
This did not need a lost or timed-out confirm: in this capture every request that waits for a confirm got exactly one, and no confirm arrived without a pending request. Same-TSN requests in flight together plus first-match delivery were enough.
Code
zigpy-znp v1.1.1 (34098a5):
- The AF
TSNis the ZCL TSN:send_packetpassessequence=packet.tsn(application.py#L927), and_send_request_rawputs it inAF.DataRequestExt/AF.DataRequestSrcRtg(L723, L734). - The confirm listener matches on
TSN=sequenceonly, and the endpoint match is commented out (application.py#L815-L825). - Listeners are appended in registration order (api.py#L962), and
frame_receivedresolves only the first matching one-shot listener (api.py#L867-L886).
Matching on the endpoint would not help, because all of these requests come from endpoint 1. AF.DataConfirm carries only Status, Endpoint and TransID, with no destination address, so (TSN, destination) matching is not possible either. The TransID has to be unique among requests that are in flight.
Proposed fix
- Have zigpy-znp choose the AF
TransIDitself. Use a coordinator-wide 8-bit counter that skips values that still have a pendingDataConfirmlistener, and match the confirm on that value. The ZCL TSN insideDatastays the same, so zigpy's response matching is not affected. Only a few requests are in flight at once, so 256 values are plenty. As far as I know, Z-Stack only echoes theTransIDback inAF_DATA_CONFIRM; please correct me if it uses it anywhere else. - A smaller alternative: before sending a request whose TSN already has a pending confirm, wait for that confirm. This only slows down the requests that would collide.
Related: zigpy/zigpy#1636 (closed: keep zigpy's TSNs away from the device's own TSNs) and #283 (the DataConfirm timeout can be shorter than Z-Stack's APS retry window; a confirm that arrives after its listener has gone would also go to another request with the same TSN). The zigpy side of this, where the genuine reply to a retry is dropped, is reported in zigpy/zigpy#1952.
- 主要言語
- Python
- スター
- 172
- フォーク
- 49
- 平均マージ
- 3分
- マージ済み PR(30日)
- 1
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
zigpy/zigpy-znp のほかの issue
-
難易度 4/5 3〜5日 初心者へのやさしさ 18/100
-
`send_packet` no longer rediscovers routes on `APS_NO_ACK`; a stale next hop black-holes devices until restart (since #260)対応中かも @zigpy-review-bot が 25 日前に担当しました。 オープンregression
難易度 2/5 1〜3時間 初心者へのやさしさ 38/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 52/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
-
discussion documentation
難易度 4/5 3〜5日 初心者へのやさしさ 28/100
zigpy/zigpy-znp の issue をすべて見る
似ている issue
-
pydanty:is-working
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
pydantic/pydantic-ai#14472 ·
メンテナーはふだん 1 日以内に返信
-
bug good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
patrickballard/wheelgap#728 ·
-
bug good first issue
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
メンテナーはふだん 1 日以内に返信
-
bug
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
choras-org/simulation-backend#58 ·
メンテナーはふだん 1 日以内に返信
-
backend part-1-modeling testing
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100