From 09053e36d343863790900f310f88e131fea0f6c8 Mon Sep 17 00:00:00 2001 From: yetone Date: Thu, 1 Oct 2026 20:34:49 +0800 Subject: [PATCH] =?UTF-8?q?devin=200.1.6:=20an=20assistant=20reply=20goes?= =?UTF-8?q?=20to=20Devin=20with=20every=20tool=20call=20it=20made=20(#416?= =?UTF-8?q?=20on=20yetone/magpie:=20swe-2=20always=20answered=20"capacity?= =?UTF-8?q?=20issues"=20on=20the=20plugin,=20never=20on=20the=20built-in)?= =?UTF-8?q?=20=E2=80=94=20build()=20let=20the=20pending=20list=20share=20t?= =?UTF-8?q?he=20reply's=20own=20calls=20array,=20so=20answering=20a=20call?= =?UTF-8?q?=20took=20it=20off=20the=20reply=20too,=20and=20Devin=20got=20t?= =?UTF-8?q?ool=20results=20with=20no=20call=20that=20asked=20for=20them=20?= =?UTF-8?q?from=20the=20first=20tool=20round=20on.=20pending=20is=20now=20?= =?UTF-8?q?a=20copy,=20as=20the=20built-in's=20buildDevin=20keeps=20it;=20?= =?UTF-8?q?with=20tool=20history=20the=20request=20decodes=20the=20same=20?= =?UTF-8?q?as=20the=20built-in's.=20request.test.mjs=20fails=20against=200?= =?UTF-8?q?.1.5.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/devin/index.mjs | 4 ++- packages/devin/package.json | 2 +- packages/devin/request.test.mjs | 53 +++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 packages/devin/request.test.mjs diff --git a/packages/devin/index.mjs b/packages/devin/index.mjs index 63b75b3..e54ab0b 100644 --- a/packages/devin/index.mjs +++ b/packages/devin/index.mjs @@ -814,7 +814,9 @@ function build(chat, uid, key) { if (!text && !calls.length) continue // a turn that only thought, or failed answer() msgs.push({ role: ASSISTANT, text, calls }) - pending = calls + // a copy: answering a call takes it off pending, never off the + // reply that made it, which goes to Devin with every call it made + pending = [...calls] continue } if (m.role === "tool") { diff --git a/packages/devin/package.json b/packages/devin/package.json index 0c13a92..951897f 100644 --- a/packages/devin/package.json +++ b/packages/devin/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-devin-auth", - "version": "0.1.5", + "version": "0.1.6", "description": "Devin subscriptions (the devin CLI's account) in OpenCode and magpie", "type": "module", "main": "./index.mjs", diff --git a/packages/devin/request.test.mjs b/packages/devin/request.test.mjs new file mode 100644 index 0000000..81c64d4 --- /dev/null +++ b/packages/devin/request.test.mjs @@ -0,0 +1,53 @@ +// The conversation goes to Devin as magpie's built-in Devin +// (internal/gateway/devin.go, buildDevin) sent it: a reply keeps the tool +// calls it made after they are answered (magpie#416: they were dropped, and +// Devin was sent answers to calls no reply had made). +import { expect, test } from "bun:test" +import { _internal } from "./index.mjs" + +const dec = new TextDecoder() + +// msgs is each message sent: its role, text, the calls it made (id/name +// args) and the call it answers. +const msgs = (b) => + _internal + .fields(b) + .filter((f) => f.num === 3 && f.wire === 2) + .map((f) => { + const m = { role: 0, text: "", calls: [], answers: "" } + for (const g of _internal.fields(f.data)) { + if (g.num === 2) m.role = g.n + else if (g.num === 3) m.text = dec.decode(g.data) + else if (g.num === 6) m.calls.push(_internal.fields(g.data).map((h) => dec.decode(h.data)).join(" ")) + else if (g.num === 7) m.answers = dec.decode(g.data) + } + return m + }) + +test("a reply keeps the tool calls it made once they are answered", () => { + const call = (id, name, args) => ({ id, type: "function", function: { name, arguments: args } }) + const chat = { + messages: [ + { role: "user", content: "hi" }, + { role: "assistant", content: "let me look", tool_calls: [call("call_a", "read", '{"path":"a"}'), call("call_b", "bash", '{"cmd":"ls"}')] }, + { role: "tool", tool_call_id: "call_a", content: "A" }, + { role: "tool", tool_call_id: "call_b", content: "file1" }, + { role: "assistant", content: null, tool_calls: [call("call_c", "read", "{}")] }, + { role: "tool", tool_call_id: "call_c", content: "C" }, + { role: "assistant", content: "", tool_calls: [call("call_d", "read", "{}")] }, + ], + } + const got = msgs(_internal.build(chat, "swe-2-high", "k")) + expect(got.map((m) => [m.role, m.calls, m.answers])).toEqual([ + [1, [], ""], + [2, ['call_a read {"path":"a"}', 'call_b bash {"cmd":"ls"}'], ""], + [4, [], "call_a"], + [4, [], "call_b"], + [2, ["call_c read {}"], ""], + [4, [], "call_c"], + // one never answered keeps its call, and is answered for it + [2, ["call_d read {}"], ""], + [4, [], "call_d"], + ]) + expect(got[7].text).toBe("Tool use was interrupted and did not produce a result.") +})