devin 0.1.11: a turn's parallel tool calls split over two consecutive assistant messages keep their results (yetone/magpie#1275)

An agent can send one turn's tool calls in two assistant messages in a
row, answered together after. build() answered the first message's calls
at the second one: toolu_a went to Devin as "Tool use was interrupted and
did not produce a result." and its real result A! was dropped.
joinSplitCalls now joins an assistant message onto an assistant message
before it that made tool calls, as Anthropic reads consecutive assistant
messages and as magpie's built-in buildDevin does since 7067fce5. A call
of the split turn that really went unanswered is still answered for; two
text-only assistant messages stay two.

split-calls.test.mjs is #1275's request in Chat form: 3 of its 4 tests fail
on 0.1.10 and pass now. HOME=$(mktemp -d) bun test (43 pass, 0 fail) and
bun scripts/check.mjs pass. Not tried against a real Devin account.
This commit is contained in:
yetone
2026-10-08 16:54:48 +08:00
parent 78780b81be
commit 994d58077a
3 changed files with 88 additions and 2 deletions
+21 -1
View File
@@ -957,6 +957,26 @@ const NO_RESULT = "Tool use was interrupted and did not produce a result."
const textOf = (c) =>
typeof c === "string" ? c : Array.isArray(c) ? c.filter((p) => p?.type === "text").map((p) => p.text ?? "").join("") : ""
// joinSplitCalls joins an assistant message onto the assistant message
// before it when that one made tool calls: Anthropic takes consecutive
// assistant messages as one turn, and an agent can send a turn's parallel
// calls split over two of them, answered together after (yetone/magpie#1275).
// Answered at the second message, the first calls would be marked
// interrupted and their real results dropped. msgs is left as it is.
function joinSplitCalls(msgs) {
const out = []
for (const m of msgs) {
const prev = out.at(-1)
if (m?.role === "assistant" && prev?.role === "assistant" && prev.tool_calls?.length) {
const content = [textOf(prev.content), textOf(m.content)].filter(Boolean).join("\n\n")
out[out.length - 1] = { ...prev, content, tool_calls: [...prev.tool_calls, ...(m.tool_calls ?? [])] }
continue
}
out.push(m)
}
return out
}
// effortOf is the effort a request names, as magpie reads it.
function effortOf(s) {
const e = String(s ?? "").trim().toLowerCase()
@@ -1087,7 +1107,7 @@ function build(chat, uid, key) {
pending = []
}
const system = []
for (const m of chat.messages ?? []) {
for (const m of joinSplitCalls(chat.messages ?? [])) {
if (m.role === "system" || m.role === "developer") {
system.push(textOf(m.content))
continue
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-devin-auth",
"version": "0.1.10",
"version": "0.1.11",
"description": "Devin subscriptions (the devin CLI's account) in OpenCode and magpie",
"type": "module",
"main": "./index.mjs",
+66
View File
@@ -0,0 +1,66 @@
// One turn's parallel tool calls split over two consecutive assistant
// messages, answered together after (yetone/magpie#1275): both calls keep
// their real results, as magpie's built-in buildDevin does since 7067fce5
// (internal/gateway/split_calls_test.go).
import { expect, test } from "bun:test"
import { _internal } from "./index.mjs"
const NO_RESULT = "Tool use was interrupted and did not produce a result."
const dec = new TextDecoder()
const call = (id, path) => ({ id, type: "function", function: { name: "read", arguments: JSON.stringify({ path }) } })
const split = () => ({
messages: [
{ role: "user", content: "read a and b" },
{ role: "assistant", content: null, tool_calls: [call("toolu_a", "a")] },
{ role: "assistant", content: null, tool_calls: [call("toolu_b", "b")] },
{ role: "tool", tool_call_id: "toolu_a", content: "A!" },
{ role: "tool", tool_call_id: "toolu_b", content: "B!" },
],
})
// summary is each message sent, as magpie's devinSummary writes it: role,
// text, the calls it made and the call it answers.
const summary = (chat) =>
_internal
.fields(_internal.build(chat, "swe-2-high", "k"))
.filter((f) => f.num === 3 && f.wire === 2)
.map((f) => {
let role = 0, text = "", answers = ""
const calls = []
for (const g of _internal.fields(f.data)) {
if (g.num === 2) role = g.n
else if (g.num === 3) text = dec.decode(g.data)
else if (g.num === 6) calls.push(_internal.fields(g.data).slice(0, 2).map((h) => dec.decode(h.data)).join("/"))
else if (g.num === 7) answers = dec.decode(g.data)
}
return `${role}:${text}${calls.map((c) => " call " + c).join("")}${answers ? " for " + answers : ""}`
})
test("a split turn's calls are answered by their real results", () => {
const got = summary(split())
expect(got.join("\n")).not.toContain(NO_RESULT)
expect(got.slice(1)).toEqual(["2: call toolu_a/read call toolu_b/read", "4:A! for toolu_a", "4:B! for toolu_b"])
})
test("a call of a split turn that went unanswered is still answered for", () => {
const chat = split()
chat.messages.splice(3, 1)
expect(summary(chat).slice(1)).toEqual(["2: call toolu_a/read call toolu_b/read", "4:B! for toolu_b", `4:${NO_RESULT} for toolu_a`])
})
test("text the turn said after its call, in a message of its own, joins it", () => {
const chat = {
messages: [
{ role: "user", content: "read a" },
{ role: "assistant", content: null, tool_calls: [call("toolu_a", "a")] },
{ role: "assistant", content: "reading" },
{ role: "tool", tool_call_id: "toolu_a", content: "1" },
],
}
expect(summary(chat).slice(1)).toEqual(["2:reading call toolu_a/read", "4:1 for toolu_a"])
})
test("two assistant messages with no calls stay two", () => {
const chat = { messages: [{ role: "user", content: "hi" }, { role: "assistant", content: "one" }, { role: "assistant", content: "two" }] }
expect(summary(chat).slice(1, 3)).toEqual(["2:one", "2:two"])
})