Skip to content

fix(ai): one retry layer for a gateway call #5965

Description

@dan-petty

Problem

A model call of a roadmap job is retried in three layers that do not agree, and the failure that hurt most is retried by none of them.

Layer Retries Source
Gateway (LiteLLM v1.103.11) num_retries: 5 on the group, allowed_fails: 3, cooldown_time: 30, then the fallback deepseek-v4.1-flash-1017 -> deepseek-v4.1-flash; timeout: 1500 s for each attempt k8s/llm/gateway/config.yaml
Client, pydantic-ai path (refine, alternatives, stage, implement) 3 attempts, fixed in code: async_http_client(level, retries=3); tenacity waits Retry-After or 1 s, 2 s (max 60 s) on transport errors, timeouts, 408, 429 and 5xx src/devops_cli/ai/providers/__init__.py:171-181, src/devops_cli/ai/retries/__init__.py
Client, direct path ai.max_retries + 1 = 2 attempts src/devops_cli/ai/client/base.py

Defects:

  1. A failure inside a streamed reply is not retried. On 2026-11-16 from 10:40Z to 11:35Z, OpenRouter timed out inside the stream (OpenRouterException: A Timeout Occurred in chunk_parser, 12 times). The gateway and the client had a status 200 already, so no retry and no fallback ran, and the steps failed: refine 4, alternatives 3, stage 3, implement 2 (class=provider).
  2. The pydantic-ai path ignores ai.max_retries. The requirement "A model call in the cluster is sent at most two times" (feat(service): roadmap-service runs again at one replica, with one model retry in the cluster #2494, openspec/specs/roadmap-service-deployment/spec.md) and the ConfigMap value 1 do not reach it.
  3. The retries multiply, and no deadline bounds them. 3 client attempts times 6 gateway attempts, plus the fallback, can send one call more than 18 times, and each attempt may wait 1500 s.

Over 7 days the :floor deployment had 964 failures in 44,521 calls (2.2%), and the fallback recovered 564.

Expected behavior

  • One layer owns the retries of a gateway call: the gateway, which holds the fallback. The client retries only a connection that never reached the gateway, and it reads ai.max_retries.
  • A stream that fails before its first token is retried or falls back. A stream that fails after its first token fails the call once, with a clear class.
  • Each call has one total deadline, below the step time limit of its job (nested timeouts: the inner fires first).

Test first: a fake gateway that returns 200 and then breaks the stream before the first token gets one retry, and the pydantic-ai provider sends at most ai.max_retries + 1 attempts.

Related

Activity

  1. dan-petty commented on Nov 16, 2026

    @dan-petty
    OwnerAuthor
    • Priority: P0-Critical. Job steps are failing (refine, alternatives, stage, implement) due to unhandled stream timeouts and multiplied retries without a deadline.
    • Related: fix(ai): retry a reset in the answer read of a pydantic-ai agent run #5806, which asks for a different change. Both target retry in the pydantic-ai path, but #5806 fixes one specific reset during answer read while the candidate consolidates all retry layers, adds a total deadline, and handles stream failures before the first token.
  2. added
    type/bug
    scope/ai
    source/agent
    status/new
    effort/high
    value/high
    priority/p0-critical
    owner/agent
    status/in-progress
    status/in-review
    and removed
    status/new
    status/in-progress
    on Nov 16, 2026
  3. removed
    status/in-review
    owner/agent
    on Nov 16, 2026
  4. devops-cli-service commented on Nov 16, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-16 13:55 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/highpriority/p0-criticalscope/aisource/agenttype/bugvalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions