Skip to content

feature: re-send inference requests that get no answer — recover the 5-minute stalls on bad gateway days #1473

Closed as not planned

Description

@huang195

Summary

When a gateway takes a request and never answers it, Claude Code waits about five minutes before it gives up and sends the request again. The retry almost always succeeds at normal speed. Cortex is in the request path and sees when an answer starts. It could send a second copy of a request that hasn't started answering after a short, measured cut-off, and use whichever copy answers first. Measured on one laptop's history, that recovers 17.7% of active time on days the gateway misbehaves, and 6.3% over two weeks. Normal days cost almost nothing.

This issue records the evidence and the open design questions. It is not a design.

The problem, measured

Source: one user's Cortex session archive, Oct 8–20, 2026. 25.4k model calls, 223 sessions with at least 10 minutes active, 217 h of active time (pauses over 10 minutes excluded). Path: Claude Code → Cortex → ete-litellm → AWS Bedrock.

  1. Stalled main-agent calls.
    • 161 Opus calls got zero bytes for 305–360 s (median 329 s), then Claude Code cancelled them. Cortex recorded each as 499 client_canceled.
    • Total cost: 14.8 h, 6.8% of active time.
    • 154 of the 161 fell on Oct 13–15, where 3.6–6.1% of Opus calls stalled. On those days stalls cost 18–22% of active time.
  2. The stuck request is the only problem.
    • Claude Code re-sent at a median 0.8 s after the cancel, and 104 retries were the identical request.
    • The first retry succeeded 92% of the time, in a median 17.5 s.
    • No request stalled three times in a row.
    • During 143 of the 161 stalls, some other Opus call started and succeeded. Of the calls started 30–120 s into a stall (the window a second copy would go out in), 89% succeeded.
    • So the gateway is never fully down. Individual requests get stuck.
  3. Stalled auto-mode safety checks.
    • Claude Code sends a short check (max_tokens 64, user message starting <transcript>, about 100k tokens, mostly from cache) before each tool call in auto mode.
    • 164 checks took 30 s or longer, and 150 of them fell on the same three days.
    • 99 eventually answered after a median 43 s, with 9 output tokens, so the time was spent waiting for the first byte.
    • 65 never answered, and Claude Code cancelled them at a median 80 s. The tool call is then refused ("… is temporarily unavailable (timed out), so auto mode cannot determine the safety of Bash"), and the agent has to retry.
  4. Claude Code can't fix this on a gateway.
    • CLAUDE_STREAM_FIRST_BYTE_TIMEOUT_MS exists, but the timer is armed only when the base URL is Anthropic's own API.
    • With ANTHROPIC_BASE_URL pointing at a gateway, it does nothing. Measured against an injected stall: retry at 362 s with or without it.
    • It works only together with the internal _CLAUDE_CODE_ASSUME_FIRST_PARTY_BASE_URL=1 (retry at 35 s). That flag changes a "first-party API?" check used in about 54 places.

Healthy timing, which sets the cut-offs

Time to response headers, measured direct to the gateway on 3,069 healthy calls built from real conversations under 200k tokens:

Cut-off Healthy main calls it would duplicate Main-call stall time recovered (of 14.8 h)
30 s 1.47% 13.4 h
45 s 0.23% 12.8 h
60 s 0.13% 12.1 h

The p99 was 35 s and the slowest healthy call took 138 s. Stalls ran 305–360 s, so nothing fell between about 140 s and 300 s.

Safety checks, healthy calls on normal days (n = 2,767): p50 2.5 s, p99 22.1 s, max 73 s.

Cut-off Healthy checks it would duplicate Time recovered Refused tool calls avoided (of 65)
20 s 1.3% 2.0 h 64
25 s 0.6% 1.7 h 64
30 s 0.4% 1.4 h 64

Expected benefit at 45 s (main) and 25 s (checks)

Saved Share of active time
Bad days (Oct 13–15) 13.0 h of 73.6 h 17.7%
Other days 0.6 h of 143.8 h 0.4%
Whole period 13.7 h of 217 h 6.3%

