fix: support Claude Opus 5 / Sonnet 5 adaptive thinking; unique Gemini tool-call IDs

Anthropic: add claude-opus-5 and claude-sonnet-5 to the adaptive-thinking-only
model list. These models also think by default when the thinking param is
omitted (unlike Fable 5/Mythos/Opus 4.7/4.8), so ReasoningOff now sends an
explicit {type:"disabled"} on them instead of relying on omission.

Gemini: replace the empty-FunctionCall.ID fallback (function name) with a
synthetic toolu_-shaped random ID. The name-based fallback wasn't unique —
repeated calls to the same tool in one conversation collided on one ID,
which produced duplicate tool_use ids if that history was later replayed to
a different (Anthropic) model on a routing switch, rejected with a 400.
This commit is contained in:
sausheong committed 2026-07-28 13:40:22 +08:00
1 parent c7846eeab9
commit 445614757b
6 files changed
+144 -560

No files matched your search

+20
View File
@@ -1,6 +1,7 @@
package gemini
import (
"strings"
"testing"
"github.com/stretchr/testify/require"
@@ -33,3 +34,22 @@ func TestGeminiUsageBuffer_KeepsLast(t *testing.T) {
require.Equal(t, 20, last.InputTokens)
require.Equal(t, 9, last.OutputTokens)
}
// TestSyntheticToolCallID_UniqueAndAnthropicShaped guards against the bug
// where an empty Gemini FunctionCall.ID fell back to the function name.
// That fallback isn't a valid provider-neutral tool-call ID shape, and
// worse, it isn't unique: two calls to the same tool (parallel calls, or
// the same tool called again later in a conversation — routine for a
// coding agent re-reading files) collided on one ID. When that history
// was later replayed to Anthropic on a routing switch, the duplicate
// tool_use ids were rejected with a 400.
func TestSyntheticToolCallID_UniqueAndAnthropicShaped(t *testing.T) {
seen := make(map[string]bool)
for range 100 {
id := syntheticToolCallID()
require.True(t, strings.HasPrefix(id, "toolu_"),
"synthetic ID must be shaped like an Anthropic tool_use id so a later replay to Anthropic is accepted")
require.False(t, seen[id], "synthetic IDs must be unique across calls in the same process")
seen[id] = true
}
}