Skip to content

stack 4/7: keep an explicit thinking disable through translation (#545) - #954

Merged
lidge-jun merged 4 commits into
devfrom
codex/545-classifier-thinking-disabled
Aug 4, 2026
Merged

stack 4/7: keep an explicit thinking disable through translation (#545)#954
lidge-jun merged 4 commits into
devfrom
codex/545-classifier-thinking-disabled

Conversation

@lidge-jun

@lidge-jun lidge-jun commented Aug 3, 2026

Copy link
Copy Markdown
Owner

Stack

4/4 — Claude Desktop classifier thinking round-trip

Base: codex/carry-contributor-bugfixes (#953)

Summary

Claude Desktop 3P Auto Mode sends thinking: {type: "disabled"} with max_tokens: 64 and a </block> stop sequence. The instruction was dropped in translation, so the model thought anyway and spent the 64-token budget before it could close the tag — and Claude Code retried, up to five times per tool approval. The reporter measured 1,084 truncated requests against 143 that completed.

  • src/claude/inbound.ts — an explicit disable is preserved as the parser's "none" sentinel instead of becoming undefined
  • src/adapters/anthropic.ts — emit thinking: {type: "disabled"} for models that both default to thinking-on and accept the explicit disable

The standing hypothesis was impossible

The recorded analysis on #545 said the prepended OAuth identity block consumed the classifier's 64 output tokens. It cannot: the identity goes into the system prompt, and max_tokens caps output. Different budgets. This repository had already reached that conclusion once — devlog/_fin/260728_bug_bundle_resolution/030_claude_system_dedup.md abandoned an identity-dedup patch for exactly this reason — and I re-derived the rejected theory before testing it.

The real chain is a round-trip fidelity loss:

  1. src/claude/inbound.ts:494 treated disabled as nothing to translate, leaving reasoning undefined
  2. that is indistinguishable from a request that never mentioned thinking, and tests/claude-inbound.test.ts pinned both to undefined
  3. the adapter emits thinking only for a real non-none effort, so the field was omitted outbound
  4. for Sonnet 5, an omitted thinking field means adaptive thinking is ON, and thinking tokens count against max_tokens

The client asked for no thinking and got thinking. That also explains the shape of the reporter's data: the 143 requests that completed are the ones where thinking happened to stay short.

The gate is deliberately narrow

usesAdaptiveThinking() looks like the right predicate and is not — it answers which wire shape a family accepts, not whether omission means thinking-on. The sets differ both ways: Fable always thinks and rejects an explicit disable, while Opus 4.7/4.8 use the adaptive wire but leave thinking off when omitted. Reusing it would have required breaking a passing test (tests/anthropic-reasoning.test.ts asserts claude-fable-5 + "none" sends no thinking config) in order to ship a production 400.

So supportsExplicitThinkingDisable() is seeded with sonnet: [5,0] only. Widen it per family with vendor evidence.

What the audit caught

Three rounds, two FAIL. Both findings were reproduced at runtime before fixing.

Round 1anthropic/claude-sonnet-5 silently missed the gate. A modelMap entry can point at a routed destination that routing decodes back into a slash-carrying native id, and the predicate anchored on ^claude-.

Round 2 — my own round-1 fix was worse than the bug. Normalizing with lastIndexOf("/") repaired the prefix case and broke the suffix case (claude-sonnet-5/variant), and because the adaptive-wire predicate shares that parse, such a model would have been sent obsolete manual thinking.enabled and 400d. A silent truncation traded for a hard failure.

Both now match the segment that actually begins with claude-, at either boundary, with all shapes pinned in the matrices — including a new adaptive-shape test covering the 400 path.

Cross-provider note

A modelMap that routes such a request to Cursor now selects the model's lowest tier rather than its top one. Cursor has no off switch for a reasoning model, so the lowest tier is the closest honest reading of "do not think" — the previous behavior sent these to the maximum tier, the opposite of the caller's instruction. Pinned in tests/cursor-effort-suffix.test.ts so it is deliberate rather than emergent.

Verification

  • bun x tsc --noEmit — exit 0
  • bun run test — 7711 pass, 8 skip, 0 fail, 507 files
  • bun run privacy:scan — passed
  • red-green, both halves independently: ablating the inbound preservation fails 3 tests; ablating the adapter emission fails 2 different ones

Two honest limits

The tests prove the wire shape, not that the retries stop. Confirming that needs a live Claude Desktop 3P + Anthropic OAuth session showing the classifier terminating on </block> instead of max_tokens. I have asked the reporter rather than claiming the symptom fixed.

This changes request construction on an Anthropic OAuth execution path, so MAINTAINERS.md requires explicit human security review — no credential handling is touched, but the boundary is. Please do not merge on CI alone.

Refs #545

Summary by CodeRabbit

  • Bug Fixes
    • Improved recognition of Claude model identifiers across routed, versioned, and suffixed formats.
    • Explicitly disabling Claude thinking now reliably sends the correct setting for supported models.
    • Disabled reasoning is preserved consistently when translating requests and responses.
    • Requests with no reasoning preference continue using existing behavior.
    • Cursor routing now selects the lowest available reasoning tier when reasoning is explicitly disabled.
  • Tests
    • Expanded coverage for Claude model detection, reasoning behavior, routing, token limits, and stop sequences.

)

Claude Desktop 3P Auto Mode sends thinking:{type:"disabled"} with max_tokens:64
and a stop sequence. Inbound translation dropped the instruction — reasoning
stayed undefined, indistinguishable from a request that never mentioned
thinking — so the outbound Anthropic body omitted the field entirely. For
Sonnet 5 an omitted thinking field means adaptive thinking is ON, and thinking
shares max_tokens, so generation ran out of budget before it could emit
</block>. Claude Code then retried, up to five times per tool approval.

The gate is deliberately its own predicate rather than usesAdaptiveThinking(),
which answers a different question: Fable always thinks and rejects an explicit
disable, while Opus 4.7/4.8 leave thinking off when the field is omitted.
Widening it would trade a silent truncation for a 400.

Refs #545
A modelMap entry can point at a routed destination like anthropic/claude-sonnet-5,
which custom-provider routing decodes back into a slash-carrying native id. Both
capability predicates anchored on ^claude-, so those requests silently missed the
gate and the model thought anyway — the exact defect, just harder to see.

Extracted the shared family/version parse so usesAdaptiveThinking() gets the same
tolerance, and pinned all four id shapes plus a prefixed negative case.

Also pins the Cursor effect: an explicit "none" now selects the lowest tier rather
than the top one. Cursor has no off switch for a reasoning model, and the lowest
tier is the closest honest reading of "do not think" — dropping the instruction
sent these to the maximum tier, the opposite of what the caller asked for.
#545)

The previous normalization took the last slash-separated segment, which fixed
anthropic/claude-sonnet-5 and broke claude-sonnet-5/variant — a custom provider
can expose a native id where the slash carries a vendor suffix rather than a
routing prefix. That regression was worse than the bug: the adaptive-wire
predicate shares this parse, so a slash-suffixed Sonnet 5 would have been sent
obsolete manual thinking.enabled and 400d.

Match the segment that actually begins with claude-, at either boundary, and pin
both directions plus a double prefix and the adaptive-shape cases.
@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Claude model detection now supports routed model IDs and Sonnet 5+ thinking disablement. Explicit "none" reasoning propagates through Anthropic and Responses translations. Tests cover adaptive formats, round trips, preserved limits, and Cursor tier selection.

Changes

Claude thinking control flow

Layer / File(s) Summary
Claude capability detection and request wiring
src/adapters/anthropic.ts lines 411–472, 821–828; tests/anthropic-reasoning.test.ts lines 140–207
Model parsing accepts prefixes, suffixes, and slash-containing identifiers. Sonnet 5+ models receive thinking: { type: "disabled" } only for explicit "none" reasoning.
Disabled thinking inbound translation
src/claude/inbound.ts lines 501–507; tests/anthropic-reasoning.test.ts lines 4, 234–256; tests/claude-inbound.test.ts lines 97–99, 131–137
Disabled thinking maps to explicit reasoning: { effort: "none", summary: "none" }. Tests verify configured effort is replaced and request limits remain preserved.
Explicit none reasoning routing
tests/cursor-effort-suffix.test.ts lines 51–62
Explicit "none" reasoning selects the lowest Cursor tier, while omitted reasoning selects the highest tier.

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

Sequence Diagram(s)

sequenceDiagram
  participant ClaudeRequest
  participant AnthropicAdapter
  participant ClaudeCapabilityParser
  participant AnthropicAPI
  ClaudeRequest->>AnthropicAdapter: reasoning effort
  AnthropicAdapter->>ClaudeCapabilityParser: parse routed Claude model ID
  ClaudeCapabilityParser-->>AnthropicAdapter: thinking disable capability
  AnthropicAdapter->>AnthropicAPI: thinking disabled configuration
Loading

Possibly related PRs

Suggested labels: bug

Suggested reviewers: ingwannu, wibias

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes preserving an explicit thinking disable through translation, which is the primary change in the pull request.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/545-classifier-thinking-disabled

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

@lidge-jun

Copy link
Copy Markdown
Owner Author

Stack navigation

  1. stack 1/6: triage the open issue surface and lock the bug plan #951 — triage the open issue surface and lock the bug plan (base dev)
  2. stack 2/7: price long-context requests at the published long rate (#908) #952 — long-context pricing tiers, Cost estimates ignore published long-context pricing tiers (OpenAI >272k, xAI >=200k) #908 (base stack 1/6: triage the open issue surface and lock the bug plan #951)
  3. stack 3/7: carry six contributor bug fixes with authorship intact #953 — carry six contributor bug fixes (base stack 2/7: price long-context requests at the published long rate (#908) #952)
  4. stack 4/7: keep an explicit thinking disable through translation (#545) #954 — Claude Desktop classifier thinking round-trip, Claude Desktop 3P Auto Mode classifier retries after 64-token Anthropic OAuth outputs #545 (base stack 3/7: carry six contributor bug fixes with authorship intact #953)

Review and merge bottom-up. Each PR targets the preceding stack branch, so its Files changed view contains only that layer.

The layers touch disjoint files — devlog/, src/usage/, the carried contributors' paths, and src/claude/ + src/adapters/anthropic.ts — so any layer can be retargeted to dev and taken independently without a rebase conflict.

#954 needs human security review per MAINTAINERS.md: it changes request construction on an Anthropic OAuth execution path. It is last in the stack so the first three can land without waiting on that.

Carried in #953, with authorship preserved: #939, #942, #943, #944, #945, #948.

@lidge-jun

Copy link
Copy Markdown
Owner Author

Stack navigation

  1. stack 1/6: triage the open issue surface and lock the bug plan #951 — triage the open issue surface and lock the bug plan (base dev)
  2. stack 2/7: price long-context requests at the published long rate (#908) #952 — long-context pricing tiers, Cost estimates ignore published long-context pricing tiers (OpenAI >272k, xAI >=200k) #908 (base stack 1/6: triage the open issue surface and lock the bug plan #951)
  3. stack 3/7: carry six contributor bug fixes with authorship intact #953 — carry six contributor bug fixes (base stack 2/7: price long-context requests at the published long rate (#908) #952)
  4. stack 4/7: keep an explicit thinking disable through translation (#545) #954 — Claude Desktop classifier thinking round-trip, Claude Desktop 3P Auto Mode classifier retries after 64-token Anthropic OAuth outputs #545 (base stack 3/7: carry six contributor bug fixes with authorship intact #953)
  5. stack 5/7: probe reset-derived cooldowns without waiting to be selected (#915) #955 — cooldown early-recovery probe, [Bug]: Reset-derived cooldowns can miss early recovery while another pool account remains eligible #915 (base stack 4/7: keep an explicit thinking disable through translation (#545) #954)

Review and merge bottom-up. Each PR targets the preceding stack branch, so its Files changed view contains only that layer.

The layers touch disjoint files — devlog/, src/usage/, the carried contributors' paths, src/claude/ + src/adapters/anthropic.ts, and src/codex/ — so any layer can be retargeted to dev and taken independently without a rebase conflict.

#954 needs human security review per MAINTAINERS.md: it changes request construction on an Anthropic OAuth execution path. #955 sits above it in the chain but is independent of it in code, so if that review blocks, #955 can be retargeted to #953 without conflict.

Carried in #953, with authorship preserved: #939, #942, #943, #944, #945, #948.

@lidge-jun

Copy link
Copy Markdown
Owner Author

Stack navigation

  1. stack 1/6: triage the open issue surface and lock the bug plan #951 — triage the open issue surface and lock the bug plan (base dev)
  2. stack 2/7: price long-context requests at the published long rate (#908) #952 — long-context pricing tiers, Cost estimates ignore published long-context pricing tiers (OpenAI >272k, xAI >=200k) #908 (base stack 1/6: triage the open issue surface and lock the bug plan #951)
  3. stack 3/7: carry six contributor bug fixes with authorship intact #953 — carry six contributor bug fixes (base stack 2/7: price long-context requests at the published long rate (#908) #952)
  4. stack 4/7: keep an explicit thinking disable through translation (#545) #954 — Claude Desktop classifier thinking round-trip, Claude Desktop 3P Auto Mode classifier retries after 64-token Anthropic OAuth outputs #545 (base stack 3/7: carry six contributor bug fixes with authorship intact #953)
  5. stack 5/7: probe reset-derived cooldowns without waiting to be selected (#915) #955 — cooldown early-recovery probe, [Bug]: Reset-derived cooldowns can miss early recovery while another pool account remains eligible #915 (base stack 4/7: keep an explicit thinking disable through translation (#545) #954)
  6. stack 6/7: triage the overnight PRs and fix the #955 defects they found #973 — overnight PR triage + the stack 5/7: probe reset-derived cooldowns without waiting to be selected (#915) #955 defects it surfaced (base stack 5/7: probe reset-derived cooldowns without waiting to be selected (#915) #955)

Review and merge bottom-up. Each PR targets the preceding stack branch, so its Files changed view contains only that layer.

The layers touch largely disjoint files, so any layer can be retargeted to dev and taken independently. The one real dependency is #973 on #955 — it fixes defects in #955's own code, so those two should land together or in that order.

#954 needs human security review per MAINTAINERS.md (Anthropic OAuth request construction). It is deliberately below #955/#973 so the first three can land without waiting on it.

Carried with authorship preserved: #939, #942, #943, #944, #945, #948 in #953; #965, #967, #968 in #973.

@lidge-jun lidge-jun changed the title stack 4/5: keep an explicit thinking disable through translation (#545) stack 4/6: keep an explicit thinking disable through translation (#545) Aug 4, 2026
@lidge-jun lidge-jun changed the title stack 4/6: keep an explicit thinking disable through translation (#545) stack 4/7: keep an explicit thinking disable through translation (#545) Aug 4, 2026
@lidge-jun

Copy link
Copy Markdown
Owner Author

Stack navigation — 7 layers, review and merge bottom-up

Layer PR Contents
1/7 #951 merged af3ddedb4 — 22 label corrections + the plan unit
2/7 #952 long-context pricing tiers (#908)
3/7 #953 six carried contributor bug fixes, authorship intact
4/7 #954 explicit thinking disable through translation (#545)
5/7 #955 cooldown early-recovery probe (#915)
6/7 #973 overnight PR triage + fixes to #955's own defects
7/7 #980 NIM vision classification (#956), service repair (#970), qwen3.8-max rename

Each layer targets the branch below it, so its diff only makes sense on that base — enforce-target skips the wrong-base gate for stacked children by design (AGENTS.md, Branch policy). Review bottom-up; a layer cannot merge before its parent lands.

Note for the merge sequence: retargeting a child after its parent merges emits an edited event, which ci.yml does not listen for. A green check on the same head sha therefore proves nothing about the new merge base — merge current dev into the child to force a synchronize run before merging it.

@lidge-jun
lidge-jun changed the base branch from codex/carry-contributor-bugfixes to dev August 4, 2026 04:03

@coderabbitai coderabbitai 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.

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 `@src/adapters/anthropic.ts`:
- Around line 427-437: Update claudeFamilyVersion to accept either a hyphen or
dot separator before the optional minor version, so IDs such as
claude-sonnet-4.5 produce minor 5 while preserving existing hyphenated parsing.
Add a dot-separated model ID regression case to the capability tests covering
meetsFamilyMinimum().
🪄 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: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 3d4f0740-8646-494e-b0cc-2b9d2bd50a23

📥 Commits

Reviewing files that changed from the base of the PR and between 53f390b and d1ec013.

📒 Files selected for processing (5)
  • src/adapters/anthropic.ts
  • src/claude/inbound.ts
  • tests/anthropic-reasoning.test.ts
  • tests/claude-inbound.test.ts
  • tests/cursor-effort-suffix.test.ts

Comment thread src/adapters/anthropic.ts
Comment on lines +427 to +437
function claudeFamilyVersion(modelId: string): { family: string; major: number; minor: number } | undefined {
// Find the segment that actually starts with `claude-`, rather than assuming it is either
// the first (breaks `anthropic/claude-sonnet-5`) or the last (breaks `claude-sonnet-5/variant`,
// where the slash carries a vendor suffix rather than a routing prefix).
const match = /(?:^|\/)claude-([a-z]+)-(\d+)(?:-(\d{1,2}))?(?!\d)/.exec(modelId);
if (!match) return undefined;
return {
family: match[1]!,
major: Number(match[2]),
minor: match[3] === undefined ? 0 : Number(match[3]),
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Parse dot-separated Claude minor versions.

Line 431 parses anthropic/claude-sonnet-4.5 as version 4.0. The optional minor group only accepts -5, and the negative lookahead permits the . after 4. This makes meetsFamilyMinimum() evaluate the wrong version for model IDs already used in tests/anthropic-reasoning.test.ts.

Accept both - and . before the minor version. Add a dot-separated ID to the capability regression cases.

Proposed fix
-  const match = /(?:^|\/)claude-([a-z]+)-(\d+)(?:-(\d{1,2}))?(?!\d)/.exec(modelId);
+  const match = /(?:^|\/)claude-([a-z]+)-(\d+)(?:[-.](\d{1,2}))?(?!\d)/.exec(modelId);
📝 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
function claudeFamilyVersion(modelId: string): { family: string; major: number; minor: number } | undefined {
// Find the segment that actually starts with `claude-`, rather than assuming it is either
// the first (breaks `anthropic/claude-sonnet-5`) or the last (breaks `claude-sonnet-5/variant`,
// where the slash carries a vendor suffix rather than a routing prefix).
const match = /(?:^|\/)claude-([a-z]+)-(\d+)(?:-(\d{1,2}))?(?!\d)/.exec(modelId);
if (!match) return undefined;
return {
family: match[1]!,
major: Number(match[2]),
minor: match[3] === undefined ? 0 : Number(match[3]),
};
function claudeFamilyVersion(modelId: string): { family: string; major: number; minor: number } | undefined {
// Find the segment that actually starts with `claude-`, rather than assuming it is either
// the first (breaks `anthropic/claude-sonnet-5`) or the last (breaks `claude-sonnet-5/variant`,
// where the slash carries a vendor suffix rather than a routing prefix).
const match = /(?:^|\/)claude-([a-z]+)-(\d+)(?:[-.](\d{1,2}))?(?!\d)/.exec(modelId);
if (!match) return undefined;
return {
family: match[1]!,
major: Number(match[2]),
minor: match[3] === undefined ? 0 : Number(match[3]),
};
🧰 Tools
🪛 OpenGrep (1.26.0)

[ERROR] 431-431: Dynamic command passed to child_process.exec/execSync. Use child_process.execFile or spawn with an argument array instead.

(coderabbit.command-injection.exec-js)

🤖 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 `@src/adapters/anthropic.ts` around lines 427 - 437, Update claudeFamilyVersion
to accept either a hyphen or dot separator before the optional minor version, so
IDs such as claude-sonnet-4.5 produce minor 5 while preserving existing
hyphenated parsing. Add a dot-separated model ID regression case to the
capability tests covering meetsFamilyMinimum().

@lidge-jun
lidge-jun merged commit 5d2973c into dev Aug 4, 2026
26 checks passed
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