Skip to content

fix(openai-compat): drop top_k for active Claude thinking - #5767

Open
smartershining wants to merge 1 commit into
router-for-me:devfrom
smartershining:fix/openai-compat-claude-top-k
Open

smartershining wants to merge 1 commit into
router-for-me:devfrom
smartershining:fix/openai-compat-claude-top-k

Conversation

@smartershining

Copy link
Copy Markdown

Summary

Remove top_k from OpenAI-compatible payloads when a Claude request has active thinking.

Claude clients may send top_k together with extended/adaptive thinking. After Claude-to-OpenAI translation and payload overrides, that combination can reach a Claude-backed compatibility upstream and be rejected with -4003 top_k must be unset when thinking is enabled/adaptive.

This change runs after payload overrides and:

  • applies only to Claude-source requests;
  • treats thinking.type=enabled|adaptive|auto and non-none effort fields as active thinking;
  • removes only top_k;
  • preserves top_k for non-Claude, no-thinking, and explicit-none requests;
  • keeps sibling sampling fields unchanged.

Both streaming and non-streaming execution paths are covered.

Tests

  • go test -count=1 -run 'TestNormalizeOpenAICompatClaudeSampling|TestOpenAICompatExecutorUsesCompatibleClaudeTranslation|TestNormalizeClaudeSamplingForUpstream' ./internal/runtime/executor
  • go build -buildvcs=false -trimpath -o /tmp/cpa-pr2-build ./cmd/server

@github-actions
github-actions Bot changed the base branch from main to dev September 12, 2026 14:19
@github-actions

Copy link
Copy Markdown

This pull request targeted main.

The base branch has been automatically changed to dev.

@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: 23546faf49

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +587 to +589
switch strings.ToLower(strings.TrimSpace(gjson.GetBytes(source, "thinking.type").String())) {
case "enabled", "adaptive", "auto":
thinkingActive = true

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Respect final thinking overrides before dropping top_k

When a Claude request initially enables thinking but a model suffix such as (none) or a payload override disables it, ApplyRequestThinking and the override stage produce a final non-thinking request, yet this switch still marks thinking active from the pre-override source and deletes top_k. This silently changes a valid sampling configuration even though the upstream-invalid combination no longer exists; determine activity from the finalized canonical/transformed body so the established suffix and override precedence is preserved.

AGENTS.md reference: AGENTS.md:L29-L29

Useful? React with 👍 / 👎.

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.

1 participant