Repository navigation
fix(core): include Gemini thinking tokens in output usage - #5334
Merged
Merged
Conversation
🦋 Changeset detectedLatest commit: e421876 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
commit: |
sailist
approved these changes
Nov 24, 2026
Merged
7723qqq
pushed a commit
to 7723qqq/kimi-code
that referenced
this pull request
Nov 25, 2026
Route file download and session media URL calls through a sessionSync route that answers from the current owner without a session load (MoonshotAI#5336). Add thoughtsTokenCount to the Google GenAI output usage with thinking and zero-thinking fixtures (MoonshotAI#5334), update the desktop composer e2e specs for the label-only slash menu (MoonshotAI#5274), and document the Bash session/workspace env vars (MoonshotAI#5053).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requirement or Bug
Resolve #5228
使用 Gemini thinking 模型时,
google-genai解码器漏算thoughtsTokenCount,导致 output usage、tokenBudget 和遥测少算生成的 tokens。本 PR 将 thinking tokens 计入 output usage。关联反馈:
cfdc64e9-e3f3-4e30-82f6-4667ea8a8748。Bug Reproduction Steps
See linked issue.
Root Cause
Gemini 分开返回
candidatesTokenCount和thoughtsTokenCount,但解码器只把前者写入usage.output,因此遗漏 thinking tokens。这是根本修复:在现有 usage 解码入口合并两类 output tokens,不改变其他协议或上层计量逻辑。
Code Changes
thoughtsTokenCount计入 output;字段缺失或不是数值时按 0 处理。raw继续保留原始usageMetadata,input 与 cache 计量逻辑不变。@moonshot-ai/core的 patch 条目。Behavior Changes and Affected Users
thoughtsTokenCountthoughtsTokenCount缺失、非数值或为 0受影响模块与覆盖:
packages/core的google-genaiusage 解码:新增 thinking、cached prompt tokens 和总量一致性回归,并覆盖 thinking 为 0 的情况。验证命令与结果
pnpm exec vitest run --reporter=agent packages/core/test/llm/google-genai/google-genai.test.ts,15/15 通过。pnpm exec tsc -p packages/core/tsconfig.json --noEmit:通过。pnpm lint:通过。pnpm run check:duplication 9ff76d8e1982e08c95dfea60a25e5fb077ddf402:通过。Checklist
gen-changesetsskill and included the confirmed core-only patch changeset.