troilus1011 on X: WorkBuddy's DeepSeek in OpenCode through magpie thought at low and high, never at the default. OpenCode's default variant names no reasoning_effort, and WorkBuddy doesn't think without one: measured on www.workbuddy.ai with 0.1.42, deepseek-v4.1-flash gave 0 reasoning tokens with no effort (2 of 2), 0 at none, 16/37 at low, 34/56 at high. WorkBuddy's own client (CLI 2.165.0 in WorkBuddy 5.9.3, configureThinkingSettings) sends the session's effort, else the reasoningEffort setting, else the model's reasoning.defaultEffort from /v3/config, which is "high" for this model on both builds. A chat that names no effort now gets the model's own defaultEffort when its listed levels hold it, read from the same cached /v3/config list (one read per minute; a failed read leaves the chat as it came and is not retried on every chat). An effort the client names, none included, is untouched and the list isn't read for it. Models with no reasoning config get nothing. runmiNeverstop on X: 2.89 GB up to copilot.tencent.com through magpie. WorkBuddy's client gzips a model request's body (GzipRequestProcessor, on with productFeatures.RequestBodyGzip, true in both builds' product.json and not turned off by the remote config); the plugin sent it as plain JSON. Agent chat JSON (the whole history each turn, tool schemas) compresses several-fold, so the upload was several times what the official client sends for the same turns. A chat-completions body now goes gzipped with Content-Encoding: gzip on both builds; unanswered() weighs the gzipped size against the front door's 2 MiB. Claude's Messages route goes as it came (not tried gzipped live). Run (on mote, HOME=$(mktemp -d) bun test in packages/workbuddy): 197 pass, 0 fail. bun scripts/check.mjs: exit 0. Fakes that parse the sent body gunzip it (testdata/unz.mjs); reset.test.mjs's 2 MiB bodies are random base64 so they stay over 2 MiB on the wire. Live (www.workbuddy.ai, a real account in a sandbox HOME): with 0.1.43 the default sent reasoning_effort high gzipped and thought (34 and 51 reasoning tokens), none stayed 0, low and high as before, all 200. A gzipped chat answered 200 the same as a plain one. Broken by hand: origin/main's index.mjs with the new default-effort.test.mjs: 5 of 8 red (default effort, failed-read reuse, both gzip tests, defaultEffortOf); the 3 that pass guard what must not change (named efforts, models without a default, Messages). Not tried: a live chat on the China build (copilot.tencent.com answered 401 to every token available here, its /v3/config read fine); Messages gzipped; the reporters' own OpenCode sessions end to end.
134 lines
5.6 KiB
JavaScript
134 lines
5.6 KiB
JavaScript
// WorkBuddy's front door answers a sign-in it refuses with 401, but only
|
|
// for a request of up to 2 MiB: past that it resets the connection, and a
|
|
// long Claude Code session's every turn failed as ECONNRESET (wyp on
|
|
// Discord, 2026-10-15). The fake below is that front door on a real
|
|
// socket, so Bun's fetch meets the same reset it met on www.workbuddy.ai.
|
|
import { afterAll, beforeAll, expect, test } from "bun:test"
|
|
import net from "node:net"
|
|
import { randomBytes } from "node:crypto"
|
|
import { WorkBuddyAIAuthPlugin, WorkBuddyAuthPlugin, _internal } from "./index.mjs"
|
|
|
|
const { EDGE_READS } = _internal
|
|
const GOOD = "Bearer good"
|
|
|
|
let server
|
|
let origin
|
|
let meterAsked = 0
|
|
let resetAll = false // a reset that isn't the sign-in's: every long body
|
|
|
|
beforeAll(async () => {
|
|
server = net.createServer((s) => {
|
|
let buf = Buffer.alloc(0)
|
|
let head = null
|
|
s.on("error", () => {})
|
|
s.on("data", (d) => {
|
|
buf = Buffer.concat([buf, d])
|
|
if (!head) {
|
|
const end = buf.indexOf("\r\n\r\n")
|
|
if (end < 0) return
|
|
const lines = buf.subarray(0, end).toString("latin1").split("\r\n")
|
|
const h = Object.fromEntries(lines.slice(1).map((l) => [l.slice(0, l.indexOf(":")).toLowerCase(), l.slice(l.indexOf(":") + 1).trim()]))
|
|
head = { path: lines[0].split(" ")[1], auth: h.authorization, length: Number(h["content-length"] ?? 0) }
|
|
buf = buf.subarray(end + 4)
|
|
}
|
|
const refused = head.auth !== GOOD
|
|
if (head.length > EDGE_READS && (refused || resetAll)) {
|
|
// the front door reads its 2 MiB, then drops the connection unanswered
|
|
if (buf.length > EDGE_READS) s.resetAndDestroy()
|
|
return
|
|
}
|
|
if (buf.length < head.length) return
|
|
const { path } = head
|
|
head = null
|
|
buf = Buffer.alloc(0)
|
|
if (path.startsWith("/billing/")) meterAsked++
|
|
if (refused) {
|
|
const html = "<html><head><title>401 Authorization Required</title></head></html>"
|
|
s.end(`HTTP/1.1 401 Unauthorized\r\ncontent-type: text/html\r\ncontent-length: ${html.length}\r\nconnection: close\r\n\r\n${html}`)
|
|
return
|
|
}
|
|
const body = path.startsWith("/billing/") ? '{"code":0,"msg":"OK","data":{}}' : 'data: {"choices":[{"delta":{"content":"pong"}}]}\n\ndata: [DONE]\n\n'
|
|
s.end(`HTTP/1.1 200 OK\r\ncontent-type: ${path.startsWith("/billing/") ? "application/json" : "text/event-stream"}\r\ncontent-length: ${body.length}\r\nconnection: close\r\n\r\n${body}`)
|
|
})
|
|
})
|
|
await new Promise((r) => server.listen(0, "127.0.0.1", r))
|
|
origin = `http://127.0.0.1:${server.address().port}`
|
|
})
|
|
|
|
afterAll(() => server.close())
|
|
|
|
// chat is a loader fetch of a body of about size bytes on the wire, signed
|
|
// in as token,
|
|
// with the site (WorkBuddy AI's, else the China build's) served by the fake
|
|
async function chat(token, size, plugin = WorkBuddyAIAuthPlugin, site = "https://www.workbuddy.ai") {
|
|
const realFetch = globalThis.fetch
|
|
globalThis.fetch = (u, init) => realFetch(String(u instanceof Request ? u.url : u).replace(site, origin), init)
|
|
try {
|
|
const hooks = await plugin({ client: {} })
|
|
const loader = await hooks.auth.loader(async () => ({ type: "oauth", access: token, uid: "uid", expires: Date.now() + 3600_000 }))
|
|
const body = JSON.stringify({
|
|
model: "fast-model",
|
|
stream: true,
|
|
messages: [
|
|
{ role: "system", content: "You are helpful." },
|
|
// a chat goes gzipped, so its text is random: base64 of random bytes
|
|
// gzips to about 3/4 of its length, and size is what goes out
|
|
{ role: "user", content: randomBytes(Math.ceil(size * 1.4)).toString("base64").slice(0, Math.ceil(size * 1.4)) },
|
|
],
|
|
})
|
|
return await loader.fetch(site + "/v2/chat/completions", { method: "POST", body })
|
|
} finally {
|
|
globalThis.fetch = realFetch
|
|
}
|
|
}
|
|
|
|
test("a refused sign-in on a chat past 2 MiB says the 401, not ECONNRESET", async () => {
|
|
meterAsked = 0
|
|
const res = await chat("refused", EDGE_READS + 100_000)
|
|
expect(res.status).toBe(401)
|
|
expect(res.headers.get("X-Magpie-Sign-In")).toBe("kept")
|
|
const { error } = await res.json()
|
|
expect(error.message).toContain("refused this account's sign-in (401)")
|
|
expect(error.message).toContain("which is why it read as ECONNRESET")
|
|
expect(error.message).toContain("Sign in to it again in magpie")
|
|
expect(meterAsked).toBe(1)
|
|
})
|
|
|
|
test("the China build's front door is read the same way", async () => {
|
|
meterAsked = 0
|
|
const res = await chat("refused", EDGE_READS + 100_000, WorkBuddyAuthPlugin, "https://copilot.tencent.com")
|
|
expect(res.status).toBe(401)
|
|
expect((await res.json()).error.message).toContain("Providers → WorkBuddy →")
|
|
expect(meterAsked).toBe(1)
|
|
})
|
|
|
|
test("a refused sign-in on a short chat is the front door's own 401, nothing else asked", async () => {
|
|
meterAsked = 0
|
|
const res = await chat("refused", 1000)
|
|
expect(res.status).toBe(401)
|
|
// with no refresh token to renew it with, said so (unauthorized.test.mjs)
|
|
expect((await res.json()).error.message).toContain("there is no refresh token to renew it with")
|
|
expect(meterAsked).toBe(0)
|
|
})
|
|
|
|
test("a reset past 2 MiB with the sign-in accepted stays the reset", async () => {
|
|
meterAsked = 0
|
|
resetAll = true
|
|
try {
|
|
let err
|
|
await chat("good", EDGE_READS + 100_000).catch((e) => (err = e))
|
|
expect(err?.code).toBe("ECONNRESET")
|
|
expect(meterAsked).toBe(1)
|
|
} finally {
|
|
resetAll = false
|
|
}
|
|
})
|
|
|
|
test("an accepted sign-in's chat past 2 MiB goes through", async () => {
|
|
meterAsked = 0
|
|
const res = await chat(GOOD.slice(7), EDGE_READS + 100_000)
|
|
expect(res.status).toBe(200)
|
|
expect(await res.text()).toContain("pong")
|
|
expect(meterAsked).toBe(0)
|
|
})
|