Per session:

  • 77% of sessions gain nothing; the mean is 5.3%.
  • The 51 sessions (23%) that hit a stall save a median 20.6% (about 5 minutes), a p90 of 49% (28 minutes), and up to 78%.
  • The worst session, on Oct 15, had 4.5 h of its 10.5 h active time recoverable.

Extra copies over the period:

  • About 195 extra Opus calls, against 14,692 Opus calls in total.
  • About 206 extra checks, at about $0.02 each.

Prototype results

The prototype is a Python reverse proxy, not Cortex. Its logic: send the request; if no response headers arrive within the cut-off, send an identical copy (up to 3); relay the first copy whose headers arrive and close the others.

Headless Claude Code ran 6 coding tasks × 2 repetitions × 3 settings. Injected stalls were placed at the bad-day rate (4.7% of calls).

Setting Runs Pass 5-min stalls hit Re-sends on calls with no injected stall
Stalls injected, no re-send 12 (1 errored) 11/11 4 —
Stalls injected, re-send at 45 s 12 12/12 0 (each recovered in ~46 s) 0 of 273
No stalls injected, re-send at 45 s 12 12/12 0 0 of 244

The difference in run time between settings is smaller than the run-to-run noise, so the benefit figures come from the historical data, not this test.

Questions for the design

  • Where it lives. Forward-proxy listener (core/listener/forwardproxy/server.go, around client.Do(r)), or the pipeline? Today Resender (core/pipeline/resend.go) acts only after a non-2xx answer, at most MaxResends (2) times, and nothing in the framework sends two requests in parallel. The transport has no ResponseHeaderTimeout, on purpose: MCP servers can hold headers for a long time. So the cut-off must be scoped to inference endpoints.
  • The trigger. First response byte, or first SSE event? A gateway that holds headers until generation is under way behaves differently from one that sends headers first.
  • Cut-offs.
    • Main calls: fixed 45 s, or grown with request size like Claude Code's own rule (+1 s per 32 KB, which gives about 64 s for a 600 KB request)? No healthy samples above 300k tokens were measured.
    • Checks: recognise them by max_tokens 64 plus a leading <transcript>? That's an undocumented pattern, so it needs a fallback to the main cut-off.
    • Configurable per endpoint?
  • Cancel or keep. Close the losing copy, or let it run? It's unknown whether Bedrock bills a cancelled streaming request. Measuring through the litellm key's spend header didn't work, because other traffic on the key drowned the signal.
  • Limits.
  • Visibility. Record each copy as its own request row, as resends do today (RenewRequestID), so agentop shows that a re-send happened and which copy won. Count re-sends per endpoint. The same signal could feed feature: alert when an inference backend's performance drops below its baseline #1400 (alerts).
  • Default. Off, with a measure-only mode that records "would have re-sent" without changing traffic. Bad days can't be reproduced on demand, so measure-only on real traffic is how to confirm the figures on another machine.
  • Other agents. Does the same pattern hold for OpenCode, Codex and Bob traffic, and for non-Anthropic gateways?

Not covered

  • Streams that start and then stop (74 calls, 3.5 h): they need a different trigger.
  • Fixed sleep waits that outlast what they wait for (about 7.9 h): a Claude Code hook problem, not a proxy one.

Pointers

Assisted-By: Claude (Anthropic AI) [email protected]

Activity

  1. added
    enhancement
    laptop
    on Oct 22, 2026
  2. huang195 commented on Nov 3, 2026

    @huang195
    MemberAuthor

    Measured again on 2026-11-03 over the full archive (Oct 8 – Nov 3).

    • 156 of the 161 stalls happened in one incident, Oct 12–15.
    • From Oct 21 to Nov 3 there were 0 stalls of 5 minutes.
    • For Oct 27 – Nov 3, a re-send at 45 s would have saved about 5 minutes of 71 h of active time (0.11%).

    The gateway problem was one incident, not a steady condition. I am closing this issue as not planned. Reopen it if the 5-minute stalls come back on more than one day in a month. The evidence and the design questions above stay valid.

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

    enhancementlaptop

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions