Skip to content

feat: gpt-5.6 - #6049

Draft
seefs001 wants to merge 1 commit into
QuantumNous:mainfrom
seefs001:feature/gpt-5.6
Draft

feat: gpt-5.6#6049
seefs001 wants to merge 1 commit into
QuantumNous:mainfrom
seefs001:feature/gpt-5.6

Conversation

@seefs001

@seefs001 seefs001 commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

⚠️ 提交说明 / PR Notice

Important

  • 请提供人工撰写的简洁摘要,避免直接粘贴未经整理的 AI 输出。

📝 变更描述 / Description

(简述:做了什么?为什么这样改能生效?请基于你对代码逻辑的理解来写,避免粘贴未经整理的内容)

引入gpt-5.6 缓存创建

🚀 变更类型 / Type of change

  • 🐛 Bug 修复 (Bug fix) - 请关联对应 Issue,避免将设计取舍、理解偏差或预期不一致直接归类为 bug
  • ✨ 新功能 (New feature) - 重大特性建议先通过 Issue 沟通
  • ⚡ 性能优化 / 重构 (Refactor)
  • 📝 文档更新 (Documentation)

🔗 关联任务 / Related Issue

  • Closes # (如有)

✅ 提交前检查项 / Checklist

  • 人工确认: 我已亲自整理并撰写此描述,没有直接粘贴未经处理的 AI 输出。
  • 非重复提交: 我已搜索现有的 IssuesPRs,确认不是重复提交。
  • Bug fix 说明: 若此 PR 标记为 Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。
  • 变更理解: 我已理解这些更改的工作原理及可能影响。
  • 范围聚焦: 本 PR 未包含任何与当前任务无关的代码改动。
  • 本地验证: 已在本地运行并通过测试或手动验证,维护者可以据此复核结果。
  • 安全合规: 代码中无敏感凭据,且符合项目代码规范。

📸 运行证明 / Proof of Work

(请在此粘贴截图、关键日志或测试报告,以证明变更生效)

Summary by CodeRabbit

  • New Features

    • Added support for moderation and prompt-cache options in response requests and compaction requests.
    • Added prompt-cache retention controls for compaction workflows.
    • Exposed cache write token usage in responses and streaming responses.
  • Bug Fixes

    • Improved cache usage reporting across OpenAI, Claude, and response conversion flows.
    • Added default cache ratios for three additional models.

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The change adds prompt-cache request fields, cache-write token details, propagation across Claude and OpenAI response handlers, compaction forwarding, and default cache ratios for three GPT models.

Changes

Prompt cache support

Layer / File(s) Summary
Request contracts and compaction propagation
dto/openai_request.go, dto/openai_responses_compaction_request.go, relay/responses_handler.go
Response and compaction requests accept prompt-cache fields, which are forwarded during compaction conversion.
Cache-write usage propagation
dto/openai_response.go, relay/channel/claude/..., relay/channel/openai/..., service/relayconvert/...
Cache-write token counts are captured from Claude and OpenAI responses and mapped into prompt usage details.
Model cache ratio defaults
setting/ratio_setting/cache_ratio.go
Adds three GPT model entries with a default cache-creation ratio of 1.25.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CompactionRequest
  participant ResponsesHelper
  participant ResponsesRequest
  participant ResponseHandler
  participant ChatUsage
  CompactionRequest->>ResponsesHelper: Prompt cache fields
  ResponsesHelper->>ResponsesRequest: Forward prompt cache fields
  ResponseHandler->>ChatUsage: Map CacheWriteTokens to cache creation usage
Loading

Possibly related PRs

Poem

