devin: gzip a Connect request frame past 8 KiB, as the devin CLI does (#275, BGMYE)

Devin's nginx turns a GetChatMessage body past 10 MiB away with 413, so a
long turn failed. A Connect frame's message is now gzipped (flag 1,
Connect-Content-Encoding: gzip) past 8 KiB, as the devin CLI sends it.

Review commit da6c664 on top of 05d8a65, from the official client: the
devin CLI 3000.11.92, run in a sandbox through a logging proxy, sends 8,083
bytes plain and 8,333 gzipped, names the encoding only on a gzipped frame,
and sends no Connect-Accept-Encoding. The PR's 64 KiB threshold, header on
every request and Connect-Accept-Encoding were changed to match.

Run at da6c664fa917ee995a10a457a10fb94ad743e8ab: bun test in packages/devin,
98 pass 0 fail; bun scripts/check.mjs devin ok. The new tests are red on
main f906a22 (3 fail) and on 05d8a65 (3 fail). Live, owner's account,
swe-1-6: a 12 MiB plain frame gets 413, gzipped it passes nginx (the model
then refuses the size); complete() with a short and a >64 KiB message both
200.
This commit is contained in:
Jinx
2026-10-21 00:21:16 +08:00
committed by GitHub
parent 9c34e006c5
commit 4fd68ba046
2 changed files with 77 additions and 7 deletions
+60
View File
@@ -0,0 +1,60 @@
// Devin's nginx turns away a request body past 10 MiB on the wire (413
// Request Entity Too Large), so a long turn goes gzipped, a short one as it
// was, at the size the devin CLI gzips from (8,083 bytes plain, 8,333
// gzipped, captured from 3000.11.92).
import { expect, test } from "bun:test"
import { gunzipSync } from "node:zlib"
import { _internal } from "./index.mjs"
const unframe = (b) => ({ flags: b[0], data: b.subarray(5, 5 + new DataView(b.buffer, b.byteOffset).getUint32(1)) })
test("a short message goes as it is", () => {
const msg = new TextEncoder().encode("hi")
const { flags, data } = unframe(_internal.frame(msg))
expect(flags).toBe(0)
expect([...data]).toEqual([...msg])
})
test("the CLI's sizes: 8,083 bytes go as they are, 8,333 gzipped", () => {
expect(unframe(_internal.frame(new Uint8Array(8083))).flags).toBe(0)
expect(unframe(_internal.frame(new Uint8Array(8333))).flags).toBe(1)
})
test("a long message goes gzipped, and inflates to itself", () => {
const msg = new TextEncoder().encode("x".repeat(12 << 20))
const out = _internal.frame(msg)
const { flags, data } = unframe(out)
expect(flags).toBe(1)
expect(out.length).toBeLessThan(1 << 20)
expect(Buffer.from(gunzipSync(data)).equals(Buffer.from(msg))).toBe(true)
})
const sent = async (content) => {
let seen
const was = globalThis.fetch
globalThis.fetch = async (url, init) => {
seen = init
return new Response("{}", { status: 400 })
}
try {
await _internal.complete({ key: "k", server: "https://devin.test", families: [] }, { model: "swe-2", messages: [{ role: "user", content }] })
} finally {
globalThis.fetch = was
}
return seen
}
test("a long chat request is gzipped and says so", async () => {
const seen = await sent("y".repeat(200 << 10))
expect(seen.headers["Connect-Content-Encoding"]).toBe("gzip")
expect(unframe(seen.body).flags).toBe(1)
// the CLI asks for no encoding of the reply; Devin gzips it anyway
expect(seen.headers["Connect-Accept-Encoding"]).toBeUndefined()
})
test("a short chat request names no encoding, as the CLI's doesn't", async () => {
const seen = await sent("hi")
expect(unframe(seen.body).flags).toBe(0)
expect(seen.headers["Connect-Content-Encoding"]).toBeUndefined()
expect(seen.headers["Connect-Accept-Encoding"]).toBeUndefined()
})
+17 -7
View File
@@ -8,7 +8,7 @@
import { Buffer } from "node:buffer"
import { createHash, randomBytes, randomUUID } from "node:crypto"
import { createServer, STATUS_CODES } from "node:http"
import { gunzipSync } from "node:zlib"
import { gunzipSync, gzipSync } from "node:zlib"
import { spawn } from "node:child_process"
import { existsSync, readFileSync, realpathSync, statSync } from "node:fs"
import { mkdir, readFile, writeFile } from "node:fs/promises"
@@ -1065,11 +1065,20 @@ function fields(b) {
return out
}
// frame wraps a message as the one frame of a Connect stream.
// frame wraps a message as the one frame of a Connect stream. A message
// past GZIP_AT goes gzipped (flag 1, with Connect-Content-Encoding: gzip),
// as the devin CLI sends it: Devin's nginx turns away a body past 10 MiB on
// the wire (413). The CLI (3000.11.92) gzips a GetChatMessage of 8,333
// bytes and sends one of 8,083 as it is, and names the encoding only on a
// gzipped request; it sends no Connect-Accept-Encoding.
const GZIP_AT = 8 << 10
function frame(msg) {
const out = new Uint8Array(5 + msg.length)
new DataView(out.buffer).setUint32(1, msg.length)
out.set(msg, 5)
const zip = msg.length > GZIP_AT
const body = zip ? gzipSync(msg) : msg
const out = new Uint8Array(5 + body.length)
out[0] = zip ? 1 : 0
new DataView(out.buffer).setUint32(1, body.length)
out.set(body, 5)
return out
}
@@ -1628,12 +1637,13 @@ const errorResponse = ({ status, message }) =>
// 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))
const body = frame(build(chat, uid, key))
let res
try {
res = await fetch(server + CHAT_RPC, {
method: "POST",
headers: { "Content-Type": "application/connect+proto", "Connect-Protocol-Version": "1", Authorization: "Basic " + key },
body: frame(build(chat, uid, key)),
headers: { "Content-Type": "application/connect+proto", "Connect-Protocol-Version": "1", ...(body[0] & 1 ? { "Connect-Content-Encoding": "gzip" } : {}), Authorization: "Basic " + key },
body,
signal,
})
} catch (e) {