feat(executor): add upstream disconnect handling for Codex WebSocket sessions

- Introduced `UpstreamDisconnectChan` for Codex WebSocket sessions to notify downstream connections of upstream disconnections.
- Implemented `notifyUpstreamDisconnect` to signal errors and close channels on disconnect events.
- Added integration tests to validate WebSocket session behavior on upstream disconnect.
- Updated OpenAI WebSocket response handlers to properly close connections upon upstream disconnect notifications.
This commit is contained in:
Luis Pater
2026-05-06 22:09:33 +08:00
parent ed1458aa6d
commit fb08b92402
4 changed files with 233 additions and 1 deletions
@@ -56,6 +56,31 @@ func (h *OpenAIResponsesAPIHandler) ResponsesWebsocket(c *gin.Context) {
retainResponsesWebsocketToolCaches(downstreamSessionKey)
clientIP := websocketClientAddress(c)
log.Infof("responses websocket: client connected id=%s remote=%s", passthroughSessionID, clientIP)
wsDone := make(chan struct{})
defer close(wsDone)
if h != nil && h.AuthManager != nil {
if exec, ok := h.AuthManager.Executor("codex"); ok && exec != nil {
type upstreamDisconnectSubscriber interface {
UpstreamDisconnectChan(sessionID string) <-chan error
}
if subscriber, ok := exec.(upstreamDisconnectSubscriber); ok && subscriber != nil {
disconnectCh := subscriber.UpstreamDisconnectChan(passthroughSessionID)
if disconnectCh != nil {
go func() {
select {
case <-wsDone:
return
case <-disconnectCh:
_ = conn.Close()
}
}()
}
}
}
}
var wsTerminateErr error
var wsTimelineLog strings.Builder
defer func() {