Skip to content

Reset the protocol version before each startup attempt - #774

Open
aguilaair wants to merge 1 commit into
zigpy:devfrom
aguilaair:fix-startup-reset-protocol-version
Open

aguilaair wants to merge 1 commit into
zigpy:devfrom
aguilaair:fix-startup-reset-protocol-version

Conversation

@aguilaair

Copy link
Copy Markdown

startup_reset() replaces the protocol object with EZSPv4 on every attempt, but leaves _ezsp_version at whatever a failed attempt had already negotiated. On the retry, version() sends desiredProtocolVersion with the stale version, sees the stick answer with that same version, and skips _switch_protocol_version(). The protocol object stays v4, so later replies are framed for the wrong version and startup times out.

When it happens

zigbeed over TCP (socket://host:port) when its startup reset takes longer than NETWORK_COORDINATOR_STARTUP_RESET_WAIT. Seen with zigbeed 7.3.3 (EZSP 12) on an Aqara Panel Hub S1 Plus, whose reset answer takes about 4 s. The first attempt negotiates v12 and then fails, and every retry is stuck on v4 framing. In ZHA, form new network and restore backup hang. Monkeypatching the one line below makes both work.

Change

Use self._switch_protocol_version(v4.EZSPv4.VERSION) at the start of each attempt, so the version and the protocol object always agree.

Tests

  • New test_ezsp_connect_retry_resets_protocol_version: the first attempt switches to v12 and fails, and the retry must start at v4 with an EZSPv4 object. It fails without the fix.
  • pytest tests: 767 passed.

startup_reset() replaced the protocol object with v4 on every attempt but
left _ezsp_version at whatever a failed attempt had negotiated. On the
retry, version() then saw the stick's version equal to the stale one and
never switched back from v4 framing, so later replies were misparsed and
startup timed out.

This happens with zigbeed over TCP when its reset takes longer than the
startup wait (seen at ~4 s): ZHA's form/restore flows hang. Use
_switch_protocol_version(v4) so the version and protocol object agree.
Copilot AI balanced review requested due to automatic review settings November 10, 2026 15:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@zigpy-review-bot zigpy-review-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review

Looks good to me, no blockers.

startup_reset() previously rebuilt only the protocol object, so after a failed attempt that had already negotiated a newer version, _ezsp_version stayed stale and version() skipped _switch_protocol_version(). _switch_protocol_version(v4.EZSPv4.VERSION) resets the version and the object together, and it is the same call reset() already makes ("Always switch back to protocol v4 after a reset"), so the two paths are now consistent.

Verified in a worktree at 9f71434: tests/test_ezsp.py passes (88 passed), and test_ezsp_connect_retry_resets_protocol_version fails with the old one-line v4.EZSPv4(...) construction, so the test does exercise the bug.

The PR description matches the diff.

@codecov

codecov Bot commented Nov 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.59%. Comparing base (6210ab5) to head (9f71434).

Additional details and impacted files
@@           Coverage Diff           @@
##              dev     #774   +/-   ##
=======================================
  Coverage   99.59%   99.59%           
=======================================
  Files          64       64           
  Lines        4417     4417           
=======================================
  Hits         4399     4399           
  Misses         18       18           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

3 participants