Skip to content

Fix InvalidSessionException treated as permanent auth failure - #273

Closed
arpena wants to merge 1 commit into
iMicknl:mainfrom
arpena:fix/invalid-session-handling
Closed

Fix InvalidSessionException treated as permanent auth failure#273
arpena wants to merge 1 commit into
iMicknl:mainfrom
arpena:fix/invalid-session-handling

Conversation

@arpena

@arpena arpena commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Summary

InvalidSessionException inherits from UnauthorizedException, so it was being caught by the (AuthenticationException, UnauthorizedException) handler which raises ConfigEntryAuthFailed. This permanently disables the integration and marks all entities as unavailable, requiring user re-authentication.

Problem

When the router invalidates a session (e.g., due to a concurren login to the web interface using the same client IP as the Home Assistant server), the integration receives XMO_INVALID_SESSION_ERR. This is a transient condition, not a credentials problem. However, due to the exception hierarchy (InvalidSessionExceptionUnauthorizedException), it was treated as a permanent auth failure.

Fix

Catch InvalidSessionException explicitly before the UnauthorizedException handler and raise UpdateFailed instead of ConfigEntryAuthFailed. This allows the coordinator to retry on the next polling cycle and recover automatically.

Testing

Reproduced the issue by logging into the router web interface during a poll cycle. Before the fix, the integration died permanently. After the fix, it logs a warning and recovers on the next poll.

InvalidSessionException inherits from UnauthorizedException, so it was
being caught by the (AuthenticationException, UnauthorizedException)
handler and raising ConfigEntryAuthFailed. This caused the integration
to permanently stop polling and mark all entities as unavailable.

InvalidSessionException is a transient error that occurs when the
router invalidates the session (e.g., due to a concurrent login from
the web interface). It should be treated as a retryable UpdateFailed
so the integration recovers on the next polling cycle.
@arpena
arpena requested a review from iMicknl as a code owner July 23, 2026 12:14
@github-actions github-actions Bot added the fix label Jul 23, 2026
@iMicknl

iMicknl commented Jul 26, 2026

Copy link
Copy Markdown
Owner

Thanks @arpena! We might want to fix this in the underlying library, what do you think? It seems that this is a transient error indeed, not an authentication error.

@arpena

arpena commented Jul 29, 2026

Copy link
Copy Markdown
Contributor Author

Hi @iMicknl ! You are saying that we should change InvalidSessionException to inherit from BaseSagemcomException in exceptions.py?

@iMicknl

iMicknl commented Aug 1, 2026

Copy link
Copy Markdown
Owner

Yes!

@arpena

arpena commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

Closing in favor of fixing this at the library level: iMicknl/python-sagemcom-api#520

The root cause is that InvalidSessionException inherits from UnauthorizedException, so the fix belongs in python-sagemcom-api by changing the exception hierarchy. Once that's merged, this integration-side workaround is no longer needed.

@arpena arpena closed this Aug 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants