qoder 0.2.65: two tool calls at one index with their own ids are two (#930)
Qoder Ultimate sent two native tool calls at tool_calls[].index 0, each
with its own id and name. events() kept one call per upstream index, so
the second call's arguments were sent as more of the first:
{"key":"A"}{"key":"B"}, which the client refused as unparseable JSON.
A fragment with a non-empty id that differs from the open call's id at
that index now starts a new call with an output index of its own. A
fragment with no id, or the open call's id, still goes on with the open
call (OpenAI's argument fragments, and relays that repeat the id). A call
pushed aside before it got a name still counts as nameless (#579).
After two ids at one index, id-less fragments go to the newer call; the
report suggested failing there instead, but OpenAI streams each call's
fragments right after its start, so the newest is the one open.
Siblings with the same index-keyed fold, fixed the same way:
- zed 0.1.19: chatWhole (a streamed chat reply folded for stream:false).
- codearts 0.3.7: completionFromChunks.
- zen-free 0.1.27: stream.mjs chatAccumulator, and tool-response.mjs's
chat buffer, which gives each call its own index when two collided.
- page-chat 0.1.13: lib/server.mjs folds through toolCallFolder.
Looked at and left: codearts' stream name restorer and kimi-desktop's
Agent hold pass fragments through unchanged and join no arguments;
zed's streaming path passes Zed's chunks through, and magpie's gateway
already starts a new call on a new id (internal/gateway/chat.go).
Run (WSL magpie-desktop, bun 1.4.2, node 22):
- pedh's repro.mjs with his fixture: [0,0] gave one tool event plus an
args event on 0.2.64; now two tool events (index 0 and 1), each with
valid JSON. [0,1] unchanged.
- HOME=$(mktemp -d) bun test packages/qoder packages/zed
packages/codearts packages/zen-free packages/chat: 987 pass, 0 fail,
1 skip (the epub reader's, as before). bun scripts/check.mjs: every
package and registry.json ok.
Broken by hand:
- qoder back to index-only: 3 of the new tests fail (two ids, id-less
after a second id, streaming adapter).
- qoder starting a call on any fragment without the open id: 8 fail,
the id-less continuation test among them.
- qoder treating any id as new: the repeated-id test fails.
- zed, codearts, zen-free (both) on main's code and chat keyed by index
only: each new collision test fails (5 of 5).
Not tried: a real Qoder account (no Qoder Ultimate here), real Zed,
CodeArts or OpenCode Zen replies with a collision, and the chat page
in a browser.
Reported-by: pedh <pedh@users.noreply.github.com>
This commit is contained in:
@@ -1427,6 +1427,7 @@ function completionFromChunks(events) {
|
||||
const content = []
|
||||
const reasoning = []
|
||||
const toolCalls = []
|
||||
const open = new Map() // upstream index -> the call being written there
|
||||
let finish = null
|
||||
let usage = null
|
||||
let model = first.model
|
||||
@@ -1440,7 +1441,17 @@ function completionFromChunks(events) {
|
||||
if (typeof delta.content === "string") content.push(delta.content)
|
||||
if (typeof delta.reasoning_content === "string") reasoning.push(delta.reasoning_content)
|
||||
for (const call of Array.isArray(delta.tool_calls) ? delta.tool_calls : []) {
|
||||
const slot = (toolCalls[num(call.index)] ??= { id: "", type: "function", function: { name: "", arguments: "" } })
|
||||
// a new id at an index in use is a new call, not more of the open
|
||||
// one: two calls at one index ran together as {"a"}{"b"}
|
||||
// (plugins#930). No id, or the same one, goes on with it.
|
||||
let slot = open.get(num(call.index))
|
||||
const id = typeof call.id === "string" ? call.id : ""
|
||||
if (!slot || (id && slot.id && id !== slot.id)) {
|
||||
slot = { id: "", type: "function", function: { name: "", arguments: "" } }
|
||||
if (toolCalls[num(call.index)]) toolCalls.push(slot)
|
||||
else toolCalls[num(call.index)] = slot
|
||||
open.set(num(call.index), slot)
|
||||
}
|
||||
if (typeof call.id === "string" && call.id) slot.id = call.id
|
||||
if (typeof call.type === "string" && call.type) slot.type = call.type
|
||||
if (typeof call.function?.name === "string") slot.function.name += call.function.name
|
||||
|
||||
@@ -3874,3 +3874,23 @@ test("a removed OfficeAce record is not written back when no restart separates t
|
||||
await ca2.auth.refresh(store.get(keyOf("codearts")))
|
||||
assert.equal(store.has(keyOf("officeace")), false, "a single removed record must stay removed without a restart")
|
||||
})
|
||||
|
||||
// plugins#930: a streamed reply folded into one for a client that asked for
|
||||
// it whole. Two calls with their own ids at one index are two calls, not
|
||||
// one with {"a"}{"b"} arguments; fragments with no id, or the same id, go on
|
||||
// with the open call.
|
||||
test("folding a stream keeps two ids at one index as two calls", () => {
|
||||
const ev = (call) => ({ id: "c1", model: "GLM-5.2", choices: [{ index: 0, delta: { tool_calls: [call] }, finish_reason: null }] })
|
||||
const A = { index: 0, id: "call_fixture_A", type: "function", function: { name: "fixture_alpha", arguments: '{"key":"A"}' } }
|
||||
const B = (index) => ({ index, id: "call_fixture_B", type: "function", function: { name: "fixture_beta", arguments: '{"key":"B"}' } })
|
||||
const fold = (calls) => x.completionFromChunks([...calls.map(ev), { choices: [{ index: 0, delta: {}, finish_reason: "tool_calls" }] }])
|
||||
.choices[0].message.tool_calls.map((c) => [c.id, c.function.name, c.function.arguments])
|
||||
const both = [["call_fixture_A", "fixture_alpha", '{"key":"A"}'], ["call_fixture_B", "fixture_beta", '{"key":"B"}']]
|
||||
assert.deepEqual(fold([A, B(0)]), both)
|
||||
assert.deepEqual(fold([A, B(1)]), both)
|
||||
assert.deepEqual(fold([
|
||||
{ index: 0, id: "call_fixture_A", type: "function", function: { name: "fixture_alpha", arguments: '{"ke' } },
|
||||
{ index: 0, function: { arguments: 'y":' } },
|
||||
{ index: 0, id: "call_fixture_A", function: { arguments: '"A"}' } },
|
||||
]), [["call_fixture_A", "fixture_alpha", '{"key":"A"}']])
|
||||
})
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@magpie-community/opencode-codearts-auth",
|
||||
"version": "0.3.6",
|
||||
"version": "0.3.7",
|
||||
"description": "Huawei Cloud in OpenCode and magpie: CodeArts (码道) and OfficeAce (AgentArts), each from its own Huawei Cloud OAuth sign-in — models, credit rates, credit usage and the daily check-in (unofficial)",
|
||||
"type": "module",
|
||||
"main": "./opencode.mjs",
|
||||
|
||||
Reference in New Issue
Block a user