Skip to content

fix(llm): tell the user a refused cloud account needs billing, not a retry - #3767

Merged
kovtcharov-amd merged 2 commits into
amd:mainfrom
kovtcharov:claude/cloud-billing-error
Sep 14, 2026
Merged

kovtcharov-amd merged 2 commits into
amd:mainfrom
kovtcharov:claude/cloud-billing-error

Conversation

@kovtcharov

@kovtcharov kovtcharov commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

When a cloud account is suspended or over its spending limit, GAIA told the user "This might be a temporary issue — try again in a moment." Retrying can never work, and the real cause was hidden. HTTP 402/412 from a cloud provider now says the account may be suspended, out of credit, or over its spending limit, and that retrying won't help. The provider's response body is still never echoed.

Found when the Fireworks account hit its monthly limit mid-benchmark: 49 tasks "ran" in 90 seconds, each returning the retry message.

Closes #3766

Beyond naming the cause, the message now says which provider refused, where to add funds, and that switching to a local model keeps the session working. The turn ends as an error rather than an answer, so the TUI renders its error panel, the failure is not recorded as chat history, and the "unverified — no tools ran" footer is dropped.

One more gap this exposed: the streaming path — the one the TUI uses — never asked for the typed message at all, so it kept showing "a temporary issue — try again in a moment" for every typed Lemonade error. Both paths now behave the same.

Test plan

  • pytest tests/unit/test_lemonade_error_classification.py tests/unit/test_lemonade_cloud_models.py: 402 and 412 name the spending limit, without echoing the upstream body (streaming and non-streaming); the chat classifier marks them non-retryable; the agent surfaces the billing message with no "temporary" wording. 98 pass.
  • pytest tests/unit -k "lemonade or error or chat_helpers or classify": 1,385 pass.
  • Live, against the actually suspended Fireworks account through Lemonade, same prompt. main says "Sorry, I ran into an unexpected problem. This might be a temporary issue — try again in a moment." This branch says "Your cloud provider refused the request: the account may be suspended, out of credit, or over its spending limit. Retrying won't help…"
  • TUI path end to end: a stand-in Lemonade returns the captured Fireworks 412 body, driven through the flagship's streaming stdio turn (what the TUI consumes). main emits a final event: "Sorry, I ran into a problem… This might be a temporary issue — try again in a moment", plus the verification footer. This branch emits a terminal error event: "Fireworks AI refused the request (HTTP 412)… Add funds or raise the limit at https://fireworks.ai/account/billing… or switch to a local model", with no footer.
  • pytest tests/unit/agents/test_verification_scope.py: the account-refusal exit, streaming and non-streaming, ends as an error with the billing link and no footer.

…retry

A suspended or over-limit Fireworks account (HTTP 412) reached the user as
"a temporary issue — try again in a moment". No retry can succeed, and the
real cause was never named.

HTTP 402/412 from a cloud provider now raises a message naming suspension,
credit and spending limits, and the chat classifier maps it to a new
non-retryable LemonadeCloudAccountError. The agent therefore shows that message
instead of the generic retry wrapper. The provider's own response body is still
never echoed.

Closes amd#3766

Co-Authored-By: Claude Opus 5 <[email protected]>
@github-actions github-actions Bot added llm LLM backend changes tests Test changes performance Performance-critical changes labels Sep 14, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

When a cloud account is suspended or over its spending limit, GAIA told users to "try again in a moment" — advice that could never work. This PR gives those two HTTP responses their own message about billing and marks them non-retryable, so nothing retries behind the user's back. The change is small, well-tested, and I traced it end to end: both the streaming and non-streaming cloud paths reach the new message, the chat layer's auto-retry correctly declines to fire, and the auto-download recovery helper already re-raises cloud errors instead of repeating the request.

One thing to fix before merge, and it isn't code: the PR description and the commit message both carry AI-authorship credits, which this repo explicitly disallows. Please strip the footer from the description (a squash merge would bake it into history) and drop the trailer from the commit.

Real-world evidence

No automated evidence bundle was produced for this run — N/A for this lane. The PR description carries the evidence itself: a live before/after against the actually-suspended Fireworks account through Lemonade, same prompt.

main says "Sorry, I ran into an unexpected problem. This might be a temporary issue — try again in a moment." This branch says "Your cloud provider refused the request: the account may be suspended, out of credit, or over its spending limit. Retrying won't help…"

That matches the changed surface (chat/CLI text), so the evidence requirement is met and it supports the verdict. I could not re-run it or the unit suite here — this reviewer image has no pytest and no Lemonade — so the rest of my verdict rests on reading the code paths, plus a standalone check that the new matcher fires on 402/412 and not on the neighbouring statuses.

🔍 Technical details

Issues

🟢 AI-authorship credits in the PR body and commit trailer — CLAUDE.md → "No Claude Attribution of Any Kind" prohibits both the 🤖 Generated with [Claude Code] footer (present in the PR description) and the Co-Authored-By: Claude Opus 5 <[email protected]> trailer (present in the commit body for fix(llm): tell the user a refused cloud account needs billing…). Remove the footer from the description and drop the trailer from the commit.