A bunny saw caches bloom,
With tokens counted in the room.
Requests carried options bright,
Ratios hopped to models’ delight.
“Cache-write crumbs now flow just right!”

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and directly related to the PR’s GPT-5.6 cache-creation support, though it is somewhat broad.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@relay/channel/claude/relay-claude.go`:
- Around line 619-621: Update the Claude handler’s token accounting to keep both
cache creation fields consistent: in the logic using
cacheCreationTokensForOpenAIUsage, assign cacheCreationTokens to
clone.PromptTokensDetails.CachedCreationTokens as well as CacheWriteTokens
before calculating totalInputTokens, matching the behavior of the other response
handlers.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d89df1df-0e3b-43c9-97ba-50c3069c0e5f

📥 Commits

Reviewing files that changed from the base of the PR and between 246d62a and 5ec205f.

📒 Files selected for processing (9)
  • dto/openai_request.go
  • dto/openai_response.go
  • dto/openai_responses_compaction_request.go
  • relay/channel/claude/relay-claude.go
  • relay/channel/openai/relay_responses.go
  • relay/channel/openai/relay_responses_compact.go
  • relay/responses_handler.go
  • service/relayconvert/responses_to_chat.go
  • setting/ratio_setting/cache_ratio.go

Comment on lines 619 to 621
cacheCreationTokens := cacheCreationTokensForOpenAIUsage(usage)
clone.PromptTokensDetails.CacheWriteTokens = cacheCreationTokens
totalInputTokens := usage.PromptTokens + usage.PromptTokensDetails.CachedTokens + cacheCreationTokens

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

CachedCreationTokens not updated on the clone, inconsistent with other handlers.

cacheCreationTokens is computed as the max of splitCacheCreationTokens and usage.PromptTokensDetails.CachedCreationTokens. Line 620 sets clone.PromptTokensDetails.CacheWriteTokens = cacheCreationTokens, but clone.PromptTokensDetails.CachedCreationTokens retains the original (possibly smaller) value from the shallow copy at line 613.

When splitCacheCreationTokens > 0 and the original CachedCreationTokens <= splitCacheCreationTokens, cacheCreationTokens equals splitCacheCreationTokens, but clone.CachedCreationTokens stays at the smaller original value. Downstream quota accounting (text_quota.go:209) reads CachedCreationTokens, not CacheWriteTokens, so cache creation tokens would be undercounted.

All other handlers (relay_responses.go:54, relay_responses.go:108, relay_responses_compact.go:40, responses_to_chat.go:151-152) explicitly set CachedCreationTokens from the same source as CacheWriteTokens. The Claude path should follow suit.

🔧 Proposed fix
 	cacheCreationTokens := cacheCreationTokensForOpenAIUsage(usage)
 	clone.PromptTokensDetails.CacheWriteTokens = cacheCreationTokens
+	clone.PromptTokensDetails.CachedCreationTokens = cacheCreationTokens
 	totalInputTokens := usage.PromptTokens + usage.PromptTokensDetails.CachedTokens + cacheCreationTokens
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
cacheCreationTokens := cacheCreationTokensForOpenAIUsage(usage)
clone.PromptTokensDetails.CacheWriteTokens = cacheCreationTokens
totalInputTokens := usage.PromptTokens + usage.PromptTokensDetails.CachedTokens + cacheCreationTokens
cacheCreationTokens := cacheCreationTokensForOpenAIUsage(usage)
clone.PromptTokensDetails.CacheWriteTokens = cacheCreationTokens
clone.PromptTokensDetails.CachedCreationTokens = cacheCreationTokens
totalInputTokens := usage.PromptTokens + usage.PromptTokensDetails.CachedTokens + cacheCreationTokens
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@relay/channel/claude/relay-claude.go` around lines 619 - 621, Update the
Claude handler’s token accounting to keep both cache creation fields consistent:
in the logic using cacheCreationTokensForOpenAIUsage, assign cacheCreationTokens
to clone.PromptTokensDetails.CachedCreationTokens as well as CacheWriteTokens
before calculating totalInputTokens, matching the behavior of the other response
handlers.

@walker1211

Copy link
Copy Markdown

I reproduced the accounting gap on v1.0.0-rc.20 in a live deployment: GPT-5.6 requests repeatedly recorded cache-read tokens, while cache-write/cache-creation tokens stayed at zero even with a 1.25 creation ratio configured. The mapping in this PR matches the missing usage field.

Before merge, could we add focused tests for:

  • non-stream Responses usage: input_tokens_details.cache_write_tokens -> CachedCreationTokens
  • streaming Responses usage
  • compact Responses conversion
  • quota/log settlement applying CreateCacheRatio exactly once (not ordinary input and not double-counted)

I also agree with the existing review: the Claude conversion should keep CacheWriteTokens and CachedCreationTokens in sync before total input is calculated.

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