Open
Conversation
- Add 401 response handling in AnsysIDAuth.auth_flow to force-refresh the token and retry the request when the server rejects it as expired - Increase stop_after_delay from 10s to 120s so the retry window is actually wider than the max exponential backoff interval (60s) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- test_auth_flow_retries_on_401_with_fresh_token: simulates an expired token by mocking the first request to return 401, verifies that get_ansyId_token is called a second time with force=True and the retry request succeeds with the fresh token - test_auth_flow_does_not_retry_on_other_errors: asserts that non-401 errors do not trigger a token refresh Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ng jobs - Fix NameError: add missing get_ansyId_token import to progress.py so the token refresh on WebSocket reconnect (line 118) actually works at runtime - test_auth_flow_token_expires_mid_sequence: sends 4 HTTP requests via a shared client; the 3rd returns 401 (expired token), verifies that auth_flow retries with force=True and requests 1, 2, 3 (retry), and 4 all complete with 200 - test_token_refreshed_on_websocket_reconnect: simulates a long-running job where the WebSocket disconnects mid-job (token expiry), verifies that get_ansyId_token is called to fetch a fresh token and the second connection uses that token to receive the completion message Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
RobKellyAnsys
approved these changes
Mar 31, 2026
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.
This pull request introduces improvements to authentication token handling and reliability, particularly around token refresh logic and error handling, and adds comprehensive tests for these scenarios. The main changes include extending the HTTP client retry timeout, improving automatic token refresh on authentication failures, and ensuring WebSocket reconnections use fresh tokens. Several new tests have been added to verify these behaviors.
Authentication and Token Refresh Improvements
auth_flowmethod inAnsysIDAuthto automatically detect a 401 Unauthorized response, force-refresh the authentication token, and retry the request with the new token. This ensures more robust handling of expired or rejected tokens.HTTP Client Reliability
get_http_clientfrom 10 seconds to 120 seconds, allowing for longer retry periods during transient failures.WebSocket and Progress Monitoring
get_ansyId_tokeninprogress.pyto support token refresh during WebSocket reconnections.Testing Enhancements
These changes collectively improve the robustness of authentication and progress monitoring, ensuring seamless operation even in the face of token expiry and transient network issues.