Repository navigation
test(agent-server): cover budget denial after managed-key refresh - #5378
Conversation
Co-authored-by: openhands <openhands@all-hands.dev>
c97fe6f to
7d7a94d
Compare
REST API breakage checks (OpenAPI) — ✅ PASSEDResult: ✅ PASSED |
all-hands-bot
left a comment
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
Assessment
Test-only change to tests/agent_server/test_managed_llm_key_http.py (+41/-2). No production code is touched. The new regression is well constructed and the behavior it claims is genuinely exercised, but it cannot be approved as-is because a repository gate is red on this exact head.
Verified on head 7d7a94d4db5dbde7d3b962b7117615dc569c009f:
uv run pytest tests/agent_server/test_managed_llm_key_http.py tests/agent_server/test_managed_llm_key.py tests/sdk/llm/test_budget_denial_http.py tests/sdk/llm/test_auth_refresh_retry.py -q-> 103 passed.- The end-to-end test paths are real: a
ThreadingHTTPServerserves 401/429/200, and the assertions run through the SDK transport and the agent-server refresh hook (register_managed_llm_key_refresh). No mocks substitute for the code under test.
What the change gets right
- The new case inverts the pre-existing fixture in a meaningful way: the stale key is rejected (401) but the refreshed key is accepted, then the provider denies on budget. That is the only combination that distinguishes "refresh succeeded but budget is exhausted" from "refresh failed", so the added coverage is not redundant with
test_managed_refresh_is_bounded_over_http. LLMRateLimitErroris the correct mapped exception.is_budget_exceeded_error()(openhands-sdk/openhands/sdk/llm/exceptions/classifier.py) matches on thebudget_exceededpayload type,is_quota_exhaustion_error()then excludes it from the retry predicate inLLM._make_retry_decorator(), andmax_retries=0is passed at the LiteLLM boundary. Asserting exactly["Bearer stale-key", "Bearer fresh-key"]therefore genuinely proves no budget retry occurred; a retrying implementation would emit more than two POSTs.- Reusing the same
LLMinstance for the follow-up call and asserting the request log doubles to four entries verifies that recovery after the limit is lifted works on the existing instance, not just on a fresh one. - Both sync and async are parametrized.
- Adding a leading
systemmessage tomessages()now satisfies the repository's "system message before the first user message" invariant inDEVELOPMENT.md/AGENTS.md. - Import ordering and the new
LLMRateLimitErrorimport are fine; pre-commit passes.
Actionable finding
The Validate PR description check is failing on head 7d7a94d4 (run 36619818894, job 109582043809). The job log reports:
Linked issue(s) (#5222, #5309) carry neither
ready-for-devnor a pre-rollout creation date. Newly referenced issues must meet the readiness criteria before a PR can be opened.
## Issue Number currently reads "Builds on merged #5222 and #5309...". .github/scripts/check_pr_description.py scans that section for bare #NNN tokens (BARE_ISSUE_REF_RE) and treats them as linked issues; both referenced items were created after the 2026-08-13 cutoff and carry no ready-for-dev label, so the gate fails deterministically. These are merged PRs, not issues awaiting development, so the gate is misreading an informational reference. This is not a code defect, but it is a concrete, merge-blocking CI failure on the current head and should be fixed before the PR lands - for example by referring to them as "PR 5222" / "PR 5309" in the ## Issue Number section (or linking an actual ready-for-dev issue) and skipping the bare #NNN form.
Notes
The fixture budget assertion matches how a real managed proxy sends LiteLLM budget denials, and the PR description correctly limits the claim (it does not claim to prove deployed Enterprise/LiteLLM or UI behavior), which is honest scoping. Nothing in the changed file is out of scope for this repository.
🔄 CHANGES REQUESTED
|
Updated the Issue Number section to link the existing managed-key issue #5189, which is ready-for-dev. The description explicitly limits this PR to regression coverage and does not claim to close the hosted issue. No code changed. |
all-hands-bot
left a comment
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
Assessment
Test-only change to tests/agent_server/test_managed_llm_key_http.py (+41/-2). No production code is touched. The change is in scope for this repository (Agent Server test suite) and the previously blocking gate is now resolved on this head.
Verified on head c5d171756cf2cbbef014a2224c0fe8f9d6e132dc:
- The PR diff is exactly one file (
tests/agent_server/test_managed_llm_key_http.py); the merge ofmainbrought in only version/lockfile churn outside the PR's file set. uv run pytest tests/agent_server/test_managed_llm_key_http.py tests/agent_server/test_managed_llm_key.py tests/sdk/llm/test_budget_denial_http.py tests/sdk/llm/test_auth_refresh_retry.py -q-> 103 passed.- All current-head checks are green: 28 success, 2 skipped, 0 failures, including
Validate PR description,pre-commit,agent-server-tests-family checks,sdk-tests, and the binary/build jobs. - The linked issue
#5189carriesready-for-dev, and the PR description now limits its claim ("Related to #5189 ... Does not close"), so the description gate passes.
What the change gets right
- The new case is not redundant with
test_managed_refresh_is_bounded_over_http: it exercises the only combination that distinguishes "refresh succeeded but the budget is exhausted" from "refresh failed" - stale key rejected (401), refreshed key accepted, then a budget denial. LLMRateLimitErroris the correct mapped exception.is_budget_exceeded_error()(openhands-sdk/openhands/sdk/llm/exceptions/classifier.py) matches thebudget_exceededpayload,is_quota_exhaustion_error()excludes it from the retry predicate inLLM._make_retry_decorator(), andmax_retries=0is passed at the LiteLLM boundary. Asserting exactly["Bearer stale-key", "Bearer fresh-key"]therefore genuinely proves no budget retry occurred; a retrying implementation would emit more than two POSTs.- Reusing the same
LLMinstance for the follow-up call and asserting the request log doubles to four entries verifies recovery on the existing instance, not just on a fresh one. - Both sync and async paths are parametrized, and the leading
systemmessage now satisfies the repository's system-before-user message invariant. - The evidence is real end-to-end HTTP (a
ThreadingHTTPServerserving 401/429/200) through the SDK transport and the agent-server refresh hook; no mocks substitute for the code under test.
No material correctness, security, compatibility, or acceptance-criterion defect found on this head. The prior description-gate finding is resolved.
✅ APPROVED
HUMAN:
Adds regression tests proving that a stale managed key can refresh, an exhausted budget then fails without retries, and
the same LLM succeeds after the limit is raised
AGENT:
Why
Managed-key recovery and budget fail-fast are tested separately. This adds coverage for a stale key that refreshes successfully but then hits an exhausted budget.
Summary
Issue Number
Related to #5189: regression coverage for managed-key recovery followed by budget denial. Does not close the hosted-account issue or claim deployed recovery validation. Builds on merged PR 5222 and PR 5309.
How to Test
Validated on current main
d62d87e79, which includes both dependencies:103 passed. Changed-file pre-commit passes. Fresh CI runs on the rebased branch.
Before #5309, both new cases failed with 10 provider requests instead of 2. With the merged fix, stale-key refresh and budget denial make exactly two requests, and the same LLM succeeds after lifting the fixture budget.
Video/Screenshots
No UI change. The fixture starts a real local HTTP server with synthetic credentials and controlled 401/429/200 responses. This validates SDK transport and registered refresh behavior; it does not prove deployed Enterprise/LiteLLM behavior, conversation persistence, or UI Retry.
Type
Notes
No production code changes. The same LLM instance is reused; full same-conversation recovery remains part of packaged acceptance.
🐳 Agent Server images for this PR — GHCR package, pull/run commands, and all pushed tags (click to expand)
• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server
Variants & Base Images
eclipse-temurin:17-jdkpython-node-runtimepython-node-runtimepython-node-runtimegolang:1.21-bookwormPull (multi-arch manifest)
# Each variant is a multi-arch manifest supporting both amd64 and arm64 docker pull ghcr.io/openhands/agent-server:c5d1717-pythonRun
All tags pushed for this build
About Multi-Architecture Support
c5d1717-python) is a multi-arch manifest supporting both amd64 and arm64c5d1717-python-amd64) are also available if needed