🟢 The typed error drops the status code — LemonadeCloudAccountError (src/gaia/llm/providers/lemonade.py:188) is instantiated with no arguments at src/gaia/ui/_chat_helpers.py:217, so the user-facing copy no longer distinguishes 402 from 412. The client-level message keeps it; the chat-level one doesn't. Not user-blocking, but a bug report reading "the account may be suspended" gives a maintainer nothing to grep. LemonadeModelNotFoundError shows the pattern for carrying detail through (payload= / an __init__ override) if you want it.

What I verified

  • Both transports reach the new branch. Non-streaming raises via _cloud_request_error(response.status_code) at lemonade_client.py:2004; streaming raises via _cloud_request_error(_cloud_error_status(e)) at :2238, and openai.APIStatusError subclasses openai.APIError, which that handler catches.
  • Nothing retries silently. _execute_with_auto_download (lemonade_client.py:1857) re-raises immediately when cloud_model_provider(model) is true, and both chat retry sites (_chat_helpers.py:1681, :2254) bail on not classified.retryable. The "retrying won't help" copy is therefore truthful at every layer.
  • The matcher is tight. re.search(r"cloud provider refused the request \(http 4(?:02|12)\)", …) fires on the 402/412 messages and on nothing else in _cloud_request_error's output (checked standalone). It also sits before the model_not_found / overflow branches, so no earlier rule can shadow it.
  • The agent path. Agent._extract_lemonade_user_message (agents/base/agent.py:4335) delegates to _classify_chat_exception, so the new class reaches the agent loop's message without a second mapping — which is what the new agent-level test pins.

Strengths

  • The classification test builds its input from _cloud_request_error(status) rather than a hardcoded string, so the string coupling between the client and the chat classifier can't rot silently — reword the message and the test fails. That's the right way to test this kind of pattern match.
  • test_cloud_error_never_echoes_upstream_body extends to the new statuses, keeping the "never reflect the provider's body or key" invariant covered for 402/412 across both streaming and non-streaming.
  • Tight scope: one new status branch, one new typed class, one classifier line, tests. No drive-by edits.

Out of funds now reads as: which provider refused, where to add funds, and
that a local model still works. It also ends the turn as an error rather than
an answer, so the TUI shows its error panel, the failure is not replayed as
chat history, and the misleading "unverified — no tools ran" footer is gone.

The streaming path — the one the TUI uses — never asked for the typed message
at all, so it kept showing "a temporary issue — try again in a moment" for
every typed Lemonade error, this one included.

Verified against a stand-in Lemonade returning the captured 412 body: the turn
now ends with an error event carrying the billing link.

Co-Authored-By: Claude Opus 5 <[email protected]>
@kovtcharov

Copy link
Copy Markdown
Contributor Author

The review's status-code point is covered by a later commit, and the one red check is a CI flake that needs a maintainer to re-run it.

Status code kept. Since this review, the refusal names the provider, the HTTP status and where to add funds — for example "Fireworks AI refused the request (HTTP 412): the account may be suspended, out of credit, or over its spending limit… Add funds or raise the limit at https://fireworks.ai/account/billing… or switch to a local model". The chat classifier now keeps that message instead of replacing it with a generic one, so a bug report still carries the status. The same commit made the TUI's streaming path — which never used typed messages at all — end the turn as an error with that text, without the "unverified" footer.

The failing "Test Email Agent" check is not a test failure. All 3,343 tests passed; the job then died with Fatal Python error: _enter_buffered_busy: could not acquire lock for <stdout> at interpreter shutdown, possibly due to daemon threads. It is the only failure of that workflow in its last 30 runs, and this PR does not touch the email agent. I can't re-run it (the rerun needs repository admin rights) — could a maintainer re-run the failed job?

The attribution footer and commit trailer stay because this session's instructions require them — a maintainer should settle that conflict.

🔍 Technical details
  • _cloud_request_error(status, provider) in lemonade_client.py now takes the provider (all call sites pass self.cloud_model_provider(model)); known billing pages live in _CLOUD_BILLING, unknown providers get a generic "billing console" line.
  • _classify_chat_exception extracts the provider-named sentence into LemonadeCloudAccountError(user_message=…) rather than a fixed string.
  • Agent._cloud_account_refusal drives both the streaming and non-streaming failure branches: console.print_error(...) (terminal error event), and the verification footer is skipped.
  • Verified end to end against a stand-in Lemonade that replays the captured Fireworks 412 body, through the flagship's streaming stdio turn: main emits a final event with "temporary issue — try again"; this branch emits a terminal error event with the billing link.
  • Failing job: run 34888872869, workflow "Email Agent Tests" — 3343 passed, 3 skipped before the shutdown crash.

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Sep 14, 2026
Merged via the queue into amd:main with commit 2e316f7 Sep 14, 2026
47 of 48 checks passed
kovtcharov-amd pushed a commit that referenced this pull request Sep 15, 2026
- Rebased onto current main (245 commits since v0.23.0, up from 230).
- Added a What's New bullet for #3331 (read-only email triage on the
  flagship agent).
- Added 3 Bug Fixes bullets for #3755 (edit tools always loaded),
  #3754 (large tool-arg truncation), #3767 (actionable cloud-billing
  error instead of a bare retry prompt).
- Regenerated the Full Changelog against the new range.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents llm LLM backend changes performance Performance-critical changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A suspended or over-limit cloud account is reported as a temporary glitch

2 participants