From 6a39543288ead9724a5aae76156c9cbf2a47731a Mon Sep 17 00:00:00 2001 From: "CJACK." Date: Sun, 22 Mar 2026 08:29:01 +0800 Subject: [PATCH] fix tool-call json leaks when feature_match is disabled --- internal/adapter/openai/handler_chat.go | 4 ++-- internal/adapter/openai/responses_handler.go | 4 ++-- internal/js/chat-stream/toolcall_policy.js | 4 ++-- tests/node/chat-stream.test.js | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/internal/adapter/openai/handler_chat.go b/internal/adapter/openai/handler_chat.go index 27ef187..5f4668f 100644 --- a/internal/adapter/openai/handler_chat.go +++ b/internal/adapter/openai/handler_chat.go @@ -128,8 +128,8 @@ func (h *Handler) handleStream(w http.ResponseWriter, r *http.Request, resp *htt } created := time.Now().Unix() - bufferToolContent := len(toolNames) > 0 && h.toolcallFeatureMatchEnabled() - emitEarlyToolDeltas := h.toolcallEarlyEmitHighConfidence() + bufferToolContent := len(toolNames) > 0 + emitEarlyToolDeltas := h.toolcallFeatureMatchEnabled() && h.toolcallEarlyEmitHighConfidence() initialType := "text" if thinkingEnabled { initialType = "thinking" diff --git a/internal/adapter/openai/responses_handler.go b/internal/adapter/openai/responses_handler.go index b204442..dafd9a7 100644 --- a/internal/adapter/openai/responses_handler.go +++ b/internal/adapter/openai/responses_handler.go @@ -146,8 +146,8 @@ func (h *Handler) handleResponsesStream(w http.ResponseWriter, r *http.Request, if thinkingEnabled { initialType = "thinking" } - bufferToolContent := len(toolNames) > 0 && h.toolcallFeatureMatchEnabled() - emitEarlyToolDeltas := h.toolcallEarlyEmitHighConfidence() + bufferToolContent := len(toolNames) > 0 + emitEarlyToolDeltas := h.toolcallFeatureMatchEnabled() && h.toolcallEarlyEmitHighConfidence() streamRuntime := newResponsesStreamRuntime( w, diff --git a/internal/js/chat-stream/toolcall_policy.js b/internal/js/chat-stream/toolcall_policy.js index ff4611e..e881bab 100644 --- a/internal/js/chat-stream/toolcall_policy.js +++ b/internal/js/chat-stream/toolcall_policy.js @@ -10,10 +10,10 @@ function resolveToolcallPolicy(prepBody, payloadTools) { const preparedToolNames = normalizePreparedToolNames(prepBody && prepBody.tool_names); const toolNames = preparedToolNames.length > 0 ? preparedToolNames : extractToolNames(payloadTools); const featureMatchEnabled = boolDefaultTrue(prepBody && prepBody.toolcall_feature_match); - const emitEarlyToolDeltas = boolDefaultTrue(prepBody && prepBody.toolcall_early_emit_high); + const emitEarlyToolDeltas = featureMatchEnabled && boolDefaultTrue(prepBody && prepBody.toolcall_early_emit_high); return { toolNames, - toolSieveEnabled: toolNames.length > 0 && featureMatchEnabled, + toolSieveEnabled: toolNames.length > 0, emitEarlyToolDeltas, }; } diff --git a/tests/node/chat-stream.test.js b/tests/node/chat-stream.test.js index 6f3317a..88419d2 100644 --- a/tests/node/chat-stream.test.js +++ b/tests/node/chat-stream.test.js @@ -44,7 +44,7 @@ test('resolveToolcallPolicy respects prepare flags and prepared tool names', () [{ type: 'function', function: { name: 'fallback_tool', parameters: { type: 'object' } } }], ); assert.deepEqual(policy.toolNames, ['prepped_tool']); - assert.equal(policy.toolSieveEnabled, false); + assert.equal(policy.toolSieveEnabled, true); assert.equal(policy.emitEarlyToolDeltas, false); });