fix(proxy): add provider-aware Anthropic thinking policy#4413
Draft
DeliciousBuding wants to merge 2 commits into
Draft
fix(proxy): add provider-aware Anthropic thinking policy#4413DeliciousBuding wants to merge 2 commits into
DeliciousBuding wants to merge 2 commits into
Conversation
Owner
|
@codex review |
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This is a smaller provider-aware alternative to #4210.
Instead of replacing proactive placeholder injection with a reactive retry path, this PR keeps the current default behavior for compatibility and adds an explicit provider metadata policy for Anthropic-format tool-use thinking history:
auto/ unset: keep historical behavior for reasoning-vendor hints.preserve_only: preserve realthinkingblocks and safe structural cleanup only; do not synthesize{"type":"thinking","thinking":"tool call"}.placeholder_always: explicitly opt a provider into placeholder synthesis, even without a vendor hint.The intent is to stop treating synthetic thinking placeholders as a hardcoded behavior for every reasoning-vendor Anthropic path. They become a provider capability / compatibility choice.
Context collected
tool_useturns always include a plainthinkingblock."tool call"thinking placeholders may correlate with visible text being emitted insidethinkingblocks and session freezes.thinking: disabled+ effort conflicts. That is a separate issue, but it follows the same direction: precise provider-scoped behavior instead of broad request rewriting.Why this shape
A pure reactive retry path is useful as a compatibility fallback, but it has drawbacks:
This PR does not claim that every DeepSeek-compatible Anthropic endpoint has relaxed thinking backpass requirements. It only makes the existing synthetic placeholder behavior configurable and safe to disable for providers where it is harmful.
Private A/B validation
I also ran a sanitized private A/B against a DeepSeek-compatible Anthropic relay. No private endpoint names, machine names, or credentials are included here.
x-api-keywas rejected by that relay./v1/messages, small tool-use history:thinking+textblocks."tool call"placeholder: HTTP 200, response containedthinking+textblocks./v1/messages, non-streaming long-history fixture (~63 KB request, 12 tool turns, ~21.9k input tokens):thinking+text,stop_reason=end_turn.thinkingbeforemax_tokens./v1/messages, streaming stress fixture (~304 KB request, 18 tool turns, ~107k input tokens):thinking+text,stop_reason=end_turn.thinking+text,stop_reason=end_turn.Interpretation: this is not proof that disabling placeholders fixes every long-context freeze. It does confirm that this tested DeepSeek-compatible Anthropic path accepts tool-use history without synthetic placeholders, and that synthetic placeholders can still affect the output block mix / budget under longer histories. That is why this PR exposes a provider-scoped policy instead of changing the global default.
Changes
src-tauri/src/provider.rsAnthropicToolThinkingPolicyandProviderMeta.anthropicToolThinkingPolicy.src-tauri/src/proxy/providers/claude.rsredacted_thinkingconversion; soften outdated comments that implied all DeepSeek-compatible endpoints still require placeholder replay.src/types.tsBehavior
autobehavior.preserve_onlyprevents missing / empty thinking blocks from being filled with synthetic"tool call", but still strips invalidsignaturefields from real thinking blocks.placeholder_alwaysallows explicit opt-in for a provider that requires synthetic placeholders even when it does not match the built-in vendor hints.Verification
Passed:
Also ran:
Result: 1654 passed, 8 failed, 2 ignored. The failures are outside this PR's touched area (
codex_history_migration,commands::misc::anchored_upgrade_windows,database::dao::usage_rollup) and appear unrelated to Anthropic provider normalization.Draft notes
This is intentionally draft because the maintainer may prefer one of two follow-ups:
anthropicToolThinkingPolicyin the provider UI, orpreserve_only/placeholder_alwayson specific presets after more provider verification.I kept this PR backend-focused to separate the protocol behavior from UI/preset policy decisions.