Fix: entity subscription dropped when it arrives before connect (Remote restart race) - #67
Open
SPLBendrix wants to merge 1 commit into
Conversation
On Remote restart, remote-core sends 'subscribe_events' before 'connect' over the websocket. _subscribe_events() checks _available_entities immediately, but for hub-mode integrations the entity is only created once the device driver's own connect() completes a moment later. The failed lookup just logs a warning and gives up permanently - the entity_id is never re-checked once it becomes available, so it never enters _configured_entities and every subsequent command 404s with 'no configured entity found' for the rest of that session. Fix: when an entity isn't available yet, spawn a short retry task that polls _available_entities for up to ~10s and configures the entity as soon as it appears, instead of dropping the subscription on the first miss.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On Remote restart, integrations built with the hub-mode pattern (connect-on-demand, entities created after connect completes) can end up with entities that are subscribed too early, permanently fail, and are never retried - even though the device connects successfully moments later.
Root cause
Observed in logs: remote-core sends
subscribe_eventsbeforeconnectover the websocket on session start:_subscribe_events()checks_available_entitiesimmediately when the message arrives. For integrations that create entities only after their device connects (a common and reasonable pattern), the entity doesn't exist yet at this point. The failed check just logs a warning and returns - there's no retry, and no event is emitted when an entity is later added to_available_entitiesthat could otherwise be used to catch this.Once this happens, the entity never enters
_configured_entities, and every command against it 404s with "no configured entity found" for the rest of that session, until something forces a full unsubscribe/resubscribe cycle (e.g. manually reconfiguring the integration).Fix
When an entity isn't available at subscribe time, spawn a short-lived task that polls for it (every 0.5s, up to 10s) and configures it as soon as it appears, instead of dropping the subscription permanently on the first miss.
Testing
Reproduced and confirmed fixed against a real Arcam AVR11 integration (
uc-intg-arcam, built onucapi-framework) across multiple Remote 3 restarts. Logs confirm the retry firing and the entity becoming controllable immediately afterward with no manual reconfiguration needed. Happy to share logs if useful.