gateway: drop the locked sampling fields for Kimi on Volcengine Ark too

Volcengine Ark's plans lock the sampling parameters of the Kimi models
they serve: any request carrying temperature != 1 is refused 400
"Volcengine Ark: `temperature` only 1 is allowed for this model"
(#4495, kimi-k3.1-pro / kimi-k3 / kimi-k2.8-preview at
ark.cn-beijing.volces.com/api/coding/v3), before any token is read —
clients that send their own defaults (Claude Code, Copilot) fail every
call, and a routing group spends its failover window on each try.

kimiLockedSampling already drops temperature and top_p for the locked
models on Moonshot's own endpoints (#1197), but its isKimi guard knows
only Moonshot's hosts and presets, so the same models behind an Ark
host went through with the fields. The refusal names the model ("for
this model"), not the path, and the preset's Agent Plan and pay-as-you-
go regions list the same kimi-kX.Y models, so the guard now also takes
isArk — the ark.<region>.volces.com check the draw and video code
already uses, which covers the preset's plans and a provider added by
hand — and kimiLockedSamplingModel keeps deciding per model, as it
already does for kimi-k2.5 and later, kimi-for-coding* and k3*. Ark's
other models (doubao, glm, deepseek, minimax) are untouched, as is
everyone not served by Moonshot or Ark.

Run: TestKimiLockedSampling in internal/gateway grew four cases (the
coding plan's chat and anthropic routes, an Ark model the server
doesn't lock, a provider added by hand on an Ark host): the three drop
cases fail on the unmodified code and pass with it, the keep case
passes throughout. go test -tags nogui ./internal/gateway ok (499s);
gofmt clean; go vet -tags nogui on darwin, linux and windows clean;
go build -tags nogui ./... on darwin, linux and windows ok.

Generated-by: GLM-5.3-Flash (ZCode)

Reviewed and run by yetone at the batch head over cac655c14 (this commit,
the four others from ggbdpq's #4495/#4548/#4512/#3260 patches and the
#4548 follow-up), on mote:
- gofmt -l clean; go vet ./... for darwin, linux (-tags nogui), windows;
  go build ./... for darwin and windows.
- go test -tags nogui -count=1 -timeout 45m ./...: every package ok but
  internal/gui, with two filed reds: TestSettingsSaveKeepsWhatItDoesNotSend
  (#4514), red alone at origin/main cac655c14 too, and TestColdTurnsTaken
  (#4510), red only in the full run. Rebased afterwards onto e94fb18b8,
  a usage-page change that touches none of these files.
- Windows (xiaomi-gpu): go test -run 'TestVSCode|TestClaudePicker'
  ./internal/agent ok. TestCopilotFolderFromAnIDEPluginIsNotTheCLI is red
  there at cac655c14 too (#1827).
- Broken by hand: guard back to !isKimi(p, to) -> three TestKimiLockedSampling subtests red (volcengine coding plan, its anthropic endpoint, a hand-added Ark host). Not tried: a real Volcengine Ark Kimi request.
This commit is contained in:
ggbdpq
2026-10-31 20:54:37 +08:00
committed by yetone
parent e94fb18b8f
commit 7804dfbb03
2 changed files with 58 additions and 12 deletions
+14 -11
View File
@@ -196,18 +196,21 @@ func valuesType(vals []gjson.Result) string {
// kimiLockedSampling is body without temperature and top_p when the model's
// server locks them to one value: since kimi-k2.5 every kimi-kX.Y on both
// Kimi platforms (Moonshot's API and a Kimi Code membership's), and Kimi
// Code's own kimi-for-coding and k3*. A client that sends its own
// defaults — VS Code Copilot's chat sends temperature 0.1 and top_p 1 — is
// refused 400 "invalid temperature: only 1 is allowed for this model"
// before any token is read (a K2.5/K2.6 with thinking off takes only 0.6),
// and the whole request fails. Left out, the server fills in the value the
// model and mode want, so no number is written here. Models that take a
// range — moonshot-v1-*, kimi-k2-0905-preview, kimi-k2-thinking,
// kimi-latest — keep what the user set, as does anyone not served by
// Moonshot.
// Kimi platforms (Moonshot's API and a Kimi Code membership's), Kimi
// Code's own kimi-for-coding and k3*, and the same models on Volcengine
// Ark, whose coding plan serves kimi-kX.Y behind hosts the preset's plans
// and a provider added by hand both reach (#4495: 400 "Volcengine Ark:
// `temperature` only 1 is allowed for this model"). A client that sends
// its own defaults — VS Code Copilot's chat sends temperature 0.1 and
// top_p 1 — is refused 400 "invalid temperature: only 1 is allowed for
// this model" before any token is read (a K2.5/K2.6 with thinking off
// takes only 0.6), and the whole request fails. Left out, the server
// fills in the value the model and mode want, so no number is written
// here. Models that take a range — moonshot-v1-*, kimi-k2-0905-preview,
// kimi-k2-thinking, kimi-latest — keep what the user set, as does anyone
// not served by Moonshot or Ark.
func kimiLockedSampling(p provider.Provider, to provider.Protocol, body []byte) []byte {
if !isKimi(p, to) {
if !isKimi(p, to) && !isArk(p) {
return body
}
if !kimiLockedSamplingModel(gjson.GetBytes(body, "model").String()) {
+44 -1
View File
@@ -192,8 +192,14 @@ func TestKimiLockedSampling(t *testing.T) {
}
moonshot.ID, moonshot.Key = "moonshot", "k"
moonshot.Models = []string{"moonshot-v1-8k", "kimi-k2.5", "kimi-k2.6", "kimi-k2-0905-preview", "kimi-k2-thinking", "moonshotai/kimi-k2.6"}
volc, err := provider.FromPreset("volcengine")
if err != nil {
t.Fatal(err)
}
volc.ID, volc.Key, volc.Models = "volc", "k", []string{"kimi-k3.1-pro", "kimi-k2.8-preview", "doubao-seed-2.1-pro"}
arkpay := provider.Provider{ID: "arkpay", Name: "Ark pay", Key: "k", Chat: "https://ark.ap-southeast.volces.com/api/v3", Models: []string{"kimi-k3"}}
other := provider.Provider{ID: "other", Name: "Other", Key: "k", Chat: "https://other.test/v1", Models: []string{"m"}}
for _, p := range []provider.Provider{kimi, moonshot, other} {
for _, p := range []provider.Provider{kimi, moonshot, volc, arkpay, other} {
if err := provider.Save(p); err != nil {
t.Fatal(err)
}
@@ -314,6 +320,43 @@ func TestKimiLockedSampling(t *testing.T) {
t.Errorf("kimi-k2-thinking's temperature was not kept: %s", got.body)
}
})
// #4495: Volcengine Ark locks the same models' sampling the same way
// ("Volcengine Ark: `temperature` only 1 is allowed for this model"),
// at its coding plan and — an Ark host being an Ark host — wherever
// else its Kimi models are served.
t.Run("volcengine's coding plan drops the fields", func(t *testing.T) {
got := post(t, "/v1/chat/completions", `{"model":"volc/kimi-k3.1-pro","messages":[{"role":"user","content":"hi"}],"temperature":0.6,"top_p":0.95}`)
if got.host != "ark.cn-beijing.volces.com" {
t.Fatalf("the request went to %s", got.host)
}
if gjson.Get(got.body, "temperature").Exists() || gjson.Get(got.body, "top_p").Exists() {
t.Errorf("Ark was sent the sampling fields: %s", got.body)
}
})
t.Run("volcengine's anthropic endpoint drops the fields", func(t *testing.T) {
got := post(t, "/v1/messages", `{"model":"volc/kimi-k3.1-pro","messages":[{"role":"user","content":"hi"}],"temperature":0.6,"top_p":0.95,"max_tokens":5}`)
if got.host != "ark.cn-beijing.volces.com" {
t.Fatalf("the request went to %s", got.host)
}
if gjson.Get(got.body, "temperature").Exists() || gjson.Get(got.body, "top_p").Exists() {
t.Errorf("Ark was sent the sampling fields: %s", got.body)
}
})
t.Run("volcengine keeps the fields for a model its server doesn't lock", func(t *testing.T) {
got := post(t, "/v1/chat/completions", `{"model":"volc/doubao-seed-2.1-pro","messages":[{"role":"user","content":"hi"}],"temperature":0.6,"top_p":0.95}`)
if !strings.Contains(got.body, `"temperature":0.6`) {
t.Errorf("doubao was not sent its temperature: %s", got.body)
}
})
t.Run("a provider added by hand on an Ark host drops the fields", func(t *testing.T) {
got := post(t, "/v1/chat/completions", `{"model":"arkpay/kimi-k3","messages":[{"role":"user","content":"hi"}],"temperature":0.6,"top_p":0.95}`)
if got.host != "ark.ap-southeast.volces.com" {
t.Fatalf("the request went to %s", got.host)
}
if gjson.Get(got.body, "temperature").Exists() || gjson.Get(got.body, "top_p").Exists() {
t.Errorf("Ark was sent the sampling fields: %s", got.body)
}
})
t.Run("another provider is sent the body as it was", func(t *testing.T) {
got := post(t, "/v1/chat/completions", `{"model":"other/m","messages":[{"role":"user","content":"hi"}],"temperature":0.1,"top_p":1}`)
if !strings.Contains(got.body, `"temperature":0.1,"top_p":1`) {