Skip to content

fix(llm): bound same-key recovery for proxy token lookup failures - #6226

Open
MuonChaser wants to merge 1 commit into
OpenHands:mainfrom
MuonChaser:codex/6225-proxy-token-lookup-retry
Open

MuonChaser wants to merge 1 commit into
OpenHands:mainfrom
MuonChaser:codex/6225-proxy-token-lookup-retry

Conversation

@MuonChaser

@MuonChaser MuonChaser commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

HUMAN:

I confirm the scope of this fix: one additional retry for specific non-streaming proxy token-lookup authentication failures, while preserving persistent authentication errors. The reported local tests were run by Codex. I agree to submit this change for maintainer review.


AGENT:

Why

A specific LiteLLM proxy token-lookup 401 currently surfaces immediately even when the next request with the same key would succeed. A lookup miss can also mean invalid credentials; this change does not establish a cache race.

Summary

  • Allow one additional non-streaming same-key auth recovery attempt across all four sync/async chat and Responses methods; honor num_retries=0 and keep changed-key refresh precedence.
  • Preserve persistent/generic auth classification, subscription boundaries, and budget/fallback handling. Streaming is excluded to prevent partial replay.
  • Log only safe retry/recovery phase and counter information.

Issue Number

Fixes #6225 (bounded SDK recovery; no proxy root-cause claim).

How to Test

Offline loopback HTTP tests use fabricated tokens and actual LiteLLM normalization. No paid API or private Cloud access.

uv run --frozen pytest tests/sdk/llm tests/sdk/event tests/sdk/utils/test_pydantic_secrets.py tests/sdk/utils/test_redact.py tests/agent_server/test_managed_llm_key.py -n 4 -q
uv run --frozen pre-commit run --files openhands-sdk/openhands/sdk/llm/llm.py tests/sdk/llm/test_auth_refresh_retry.py tests/sdk/llm/test_proxy_token_lookup_retry.py

Results: 1,596 scoped tests passed; four subsequently added latest-error propagation cases also passed. Pre-commit, including Pyright, passed.

Reproduce the original symptom from this PR checkout:

git worktree add ../sdk-6225-base d2ee0cdea60825608c2f8906eb54e1d4d264fb42
cp tests/sdk/llm/test_proxy_token_lookup_retry.py ../sdk-6225-base/tests/sdk/llm/
cd ../sdk-6225-base
uv run --frozen pytest tests/sdk/llm/test_proxy_token_lookup_retry.py -k 'recovers and absent' -q

Base: four failures with LLMAuthenticationError. Fixed code: all four recover. Regressions also cover exact persistent attempt counts, unchanged/changed refresh hooks, disabled retries, generic auth, budgets/fallbacks, secret-free logs, repeated public calls, and partial-stream failure without replay.

Video/Screenshots

Nonvisual SDK change; executable HTTP reproduction above.

Design Doc

Not applicable: scoped recovery guard with no public schema change.

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

Notes

AI-assisted implementation and validation by Codex. Reporter Cloud observations are third-party evidence; proxy causality and live Cloud behavior were not verified. Historical events are unchanged. Final exact/domain searches found no competing implementation; merged #5218 covers changed-key refresh only.

Companion docs: OpenHands/docs#1004

Jev-Fast-Audit

⚡ Jev fast audit · estimates · 0.30s · commit fafc516
Strongest signal: Weakened authentication · 24% estimated likelihood.
Evidence: F001H004 · openhands-sdk/openhands/sdk/llm/llm.py:1891–1907.
Coverage: complete supplied coverage; 9/9 hunks, 3/3 files.

All estimates and evidence
Estimate Likelihood / value Direct evidence
SQL injection 3.0% No direct hunk selected
Command injection 3.0% No direct hunk selected
Weakened authentication 24.0% F001H004 · openhands-sdk/openhands/sdk/llm/llm.py:1891–1907
Weakened authorization 7.0% No direct hunk selected
Contract regression 16.0% No direct hunk selected
Data loss 3.0% No direct hunk selected
Sensitive data disclosure 6.0% No direct hunk selected
Unexpected data transfer 4.0% No direct hunk selected
Credential misuse 8.0% No direct hunk selected
Untrusted instruction authority 3.0% No direct hunk selected
Package source redirection 4.0% No direct hunk selected
Unverified remote execution 2.0% No direct hunk selected
Privileged environment access 5.0% No direct hunk selected
Security assessment bypass 5.0% No direct hunk selected
Prohibited workload 2.0% No direct hunk selected
Primary concern Weakened authentication; confidence 42.0% F001H004 · openhands-sdk/openhands/sdk/llm/llm.py:1891–1907

Co-authored-by: openhands <openhands@all-hands.dev>
@MuonChaser
MuonChaser marked this pull request as ready for review October 25, 2026 17:27
Copilot AI balanced review requested due to automatic review settings October 25, 2026 17:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants