Repository navigation
fix(#3109): catch httpx.HTTPStatusError in Watsonx model discovery - #3111
Conversation
WatsonxIAMAuth.raise_for_status() raises httpx.HTTPStatusError on IAM token exchange failures (401/403/5xx), which is not a subclass of openai.APIError. This escaped the except clause in _discover_models, propagating unwrapped instead of as ModelDiscoveryError. Widen the except tuple to (APIError, httpx.HTTPStatusError) so IAM failures are wrapped consistently with other discovery errors. Add a parametrized test case for httpx.HTTPStatusError to the existing test_discover_models_wraps_api_error test. Closes #3109
|
Important Review skippedBot user detected. To trigger a single review, invoke the
|
|
🤖 Finished Review · ✅ Success · Started 2:04 PM UTC · Completed 2:18 PM UTC Commit: Runtime: pi · Model: opus → claude-opus-4-6 · Effort: high · Cost: $3.76 |
ReviewFindingsLow
Labels: Bug fix PR addressing an exception handling gap in the Watsonx provider. |
There was a problem hiding this comment.
Note: The following review comments could not be posted on the diff (GitHub returned 422) and are included here instead:
tests/unit/providers/inference/watsonx/test_provider.py(file-level): Line 148 ·
[low] missing-test
The new httpx.HTTPStatusError test case injects the error only via models.list while stubbing _list_foundation_model_functions to succeed. The except clause covers both coroutines in asyncio.gather, but no test verifies the error path when _list_foundation_model_functions raises httpx.HTTPStatusError from the IAM auth layer.
| self._list_foundation_model_functions(), | ||
| ) | ||
| except APIError as exc: | ||
| except (APIError, httpx.HTTPStatusError) as exc: |
There was a problem hiding this comment.
[low] edge-case
The except (APIError, httpx.HTTPStatusError) handler does not catch raw httpx transport errors (httpx.ConnectError, httpx.TimeoutException). However, these would only be unhandled if they escape the openai SDK's own error-wrapping layer, which normally converts them to APIConnectionError/APITimeoutError (both subclasses of APIError). The practical risk is low and unconfirmed.
|
🤖 Finished Retro · ✅ Success · Started 9:07 AM UTC · Completed 9:14 AM UTC Commit: Runtime: pi · Model: opus → claude-opus-4-6 · Effort: high · Cost: $1.89 |
Retro: PR #3111 — catch httpx.HTTPStatusError in Watsonx model discoveryTimeline
What went well
Model unavailability degraded review coverage4 of 7 sonnet-tier review sub-agents (intent-coherence, style-conventions, docs-currency, risk-assessment) failed because both This is a well-tracked problem across multiple open issues — this retro adds PR #3111 as another data point:
Autonomy assessmentInconclusive. Both human reviewers approved without substantive findings, so the delta between agent and human review cannot be meaningfully computed for this PR. No new proposalsAll improvement opportunities identified in this retro are already tracked by existing open issues. No new proposals are warranted. |
Description
Catch
httpx.HTTPStatusErrorinWatsonxInferenceProvider._discover_modelsso that IBM IAM token exchange failures are wrapped inModelDiscoveryErrorlike all other provider discovery errors.WatsonxIAMAuth._exchange_token()callsresponse.raise_for_status()on the IAM endpoint response. When IAM rejects the API key (HTTP 401/403) or is unreachable (HTTP 5xx), this raiseshttpx.HTTPStatusError, which is not a subclass ofopenai.APIErrorand was escaping the existingexcept APIErrorhandler.The fix widens the except clause to
except (APIError, httpx.HTTPStatusError) as exc.Type of change
Tools used to create PR
Related Tickets & Documents
Checklist before requesting a review
Testing
Added a parametrized
httpx.HTTPStatusErrortest case to the existingtest_discover_models_wraps_api_errortest. The test mocksmodels.listto raisehttpx.HTTPStatusError(simulating an IAM 401) and asserts thatModelDiscoveryErroris raised with the original exception chained as__cause__.All 13 tests in
tests/unit/providers/inference/watsonx/test_provider.pypass.Closes #3109
Post-script verification
agent/3109-watsonx-iam-discovery-error)0b7d2138a96689f06ac4330cf28069f122ff1fbe..HEAD)