fix(proxy): strip Claude total token markers - #6803
Conversation
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e030a95cdf
ℹ️ 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".
|
|
||
| stripped.push_str(&remaining[..open_offset]); | ||
| let content_start = open_offset + ANTHROPIC_TOTAL_TOKENS_OPEN_TAG.len(); | ||
| let Some(close_offset) = remaining[content_start..].find(ANTHROPIC_TOTAL_TOKENS_CLOSE_TAG) |
There was a problem hiding this comment.
Restrict removal to standalone Claude markers
When an application-authored system prompt contains any balanced <total_tokens>...</total_tokens> element—for example, an XML schema or few-shot example—this search treats the first subsequent closing tag as Claude metadata and deletes the entire element. The marker is documented above as a standalone Claude message, so matching arbitrary embedded elements silently corrupts legitimate system instructions; restrict removal to the known standalone marker shape and expected payload.
Useful? React with 👍 / 👎.
Summary / 概述
Fix the Claude-to-OpenAI conversion path so Claude Code's dynamic
<total_tokens>...</total_tokens>markers do not accumulate in themerged OpenAI system prompt.
修复 Claude→OpenAI 转换路径,避免 Claude Code 的动态
<total_tokens>...</total_tokens>标签不断累积到 OpenAI system 字符串中,导致 OpenAI 兼容端点的 prompt cache 命中率下降。
The fix only affects system messages. User and assistant content remains unchanged.
该修复只处理 system 消息,不会修改 user 和 assistant 内容。
Related Issue / 关联 Issue
Fixes #6789
Screenshots / 截图
Validation / 验证
cargo fmt --check --manifest-path src-tauri/Cargo.tomlpassed.cargo clippy --manifest-path src-tauri/Cargo.toml -- -D warningspassed.git diff --checkpassed.user content preservation, and unterminated markers.
Checklist / 检查清单
pnpm typecheckwas not run; this is a Rust-only change /未运行;本次仅修改 Rust 后端代码
pnpm format:checkwas not run; this is a Rust-only change /未运行;本次仅修改 Rust 后端代码
cargo clippypasses /cargo clippy已通过未修改用户可见文本,不需要更新国际化文件