Files
plugins/packages/devin/split-calls.test.mjs
yetone 994d58077a 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.
2026-10-08 16:54:48 +08:00

67 lines
2.9 KiB
JavaScript

// 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"])
})