workbuddy 0.2.6: an empty tool_calls list is no call, so the filter's refusal is still caught (#540)

itspig (#540, 2026-10-31) ran magpie v0.1.2283 with workbuddy 0.2.5 on
the live account, through a [workbuddy, volcengine] group: the refusal
still reached the client and routing.jsonl had the workbuddy try
done/200 with firstText 3208, no try of volcengine.

The cause: copilot.tencent.com puts "tool_calls": [] on every delta, text
too (magpie f2c7536d7 recorded it for Qoder). unsaid let the reply
through at the first delta whose tool_calls was truthy, and [] is truthy
in JS, so the gate opened at the reasoning chunk and nothing was held or
taken out. itspig's paste had no tool_calls because it was read off
magpie after chatTidy dropped the empty list and Go re-wrote the chunk
with its keys sorted; 0.2.5's fixture was built from that paste.

unsaid now counts a tool_calls list only when it holds a call.

Run (on mote, mote-run):
- HOME=$(mktemp -d) bun test packages/workbuddy: 291 pass, 0 fail.
- bun scripts/check.mjs: exit 0.
- filtered.test.mjs: the paste's chunks with WorkBuddy's own framing
  ("tool_calls": [], "finish_reason": "" until the last, an empty
  reasoning_content beside the line) cut every 1, 7 and 1MiB bytes; the
  line split over deltas that each carry the empty list; a real call
  still lets the reply through as it came.
- End to end, in magpie's plugin host (a magpie worktree's gateway test,
  not committed there): this file loaded by the host behind a fetch
  shim pointing copilot.tencent.com at a fake vendor, signed in with an
  API key, in a group [workbuddy-plugin/deepseek-v4.1-flash, b/m], asked
  as a streamed chat, a one-body chat, Messages (Claude Code's ask) and
  Responses (Codex's ask). With 0.2.6, 8 of 8 hand on to b and say no
  "Sorry", for the paste and for the wire framing.

Broken by hand:
- 0.2.5 (b5cc782): the 4 new wire-framing tests go red; end to end the
  wire framing goes red on chat, Messages and Responses (b never asked,
  "Sorry" in the reply), the paste stays green, as itspig saw.

Not tried: a live WorkBuddy account; the trigger prompt was not run.
This commit is contained in:
yetone
2026-10-31 08:36:42 +08:00
parent b5cc78266f
commit d0d07168ef
4 changed files with 41 additions and 3 deletions
+3 -1
View File
@@ -251,7 +251,9 @@ same words ending `stop`, or the filter cutting off a reply after other
words, go through as they came.
copilot.tencent.com sends the line with a newline on each side
(`"\nSorry, I can't respond to this question.\n"`); since 0.2.5 white
space around it no longer lets it through.
space around it no longer lets it through. It also puts `"tool_calls": []` on
every delta; since 0.2.6 only a list with a call in it lets the reply
through as it came.
## Models
+33
View File
@@ -159,3 +159,36 @@ test("a reply that opens with a newline and then answers goes through whole", as
const upstream = chunk({ content: "\n" }) + chunk({ content: "Hello" }) + chunk({}, "stop") + "data: [DONE]\n\n"
expect(await through(upstream)).toBe(upstream)
})
// copilot.tencent.com puts "tool_calls": [] on every delta, text too, and
// "finish_reason": "" until the last (magpie f2c7536d7, ARNO on Discord).
// magpie's gateway drops the empty list (chatTidy) and writes the chunk
// back with its keys sorted, so itspig's paste, read off magpie, had
// neither. An empty list is no call: the refusal is still the filter's.
const WIRE =
'data: {"choices":[{"delta":{"content":"","extra_fields":null,"function_call":null,"reasoning_content":" node","refusal":"","tool_calls":[]},"finish_reason":"","index":0,"logprobs":null}],"created":1793401068,"id":"c56c77084382622efa17c799396db5cf","model":"deepseek-v4.1-flash","object":"chat.completion.chunk","usage":null}\n\n' +
'data: {"choices":[{"delta":{"content":"\\nSorry, I can\'t respond to this question.\\n","extra_fields":null,"function_call":null,"reasoning_content":"","refusal":"","role":"assistant","tool_calls":[]},"finish_reason":"content_filter","index":0,"logprobs":null}],"created":0,"id":"c56c77084382622efa17c799396db5cf","model":"deepseek-v4.1-flash","object":"chat.completion.chunk","usage":null}\n\n' +
"data: [DONE]\n\n"
for (const cuts of [1, 7, 1 << 20]) {
test(`the refusal with WorkBuddy's empty tool_calls on every delta says nothing (cut every ${cuts} bytes)`, async () => {
const out = await through(WIRE, cuts)
expect(out).not.toContain("Sorry")
const cs = contents(out)
expect(cs.map((c) => c.delta.reasoning_content ?? "").join("")).toBe(" node")
expect(cs.at(-1).finish_reason).toBe("content_filter")
})
}
test("the filter's line split over deltas that each carry an empty tool_calls is taken out", async () => {
const d = (content, finish = "") => chunk({ content, reasoning_content: "", tool_calls: [] }, finish)
const upstream = chunk({ role: "assistant", content: "", reasoning_content: "hm", tool_calls: [] }, "") + d("\n") + d("Sorry") + d(", I can't respond") + d(" to this question.") + d("\n") + d("", "content_filter") + "data: [DONE]\n\n"
const out = await through(upstream)
expect(out).not.toContain("Sorry")
expect(contents(out).at(-1).finish_reason).toBe("content_filter")
})
test("a real tool call still lets the reply through as it came", async () => {
const upstream = chunk({ content: "", tool_calls: [{ index: 0, id: "c1", type: "function", function: { name: "grep", arguments: "{}" } }] }) + chunk({ content: said }) + chunk({}, "content_filter") + "data: [DONE]\n\n"
expect(await through(upstream)).toBe(upstream)
})
+4 -1
View File
@@ -1660,7 +1660,10 @@ function unsaid(res) {
const c = chunkOf(ev)?.choices?.[0]
const text = typeof c?.delta?.content === "string" ? c.delta.content : ""
const finish = c?.finish_reason
if (c?.delta?.tool_calls || (text && !filterSaid(said + text))) {
// copilot.tencent.com sends "tool_calls": [] on every delta, text
// too: only a list with a call in it is one
const calls = c?.delta?.tool_calls
if ((Array.isArray(calls) ? calls.length > 0 : calls) || (text && !filterSaid(said + text))) {
open = false
const out = [...held, ev]
held = []
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-workbuddy-auth",
"version": "0.2.5",
"version": "0.2.6",
"description": "OpenCode provider plugins for WorkBuddy's plans: WorkBuddy (CodeBuddy, copilot.tencent.com) and WorkBuddy AI (www.workbuddy.ai)",
"type": "module",
"main": "./index.mjs",