SWE-2 names a call after its tool and turn ("Bash:0#a65b6a5e02194b87bbc796c4428c946d"), and the plugin passed that on as the call's id. Claude Code takes a tool_use id only of [A-Za-z0-9_-]: it dropped every such call and the turn failed with "The model's tool call could not be parsed (retry also failed)". Codex and pi take any id and were fine.
An id with any other character, or one that begins "dv_", now goes out as "dv_" and its base64url (stateless, so it holds across restarts and accounts); build() turns it back into Devin's own id on the assistant's call and on the tool result that answers it, so Devin still sees the id it gave. A safe id goes both ways as it came. magpie passes a chat tool_call id through unchanged to Anthropic's tool_use.id, Responses' call_id and Chat, so the one mapping covers all three.
tool-ids.test.mjs builds Devin's reply frame from the reporter's literal id: with the change taken out, both the whole and the streamed test fail (Received: "Bash:0#a65b6a5e02194b87bbc796c4428c946d" against /^[A-Za-z0-9_-]+$/); with it, the id out is safe and the call and its result reach Devin as "Bash:0#a65b…". HOME=$(mktemp -d) bun test packages/devin: 45 pass; the 4 CLI tests in identity.test.mjs time out at 30 s on this Mac with and without the change (a script just written under $TMPDIR doesn't start: exec of a fresh /bin/sh script hangs here), and pass in CI. bun scripts/check.mjs devin passes. Not tried against a real Devin account.
85 lines
3.3 KiB
JavaScript
85 lines
3.3 KiB
JavaScript
// Devin's SWE-2 names a call "Bash:0#a65b6a5e02194b87bbc796c4428c946d"
|
|
// (yetone/magpie#1304, StarMoonCity's capture). Claude Code takes a
|
|
// tool_use id only of [A-Za-z0-9_-] and dropped every such call ("The
|
|
// model's tool call could not be parsed"). The id goes out safe, and its
|
|
// result goes back to Devin under the id Devin gave.
|
|
import { afterEach, expect, test } from "bun:test"
|
|
import { _internal } from "./index.mjs"
|
|
|
|
const { PB, frame, fields, build, complete } = _internal
|
|
const real = globalThis.fetch
|
|
afterEach(() => (globalThis.fetch = real))
|
|
|
|
const RAW = "Bash:0#a65b6a5e02194b87bbc796c4428c946d" // the reporter's literal id
|
|
const ARGS = '{"command":"date","description":"Print the date"}'
|
|
const SAFE = /^[A-Za-z0-9_-]+$/
|
|
const enc = new TextEncoder()
|
|
const dec = new TextDecoder()
|
|
|
|
const reply = () => {
|
|
const call = new PB().str(1, RAW).str(2, "Bash").str(3, ARGS).done()
|
|
const msg = new PB().bytes(6, call).varint(5, 10).done()
|
|
const end = enc.encode("{}")
|
|
const tail = new Uint8Array(5 + end.length)
|
|
tail[0] = 2
|
|
new DataView(tail.buffer).setUint32(1, end.length)
|
|
tail.set(end, 5)
|
|
return new Response(new Blob([frame(msg), tail]))
|
|
}
|
|
|
|
const ask = async (stream) => {
|
|
globalThis.fetch = async () => reply()
|
|
const res = await complete(
|
|
{ key: "k", server: "https://devin.test", families: _internal.familiesOf(_internal.SNAPSHOT) },
|
|
{ model: "swe-2", stream, messages: [{ role: "user", content: "用 Bash 跑一下 date" }] },
|
|
)
|
|
return res.text()
|
|
}
|
|
|
|
const sentIDs = (chat) => {
|
|
const out = { calls: [], answers: [] }
|
|
for (const f of fields(build(chat, "swe-2-high", "k"))) {
|
|
if (f.num !== 3 || f.wire !== 2) continue
|
|
for (const g of fields(f.data)) {
|
|
if (g.num === 6) out.calls.push(dec.decode(fields(g.data).find((h) => h.num === 1).data))
|
|
if (g.num === 7) out.answers.push(dec.decode(g.data))
|
|
}
|
|
}
|
|
return out
|
|
}
|
|
|
|
const answered = (id) => ({
|
|
messages: [
|
|
{ role: "user", content: "用 Bash 跑一下 date" },
|
|
{ role: "assistant", content: null, tool_calls: [{ id, type: "function", function: { name: "Bash", arguments: ARGS } }] },
|
|
{ role: "tool", tool_call_id: id, content: "Thu Oct 8 10:00:00 CST 2026" },
|
|
],
|
|
})
|
|
|
|
for (const stream of [false, true])
|
|
test(`Devin's call id goes out of [A-Za-z0-9_-] only and comes back as Devin gave it (${stream ? "streamed" : "whole"})`, async () => {
|
|
const body = await ask(stream)
|
|
let id
|
|
if (stream) {
|
|
for (const line of body.split("\n"))
|
|
if (line.startsWith("data: {")) id ??= JSON.parse(line.slice(6)).choices?.[0]?.delta?.tool_calls?.[0]?.id
|
|
} else id = JSON.parse(body).choices[0].message.tool_calls[0].id
|
|
expect(id).toMatch(SAFE)
|
|
const sent = sentIDs(answered(id))
|
|
expect(sent.calls).toEqual([RAW])
|
|
expect(sent.answers).toEqual([RAW])
|
|
})
|
|
|
|
test("a safe id goes both ways as it came", () => {
|
|
for (const id of ["toolu_01AbC", "call_abc-123"]) {
|
|
expect(_internal.outID(id)).toBe(id)
|
|
expect(sentIDs(answered(id))).toEqual({ calls: [id], answers: [id] })
|
|
}
|
|
})
|
|
|
|
test("an id of the caller's own that begins dv_ goes both ways as it came", () => {
|
|
for (const id of ["dv_", "dv_abc", "dv_QmFzaDowI2E"]) expect(_internal.inID(_internal.outID(id))).toBe(id)
|
|
// not one outID makes: sent to Devin untouched
|
|
for (const id of ["dv_", "dv_abc"]) expect(sentIDs(answered(id))).toEqual({ calls: [id], answers: [id] })
|
|
})
|