Skip to content

Commit dff18db

Browse files
committed
docs(triage): lidge-jun#545 is a thinking round-trip loss, not an identity-block budget
The standing hypothesis said the prepended OAuth identity consumed the classifier's 64 output tokens. A system prompt is input; it cannot. The real loss is that thinking:{type:disabled} translates to reasoning:undefined, which is indistinguishable from omitted — and omitted means adaptive thinking ON.
1 parent 7a3c7a9 commit dff18db

1 file changed

Lines changed: 129 additions & 0 deletions

File tree

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# 060 — #545 Claude Desktop classifier retries
2+
3+
Stack layer 3. Work class C4 by promotion: the change lands on an Anthropic
4+
OAuth execution path, so `MAINTAINERS.md` security review applies even though
5+
no credential handling is touched.
6+
7+
## The reported symptom
8+
9+
In Claude Desktop 3P gateway-key mode with an Anthropic OAuth provider, Claude
10+
Code's Auto Mode permission classifier is truncated at exactly 64 output tokens
11+
with `max_tokens` and retries up to five times. The reporter's own aggregate:
12+
1,084 truncated requests against 143 that completed under 64 tokens. Every tool
13+
approval costs 12–22 seconds.
14+
15+
## The standing hypothesis was wrong
16+
17+
The recorded analysis said the classifier's 64-token budget "has to accommodate
18+
the prepended identity block, and that is where the retries come from."
19+
20+
That cannot be the mechanism. The identity block is prepended to the **system**
21+
prompt (`src/adapters/anthropic.ts:752-757`), and `max_tokens` caps **output**.
22+
Input and output are different budgets; a longer system prompt cannot arithmetically
23+
consume output allowance.
24+
25+
This repository had already reached that conclusion once and forgotten it:
26+
`devlog/_fin/260728_bug_bundle_resolution/030_claude_system_dedup.md` abandoned
27+
an identity-dedup patch for exactly this reason. Re-deriving a rejected theory
28+
is what a devlog is supposed to prevent.
29+
30+
## The actual mechanism
31+
32+
A round-trip fidelity loss, three hops long.
33+
34+
**Hop 1 — the client says "no thinking".** The reporter's inbound capture
35+
carries `thinking: {type: "disabled"}` alongside `max_tokens: 64` and
36+
`stop_sequences: ["</block>"]`.
37+
38+
**Hop 2 — ocx drops the instruction.** `src/claude/inbound.ts:494-506` treats
39+
disabled thinking as *nothing to translate*:
40+
41+
```ts
42+
const thinkingDisabled = isRec(thinking) && thinking.type === "disabled";
43+
if (!thinkingDisabled && (isRec(thinking) || outputConfigEffort !== undefined)) {
44+
...
45+
body.reasoning = reasoning;
46+
}
47+
```
48+
49+
`reasoning` stays `undefined` — the same state produced by a request that never
50+
mentioned thinking at all. The existing test pins this
51+
(`tests/claude-inbound.test.ts:96-97`): both "disabled" and "omitted" assert
52+
`reasoning` is `undefined`. Two different intentions, one representation.
53+
54+
**Hop 3 — omission means the opposite upstream.** The adapter emits `thinking`
55+
only for a real non-`none` effort (`src/adapters/anthropic.ts:769-770`), so the
56+
outbound request omits the field. Anthropic documents that for Sonnet 5 an
57+
omitted `thinking` field means *adaptive thinking is on by default*, and that
58+
thinking tokens count against `max_tokens` (retrieved 2026-08-04:
59+
[what's new in Sonnet 5](https://platform.claude.com/docs/en/about-claude/models/whats-new-sonnet-5),
60+
[extended thinking](https://platform.claude.com/docs/en/build-with-claude/extended-thinking)).
61+
62+
So the model thinks, thinking eats the 64-token budget, and generation stops
63+
before `</block>` is ever emitted. The classifier never sees its stop sequence,
64+
Claude Code retries, and the loop runs to its five-attempt ceiling. The 64
65+
tokens is the caller's own value and is faithfully preserved
66+
(`src/adapters/anthropic.ts:750`) — that part of the prior analysis was right.
67+
68+
The client asked for no thinking. It got thinking. That is the whole bug.
69+
70+
## Design
71+
72+
Give "disabled" a representation that survives the trip, using the sentinel the
73+
parser already understands — `"none"` is documented at
74+
`src/adapters/anthropic.ts:766-769` as the disable sentinel.
75+
76+
`src/claude/inbound.ts`:
77+
78+
```diff
79+
-if (!thinkingDisabled && (isRec(thinking) || outputConfigEffort !== undefined)) {
80+
+if (thinkingDisabled) {
81+
+ body.reasoning = { effort: "none", summary: "none" };
82+
+} else if (isRec(thinking) || outputConfigEffort !== undefined) {
83+
```
84+
85+
`src/adapters/anthropic.ts` — emit the explicit disable before the existing
86+
non-`none` branch, gated on models where omission enables thinking:
87+
88+
```diff
89+
+if (parsed.options.reasoning === "none" && usesAdaptiveThinking(parsed.modelId)) {
90+
+ body.thinking = { type: "disabled" };
91+
+} else
92+
if (typeof parsed.options.reasoning === "string" && parsed.options.reasoning !== "none") {
93+
```
94+
95+
**Pre-write search (DEV-NECESSITY-01).** No new predicate is needed.
96+
`usesAdaptiveThinking()` already exists at `src/adapters/anthropic.ts:411-421`
97+
and version-gates precisely the families whose omission-default this depends on,
98+
including date-pinned and suffixed ids. Adding a parallel model matcher would
99+
duplicate a subtle regex that is already correct and already tested.
100+
101+
Explicitly unchanged: `max_tokens`, `stop_sequences`, the OAuth identity block,
102+
terminal mapping, retry behavior, native passthrough.
103+
104+
## Tests
105+
106+
`tests/claude-inbound.test.ts:96` — the pinned expectation changes from
107+
`undefined` to `{effort: "none", summary: "none"}`. Line 97 (omitted thinking →
108+
`undefined`) must **stay** `undefined`: that assertion is what proves disabled
109+
and omitted are no longer the same state, which is the entire fix.
110+
111+
`tests/anthropic-reasoning.test.ts` — adaptive model + `"none"` emits
112+
`thinking: {type: "disabled"}`; adaptive model with reasoning omitted still
113+
omits `thinking`; a non-adaptive model + `"none"` emits nothing; existing
114+
enabled/adaptive paths unchanged.
115+
116+
Round-trip regression — the reporter's exact shape in, and assert the final
117+
adapter body carries `max_tokens: 64`, `stop_sequences: ["</block>"]`,
118+
`thinking: {type: "disabled"}`, and the OAuth identity still first in `system`.
119+
120+
## Honest limits
121+
122+
The unit tests prove the wire shape, not the retry disappearing. Confirming
123+
that requires a live Claude Desktop 3P + Anthropic OAuth session showing the
124+
classifier terminating on `</block>` instead of `max_tokens`. The PR says so
125+
rather than claiming the symptom fixed.
126+
127+
No public Anthropic documentation was found specifying the exact Claude Code
128+
OAuth identity string requirement; that remains repository knowledge from live
129+
behavior. The fix leaves it untouched, so nothing depends on proving it here.

0 commit comments

Comments
 (0)