claude: a reply's thinking is never told to a Claude Code run as words (#6623)
The subscription bridge tells a conversation to a Claude Code run as Human:/Assistant: text (a run started anew, the messages since a reply, the transcript a new interactive run resumes). renderCachedParts wrote each thinking part's text into the assistant's turn, so earlier reasoning reached the model verbatim in a user message. Anthropic refused it as reasoning_extraction, and every run started anew after the refusal told it again (#6623; solllin on X). Thinking and redacted_thinking parts are now left out there. Words, tool calls and tool results are told as before. renderCachedParts is the one place: renderClaudePrompt (-p and interactive first message), renderClaudeTurn (next message, typed turn) and replaySession all reach it; a grep of every `case Thinking` in the tree finds only native structured encodings besides it, and sessions' carry already drops thinking. Run (mica, at338eae3c2plus this change): - TestClaudeReplayLeavesThinkingOut: red on the old code (thinking text in the history), green with the fix. It covers renderClaudePrompt with and without client cache marks, renderClaudeTurn and replaySession's transcript, with thinking and redacted_thinking blocks, and checks the words, tool call and tool result are still there. - go test ./internal/gateway ./internal/sessions -count=1 -timeout 45m: ok. - go vet ./internal/gateway, GOOS=linux and GOOS=windows: ok. gofmt -l: clean. After rebasing on343920464(routing only): go test ./internal/gateway -run TestClaude: ok. Not tried: a real Claude subscription conversation reproducing the refusal before and after; no GUI change.
This commit is contained in:
@@ -1163,7 +1163,13 @@ history to the 1h cache at 2×.
|
||||
after the last reply that calls no tool, `historyEnd`) in
|
||||
`<current_turn>` (#1365). Told as one stretch of Human:/Assistant: text,
|
||||
earlier images read as just sent. A first turn, or messages with no
|
||||
reply among them, are told as before. `start` logs "a new Claude Code
|
||||
reply among them, are told as before. A reply's thinking and
|
||||
redacted_thinking are never told as words, here, in the messages since
|
||||
a reply (`renderClaudeTurn`) or in a resumed transcript
|
||||
(`renderCachedParts`): written as the assistant's text, earlier
|
||||
reasoning reached the model in a user message, Anthropic refused it as
|
||||
`reasoning_extraction`, and every run started anew told it again
|
||||
(#6623). `start` logs "a new Claude Code
|
||||
is told the whole conversation" with the message and image counts.
|
||||
Claude Code notes every image of the message after it, so after the
|
||||
turn to answer: `[Image: source: …/images/N.png]` where it keeps the
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
package gateway
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// A conversation told to a Claude Code run in words leaves the replies'
|
||||
// thinking out. Written into the history as the assistant's text, earlier
|
||||
// thinking reached the model as words in a user message, which Anthropic
|
||||
// refused as reasoning extraction, and every run started anew after the
|
||||
// refusal told it again (#6623; solllin on X). The words, tool calls and
|
||||
// tool results stay.
|
||||
func TestClaudeReplayLeavesThinkingOut(t *testing.T) {
|
||||
const secret = "PRIVATE-CHAIN-OF-THOUGHT-6623"
|
||||
const sealed = "U0VBTEVELVJFREFDVEVELTY2MjM="
|
||||
conv := `[` +
|
||||
`{"role":"user","content":"fix the bug"},` +
|
||||
`{"role":"assistant","content":[{"type":"thinking","thinking":"` + secret + ` one","signature":"sig1"},{"type":"redacted_thinking","data":"` + sealed + `"},{"type":"text","text":"reading the file"},{"type":"tool_use","id":"call_1","name":"read","input":{"path":"a.go"}}]},` +
|
||||
`{"role":"user","content":[{"type":"tool_result","tool_use_id":"call_1","content":"package a"}]},` +
|
||||
`{"role":"assistant","content":[{"type":"thinking","thinking":"` + secret + ` two","signature":"sig2"},{"type":"text","text":"fixed it"}]},` +
|
||||
`{"role":"user","content":"now add a test"}]`
|
||||
fields := `"tools":[{"name":"read","input_schema":{"type":"object"}}],`
|
||||
told := func(t *testing.T, blocks []map[string]any) string {
|
||||
t.Helper()
|
||||
var all strings.Builder
|
||||
for _, b := range blocks {
|
||||
s, _ := b["text"].(string)
|
||||
all.WriteString(s)
|
||||
all.WriteString("\n")
|
||||
}
|
||||
return all.String()
|
||||
}
|
||||
check := func(t *testing.T, s string, want ...string) {
|
||||
t.Helper()
|
||||
if strings.Contains(s, secret) || strings.Contains(s, sealed) {
|
||||
t.Fatalf("the replay carries the replies' thinking:\n%s", s)
|
||||
}
|
||||
for _, w := range want {
|
||||
if !strings.Contains(s, w) {
|
||||
t.Fatalf("the replay lost %q:\n%s", w, s)
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, marks := range []bool{false, true} {
|
||||
req := clientCacheRequest(t, fields, conv)
|
||||
if !marks {
|
||||
req.clientCache = nil
|
||||
}
|
||||
blocks, err := renderClaudePrompt(req)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
check(t, told(t, blocks), "fix the bug", "reading the file", "[tool call", "call_1", "package a", "fixed it", "now add a test")
|
||||
}
|
||||
|
||||
// the messages since a reply, told to a run that has the conversation
|
||||
// (the -p run's next message, and the interactive run's typed turn)
|
||||
req := clientCacheRequest(t, fields, conv)
|
||||
check(t, told(t, renderClaudeTurn(req.Messages[1:], req.Tools)), "reading the file", "[tool call", "package a", "fixed it", "now add a test")
|
||||
|
||||
// the transcript a new interactive run resumes
|
||||
dir := t.TempDir()
|
||||
long := clientCacheRequest(t, fields, strings.TrimSuffix(conv, "]")+`,{"role":"assistant","content":[{"type":"thinking","thinking":"`+secret+` three","signature":"sig3"},{"type":"text","text":"added"}]},{"role":"user","content":"thanks"}]`)
|
||||
if replaySession([]string{dir}, dir, "claude-sonnet-5", long) == nil {
|
||||
t.Fatal("no transcript was written")
|
||||
}
|
||||
files, _ := filepath.Glob(filepath.Join(dir, "*.jsonl"))
|
||||
if len(files) != 1 {
|
||||
t.Fatalf("%d transcripts", len(files))
|
||||
}
|
||||
b, err := os.ReadFile(files[0])
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
check(t, string(b), "fix the bug", "reading the file", "package a", "fixed it", "now add a test", "added")
|
||||
}
|
||||
@@ -5566,7 +5566,11 @@ func renderCachedParts(blocks []map[string]any, text *strings.Builder, parts []P
|
||||
case File:
|
||||
text.WriteString(attachmentText(p))
|
||||
case Thinking:
|
||||
text.WriteString(p.Text)
|
||||
// A reply's thinking (and redacted_thinking) is never told as
|
||||
// words: written as the assistant's text in the history, it
|
||||
// reached the model as earlier reasoning pasted into a user
|
||||
// message, which Anthropic refused as reasoning extraction,
|
||||
// and every run started anew after that told it again (#6623)
|
||||
case ToolCall:
|
||||
name := p.Name
|
||||
if offered[name] {
|
||||
|
||||
Reference in New Issue
Block a user