Skip to content

fix(http): cluster service reads retry a transient 503 #5532

Closed

Description

@dan-petty

Problem Description

A short outage of a cluster service ends a devops command with a Python traceback. The command does not try again. For example, Prometheus is not ready for some seconds after its pod restarts.

Evidence (2026-11-13):

  • devops prometheus query 'count(kubelet_pod_start_duration_seconds_count)' ran at 17:24:31Z.
  • It ended with httpx2.HTTPStatusError: Server error '503 Service Unavailable' and a 70-line traceback, logged as ERROR (trace c5f610552fc9fc8c3bce3c14d621890b).
  • The Prometheus pod had started 12 s before, at 17:24:19Z, after a planned node drain (devops infra apply). For those seconds the Service had no ready endpoint, so the tunnel answered 503.
  • One more attempt some seconds later would have passed.

Cause

  • devops_cli.http.entry.http_client has a retries option: a tenacity retry transport that tries again after 429, 5xx and connect failures.
  • Of about 30 call sites of http_client, only the AI clients (ai/client/base.py) pass retries.
  • prometheus/client.py _get_json calls response.raise_for_status() with no retry. The HTTPStatusError then reaches main.py _delegate, which logs a traceback for an exception that is not a DevOpsCLIError.
  • The same pattern is in the Loki client (k8s/logql.py, used by devops roadmap eval grades), the Grafana client and the k8s service probes (k8s/service_http.py, k8s/service_probe.py).
  • The Prometheus client is also the client of the rollout and apply health gate. That gate queries Prometheus soon after a node drain, which is when Prometheus can be restarting.

Proposed Fix

  • Give the read-only (idempotent GET) clients of cluster services one retry policy. Use the existing retries option of http_client, with backoff and jitter, a small attempt count (for example 4) and a total time bound below the command timeout.
  • Retry only 429, 502, 503, 504 and connect or read failures. Never retry a 4xx other than 429, a POST that is not idempotent, or an egress refusal.
  • Map the last failure to a DevOpsCLIError subclass in one place. It prints one line with the service, the status or the network error, the attempts and the time, and a hint, for example "the server is not ready; try again or check its pod". Exit code 1, no traceback.
  • fix(prometheus): a query that Prometheus refuses ends in a traceback #5487 (a 4xx with the error field of Prometheus) is the 4xx branch of the same mapping.
  • The health gate keeps its own wait loop. A retry inside one query must not hide a down Prometheus from the gate: the gate gets the mapped error and reports it.

Acceptance Criteria

  • A test with a fake transport that answers 503 twice and then 200 gets the JSON answer from PrometheusClient.query, after 3 attempts (devops ci fail-to-pass).
  • A test with 503 on every attempt gets one DevOpsCLIError line from devops prometheus query, exit code 1 and no traceback. The line names the attempts.
  • A test proves that a 400 is not retried.
  • The Loki client of devops roadmap eval grades, the Grafana client and the k8s service probes use the same policy. A test for each proves that it retries a 503.
  • A test proves that the apply health gate reports a Prometheus that stays down as a gate failure with the mapped message.

Related

Activity

  1. added
    source/agent
    type/bug
    status/new
    value/medium
    effort/medium
    on Nov 13, 2026
  2. dan-petty commented on Nov 13, 2026

    @dan-petty
    OwnerAuthor
    • Scope: none. The title has the scope http, and .github/labels.yml declares no scope/http label. Add the label to the file to give the scope to this item.
    • Related: fix(prometheus): a query that Prometheus refuses ends in a traceback #5487, which asks for a different change. Both map cluster-service HTTP errors to a clean DevOpsCLIError line. #5487 covers the 4xx branch; this candidate covers the 5xx retry branch.
  3. added
    priority/p2-medium
    owner/agent
    status/in-review
    and removed
    status/new
    on Nov 13, 2026
  4. removed
    status/in-review
    owner/agent
    on Nov 13, 2026
  5. devops-cli-service commented on Nov 13, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-13 21: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/mediumpriority/p2-mediumsource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions