devin 0.1.23: a reply with only usage or metadata is refused before the stream starts, not passed on as an empty success (#297)
By mameikagou. Reviewed at 0966b4b (comment on #297); squashed onto
origin/main dc59000 with the version bump.
Run at this tree: HOME=$(mktemp -d) bun test: 2083 pass, 0 fail;
bun scripts/check.mjs ok. Earlier, at 0966b4b with main's
packages/devin/index.mjs put back, the three new or changed tests
(empty-reply, error-after-metadata, metadata-only) were red.
Not tried: a real Devin account answering with an empty reply.
Co-authored-by: mameikagou <mameikagou@users.noreply.github.com>
This commit is contained in:
@@ -60,6 +60,9 @@ The plugin's `fetch` handles this:
|
||||
not: text, reasoning, tool calls and usage.
|
||||
- Failures keep their statuses: a refused token is a 401, a usage limit a
|
||||
429, a prompt too long for the model a 400.
|
||||
- A reply with only metadata and usage is a 502, even when output tokens
|
||||
were counted. The plugin waits for actual content before opening a
|
||||
successful stream, so the gateway can try another channel.
|
||||
|
||||
## Models
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import { expect, test } from "bun:test"
|
||||
import { readFile } from "node:fs/promises"
|
||||
import { _internal } from "./index.mjs"
|
||||
|
||||
const captured = new URL("./testdata/empty-reply.bin", import.meta.url)
|
||||
|
||||
test("Devin's usage-only reply fails before a successful stream is opened", async () => {
|
||||
const raw = await readFile(captured)
|
||||
const real = globalThis.fetch
|
||||
globalThis.fetch = async () => new Response(raw)
|
||||
try {
|
||||
for (const stream of [true, false]) {
|
||||
const response = await _internal.complete(
|
||||
{ key: "test", server: "https://devin.test", families: _internal.familiesOf(_internal.SNAPSHOT) },
|
||||
{ model: "gemini-4-argon", stream, messages: [{ role: "user", content: "?" }] },
|
||||
)
|
||||
expect(response.status).toBe(502)
|
||||
expect((await response.json()).error.message).toContain("empty reply")
|
||||
expect(response.headers.get("X-Magpie-Sign-In")).toBe("kept")
|
||||
}
|
||||
} finally {
|
||||
globalThis.fetch = real
|
||||
}
|
||||
})
|
||||
@@ -84,19 +84,19 @@ test("an empty reply is the built-in's 502 of a broken-off one", async () => {
|
||||
expect(errOf(r)).toBe("the reply broke off: EOF")
|
||||
})
|
||||
|
||||
test("an error after a frame with nothing in it is streamed in the built-in's words", async () => {
|
||||
test("an error after metadata fails before the stream opens", async () => {
|
||||
const empty = new Uint8Array(5) // a message frame with no fields
|
||||
const r = await ask(() => new Response(join(empty, end({ error: { code: "resource_exhausted", message: "rate limit" } }))), true)
|
||||
expect(r.status).toBe(200)
|
||||
const ev = r.body.split("\n\n").map((l) => l.replace(/^data: /, "")).find((l) => l.includes('"error"'))
|
||||
expect(JSON.parse(ev).error.message).toBe("usage limit reached: rate limit")
|
||||
expect(r.status).toBe(429)
|
||||
expect(errOf(r)).toBe("usage limit reached: rate limit")
|
||||
})
|
||||
|
||||
// a success cleared no mark the built-in's account could have had
|
||||
test("an answer says the account is kept, streamed or not", async () => {
|
||||
test("a metadata-only answer fails and keeps the account signed in", async () => {
|
||||
for (const stream of [false, true]) {
|
||||
const r = await ask(() => new Response(join(new Uint8Array(5), end({}))), stream)
|
||||
expect(r.status).toBe(200)
|
||||
expect(r.status).toBe(502)
|
||||
expect(errOf(r)).toContain("empty reply")
|
||||
expect(r.signIn).toBe("kept")
|
||||
}
|
||||
})
|
||||
|
||||
+18
-11
@@ -1636,6 +1636,10 @@ async function* events(it) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!said && tools < 0) {
|
||||
yield { error: { status: 502, message: "an empty reply (Devin returned no text, reasoning or tool call)" } }
|
||||
return
|
||||
}
|
||||
if (!usage.output) usage.output = Math.floor((said + 3) / 4)
|
||||
const prompt = usage.input + usage.cacheRead + usage.cacheWrite
|
||||
yield {
|
||||
@@ -1659,6 +1663,11 @@ const errorResponse = ({ status, message }) =>
|
||||
headers: { "Content-Type": "application/json", "X-Magpie-Sign-In": "kept" },
|
||||
})
|
||||
|
||||
async function* prepend(first, rest) {
|
||||
yield first
|
||||
yield* rest
|
||||
}
|
||||
|
||||
// complete answers a chat completion through GetChatMessage.
|
||||
async function complete({ key, server, families }, chat, signal) {
|
||||
const uid = variantFor(families, chat.model, effortOf(chat.reasoning_effort))
|
||||
@@ -1692,17 +1701,15 @@ async function complete({ key, server, families }, chat, signal) {
|
||||
const e = failure(200, dec.decode(first.value.data))
|
||||
return errorResponse(e.status < 300 ? { status: 502, message: "an empty reply" } : e)
|
||||
}
|
||||
let replay = first
|
||||
const it = events({
|
||||
next: () => {
|
||||
if (replay) {
|
||||
const r = replay
|
||||
replay = null
|
||||
return Promise.resolve(r)
|
||||
}
|
||||
return fr.next()
|
||||
},
|
||||
})
|
||||
// 先等到实际内容或错误,才能让网关在空回复时切换渠道。
|
||||
const source = events(prepend(first.value, fr))
|
||||
const head = await source.next()
|
||||
if (head.done) return errorResponse({ status: 502, message: "an empty reply" })
|
||||
if (head.value.error) {
|
||||
await fr.return?.()
|
||||
return errorResponse(head.value.error)
|
||||
}
|
||||
const it = prepend(head.value, source)
|
||||
const id = "chatcmpl-" + randomBytes(12).toString("hex")
|
||||
const created = Math.floor(Date.now() / 1000)
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@magpie-community/opencode-devin-auth",
|
||||
"version": "0.1.22",
|
||||
"version": "0.1.23",
|
||||
"description": "Devin subscriptions (the devin CLI's account) in OpenCode and magpie",
|
||||
"type": "module",
|
||||
"main": "./index.mjs",
|
||||
|
||||
BIN
Binary file not shown.
Reference in New Issue
Block a user