Generate fallback drops prior assistant reasoning from follow-up requests
On the generate fallback (transport: generate, accounts that get 403 upgrade_required), the model can no longer see its own private reasoning from previous turns, so it silently re-decides things it had already committed to in earlier thinking. Reproduced in a simple guessing game with deepseek/deepseek-v4.1-flash: the model picks a secret number, then re-picks a different one on turn 2 in every run without the fix. Because visible text and tool calls are still replayed, coding tasks mostly keep working and this presents as random model forgetfulness rather than a bug — but any multi-turn task whose state lives only in thinking (planning, games, consistency checks, long-running decisions) breaks.
The cause is in src/converters.ts: messagesToCC() has no branch for content.type === "thinking" (removed in PR #40 / 0.5.0), so assistant thinking blocks are dropped when building /alpha/generate history. PR #40's premise appears incorrect — the official Command Code CLI (1.32.2 / 1.72.4 / 1.79.2) toWireMessages always replays thinking as {type:"reasoning", text}, and its e2e assertion (both turns emit fresh thinking_delta) also passes when the model re-thinks from scratch, so it cannot catch this.
Re-adding parts.push({type:"reasoning", text: content.thinking}) for thinking blocks in src/converters.ts fixes it: wire captures show the reasoning part is sent again and the secret number stays consistent across turns. The patch applies cleanly on 0.7.5 and 0.7.6; happy to open a PR with a reproduction fixture (session JSONL + wire captures) if useful.
Thanks for the detailed report — this looks plausible and worth fixing.
Quick local confirmation on 0.7.6 (main @ 0126bc5): feeding an assistant turn with a thinking block through messagesToCC() produces only [{type:"text",...}] — the thinking content is indeed absent from the /alpha/generate history. That matches your diagnosis (branch removed in PR #40).
Two things before we merge a re-add:
- CLI reference: you cite the official CLI's
toWireMessagesreplaying thinking as{type:"reasoning", text}on 1.32.2 / 1.72.4 / 1.79.2. Could you point at the exact file/function (link or path + version) so we can verify against the current CLI instead of relying on memory of its behavior? PR #40's note claimed parity with the CLI at the time, so we want to close that loop explicitly. - PR welcome: yes, please open one against
mainwith your reproduction fixture (session JSONL + wire captures) plus a unit test intests/test-pure-functions.tscovering the thinking-block replay. That gives us something concrete to review and run.
One review consideration upfront: #40 deliberately dropped prior reasoning to stop old private traces from interfering with fresh reasoning. If replaying thinking turns out to change follow-up behavior on some models (stale plans leaking into new turns), we may need to scope the replay (e.g. only when the turn also carries tool calls, or most-recent assistant turn only). Your fixture with the number-consistency check is exactly the evidence that will settle it.
Thanks again for offering the PR — happy to review it promptly.
Thanks for the quick confirmation. Here's the exact reference you asked for.
CLI reference — [email protected] (current npm latest, published 2026-10-08), dist/cli.mjs (bundled, line 2), function toWireMessages:
"thinking"===n.type&&e.push({type:"reasoning",text:n.thinking})
| version | published | branch |
|---|---|---|
| 1.32.2 | 2026-08-24 | "thinking"===t.type&&e.push({type:"reasoning",text:t.thinking}) |
| 1.72.4 | 2026-09-30 | "thinking"===t.type&&e.push({type:"reasoning",text:t.thinking}) |
| 1.79.2 | 2026-10-08 | "thinking"===n.type&&e.push({type:"reasoning",text:n.thinking}) |
Verify locally:
npm pack [email protected]
tar -xzf command-code-1.79.2.tgz
grep -o 'function toWireMessages(.\{0,520\}' package/dist/cli.mjs
(Minified locals differ per build, hence t/n.) The same thinking → {type:"reasoning"} mapping also exists in convertAssistantBlock. These versions cover the range from just after #40 to the current release, and none of them drop prior thinking.
Why I believe full replay should be the default
- Consistency: pi's built-in providers keep prior thinking in history (I wire-captured DeepSeek resending
reasoning_contenton every assistant history message), and this plugin's Provider API path delegates history conversion to pi-ai (api: "openai-responses"inindex.ts) instead of stripping it in its own serializer. Today the generate fallback is the only path we found where the model loses its earlier reasoning; it should behave like the host and like the official CLI. - Accuracy: any state that lives only in thinking — plans, committed decisions, constraints discovered mid-analysis — survives. Without it the model re-decides them. In a 1–10000 consistency test the unpatched control changed its secret number on the next turn (0/4 unpatched runs retained; every wire capture on that path shows zero
reasoningparts), while the patched build held one number self-consistently across 4 turns (5/6 patched runs retained; the single miss was re-run from the same session state 3× and retained each time, so it was model-side variance, not the wire). - Efficiency: without replay the model re-derives the same reasoning chain from scratch on every turn. Replaying the existing trace as input is far cheaper than regenerating it as output, and it removes redundant thinking latency on long conversations (DeepSeek bills reasoning as output tokens).
Scoping data point: "tool-call turns only" would not be sufficient — DeepSeek only consumes replayed reasoning when the request carries a non-empty tools array, so in a normal tool-enabled pi session, text-only turns are exactly the ones that would still lose their history and break. "Most-recent-assistant only" would also drop state committed several turns earlier (the 4-turn test relies on cumulative replay).
De-risking: if stale traces do turn out to matter for some model, I'm happy to include an opt-out in the same PR — e.g. COMMANDCODE_REPLAY_REASONING=0 (alongside the existing COMMANDCODE_* env vars) to restore the #40 behavior, with replay on by default. That keeps CLI/host parity as the default while making the change trivially reversible. Tell me if you'd prefer the flag from day one or a separate follow-up.
PR next: converter fix + unit test in tests/test-pure-functions.ts + session/wire fixtures.
Thanks for the exact CLI reference and the additional test results — that gives us a concrete basis for reviewing the change.
Please go ahead with the PR against main: converter fix, unit coverage in tests/test-pure-functions.ts, and the session/wire fixtures. We'll verify the CLI reference and the replay behavior as part of the review.
For the first iteration, I'd prefer to keep it focused and leave out COMMANDCODE_REPLAY_REASONING. We can revisit an opt-out or model-specific scoping in a follow-up if we observe a concrete regression; no need to add a configuration switch preemptively.
Your explanation of the limitations of tool-call-only or most-recent-turn replay is helpful. The fixtures will let us check cumulative replay, including text-only assistant turns in a tool-enabled session.
Thanks again — looking forward to reviewing the PR!