agent-lightning icon indicating copy to clipboard operation
agent-lightning copied to clipboard

[Bug]: post_with_retry retries deterministic 4xx responses for ~2.5 minutes before failing

Open feiiiiii5 opened this issue 1 month ago • 0 comments

What happened?

AgentLightningSyncClient.post_with_retry treats every HTTP error status as retryable. A deterministic client error (401 for a wrong key, 404 for a missing route, 409 for a state conflict, 422 for a payload validation failure) is retried with exponential backoff for about 2.5 minutes (11 attempts, 2+4+8+16+30x6 seconds) and prints 11 POST failed lines before the real error is raised. The trainer/rollout-manager startup and the gateway pause/resume paths all use this method, so a wrong key or bad payload delays startup and the retry noise hides the root cause.

The server's own upstream retry policy only retries {408, 409, 429} plus 5xx (agentlightning/server/proxy.py), and get() never retries status codes, so the client behavior contradicts the rest of the codebase.

Steps to reproduce

import httpx
from agentlightning.client import AgentLightningSyncClient

transport = httpx.MockTransport(lambda request: httpx.Response(401))
client = AgentLightningSyncClient(max_retries=3, transport=transport)
client.post_with_retry("/api/models", json={})  # retries 3 times before raising

Expected behavior

A 4xx response that cannot succeed on retry (except 408/425/429) raises HTTPStatusError after a single request. Transport errors, 5xx, 408, 425 and 429 are still retried.

Actual behavior

Every 4xx is retried for the full backoff window, then the error is raised after ~2.5 minutes and many log lines.

Root cause

agentlightning/client.py calls raise_for_status() inside the try block, so HTTPStatusError for any 4xx is caught by the broad except Exception and retried.

Proposed fix

Add a retryable-status predicate ({408, 425, 429} and 5xx plus transport errors) and fail fast on other statuses, with a regression test that asserts a single request for 400/401/403/404/409/422 and a retry for 503/429.

feiiiiii5 avatar Nov 01 '26 11:11 feiiiiii5