workbuddy 0.2.5: the filter's line is taken out with the newlines around it (#540)
itspig (#540, 2026-10-30) ran 0.2.4 against copilot.tencent.com and the refusal still reached the agent. The real chunk's content is "\nSorry, I can't respond to this question.\n" with finish_reason content_filter. filterSaid trimmed only the start, so the trailing "\n" made the text longer than FILTER_SAYS, the prefix test failed, and the chunk went out as an ordinary answer. filterSaid now trims both sides, and text that is only white space so far may still be the line (so a "\n" sent in a chunk of its own is held, not passed on). The reporter's suggested `t.startsWith(s)` is not taken: it would treat the line followed by real words as the filter's and drop those words at content_filter. `without` already removes the whole content field, so the newlines go with it. Run (on mote, mote-run): - HOME=$(mktemp -d) bun test packages/workbuddy: 286 pass, 0 fail. - bun scripts/check.mjs: ok. - filtered.test.mjs has itspig's literal last three SSE events (the " node" reasoning chunk, the refusal chunk, [DONE]), cut every 1, 7 and 1MiB bytes, plus newline-in-its-own-chunk, line-then-more-words and newline-then-answer cases. Broken by hand: - 0.2.4's trimStart filterSaid: the 3 literal-bytes tests and the own-chunk newline test go red (4 of 15). - The reporter's trim() + t.startsWith(s) with t !== "": the own-chunk newline and line-then-more-words tests go red (2 of 15). Not tried: a live WorkBuddy account; the trigger prompt was not run.
This commit is contained in:
@@ -249,6 +249,9 @@ instead of passing it to the agent as an answer. Only text that is still
|
|||||||
the filter's line is held, so any other reply's words go as they come; the
|
the filter's line is held, so any other reply's words go as they come; the
|
||||||
same words ending `stop`, or the filter cutting off a reply after other
|
same words ending `stop`, or the filter cutting off a reply after other
|
||||||
words, go through as they came.
|
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.
|
||||||
|
|
||||||
## Models
|
## Models
|
||||||
|
|
||||||
|
|||||||
@@ -121,3 +121,41 @@ test("an answer's words are not held", async () => {
|
|||||||
globalThis.fetch = realFetch
|
globalThis.fetch = realFetch
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// The last chunks copilot.tencent.com sent itspig, byte for byte (plugins
|
||||||
|
// #540, 2026-10-30): the filter's line comes with a newline on each side, in
|
||||||
|
// the chunk that ends content_filter.
|
||||||
|
const LITERAL =
|
||||||
|
'data: {"choices":[{"delta":{"content":"","extra_fields":null,"function_call":null,"reasoning_content":" node","refusal":""},"finish_reason":null,"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,"refusal":"","role":"assistant"},"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(`WorkBuddy's own refusal chunks, newlines and all, say nothing (cut every ${cuts} bytes)`, async () => {
|
||||||
|
const out = await through(LITERAL, cuts)
|
||||||
|
expect(out).not.toContain("Sorry")
|
||||||
|
const cs = contents(out)
|
||||||
|
expect(cs.map((c) => c.delta.reasoning_content ?? "").join("")).toBe(" node")
|
||||||
|
expect(cs.some((c) => typeof c.delta.content === "string" && c.delta.content)).toBe(false)
|
||||||
|
expect(cs.at(-1).finish_reason).toBe("content_filter")
|
||||||
|
expect(out.endsWith("data: [DONE]\n\n")).toBe(true)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
test("the filter's line with its newlines in chunks of their own is taken out", async () => {
|
||||||
|
const upstream = chunk({ reasoning_content: "hm" }) + chunk({ content: "\n" }) + chunk({ content: said }) + chunk({ content: "\n" }) + chunk({}, "content_filter", zero) + "data: [DONE]\n\n"
|
||||||
|
const out = await through(upstream)
|
||||||
|
expect(out).not.toContain("Sorry")
|
||||||
|
expect(contents(out).some((c) => typeof c.delta.content === "string" && c.delta.content)).toBe(false)
|
||||||
|
expect(contents(out).at(-1).finish_reason).toBe("content_filter")
|
||||||
|
})
|
||||||
|
|
||||||
|
test("the filter's line followed by more words goes through whole", async () => {
|
||||||
|
const upstream = chunk({ content: `\n${said}\n` }) + chunk({ content: "But here is the answer." }) + chunk({}, "content_filter") + "data: [DONE]\n\n"
|
||||||
|
expect(await through(upstream)).toBe(upstream)
|
||||||
|
})
|
||||||
|
|
||||||
|
test("a reply that opens with a newline and then answers goes through whole", async () => {
|
||||||
|
const upstream = chunk({ content: "\n" }) + chunk({ content: "Hello" }) + chunk({}, "stop") + "data: [DONE]\n\n"
|
||||||
|
expect(await through(upstream)).toBe(upstream)
|
||||||
|
})
|
||||||
|
|||||||
@@ -1605,10 +1605,14 @@ function renamed(res, names) {
|
|||||||
// no output tokens counted (itspig, plugins #540).
|
// no output tokens counted (itspig, plugins #540).
|
||||||
const FILTER_SAYS = ["Sorry, I can't respond to this question."]
|
const FILTER_SAYS = ["Sorry, I can't respond to this question."]
|
||||||
|
|
||||||
// filterSaid tells whether text said so far may still be FILTER_SAYS.
|
// filterSaid tells whether text said so far may still be FILTER_SAYS, with
|
||||||
|
// white space on either side: copilot.tencent.com sends it as
|
||||||
|
// "\nSorry, I can't respond to this question.\n" (itspig, plugins #540).
|
||||||
|
// Text that is only white space so far may still be it; text that goes on
|
||||||
|
// past it is not.
|
||||||
const filterSaid = (text) => {
|
const filterSaid = (text) => {
|
||||||
const t = text.replace(/’/g, "'").trimStart()
|
const t = text.replace(/’/g, "'").trim()
|
||||||
return t !== "" && FILTER_SAYS.some((s) => s.startsWith(t))
|
return FILTER_SAYS.some((s) => s.startsWith(t))
|
||||||
}
|
}
|
||||||
|
|
||||||
// unsaid is a streamed chat whose reply WorkBuddy's filter refused with its
|
// unsaid is a streamed chat whose reply WorkBuddy's filter refused with its
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@magpie-community/opencode-workbuddy-auth",
|
"name": "@magpie-community/opencode-workbuddy-auth",
|
||||||
"version": "0.2.4",
|
"version": "0.2.5",
|
||||||
"description": "OpenCode provider plugins for WorkBuddy's plans: WorkBuddy (CodeBuddy, copilot.tencent.com) and WorkBuddy AI (www.workbuddy.ai)",
|
"description": "OpenCode provider plugins for WorkBuddy's plans: WorkBuddy (CodeBuddy, copilot.tencent.com) and WorkBuddy AI (www.workbuddy.ai)",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "./index.mjs",
|
"main": "./index.mjs",
|
||||||
|
|||||||
Reference in New Issue
Block a user