From 88306d562d9a54a55179dde7b6050963d5b8f6ae Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Sun, 24 May 2026 21:03:19 +0000 Subject: [PATCH] fix(distributed): set node header before first byte on streaming error path In the chat.go error-from-worker branch the call to applyNodeIDHeader came after fmt.Fprintf had already written to the response writer. Go's http.ResponseWriter commits headers on the first Write, so the X-LocalAI-Node header was silently dropped on streaming error responses. Move the call before each Fprintf so the header is set on both the marshal-error and the normal-error paths. The non-streaming chat path and the completion error path were already correctly ordered. Assisted-by: Claude:claude-opus-4-7[1m] Signed-off-by: Ettore Di Giacinto --- core/http/endpoints/openai/chat.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/http/endpoints/openai/chat.go b/core/http/endpoints/openai/chat.go index 65da20112..b7531349d 100644 --- a/core/http/endpoints/openai/chat.go +++ b/core/http/endpoints/openai/chat.go @@ -449,12 +449,13 @@ func ChatEndpoint(cl *config.ModelConfigLoader, ml *model.ModelLoader, evaluator respData, marshalErr := json.Marshal(errorResp) if marshalErr != nil { xlog.Error("Failed to marshal error response", "error", marshalErr) + applyNodeIDHeader() fmt.Fprintf(c.Response().Writer, "data: {\"error\":{\"message\":\"Internal error\",\"type\":\"server_error\"}}\n\n") } else { + applyNodeIDHeader() fmt.Fprintf(c.Response().Writer, "data: %s\n\n", respData) } fmt.Fprintf(c.Response().Writer, "data: [DONE]\n\n") - applyNodeIDHeader() c.Response().Flush() return nil