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.
This commit is contained in:
lij768423-svg committed 2026-08-20 11:43:29 +08:00
1 parent 731e95b924
commit 9bb6b48549
2 files changed
+10 -13

No files matched your search

@@ -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 {
@@ -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")
}
})
}