gateway: DeepSeek's reasoning is held for a refusal after it; WorkBuddy plugin min 0.2.4 (plugins #540)
itspig (plugins #540): deepseek-v4.1-flash on WorkBuddy, through group/tiered, reasoned ~5s, said "Sorry, I can't respond to this question.", and ended finish_reason content_filter with 0 output tokens under a 200. The try was recorded done/200, none of the 15 members behind it was asked, and DeepSeek Harness failed "The model refused to complete the request". Two halves: - workbuddy 0.2.4 (plugins 4883f94) takes the filter's canned line out of a streamed chat that ends content_filter with nothing else said. - refusesAfterThinking now holds DeepSeek's reasoning too (as Claude's, GPT's and Gemini's), only while another candidate could answer: with it let through as it came, a refusal after it could never go to the next member. DeepSeek's own API documents finish_reason content_filter. The cost: in a group with a member behind it, DeepSeek's thinking reaches the agent once its text begins (kept alive meanwhile), as Claude's does; on the last candidate it streams as before. GLM, Kimi and others are unchanged. - The workbuddy mover's min is 0.2.4 (npm view --prefer-online: 0.2.4). Run on mote at this tree: go test ./internal/gateway -run 'TestDeepSeekRefusalAfterThinkingFailsOver|TestThinkingHeldFor| TestRefusalAfterThinkingFailsOver|TestThinkingStreams' ok; go test ./internal/provider ok; gofmt -l clean. The full ./... suite was started at this tree minus the one-line min and is still running; its result goes on plugins #540 (owner rule: tag without waiting). Broken by hand: without the deepseek prefix, TestDeepSeekRefusalAfterThinkingFailsOver/refused goes red (DeepSeek's reasoning reached the agent, b never asked) and TestThinkingHeldFor red for the three DeepSeek ids; /answered stays green. Not tried: a real WorkBuddy refusal (no prompt reproduces it on demand); the upstream's literal chunking isn't in the issue, so the fixture is built from its fields (reasoning, content_filter, 0 tokens).
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -2266,10 +2266,15 @@ func (h *holdWriter) keptQuiet() bool {
|
||||
|
||||
// refusesAfterThinking tells whether a model's vendor may end a reply that
|
||||
// has only reasoned with its safety filter's refusal: Claude's stop_reason
|
||||
// refusal, OpenAI's content_filter or bio_policy, Gemini's SAFETY (#248).
|
||||
// Anybody else's reasoning — GLM's, DeepSeek's, Kimi's… — is shown as it
|
||||
// comes: held, GLM on a ZCode account through a group showed Claude Code
|
||||
// its thinking only once the text began, all at once (悠悠哥 on Discord).
|
||||
// refusal, OpenAI's content_filter or bio_policy, Gemini's SAFETY (#248),
|
||||
// and DeepSeek's content_filter: deepseek-v4.1-flash on WorkBuddy reasoned
|
||||
// for 5s and then ended content_filter with nothing said (the plugin takes
|
||||
// out the filter's canned line), and with its reasoning let through the
|
||||
// group's next member was never asked and DeepSeek Harness failed "The
|
||||
// model refused to complete the request" (itspig, plugins #540).
|
||||
// Anybody else's reasoning — GLM's, Kimi's… — is shown as it comes: held,
|
||||
// GLM on a ZCode account through a group showed Claude Code its thinking
|
||||
// only once the text began, all at once (悠悠哥 on Discord).
|
||||
func refusesAfterThinking(model string) bool {
|
||||
if modelFamily(model) != "" {
|
||||
return true
|
||||
@@ -2278,7 +2283,7 @@ func refusesAfterThinking(model string) bool {
|
||||
if i := strings.LastIndex(m, "/"); i >= 0 {
|
||||
m = m[i+1:]
|
||||
}
|
||||
return strings.HasPrefix(m, "gemini")
|
||||
return strings.HasPrefix(m, "gemini") || strings.HasPrefix(m, "deepseek")
|
||||
}
|
||||
|
||||
// scan reads the held stream's events so far: an error before any content
|
||||
|
||||
@@ -134,3 +134,59 @@ func TestThinkingHeldLonger(t *testing.T) {
|
||||
t.Fatal("reasoning held past holdThinking")
|
||||
}
|
||||
}
|
||||
|
||||
// DeepSeek's filter refusing after it has reasoned, on WorkBuddy through
|
||||
// a group (itspig, plugins #540): deepseek-v4.1-flash reasoned for ~5s,
|
||||
// then ended finish_reason content_filter with 0 tokens counted, all under
|
||||
// a 200. The plugin takes the filter's "Sorry, I can't respond to this
|
||||
// question." out, so this is what reaches magpie: reasoning, then
|
||||
// content_filter with nothing said. Its reasoning went through as it came,
|
||||
// so the next member was never asked and DeepSeek Harness failed "The
|
||||
// model refused to complete the request"; held, the next member answers.
|
||||
// A DeepSeek reply that goes on to answer comes through whole.
|
||||
func TestDeepSeekRefusalAfterThinkingFailsOver(t *testing.T) {
|
||||
refused := sse(`data: {"id":"c1","object":"chat.completion.chunk","model":"deepseek-v4.1-flash","choices":[{"index":0,"delta":{"role":"assistant","reasoning_content":""},"finish_reason":null}]}`,
|
||||
`data: {"id":"c1","object":"chat.completion.chunk","model":"deepseek-v4.1-flash","choices":[{"index":0,"delta":{"reasoning_content":"The user is asking"},"finish_reason":null}]}`,
|
||||
`data: {"id":"c1","object":"chat.completion.chunk","model":"deepseek-v4.1-flash","choices":[{"index":0,"delta":{"reasoning_content":" about it."},"finish_reason":null}]}`,
|
||||
`data: {"id":"c1","object":"chat.completion.chunk","model":"deepseek-v4.1-flash","choices":[{"index":0,"delta":{},"finish_reason":"content_filter"}],"usage":{"prompt_tokens":0,"completion_tokens":0,"total_tokens":0}}`,
|
||||
`data: [DONE]`)
|
||||
answered := sse(`data: {"id":"c1","object":"chat.completion.chunk","model":"deepseek-v4.1-flash","choices":[{"index":0,"delta":{"role":"assistant","reasoning_content":"The user is asking"},"finish_reason":null}]}`,
|
||||
`data: {"id":"c1","object":"chat.completion.chunk","model":"deepseek-v4.1-flash","choices":[{"index":0,"delta":{"content":"from a"},"finish_reason":null}]}`,
|
||||
`data: {"id":"c1","object":"chat.completion.chunk","model":"deepseek-v4.1-flash","choices":[{"index":0,"delta":{},"finish_reason":"stop"}],"usage":{"prompt_tokens":3,"completion_tokens":5,"total_tokens":8}}`,
|
||||
`data: [DONE]`)
|
||||
run := func(t *testing.T, up string) (*scripted, *scripted, *Server, int, string) {
|
||||
fresh(t)
|
||||
a := &scripted{replies: []reply{{200, "text/event-stream", up}}}
|
||||
b := &scripted{replies: []reply{{200, "text/event-stream", anthropicAnswer}}}
|
||||
scriptedOn(t, "a", provider.Chat, a)
|
||||
pa, err := provider.Find("a")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
pa.Models = []string{"deepseek-v4.1-flash"}
|
||||
if err := provider.Save(*pa); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
scriptedOn(t, "b", provider.Anthropic, b)
|
||||
refusalGroup(t, "a/deepseek-v4.1-flash", "b/m")
|
||||
s := New()
|
||||
code, body := sendTo(s, "/v1/messages", claudeCodeAsk)
|
||||
return a, b, s, code, body
|
||||
}
|
||||
t.Run("refused", func(t *testing.T) {
|
||||
a, b, s, code, body := run(t, refused)
|
||||
if code != 200 || !strings.Contains(body, "from b") || strings.Contains(body, `"refusal"`) || strings.Contains(body, "The user is asking") || a.n != 1 || b.n != 1 {
|
||||
t.Fatalf("%d %s (a %d, b %d)", code, body, a.n, b.n)
|
||||
}
|
||||
r := lastRoute(s)
|
||||
if len(r.Tries) != 2 || r.Tries[0].Fail != failRefused || r.Tries[0].Rest != nil || r.Status != 200 {
|
||||
t.Fatalf("tries: %+v", r.Tries)
|
||||
}
|
||||
})
|
||||
t.Run("answered", func(t *testing.T) {
|
||||
a, b, _, code, body := run(t, answered)
|
||||
if code != 200 || !strings.Contains(body, "The user is asking") || !strings.Contains(body, "from a") || strings.Contains(body, "from b") || a.n != 1 || b.n != 0 {
|
||||
t.Fatalf("%d %s (a %d, b %d)", code, body, a.n, b.n)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -128,13 +128,14 @@ func TestThinkingStreamsThroughGroup(t *testing.T) {
|
||||
}
|
||||
|
||||
// Claude's reasoning is still held for a refusal after it (#248) while
|
||||
// another candidate could answer, and so are OpenAI's and Gemini's;
|
||||
// anybody else's is let through.
|
||||
// another candidate could answer, and so are OpenAI's, Gemini's and
|
||||
// DeepSeek's (plugins #540); anybody else's is let through.
|
||||
func TestThinkingHeldFor(t *testing.T) {
|
||||
for model, held := range map[string]bool{
|
||||
"claude-opus-5-5": true, "anthropic/claude-sonnet-4.5": true, "gpt-5.2-codex": true, "o3": true,
|
||||
"gemini-3-pro-preview": true, "models/gemini-2.5-flash": true,
|
||||
"GLM-5.1": false, "glm-4.6": false, "deepseek-v4": false, "kimi-k2.5": false, "MiniMax-M2": false,
|
||||
"deepseek-v4": true, "deepseek-v4.1-flash": true, "deepseek/deepseek-v4-pro": true,
|
||||
"GLM-5.1": false, "glm-4.6": false, "kimi-k2.5": false, "MiniMax-M2": false,
|
||||
} {
|
||||
if got := refusesAfterThinking(model); got != held {
|
||||
t.Errorf("%s: held %v, want %v", model, got, held)
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user