diff --git a/internal/deepseek/protocol/constants.go b/internal/deepseek/protocol/constants.go index 3cb6c4d..83daa31 100644 --- a/internal/deepseek/protocol/constants.go +++ b/internal/deepseek/protocol/constants.go @@ -159,6 +159,6 @@ func toStringSet(in []string) map[string]struct{} { const ( KeepAliveTimeout = 5 - StreamIdleTimeout = 90 - MaxKeepaliveCount = 10 + StreamIdleTimeout = 300 + MaxKeepaliveCount = 40 ) diff --git a/internal/httpapi/openai/chat/empty_retry_runtime.go b/internal/httpapi/openai/chat/empty_retry_runtime.go index de2ff12..147024f 100644 --- a/internal/httpapi/openai/chat/empty_retry_runtime.go +++ b/internal/httpapi/openai/chat/empty_retry_runtime.go @@ -252,6 +252,9 @@ func (h *Handler) consumeChatStreamAttempt(r *http.Request, resp *http.Response, } }, }) + if r.Context().Err() != nil { + return true, false + } terminalWritten := streamRuntime.finalize(finalReason, allowDeferEmpty && finalReason != "content_filter") if terminalWritten { recordChatStreamHistory(streamRuntime, historySession) diff --git a/internal/httpapi/openai/responses/empty_retry_runtime.go b/internal/httpapi/openai/responses/empty_retry_runtime.go index 627f074..45d861d 100644 --- a/internal/httpapi/openai/responses/empty_retry_runtime.go +++ b/internal/httpapi/openai/responses/empty_retry_runtime.go @@ -223,6 +223,9 @@ func (h *Handler) consumeResponsesStreamAttempt(r *http.Request, resp *http.Resp } }, }) + if r.Context().Err() != nil { + return true, false + } terminalWritten := streamRuntime.finalize(finalReason, allowDeferEmpty && finalReason != "content_filter") if terminalWritten { return true, false