fix: stabilize anthropic passthrough timeout error

This commit is contained in:
shaw 2026-05-07 10:24:29 +08:00
parent e69319e747
commit 501b7f2772

View File

@ -5343,6 +5343,12 @@ func (s *GatewayService) handleStreamingResponseAnthropicAPIKeyPassthrough(
flusher.Flush()
}
if !sawTerminalEvent {
if clientDisconnected && streamInterval > 0 {
lastRead := time.Unix(0, atomic.LoadInt64(&lastReadAt))
if time.Since(lastRead) >= streamInterval {
return &streamingResult{usage: usage, firstTokenMs: firstTokenMs, clientDisconnect: true}, fmt.Errorf("stream usage incomplete after timeout")
}
}
return &streamingResult{usage: usage, firstTokenMs: firstTokenMs, clientDisconnect: clientDisconnected}, fmt.Errorf("stream usage incomplete: missing terminal event")
}
return &streamingResult{usage: usage, firstTokenMs: firstTokenMs, clientDisconnect: clientDisconnected}, nil