fix(ai): disable thinking when clamped to off in buildGoogleSimpleThinking (#101785)#101825
fix(ai): disable thinking when clamped to off in buildGoogleSimpleThinking (#101785)#101825liuhao1024 wants to merge 2 commits into
Conversation
…nking When clampThinkingLevel returns 'off' for a model that doesn't support the requested reasoning level, buildGoogleSimpleThinking now correctly disables thinking entirely instead of mapping 'off' to 'high' effort and incorrectly enabling it. Fixes openclaw#101785
|
Thanks for the context here. I swept through the related work, and this is now duplicate or superseded. Close as superseded: this PR contains a useful helper-level guard, but #101832 is the stronger active landing path because it fixes both the shared helper and the final Google simple-completion sanitizer path with positive runtime proof. Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Canonical path: Close this branch and land or review #101832, or an equivalent two-surface fix, so the helper and final sanitizer behavior change together. So I’m closing this here and keeping the remaining discussion on #101832. Review detailsBest possible solution: Close this branch and land or review #101832, or an equivalent two-surface fix, so the helper and final sanitizer behavior change together. Do we have a high-confidence way to reproduce the issue? Yes. Source inspection shows Is this the best way to solve the issue? No. The helper guard is useful but too narrow as a standalone fix; the maintainable solution also preserves the clamped effective level through the final simple-completion sanitizer. Security review: Security review cleared: The diff only changes Google provider request-shaping code and tests; no dependency, workflow, lockfile, script, permission, artifact, or secret-handling surface changed. AGENTS.md: found and applied where relevant. What I checked:
Likely related people:
Codex review notes: model internal, reasoning high; reviewed against 22376d80e163. |
|
Superseded by #101832, now merged as The landed fix includes this shared-builder correction and also clamps the final simple-completion payload sanitizer input, which is necessary to keep unsupported reasoning from being re-enabled later in the request path. It adds provider-builder, generic non-reasoning, and final Gemini 3 payload regressions. Exact-head CI passed: https://github.com/openclaw/openclaw/actions/runs/29005626431 Thank you for identifying the original clamp bug. |
What Problem This Solves
When a user requests a reasoning level (e.g.,
lowormedium) on a Google model that does not support thinking, theclampThinkingLevelfunction correctly clamps the requested level to"off"(indicating the model cannot support the requested reasoning capability). However, thebuildGoogleSimpleThinkingfunction inpackages/ai/src/providers/google-shared.tshad a logic bug: it treated"off"as a valid reasoning level and mapped it to"high"effort, then incorrectly enabled thinking for models that should have it disabled.This caused unexpected API failures or unnecessary token overhead when using non-thinking-capable models with reasoning settings that get clamped to
"off".Why This Change Was Made
The bug was in line 560-562 of
packages/ai/src/providers/google-shared.ts:The problem: when
clampThinkingLevelreturns"off"(meaning "model doesn't support this level"), the ternary operator mapped"off"to"high"effort, and the code then enabled thinking with that high effort.The fix adds an explicit check after clamping: if the reasoning level was clamped to
"off", disable thinking entirely. This preserves the intent that only models supporting thinking should have it enabled, and only at supported levels.User Impact
Evidence
Behavior addressed:
buildGoogleSimpleThinking()incorrectly enabled HIGH-level thinking whenclampThinkingLevel()clamped a requested reasoning level to"off"for non-reasoning-capable Google models.Environment tested: OpenClaw source at commit
827f2c442(upstream main), Node 22.19+, TypeScript strict mode.Steps run after the patch:
packages/ai/src/providers/google-shared.test.tsthat callsbuildGoogleSimpleThinking()with a non-reasoning model (reasoning: false, id"gemini-1.5-pro") andreasoning: "low"— exercising the exact clamp-to-off path.main(without fix) to confirm the bug reproduces: the function returnedenabled: trueinstead ofenabled: false.enabled: false.Evidence after fix:
Focused behavior verification — before fix (main, no patch):
After fix (patch applied):
The non-reasoning model with
reasoning: "low"now returns{ enabled: false }with nobudgetTokensand nolevel, confirming thinking is fully disabled when clamped to off.Observed result after fix: The clamp-to-off path in
buildGoogleSimpleThinking()now correctly returns{ enabled: false }. Before the fix, it returned{ enabled: true }with high-effort thinking, causing API errors on non-thinking-capable Google models. The regression case fails on main and passes with the patch.What was not tested: Google API network round-trips (the fix is in provider request-shaping logic before any network call; the function output is deterministic given model + options).
Real behavior proof
Behavior addressed:
buildGoogleSimpleThinking()incorrectly enabled HIGH-level thinking whenclampThinkingLevel()clamped a requested reasoning level to"off"for non-reasoning-capable Google models.Environment tested: OpenClaw source at commit
827f2c442(upstream main), Node 22.19+, TypeScript strict mode.Steps run after the patch:
packages/ai/src/providers/google-shared.test.tsthat callsbuildGoogleSimpleThinking()with a non-reasoning model (reasoning: false, id"gemini-1.5-pro") andreasoning: "low"— exercising the exact clamp-to-off path.main(without fix) to confirm the bug reproduces: the function returnedenabled: trueinstead ofenabled: false.enabled: false.Evidence after fix:
Focused behavior verification — before fix (main, no patch):
After fix (patch applied):
The non-reasoning model with
reasoning: "low"now returns{ enabled: false }with nobudgetTokensand nolevel, confirming thinking is fully disabled when clamped to off.Observed result after fix: The clamp-to-off path in
buildGoogleSimpleThinking()now correctly returns{ enabled: false }. Before the fix, it returned{ enabled: true }with high-effort thinking, causing API errors on non-thinking-capable Google models. The regression case fails on main and passes with the patch.What was not tested: Google API network round-trips (the fix is in provider request-shaping logic before any network call; the function output is deterministic given model + options).
AI-assisted (Hermes Agent)