Skip to content

Fix: entity subscription dropped when it arrives before connect (Remote restart race) - #67

Open
SPLBendrix wants to merge 1 commit into
unfoldedcircle:mainfrom
SPLBendrix:fix/retry-entity-subscription-before-available
Open

Fix: entity subscription dropped when it arrives before connect (Remote restart race)#67
SPLBendrix wants to merge 1 commit into
unfoldedcircle:mainfrom
SPLBendrix:fix/retry-entity-subscription-before-available

Conversation

@SPLBendrix

Copy link
Copy Markdown

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_events before connect over the websocket on session start:

[arcam] Session became active: sending subscribe_events, get_driver_version, connect
WARN: cannot subscribe entity media_player.arcam_...: entity is not available

_subscribe_events() checks _available_entities immediately 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_entities that 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 on ucapi-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.

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.
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.

2 participants