Skip to content

fix(ai): read an HTTP 402 of the provider as a spent key #7261

Done

Description

@dan-petty

Problem or Motivation

On 2026-11-25 from 13:12Z to 20:43Z the key of the hosted provider had too few credits. The provider answered HTTP 402 ("This request requires more credits, or fewer max_tokens"), and the gateway passed the status on. The roadmap jobs read the reply as a short provider failure, not as a spent key:

  • spend_limit_error in src/devops_cli/ai/client/models.py reads only the text Key limit exceeded, and each caller asks it only for HTTP 401 and 403 (fix(roadmap): name a spent provider key, not a refused key #6821).
  • model_call_error in src/devops_cli/roadmap/agent_run.py gives an HTTP 402 the plain AIClientError, so the failure class is provider.
  • A job fails one item for an AIClientError and goes on to the next item. It stops its round only for AICredentialsError. So no round failed, and the failure ledger of the Service parked no row.

Result lines of the 8 hours (Loki, roadmap job result:): 439 attempts with class=provider (refine 315 on 119 items, stage 87, alternatives 34, implement 3) and 4 successes. In the 7-day window, 452 of about 860 failed attempts have the class provider. The Service log of the same time shows HTTP 402 Payment Required (203 lines) and HTTP 429 Too Many Requests from the cooldown of the gateway (199 lines). No log line, class or metric told a person that only a higher spend limit could help.

Proposed Solution

Disposition: change the code.

  • An HTTP 402 of a model call is a spent key: spend_limit_error returns AIKeySpendLimitError for it, with no test of the body text.
  • Each site that maps HTTP 401 and 403 to a credentials error also takes HTTP 402.
  • model_call_error also maps ModelQuotaExceededError of pydantic-ai, which that library raises when a provider reports exhausted quota, credits or billing.

Then the class is spend_limit, each job stops its round at the first refused call, no item gets a failure, and the failure ledger suspends the row with a probe each hour (RETRY_AFTER), as for the 403 of #6821.

Proof: unit tests of spend_limit_error and model_call_error for HTTP 402 and for ModelQuotaExceededError, and a test that the failure class of the error is spend_limit.

Existing Tool Considered

pydantic-ai (in use) already classifies the reply: ModelQuotaExceededError covers HTTP 402 and the quota errors of each provider. The change reads that class and adds no new rule for provider text.

Related

Activity

  1. dan-petty commented on Nov 26, 2026

    @dan-petty
    OwnerAuthor
    • Priority: 439 misclassified failures in 8 hours and wrong failure class prevent correct parking and alerting.
  2. added
    type/bug
    scope/ai
    source/agent
    status/new
    effort/low
    value/high
    priority/p1-high
    owner/agent
    status/in-progress
    and removed
    status/new
    on Nov 26, 2026
  3. added
    status/in-review
    and removed
    status/in-progress
    on Nov 26, 2026
  4. removed
    status/in-review
    owner/agent
    on Nov 26, 2026
  5. devops-cli-service commented on Nov 26, 2026

    @devops-cli-service
    Contributor
  6. devops-cli-service commented on Nov 26, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-26 01:10 UTC

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/lowpriority/p1-highscope/aisource/agenttype/bugvalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions