Skip to content

fix(codex): always include output_tokens_details.reasoning_tokens in …#3514

Merged
farion1231 merged 2 commits into
farion1231:mainfrom
yeeyzy:fix/codex-missing-reasoning-tokens
Jun 3, 2026
Merged

fix(codex): always include output_tokens_details.reasoning_tokens in …#3514
farion1231 merged 2 commits into
farion1231:mainfrom
yeeyzy:fix/codex-missing-reasoning-tokens

Conversation

@yeeyzy

@yeeyzy yeeyzy commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

fix(codex): always include output_tokens_details.reasoning_tokens in chat→responses transform

Codex CLI/Codex Desktop strictly requires reasoning_tokens in the response.completed usage object. Custom providers using /chat/completions often omit completion_tokens_details, causing repeated parse failures and retries.

Summary / 概述

Codex CLI 在解析 responses API 的 usage 对象时,严格要求存在 output_tokens_details.reasoning_tokens 字段。当使用自定义 provider(走 /chat/completions 格式)时,上游往往不返回 completion_tokens_details,导致转换后的 usage 缺少该字段,Codex 解析失败并反复重试。

本 PR 在 chat→responses 的 usage 转换逻辑中确保 output_tokens_details.reasoning_tokens 始终存在:

  • 上游无 usage 时,fallback 对象包含 output_tokens_details: { reasoning_tokens: 0 }
  • 上游有 completion_tokens_details 但缺少 reasoning_tokens 时,补零
  • 上游完全无 completion_tokens_details 时,插入默认值

Related Issue / 关联 Issue

Fixes #3081

Screenshots / 截图

N/A(纯后端逻辑修改,无 UI 变动)

Checklist / 检查清单

  • pnpm typecheck passes / 通过 TypeScript 类型检查
  • pnpm format:check passes / 通过代码格式检查
  • cargo clippy passes (if Rust code changed) / 通过 Clippy 检查(如修改了 Rust 代码)
  • Updated i18n files if user-facing text changed / 如修改了用户可见文本,已更新国际化文件

…chat→responses transform

Codex CLI strictly requires reasoning_tokens in the response.completed
usage object. Custom providers using /chat/completions often omit
completion_tokens_details, causing repeated parse failures and retries.
@farion1231

Copy link
Copy Markdown
Owner

@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: 85d795c109

ℹ️ 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".

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

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src-tauri/src/proxy/providers/transform_codex_chat.rs
@yeeyzy

yeeyzy commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

补充问题现象及修复后正常运行的截图
问题现象:
image

修复后不在反复重试,正常运行:
image

@farion1231 farion1231 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

非常感谢您的贡献!

@farion1231
farion1231 merged commit b4f262c into farion1231:main Jun 3, 2026
3 checks passed
AnXiYiZhi pushed a commit to AnXiYiZhi/DevCLaw-old that referenced this pull request Jun 9, 2026
farion1231#3514)

* fix(codex): always include output_tokens_details.reasoning_tokens in chat→responses transform

Codex CLI strictly requires reasoning_tokens in the response.completed
usage object. Custom providers using /chat/completions often omit
completion_tokens_details, causing repeated parse failures and retries.

* fix(codex): guard non-object completion_tokens_details before insertion

---------

Co-authored-by: yeeyzy <yeeyzy@[email protected]>
gfunc pushed a commit to gfunc/cc-switch that referenced this pull request Jun 19, 2026
farion1231#3514)

* fix(codex): always include output_tokens_details.reasoning_tokens in chat→responses transform

Codex CLI strictly requires reasoning_tokens in the response.completed
usage object. Custom providers using /chat/completions often omit
completion_tokens_details, causing repeated parse failures and retries.

* fix(codex): guard non-object completion_tokens_details before insertion

---------

Co-authored-by: yeeyzy <yeeyzy@[email protected]>
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.

stream disconnected before completion: failed to parse ResponseCompleted: missing field `reasoning_tokens

2 participants