Reported on X (@liuzhengdong99, magpie 0.1.4146): in DSH, Devin's Gemini 4 Hydrogen often fails with "an empty reply ... (502)" or hangs; SWE-2 works. Diffing the plugin's GetChatMessage against the official devin CLI's (captured through a proxy, same account, gemini-4-hydrogen-medium, a tool turn): Devin streams Hydrogen's thought signature (field 10, type "gemini" in 21) and no visible thinking. The CLI sends it back on the assistant prompt that carries the call: signature (12), signature_type "gemini" (18) and the model that wrote it (22). The plugin dropped Gemini signatures, on the chat wire and the Messages wire, so every later turn went back to Gemini without them. Google documents thought signatures as required for Gemini 3-class function calling. Neither a chat completion nor a Messages tool_use carries a signature, so the plugin keeps each Gemini reply's signature in memory by its call ids (or by its words, for a reply with no call), up to 4096, and puts it back on the matching assistant prompt with field 22. Other models are unchanged; an unknown call, or one after a restart, goes back unsigned as before. Run: - gemini-thought.test.mjs (7 tests, fixture = a real Hydrogen tool reply captured from the CLI, testdata/gemini-tool-reply.bin, no credentials): 7/7 on mica. Broken by hand: against origin/main's index.mjs the 5 signature tests fail (Received: undefined); the 2 "goes back unsigned" tests pass on both. - Whole plugins suite on mica, HOME=$(mktemp -d) bun test, as CI: 8796 pass, 0 fail (8816 tests, 615 files); bun scripts/check.mjs ok. packages/devin alone: 220/220. - Real account (sandbox HOME, plugin through a chat-completions shim): a 4-step tool loop on the new code signed every assistant prompt (1/1 .. 4/4), all 200, right answer. dsh headless (sandbox HOME) on Hydrogen through the shim: a JSON-parser coding task on old and new code, both finished with tests passing, every request 200. Not reproduced: on the old code, 127 Hydrogen requests through dsh (up to 170 messages, a 434KB request) all answered 200, with no empty reply. So this restores what the official client sends; it is not proven to be the reporter's cause. The "hang" is likely Hydrogen's hidden thinking: the plugin waits for the first real content and Hydrogen streams no thinking text. No retry was added.
132 lines
6.7 KiB
JavaScript
132 lines
6.7 KiB
JavaScript
// A Gemini reply goes back to Devin with its thought signature, as the
|
|
// devin CLI sends it: a reply from gemini-4-hydrogen carries one in
|
|
// delta_signature (10), typed "gemini" (21), and the CLI's next request
|
|
// has it on the prompt with the reply's call, in signature (12),
|
|
// signature_type (18) and the model that wrote it (22). Without it,
|
|
// Devin's Gemini models deep in a dsh tool loop answered with usage and
|
|
// nothing else (X, @liuzhengdong99, magpie 0.1.4146).
|
|
// testdata/gemini-tool-reply.bin is a real GetChatMessage reply from
|
|
// gemini-4-hydrogen-medium to the devin CLI (a call to exec), captured
|
|
// through WINDSURF_API_SERVER_URL; it has the bot id, response id and
|
|
// usage, no credentials.
|
|
import { afterEach, expect, test } from "bun:test"
|
|
import { readFile } from "node:fs/promises"
|
|
import { _internal } from "./index.mjs"
|
|
|
|
const { PB, frame, fields, build, buildMessages, complete, completeMessages, familiesOf, SNAPSHOT } = _internal
|
|
const dec = new TextDecoder()
|
|
const real = globalThis.fetch
|
|
afterEach(() => {
|
|
globalThis.fetch = real
|
|
_internal.forgetThoughts?.()
|
|
})
|
|
|
|
const captured = await readFile(new URL("./testdata/gemini-tool-reply.bin", import.meta.url))
|
|
const SIG = "AY89a1+u1EAPOiO7CmhB"
|
|
const CALL = "call_11646388125050983982"
|
|
const UID = "gemini-4-hydrogen-medium"
|
|
// Devin's list for the account that captured it has Gemini 4 Hydrogen,
|
|
// which the snapshot predates
|
|
const hydrogen = { uid: "gemini-4-hydrogen", label: "Gemini 4 Hydrogen", aliases: [], models: ["low", "medium", "high"].map((e) => ({ id: "gemini-4-hydrogen-" + e, name: "Gemini 4 Hydrogen " + e, context: 1048576, output: 65535 })) }
|
|
const families = [...familiesOf(SNAPSHOT), hydrogen]
|
|
const ctx = { key: "k", server: "https://devin.test", families }
|
|
|
|
// prompts is each ChatMessagePrompt a request sends, with the thought it
|
|
// carries back
|
|
const prompts = (body) =>
|
|
fields(body)
|
|
.filter((f) => f.num === 3 && f.wire === 2)
|
|
.map((f) => {
|
|
const p = { role: 0, calls: [], thinking: null, signature: null, type: null, model: null }
|
|
for (const g of fields(f.data)) {
|
|
if (g.num === 2) p.role = g.n
|
|
else if (g.num === 6) p.calls.push(dec.decode(fields(g.data).find((h) => h.num === 1).data))
|
|
else if (g.num === 11) p.thinking = dec.decode(g.data)
|
|
else if (g.num === 12) p.signature = dec.decode(g.data)
|
|
else if (g.num === 18) p.type = dec.decode(g.data)
|
|
else if (g.num === 22) p.model = dec.decode(g.data)
|
|
}
|
|
return p
|
|
})
|
|
|
|
// replyAndNext sends one request to the captured reply through the given
|
|
// wire, reads the reply whole, and builds the next request with the
|
|
// reply's call answered, to the model next
|
|
async function chatAndNext(stream, next = UID) {
|
|
globalThis.fetch = async () => new Response(captured)
|
|
const res = await complete(ctx, { model: "gemini-4-hydrogen", reasoning_effort: "medium", stream, messages: [{ role: "user", content: "cat calc.py" }] })
|
|
expect(res.status).toBe(200)
|
|
let call
|
|
if (stream) {
|
|
for (const l of (await res.text()).split("\n")) {
|
|
const tc = l.startsWith("data: {") && JSON.parse(l.slice(6)).choices?.[0]?.delta?.tool_calls?.[0]
|
|
if (tc?.id) call = { id: tc.id, type: "function", function: { name: tc.function.name, arguments: '{"command":"cat calc.py"}' } }
|
|
}
|
|
} else call = (await res.json()).choices[0].message.tool_calls[0]
|
|
expect(call.id).toBe(CALL)
|
|
const messages = [
|
|
{ role: "user", content: "cat calc.py" },
|
|
{ role: "assistant", content: "", tool_calls: [call] },
|
|
{ role: "tool", tool_call_id: call.id, content: "def add(a,b): return a+b" },
|
|
]
|
|
return prompts(build({ model: "x", messages }, next, "k"))
|
|
}
|
|
|
|
for (const stream of [false, true])
|
|
test(`a chat completion's Gemini call goes back with its signature, as the CLI sends it (stream ${stream})`, async () => {
|
|
const ps = await chatAndNext(stream)
|
|
const a = ps.find((p) => p.calls.length)
|
|
expect(a.calls).toEqual([CALL])
|
|
expect(a.signature?.startsWith(SIG)).toBe(true)
|
|
expect(a.type).toBe("gemini")
|
|
expect(a.model).toBe(UID)
|
|
// the prompts around it carry none
|
|
expect(ps.filter((p) => p.signature).length).toBe(1)
|
|
})
|
|
|
|
test("a Gemini signature goes back to Gemini only", async () => {
|
|
for (const next of ["swe-2-medium", "claude-opus-4-6"]) {
|
|
const ps = await chatAndNext(false, next)
|
|
expect(ps.some((p) => p.signature || p.type || p.model)).toBe(false)
|
|
}
|
|
})
|
|
|
|
test("a call the plugin never saw goes back as before, unsigned", () => {
|
|
const messages = [
|
|
{ role: "user", content: "hi" },
|
|
{ role: "assistant", content: "", tool_calls: [{ id: "call_1", type: "function", function: { name: "exec", arguments: "{}" } }] },
|
|
{ role: "tool", tool_call_id: "call_1", content: "ok" },
|
|
]
|
|
expect(prompts(build({ model: "x", messages }, UID, "k")).some((p) => p.signature)).toBe(false)
|
|
})
|
|
|
|
for (const stream of [false, true])
|
|
test(`a Messages Gemini tool_use goes back with its signature (stream ${stream})`, async () => {
|
|
globalThis.fetch = async () => new Response(captured)
|
|
const res = await completeMessages(ctx, { model: "gemini-4-hydrogen", max_tokens: 64, stream, output_config: { effort: "medium" }, messages: [{ role: "user", content: "cat calc.py" }] })
|
|
expect(res.status).toBe(200)
|
|
let id
|
|
if (stream) id = /"id":"(call_[0-9]+)"/.exec(await res.text())[1]
|
|
else id = (await res.json()).content.find((b) => b.type === "tool_use").id
|
|
const messages = [
|
|
{ role: "user", content: "cat calc.py" },
|
|
{ role: "assistant", content: [{ type: "tool_use", id, name: "exec", input: { command: "cat calc.py" } }] },
|
|
{ role: "user", content: [{ type: "tool_result", tool_use_id: id, content: "def add(a,b): return a+b" }] },
|
|
]
|
|
const a = prompts(buildMessages({ model: "x", messages }, UID, "k")).find((p) => p.calls.length)
|
|
expect(a.signature?.startsWith(SIG)).toBe(true)
|
|
expect(a.type).toBe("gemini")
|
|
expect(a.model).toBe(UID)
|
|
})
|
|
|
|
test("a Gemini reply with only words goes back signed by its words", async () => {
|
|
const usage = new PB().varint(2, 10).varint(3, 5).done()
|
|
globalThis.fetch = async () =>
|
|
new Response(new Blob([frame(new PB().str(3, "Hi there,").done()), frame(new PB().str(3, " friend!").str(10, "SIGTEXT").str(21, "gemini").done()), frame(new PB().varint(5, 1).bytes(7, usage).done())]))
|
|
const j = await (await complete(ctx, { model: "gemini-4-hydrogen", reasoning_effort: "medium", messages: [{ role: "user", content: "hi" }] })).json()
|
|
expect(j.choices[0].message.content).toBe("Hi there, friend!")
|
|
const messages = [{ role: "user", content: "hi" }, j.choices[0].message, { role: "user", content: "again" }]
|
|
const a = prompts(build({ model: "x", messages }, UID, "k")).find((p) => p.role === 2)
|
|
expect([a.signature, a.type, a.model]).toEqual(["SIGTEXT", "gemini", UID])
|
|
})
|