Merge pull request #5676 from Perfecto23/agent/openai-capacity-failover

fix(openai): recover message-only capacity failures before output
This commit is contained in:
Wesley Liddick
2026-08-19 11:11:23 +08:00
committed by GitHub
14 changed files with 625 additions and 90 deletions
@@ -574,7 +574,7 @@ func (h *OpenAIGatewayHandler) Responses(c *gin.Context) {
// Forward request
service.SetOpsLatencyMs(c, service.OpsRoutingLatencyMsKey, time.Since(routingStart).Milliseconds())
forwardStart := time.Now()
// 用扣除 compact 心跳字节的口径快照:心跳注释不构成语义响应,
// 用扣除非语义心跳字节的口径快照:心跳注释不构成语义响应,
// 不能因心跳字节变化而放弃 failover 换号(#3887)。
writerSizeBeforeForward := service.OpenAICompactKeepaliveAdjustedWrittenSize(c)
// 跨 passthrough 边界的 failover:从 Kiro 等透传账号切到 Bedrock 等非透传账号前,
@@ -669,7 +669,9 @@ func (h *OpenAIGatewayHandler) Responses(c *gin.Context) {
h.handleFailoverExhausted(c, failoverErr, true)
return
}
if failoverErr.SafeToFailoverAfterWrite && c.Writer.Written() {
// openAIForwardMayFailover 已确认写出的字节不含语义输出,
// 但重试耗尽时仍须按已提交的 SSE 响应返回流内错误。
if c.Writer.Written() {
streamStarted = true
}
if failoverErr.ShouldReportAccountScheduleFailure() {