Repository navigation
Revive stuck-offline devices from the persisted IP after identity verification - #2014
Conversation
|
ESPHome Bot (@esphbot) review |
|
|
ESPHome Bot (esphbot)
left a comment
There was a problem hiding this comment.
No blocking issues found.
|
ESPHome Bot (@esphbot) review |
Merging this PR will not alter performance
Comparing Footnotes
|
|
Good catch on the long-uptime window. The verified cache now stores a monotonic timestamp per pair and the dial-free fast path only honors it within a 6h TTL (68f1085); past that the next revival pays one fresh device_info dial and re-stamps, so a lease reassigned during a long silent gap has to pass identity verification again. Test added for the stale-pair re-dial. ESPHome Bot (@esphbot) review |
|
|
ESPHome Bot (esphbot)
left a comment
There was a problem hiding this comment.
No blocking issues found.
Confirmed resolved. One remaining branch: empty reported name invalidates the persisted IP. |
|
|
There was a problem hiding this comment.
Pull request overview
Adds an identity-verified “last resort” reachability path to revive API-enabled devices that become permanently offline after a dashboard restart when mDNS and .local DNS resolution are unavailable, by using the persisted last-known IP as a lead (ICMP pre-filter + short-lived Native API device_info verification).
Changes:
- Introduces
ApiReviverSourceplus shared Native-API probe plumbing (_api_probe.py) to verify identity and safely re-seed ping targets from persisted IPs. - Refactors
ApiInfoSourceto reuse the shared probe/loop base and extends theapi_device_infoworker to include the device name. - Wires persisted-IP invalidation through the devices controller + adds a comprehensive test suite covering revival, mismatch invalidation, and backoff/caps.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_state_monitor_lifecycle.py | Extends lifecycle test to cover reviver task teardown. |
| tests/test_api_reviver.py | New unit tests for persisted-IP revival behavior, gating, and backoff. |
| tests/test_api_info_fallback.py | Updates tests for shared _api_probe refactor and name-inclusive worker output. |
| tests/controllers/devices/test_branches_coverage.py | Adds branch coverage for persisted-IP invalidation callback behavior. |
| tests/conftest.py | Adds callback + helper fixture for “stuck offline” device cohort setup. |
| esphome_device_builder/helpers/api_device_info.py | Worker now returns name along with MAC/version. |
| esphome_device_builder/controllers/devices/state_callbacks.py | Adds callback to clear stale persisted IP on verified mismatch. |
| esphome_device_builder/controllers/devices/controller.py | Wires new persisted-IP invalidation callback from the monitor. |
| esphome_device_builder/controllers/_device_state_monitor/shared.py | Adds shared ICMP concurrency constant + reachability helper. |
| esphome_device_builder/controllers/_device_state_monitor/ping.py | Exposes ping_once() for reuse and shares ICMP concurrency limit. |
| esphome_device_builder/controllers/_device_state_monitor/controller.py | Starts/stops the reviver loop and adds invalidation API surface. |
| esphome_device_builder/controllers/_device_state_monitor/api_reviver.py | New persisted-IP identity-verified revival source implementation. |
| esphome_device_builder/controllers/_device_state_monitor/api_info.py | Refactors to reuse shared probe plumbing; behavior stays “info-only”. |
| esphome_device_builder/controllers/_device_state_monitor/_api_probe.py | New shared subprocess/probe helpers + presence-gated sweep base class. |
| docs/ARCHITECTURE.md | Documents the new persisted-IP revival reachability path. |
| CLAUDE.md | Adds repo-internal guidance about persisted-IP revival constraints/behavior. |
ESPHome Bot (esphbot)
left a comment
There was a problem hiding this comment.
Blocking issues found.
- Empty reported name is treated as a mismatch and clears the only revival lead
|
Addressed the important finding in 1d365be: an empty or absent reported name is now treated as an inconclusive dial, it records a dial failure and backs off instead of invalidating the only revival lead; test added. The resolver suggestion landed one commit earlier as ProbeRequestError, the reviver gives a transient resolve blip the short 600s retry while the definitive no-key case keeps the 1h hold; api_info keeps its single cooldown for both. Also in this push from a /simplify pass: _prune handles duplicate-named YAML siblings via name buckets, the sweep loop and worker seam live once on ApiSweepSource, ping's DNS-failure branch and the reviver's cohort gate now share one address_resolution_exhausted predicate, and the persisted-IP invalidation flows through the constructor callback directly instead of a public forwarder. Follow-ups filed as #2020 and #2021. ESPHome Bot (@esphbot) review |
|
ESPHome Bot (@esphbot) review |
Verified both. Empty-name guard present and tested. ProbeRequestError splits transient (600s) from no-key (1h). _prune name-bucketing confirmed against the duplicate-sibling test. Remaining nit: mismatch branch records no cooldown itself, relies on the wired invalidation callback to drop the IP. Non-blocking. |
|
|
ESPHome Bot (esphbot)
left a comment
There was a problem hiding this comment.
No blocking issues found.
|
Applied in 2d42795. run_worker now classifies outcomes: a worker that completed its protocol and reported the device's refusal returns None (escalating backoff), while host-side misses (spawn failure, subprocess timeout, no parseable payload) raise the transient error and get the short retry, so a local glitch never feeds a device's 6h backoff. The exception is now ProbeError since it covers the whole dial, not just request building. Also in this push from the round-3 /simplify: a monitor-wide Semaphore(1) bounds concurrent worker subprocesses across both API sources; the crash-logging done-callback lives once in helpers.async_ (the mDNS interface monitor adopts it); ping's redundant cached-local branch collapsed into the shared no-target predicate (one cache walk instead of two); the reviver prunes through the monitor's name index instead of hand-built buckets; and cooldown keys are bound before the invalidation callback can clear the IP they need. ESPHome Bot (@esphbot) review |
|
ESPHome Bot (@esphbot) review |
Confirmed. |
|
|
ESPHome Bot (esphbot)
left a comment
There was a problem hiding this comment.
No blocking issues found.
|
Added in the latest push: the identity-blank verdict now logs at debug like its sibling branches, so a responder that connects but never reports a name is visible while it escalates. ESPHome Bot (@esphbot) review |
Confirmed at 9ee3f0e. Identity-blank branch now logs debug before backoff, matching the mismatch and MAC-conflict verdicts. Verified it is the only change since the reviewed head. Remaining gather nit is benign: ping_once catches ICMPLibError/OSError and returns None, so the pre-filter batch cannot abort. Merge-ready. |
|
|
ESPHome Bot (esphbot)
left a comment
There was a problem hiding this comment.
No blocking issues found.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2014 +/- ##
==========================================
+ Coverage 99.58% 99.60% +0.01%
==========================================
Files 239 242 +3
Lines 19532 19745 +213
==========================================
+ Hits 19451 19667 +216
+ Misses 81 78 -3
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
ESPHome Bot (@esphbot) review |
|
|
ESPHome Bot (esphbot)
left a comment
There was a problem hiding this comment.
No blocking issues found.
|
ESPHome Bot (@esphbot) review |
PR Review — Revive stuck-offline devices from the persisted IP after identity verificationMerge-ready. Identity-gated persisted-IP revival that closes the #1776 stale-lease latch class, with thorough tests and docs in the same change. No blocking issues; prior-round findings all resolved. Specific strengths:
Checklist
Silent Failure Analysis
🟡 **MEDIUM** — unisolated gather / partial silent no-op
|
ESPHome Bot (esphbot)
left a comment
There was a problem hiding this comment.
No blocking issues found.
What does this implement/fix?
When a device's mDNS responder goes quiet and the dashboard then restarts, the device shows offline forever unless the user adds
manual_ip. The ping sweep has no target: the.localname won't resolve inside a container, the zeroconf cache is empty, and the restart wiped the RAM address list. The last known IPv4 is already persisted on disk for the OTA address cache, but no reachability path consults it.This adds a last resort reviver for
api:devices. A bare ICMP reply at a wall clock old DHCP address is never trusted as online evidence, since whatever now holds the lease would answer (the #1776 latch class). Instead ICMP acts only as a negative filter; when something answers, one short lived Native APIdevice_inforound trip confirms the responder's identity (name match required, MAC corroborating when both sides know it). On a match the device comes back online under thepingsource and the ordinary sweep owns liveness and demotion from then on. On a name mismatch the persisted IP is proven stale and cleared, so neither the reviver nor the OTA cache trusts it again.API connects occupy one of the ESP's scarce connection slots, so dials are strictly bounded: only devices with no other reachability signal are eligible, dials are serial and capped at 3 per sweep with exponential backoff on failure, and a process lifetime verified cache means a device is dialed at most once per stuck episode. Deployments without ICMP are deliberately not repaired, because the negative filter can't run and a verify only online could never demote.
MQTT devices already revive via the broker; web_server only and OTA only devices have no strong identity channel and keep today's behavior.
Related issue or feature (if applicable):
manual_ipcohort)Types of changes
bugfixnew-featureenhancementbreaking-changerefactordocsmaintenancecidependenciesFrontend coordination
Checklist
ruff,codespell, yaml/json/python checks).tests/where applicable.components.index.json/definitions/components/*.jsonhave not been hand-edited (regenerate viascript/sync_components.pyif a sync is needed).docs/ARCHITECTURE.mdand/ordocs/API.md.