@@ -283,10 +283,13 @@ func (h *OpenAIGatewayHandler) Responses(c *gin.Context) {
283283 )
284284 if len (failedAccountIDs ) == 0 {
285285 if errors .Is (err , service .ErrNoAvailableCompactAccounts ) {
286+ annotateOpenAISelectionFailure (c , h .gatewayService , apiKey .GroupID , sessionHash , err , "No available OpenAI accounts support /responses/compact" )
286287 h .handleStreamingAwareError (c , http .StatusServiceUnavailable , "compact_not_supported" , "No available OpenAI accounts support /responses/compact" , streamStarted )
287288 return
288289 }
289- h .handleStreamingAwareError (c , http .StatusServiceUnavailable , "api_error" , "Service temporarily unavailable" , streamStarted )
290+ msg := selectionUnavailableMessage (err )
291+ annotateOpenAISelectionFailure (c , h .gatewayService , apiKey .GroupID , sessionHash , err , msg )
292+ h .handleStreamingAwareError (c , http .StatusServiceUnavailable , "api_error" , msg , streamStarted )
290293 return
291294 }
292295 if lastFailoverErr != nil {
@@ -297,6 +300,7 @@ func (h *OpenAIGatewayHandler) Responses(c *gin.Context) {
297300 return
298301 }
299302 if selection == nil || selection .Account == nil {
303+ annotateOpenAISelectionFailure (c , h .gatewayService , apiKey .GroupID , sessionHash , nil , "No available accounts" )
300304 h .handleStreamingAwareError (c , http .StatusServiceUnavailable , "api_error" , "No available accounts" , streamStarted )
301305 return
302306 }
@@ -315,7 +319,7 @@ func (h *OpenAIGatewayHandler) Responses(c *gin.Context) {
315319 account := selection .Account
316320 sessionHash = ensureOpenAIPoolModeSessionHash (sessionHash , account )
317321 reqLog .Debug ("openai.account_selected" , zap .Int64 ("account_id" , account .ID ), zap .String ("account_name" , account .Name ))
318- setOpsSelectedAccount (c , account .ID , account .Platform )
322+ setOpsSelectedAccount (c , account .ID , account .Name , account . Platform )
319323
320324 accountReleaseFunc , acquired := h .acquireResponsesAccountSlot (c , apiKey .GroupID , sessionHash , selection , reqStream , & streamStarted , reqLog )
321325 if ! acquired {
@@ -677,7 +681,9 @@ func (h *OpenAIGatewayHandler) Messages(c *gin.Context) {
677681 )
678682 if len (failedAccountIDs ) == 0 {
679683 if err != nil {
680- h .anthropicStreamingAwareError (c , http .StatusServiceUnavailable , "api_error" , "Service temporarily unavailable" , streamStarted )
684+ msg := selectionUnavailableMessage (err )
685+ annotateOpenAISelectionFailure (c , h .gatewayService , apiKey .GroupID , sessionHash , err , msg )
686+ h .anthropicStreamingAwareError (c , http .StatusServiceUnavailable , "api_error" , msg , streamStarted )
681687 return
682688 }
683689 } else {
@@ -690,14 +696,15 @@ func (h *OpenAIGatewayHandler) Messages(c *gin.Context) {
690696 }
691697 }
692698 if selection == nil || selection .Account == nil {
699+ annotateOpenAISelectionFailure (c , h .gatewayService , apiKey .GroupID , sessionHash , nil , "No available accounts" )
693700 h .anthropicStreamingAwareError (c , http .StatusServiceUnavailable , "api_error" , "No available accounts" , streamStarted )
694701 return
695702 }
696703 account := selection .Account
697704 sessionHash = ensureOpenAIPoolModeSessionHash (sessionHash , account )
698705 reqLog .Debug ("openai_messages.account_selected" , zap .Int64 ("account_id" , account .ID ), zap .String ("account_name" , account .Name ))
699706 _ = scheduleDecision
700- setOpsSelectedAccount (c , account .ID , account .Platform )
707+ setOpsSelectedAccount (c , account .ID , account .Name , account . Platform )
701708
702709 accountReleaseFunc , acquired := h .acquireResponsesAccountSlot (c , apiKey .GroupID , sessionHash , selection , reqStream , & streamStarted , reqLog )
703710 if ! acquired {
@@ -1598,6 +1605,10 @@ func (h *OpenAIGatewayHandler) handleConcurrencyError(c *gin.Context, err error,
15981605func (h * OpenAIGatewayHandler ) handleFailoverExhausted (c * gin.Context , failoverErr * service.UpstreamFailoverError , streamStarted bool ) {
15991606 statusCode := failoverErr .StatusCode
16001607 responseBody := failoverErr .ResponseBody
1608+ upstreamMsg := service .ExtractUpstreamErrorMessage (responseBody )
1609+
1610+ service .SetOpsUpstreamError (c , statusCode , upstreamMsg , "" )
1611+ ensureOpsUpstreamErrorEvent (c , statusCode , "failover" , upstreamMsg )
16011612
16021613 // 先检查透传规则
16031614 if h .errorPassthroughService != nil && len (responseBody ) > 0 {
@@ -1623,10 +1634,6 @@ func (h *OpenAIGatewayHandler) handleFailoverExhausted(c *gin.Context, failoverE
16231634 }
16241635 }
16251636
1626- // 记录原始上游状态码,以便 ops 错误日志捕获真实的上游错误
1627- upstreamMsg := service .ExtractUpstreamErrorMessage (responseBody )
1628- service .SetOpsUpstreamError (c , statusCode , upstreamMsg , "" )
1629-
16301637 // 使用默认的错误映射
16311638 status , errType , errMsg := h .mapUpstreamError (statusCode )
16321639 h .handleStreamingAwareError (c , status , errType , errMsg , streamStarted )
@@ -1636,6 +1643,7 @@ func (h *OpenAIGatewayHandler) handleFailoverExhausted(c *gin.Context, failoverE
16361643func (h * OpenAIGatewayHandler ) handleFailoverExhaustedSimple (c * gin.Context , statusCode int , streamStarted bool ) {
16371644 status , errType , errMsg := h .mapUpstreamError (statusCode )
16381645 service .SetOpsUpstreamError (c , statusCode , errMsg , "" )
1646+ ensureOpsUpstreamErrorEvent (c , statusCode , "failover" , errMsg )
16391647 h .handleStreamingAwareError (c , status , errType , errMsg , streamStarted )
16401648}
16411649
@@ -1658,6 +1666,8 @@ func (h *OpenAIGatewayHandler) mapUpstreamError(statusCode int) (int, string, st
16581666
16591667// handleStreamingAwareError handles errors that may occur after streaming has started
16601668func (h * OpenAIGatewayHandler ) handleStreamingAwareError (c * gin.Context , status int , errType , message string , streamStarted bool ) {
1669+ message = decorateScheduledAccountErrorMessage (c , status , message )
1670+
16611671 if streamStarted {
16621672 // Stream already started, send error as SSE event then close
16631673 flusher , ok := c .Writer .(http.Flusher )
0 commit comments