fix(cli): map exhausted transport retries to ServerError - #13079
Conversation
When httpx.TransportError exhausts retries in OmiClient._request, map the
underlying transport error to ServerError instead of letting it escape to
the unhandled exception handler in main().
- Raise ServerError("Connection failed", detail=...) with original exc as __cause__
- Preserves exit code 3 and JSON error output on stderr for --json
- Add regression tests covering connect, timeout, protocol errors, recovery, and CLI exit codes
Fixes BasedHardware#12961
Signed-off-by: Abhi <108084481+Aj2280@users.noreply.github.com>
Co-authored-by: lrodrig4 <215743880+lrodrig4@users.noreply.github.com>
|
Verified this end to end — a clean, tightly-scoped fix for #12961. Details for the record:
Verification run (isolated container, no network/secrets): full python-cli suite passes — 130 passed, 1 skipped, 0 failures ( One coordination note: #12996 also addresses #12961 (same transport-to-ServerError mapping, bundled with broader auth-login changes). This PR is the minimal, focused version of the fix. Maintainer decision needed on which one lands — either way, credit to both contributors for chasing the exit-code contract. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
kodjima33
left a comment
There was a problem hiding this comment.
Confirmed not-yet-fixed on main: exhausted-retry handler in _request only catches _RetryableHttp (5xx/429); a persistent httpx.TransportError still bubbles up raw instead of ServerError. Scoped fix + regression tests, confidence 5/5.
Summary
This PR maps exhausted
httpx.TransportErrorexceptions inOmiClient._request()toServerError(message="Connection failed", detail="Unable to reach the Omi API. Check your network connection or try again shortly."), resolving #12961.Previously, exhausted transport retries (such as connection refused, read timeout, or protocol error) escaped
_request()unmapped and fell through to the generic exception handler inmain(). This caused commands to exit with code1and emit unformatted plain text onstderreven when--jsonwas requested, violating the documented stable CLI exit code contract (3: server error / connection failure).Changes
sdks/python-cli/omi_cli/client.py:httpx.TransportErrorafter the retry loop inOmiClient._request().ServerError(message="Connection failed", detail="Unable to reach the Omi API. Check your network connection or try again shortly.") from exc.__cause__.sdks/python-cli/tests/test_client_retry.py:ConnectErrorexhausts 4 retries and raisesServerError(exit code 3).ReadTimeout.ProtocolError.ConnectErrorrecovers on retry and returns data.main()exits with code 3 in both plain and--jsonmodes and outputs the expected error structures to stderr.Verification
sdks/python-cli/venv/bin/pytest sdks/python-cli/tests/: all 134 passed, 1 skipped.omi --api-base http://127.0.0.1:54321 memory list: exits 3 with readable error on stderr.omi --api-base http://127.0.0.1:54321 --json memory list: exits 3 with JSON error payload on stderr and clean stdout.make preflight: all 12 local checks passed.Fixes #12961
Failure-Class: none