From 9bb6b48549e3615db92ef44037335a1d4cafabfa Mon Sep 17 00:00:00 2001 From: lij768423-svg Date: Thu, 20 Aug 2026 11:43:23 +0800 Subject: [PATCH] fix: hold TUI after-tool turns instead of skipping in-flight results Grok TUI tools run locally. The next /v1/responses body already contains function_call_output; retrying it on another account only regenerates the model turn and does not re-execute tools. Skipping hold on that body let 0-thinking dumps through on the common agent loop. --- .../application/gateway/quality_retry.go | 16 +++++----------- .../application/gateway/quality_retry_test.go | 7 +++++-- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/backend/internal/application/gateway/quality_retry.go b/backend/internal/application/gateway/quality_retry.go index bccf06c2..c1ac2760 100644 --- a/backend/internal/application/gateway/quality_retry.go +++ b/backend/internal/application/gateway/quality_retry.go @@ -270,13 +270,11 @@ func shouldHoldQualityStream(input Input, ownership *inferencedomain.ResponseOwn if route.Provider != accountdomain.ProviderBuild && route.Provider != accountdomain.ProviderConsole { return false } - // Retrying an in-flight tool *result* can repeat external side effects. - // Grok TUI always declares a tools schema even on the first thinking - // turn; skipping that schema would disable the hold for every agent - // request. Only skip when the body already contains tool output. - if qualityRequestHasInFlightToolResults(input.Body) { - return false - } + // Grok TUI always declares a tools schema, and after local tools run the + // next /v1/responses body already contains function_call_output. Retrying + // that body on another account does not re-execute TUI tools — it only + // regenerates the model turn. Skipping hold here let 0-thinking dumps + // through on the common agent loop. Keep holding. // Aliases are rewritten before this gate, so inspect the effective request // body instead of only the reasoning-capable base model. In particular, // grok-4.3-none becomes grok-4.3 plus an explicit disabled setting. @@ -289,10 +287,6 @@ func shouldHoldQualityStream(input Input, ownership *inferencedomain.ResponseOwn return modeldomain.SupportsReasoningForProvider(route.Provider, route.UpstreamModel) } -func qualityRequestUsesTools(body []byte) bool { - return qualityRequestHasInFlightToolResults(body) -} - func qualityRequestHasInFlightToolResults(body []byte) bool { var payload any if json.Unmarshal(body, &payload) != nil { diff --git a/backend/internal/application/gateway/quality_retry_test.go b/backend/internal/application/gateway/quality_retry_test.go index 1df6e136..f2c2a52f 100644 --- a/backend/internal/application/gateway/quality_retry_test.go +++ b/backend/internal/application/gateway/quality_retry_test.go @@ -596,8 +596,11 @@ func TestShouldHoldQualityStreamGates(t *testing.T) { t.Run(test.name, func(t *testing.T) { request := input request.Body = []byte(test.body) - if shouldHoldQualityStream(request, nil, route, audit.OperationChat, cfg) { - t.Fatal("in-flight tool results must not be held") + if !qualityRequestHasInFlightToolResults(request.Body) { + t.Fatal("fixture must still be detected as tool output") + } + if !shouldHoldQualityStream(request, nil, route, audit.OperationChat, cfg) { + t.Fatal("in-flight tool results must still be held so 0-thinking agent turns are classified") } }) }