• alfadb's avatar
    fix(gateway): wrap Anthropic stream EOF as failover error before client output · 63275735
    alfadb authored
    
    
    Anthropic streaming path (gateway_service.go) returned a plain error on
    upstream SSE read failure, so the handler-level UpstreamFailoverError check
    never fired and the client received a bare `stream_read_error` event,
    breaking long-running tasks even when no bytes had been written yet.
    
    The most common trigger is HTTP/2 GOAWAY from api.anthropic.com edge
    backends doing graceful rotation: Go's http.Transport surfaces this as
    `unexpected EOF` and never auto-retries.
    
    Mirror what the OpenAI and antigravity gateways already do: when the read
    error happens before any byte has reached the client (`!c.Writer.Written()`),
    return `*UpstreamFailoverError{StatusCode: 502, RetryableOnSameAccount: true}`
    so the handler can retry on the same or another account. After client
    output has begun, SSE has no resume protocol — keep the existing passthrough
    behavior.
    
    Tests cover both branches via streamReadCloser-based fixtures.
    Co-Authored-By: default avatarClaude Opus 4.7 (1M context) <noreply@anthropic.com>
    63275735
gateway_streaming_test.go 10.8 KB