From bcbae3bf411b7114ec17999840397f76c16a661b Mon Sep 17 00:00:00 2001 From: Ben Sheridan-Edwards Date: Tue, 21 Jul 2026 12:36:51 +0100 Subject: [PATCH] fix(stt): cover 401 retry and keep proof image out of the merge diff - parametrize the OAuth retry regression over HTTP 401 and 403 so both documented rejection statuses are exercised - reword the retry-failure warning: the except block also covers the retried request, not just the credential refresh - drop docs/proof/ from the PR diff; the live-proof screenshot now lives on the fork's proof-assets-xai-stt-oauth-retry branch and stays linked from the PR description --- tests/tools/test_transcription_tools.py | 7 ++++--- tools/transcription_tools.py | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/tools/test_transcription_tools.py b/tests/tools/test_transcription_tools.py index b7c9b9205749..c21407e2730e 100644 --- a/tests/tools/test_transcription_tools.py +++ b/tests/tools/test_transcription_tools.py @@ -1570,8 +1570,9 @@ class TestTranscribeXAI: assert "HTTP 400" in result["error"] assert "Invalid audio format" in result["error"] - def test_retries_403_with_refreshed_oauth_credentials( - self, sample_ogg, mock_xai_http_module + @pytest.mark.parametrize("rejected_status", [401, 403]) + def test_retries_auth_rejection_with_refreshed_oauth_credentials( + self, sample_ogg, mock_xai_http_module, rejected_status ): mock_xai_http_module.resolve_xai_http_credentials.side_effect = [ { @@ -1587,7 +1588,7 @@ class TestTranscribeXAI: ] rejected = MagicMock() - rejected.status_code = 403 + rejected.status_code = rejected_status rejected.json.return_value = { "error": {"message": "OAuth2 access token could not be validated"} } diff --git a/tools/transcription_tools.py b/tools/transcription_tools.py index 7f83d35df1ff..810796e960b5 100644 --- a/tools/transcription_tools.py +++ b/tools/transcription_tools.py @@ -1883,11 +1883,11 @@ def _transcribe_xai(file_path: str, model_name: str) -> Dict[str, Any]: refreshed_key, _resolve_base_url(refreshed_creds), ) - except Exception as refresh_exc: + except Exception as retry_exc: logger.warning( - "xAI STT OAuth refresh after HTTP %d failed: %s", + "xAI STT OAuth refresh-and-retry after HTTP %d failed: %s", response.status_code, - refresh_exc, + retry_exc, ) if response.status_code != 200: