Repository navigation
language_models_cloud: Classify LLM token failures as provider rejections - #64754
Merged
Merged
Conversation
…ions `CloudLlmTokenProvider` returned `anyhow::Result`, and `authenticated_llm_request` reported every failure, including failing to mint an LLM token, as `LanguageModelCompletionError::HttpSend`. An expired session (401) or a missing subscription (402) while minting a token therefore looked like a connectivity problem: the agent showed a stream error and retry logic treated it as transient. Token providers now return `ClientApiError`, and `authenticated_llm_request` returns an `LlmRequestError` that keeps token acquisition separate from building or sending the request. `LlmRequestError::into_completion_error` maps a rejected or missing session to an `Authentication` rejection, a 402 to the existing `PaymentRequired` rejection, other token-endpoint statuses by their HTTP status, and connection failures to `HttpSend`. Callers that need different wording for different credentials can match on the category.
maxbrunsfeld
approved these changes
Sep 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CloudLlmTokenProviderreturnedanyhow::Result, andauthenticated_llm_requestreported every failure, including failing to mint an LLM token, asLanguageModelCompletionError::HttpSend. An expired session (401) or a missing subscription (402) during token minting therefore looked like a connectivity problem: the agent panel showed a stream error, and retry logic treated it as transient. Downstream consumers (Delta) had to dig typed errors back out of theanyhowchain to recover the real cause.This PR:
CloudLlmTokenProvider::cached_token/refresh_tokento returnResult<String, ClientApiError>, andClient::{cached,refresh,clear_and_refresh}_llm_tokento match.LlmRequestError, returned byauthenticated_llm_request, which separates token acquisition failures from building or sending the request.LlmRequestError::into_completion_error, which maps:Unauthorized/NotSignedInto a ZedAuthenticationrejection (not retried),PaymentRequiredrejection,Permission, 5xx to retryableInternalServer),HttpSend, as before.In Zed, a token failure caused by an expired session now shows the agent panel's authentication error instead of a stream error. Messages stay neutral about whose credentials were rejected so callers can choose wording from the category.
Release Notes: