Hmbown/CodeWhale · error · LlmError::NetworkError

SSE stream request did not receive response headers after

Error message

SSE stream request did not receive response headers after {}s. `codewhale doctor` can still pass when non-streaming requests work; on Windows or proxy networks, try `CODEWHALE_FORCE_HTTP1=1` and rerun `codewhale`.

What it means

`open_sse_response` bounds how long the SSE open may take to produce response headers. When the deadline elapses and the policy is pinned to HTTP/1.1 only (so there is no HTTP/2 fallback to try), it returns this `LlmError::NetworkError` timeout — deliberately typed so the shared retry layer recognizes it as retryable.

Solutions

  1. Verify network reachability to the provider host (curl the base URL) — a total header stall is usually proxy/firewall, not codewhale.
  2. If HTTP/1.1 was pinned unnecessarily, unset `CODEWHALE_FORCE_HTTP1=1` so the dual-protocol path is available.
  3. Retry — this error is retryable by the shared retry layer and transient stalls often clear.
  4. Check provider status/incident pages if the stall persists across endpoints.

Example fix

# before (H1 pinned, headers stall)
$ CODEWHALE_FORCE_HTTP1=1 codewhale
SSE stream request did not receive response headers after 30s ...
# after
$ unset CODEWHALE_FORCE_HTTP1 && codewhale
Defensive patterns

Strategy: retry

Validate before calling

// quick header-stall probe before opening the stream
tcp_ping_or_curl_head(&host, Duration::from_secs(5))?; // fail fast if host unreachable

Type guard

fn is_header_stall_timeout(err: &anyhow::Error) -> bool {
    err.to_string().contains("did not receive response headers")
}

Try / catch

match open_sse_response(req).await {
    Err(e) if is_header_stall_timeout(&e) => {
        // retryable: backoff and try again before giving up
        tokio::time::sleep(BACKOFF).await;
        open_sse_response(req).await
    }
    other => other,
}

Prevention

When it happens

Trigger: Calling the SSE open path with `StreamHttpPolicy::Http1Only` (e.g. `CODEWHALE_FORCE_HTTP1=1` set) and the server/proxy never returns response headers within `open_req.open_timeout` seconds.

Common situations: Users who pinned HTTP/1.1 to work around an HTTP/2 issue then hit a stalled proxy; firewalls that black-hole the connection so headers never arrive; overloaded provider endpoints.

Understand the failure class

Background: Request timed out: what client-side request timeouts mean across libraries (Request timed out, TIMED_OUT, APITimeoutError) — this error's family across 39 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/5e9f66f29ab0faef. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/client/stream_entry.rs:186

    F: Fn(StreamHttpPolicy) -> Fut,
    Fut: Future<Output = Result<reqwest::Response>>,
{
    let fallback_reason = match tokio::time::timeout(
        open_req.open_timeout,
        attempt(open_req.policy),
    )
    .await
    {
        Ok(Ok(response)) => return Ok(response),
        Ok(Err(err)) => {
            if !should_retry_error_with_h1(open_req.policy, &err) {
                return Err(err);
            }
            "transport error before response headers"
        }
        Err(_elapsed) => {
            if open_req.policy == StreamHttpPolicy::Http1Only {
                return Err(anyhow::Error::new(LlmError::NetworkError(format!(
                    "SSE stream request did not receive response headers after {}s. \
                         `codewhale doctor` can still pass when non-streaming requests work; \
                         on Windows or proxy networks, try `CODEWHALE_FORCE_HTTP1=1` and rerun `codewhale`.",
                    open_req.open_timeout.as_secs()
                ))));
            }
            "response-header timeout"
        }
    };

    // No response body exists yet, so switching protocols and replaying the
    // request is safe. The policy guard above keeps this to exactly one retry.
    let h1_req = open_req.clone().with_h1_only();
    crate::logging::warn(format!(
        "SSE stream {fallback_reason}; retrying once with HTTP/1.1"
    ));
    match tokio::time::timeout(h1_req.open_timeout, attempt(h1_req.policy)).await {
        Ok(Ok(response)) => Ok(response),

View on GitHub (pinned to 73e0f67d83)