Skip to content

fix: avoid redundant Claude Code message clone - #2362

Merged
diegosouzapw merged 1 commit into
cheaper-inference:release/v3.8.0from
terence71-glitch:fix/release-v3.8.0-cc-message-clone
May 18, 2026
Merged

diegosouzapw merged 1 commit into
cheaper-inference:release/v3.8.0from
terence71-glitch:fix/release-v3.8.0-cc-message-clone

Conversation

@terence71-glitch

@terence71-glitch terence71-glitch commented May 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Avoids an unnecessary deep clone of Claude-native messages during Claude Code semantic passthrough preparation.
  • Keeps the downstream final message-cloning path intact, preserving request output isolation while reducing memory/CPU overhead for large Claude Code histories.

Context

This fix is based on a code review suggestion from @gemini-code-assist[bot] in PR #2351

prepareClaudeCodeCompatibleSemanticBody() was deep-cloning claudeBody.messages, and buildClaudeCodeCompatibleRequest() then passed those messages through cloneClaudeCodeCompatibleMessagesFromClaude(), which clones the message objects again.
This removes the first clone because the final cloning step still protects the emitted request body.

Validation

  • node --import tsx/esm --test tests/unit/claude-code-compatible-request.test.ts — passed (10/10)
  • git diff --check — passed
  • node --import tsx/esm --test tests/integration/*.test.ts — still fails with the same pre-existing integration failures observed before the fix

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request modifies the prepareClaudeCodeCompatibleSemanticBody function in open-sse/services/claudeCodeCompatible.ts to stop cloning the messages array from the input object, opting instead to cast it directly. This change likely improves performance by avoiding an unnecessary deep clone operation during the preparation of the semantic body. I have no feedback to provide as there were no review comments to evaluate.

@diegosouzapw
diegosouzapw merged commit 6c488d6 into cheaper-inference:release/v3.8.0 May 18, 2026
3 checks passed
@diegosouzapw

Copy link
Copy Markdown
Collaborator

Thanks @terence71-glitch! Excellent optimization. Merged into the upcoming v3.8.0 release.

HouMinXi pushed a commit to HouMinXi/OmniRoute that referenced this pull request Aug 2, 2026
Poid-ZA pushed a commit to Poid-ZA/OmniRoute that referenced this pull request Aug 5, 2026
muhamadgalihsaputra pushed a commit to niyatna/NiyatnaRoute that referenced this pull request Sep 27, 2026
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