Skip to content

fix(google-genai): map thinking effort off to LOW for Gemini 4 models - #4230

Merged
7Sageer merged 6 commits into
MoonshotAI:mainfrom
kimi-agent-bot:fix/gemini-4-effort-off-thinking-level
Oct 15, 2026
Merged

7Sageer merged 6 commits into
MoonshotAI:mainfrom
kimi-agent-bot:fix/gemini-4-effort-off-thinking-level

Conversation

@kimi-agent-bot

@kimi-agent-bot kimi-agent-bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

Requirement or Bug

#4207 的遗留缺口:#4208 已把 gemini-4 加入 thinkingLevel 白名单,但 effort=off 分支仍下发 thinkingLevel: 'MINIMAL'。官方文档(模型页与 thinking 指南)写明 gemini-4-argon 的思考档位只支持 low / medium / high(默认 medium)且思考永远开启、无法关闭——MINIMAL 对 Gemini 4 是非法档位,请求会被上游以 400 拒绝(与 #4207 的 budget 报错同类同因)。

设计决策(维护者拍板):不做静默降级,gemini-4 + off 直接报错,与仓内 anthropic 等协议的 always-reasons 拒绝语义一致。

Bug Reproduction Steps

配置 google-genai 类型 provider 与 gemini-4-* 模型,思考强度设为 off(模型配置 default_effort = "off" 或运行中切到 off),发任意请求 → 上游 400。

Root Cause

level 分支把 off 硬编码为 MINIMAL;该值对 Gemini 3 可用,对 Gemini 4 不存在。本 PR 在编码层对 gemini-4 + off 抛出明确的 thinking-config 错误(ThinkingConfigError('thinking-cannot-disable') / kosong ChatProviderError),报错文案与 anthropic 协议的同类拒绝同款。

Code Changes

  • packages/agent-core-v2/src/human/llm/requester/bases/google-genai/format.ts:gemini-4 + off 抛 ThinkingConfigError('thinking-cannot-disable')(走 llm.failed.syntax / code=thinking_config,与 anthropic 协议行为一致);gemini-3 的 off→MINIMAL 保持不变。
  • packages/kosong/src/providers/google-genai.ts:withThinking 同步同款拒绝(ChatProviderError),分支注释更新;getter 与 main 完全一致(净零变更)。
  • 测试:kosong 增 gemini-4 off 抛错断言、保留 gemini-3 off→MINIMAL 及 getter 全套既有行为;agent-core-v2 增 gemini-4 off → llm.failed.syntax(code thinking_config、含 'always reasons'、无 llm.sent)断言,与 anthropic 同款用例形态,gemini-3 off→MINIMAL 用例保留。
  • changeset:patch(@moonshot-ai/kimi-code)。

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
google-genai 协议下 gemini-4-* 模型 effort=off 发非法 MINIMAL,上游 400(错误文案为上游返回的英文 400) 本地抛出明确错误:思考不可关、请选 low/medium/high 无——旧行为请求必然失败 将模型配置/运行中的思考强度改为 low/medium/high
gemini-3-*、gemini-2.5-* 等其余模型的全部 effort 档 不变 不变 — —

覆盖情况:两侧引擎各有断言报错形态的新增用例;gemini-3 的 off→MINIMAL 行为由既有套件与新增用例 pin 住。

另注(本 PR 不处理):官方文档显示 gemini-3-pro-preview 同样只列 low/high 两档,现行对 3-pro 的 medium→MEDIUM、off→MINIMAL 与文档不完全一致,暂无用户报告,建议另开 issue 评估。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: issue must have a maintainer's /approve).
  • I have added tests that prove my feature works.
  • The behavior-change table above is complete, and every removed behavior or flipped default is named in the changeset and either has an escape hatch or was explicitly approved by a maintainer in this PR.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

Gemini 4 supports only LOW/MEDIUM/HIGH thinking levels and always thinks;
sending MINIMAL for effort=off makes every request fail with a 400. Degrade
'off' to LOW (thoughts still hidden) for gemini-4 models in both the
agent-core-v2 requester and the legacy kosong provider, keeping MINIMAL for
Gemini 3.

Co-authored-by: 7Hanrui <[email protected]>
@changeset-bot

changeset-bot Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7bc8445

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@7bc8445
npx https://pkg.pr.new/@moonshot-ai/kimi-code@7bc8445

commit: 7bc8445

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 82ecd70eba

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-15T04:30:06.540272Z 7bc8445 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@kimi-agent-bot

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 218674f985

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

LOW with suppressed thoughts is the Gemini 4 encoding of 'off', so map it
back to 'off' in the thinkingEffort getter instead of reporting 'low'.

Co-authored-by: 7Hanrui <[email protected]>
@kimi-agent-bot

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7ca6de7704

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

…mini-4

Only Gemini 4 encodes 'off' as LOW with suppressed thoughts, so gate the
reverse mapping on the model; a caller-supplied LOW/includeThoughts=false on
other models keeps reporting 'low'.

Co-authored-by: 7Hanrui <[email protected]>
@kimi-agent-bot

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c225911b79

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Gemini 4 encodes 'off' as LOW with suppressed thoughts, which is
indistinguishable from an explicit LOW/includeThoughts=false kwarg, so no
reverse mapping can serve both callers. Nothing in the repo reads this
getter to persist or display effort, so keep the derive-from-kwargs
semantics; for Gemini 4's 'off', 'low' is the honest report of what runs.

Co-authored-by: 7Hanrui <[email protected]>
@kimi-agent-bot

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: a658057106

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Gemini 4 supports only LOW/MEDIUM/HIGH thinking levels and always thinks,
so requesting effort 'off' now fails fast with a clear thinking-config
error (matching the always-reasons rejection other protocols already use)
instead of sending an invalid MINIMAL level or silently degrading to LOW.

Co-authored-by: 7Hanrui <[email protected]>
@kimi-agent-bot

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 7bc8445bd2

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@7Sageer
7Sageer merged commit b260326 into MoonshotAI:main Oct 15, 2026
17 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 20, 2026
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Oct 22, 2026
…MoonshotAI#4230)

Ported from MoonshotAI/kimi-code 2.3.0 (b260326).

Adaptation: kept this fork's extra `#/llm/protocol/format` import in the
google-genai format module and widened the neighbouring `#/llm/thinking` import
to carry `ThinkingConfigError`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants