workbuddy 0.2.15: no default effort for a chat whose max_tokens is 1024 or less (#643, itspig)

itspig's change (the commit before) skips the default reasoning_effort at
max_tokens 256 or less. This raises the bound to 1024, as SMALL_BUDGET,
and reads max_completion_tokens too. Anthropic's API takes no thinking
under a 1024-token budget, so a /v1/messages request magpie translates with
max_tokens 1024 or less can't have asked for thinking, and the gateway
sends it with no effort, the same as OpenCode's default variant. 256 left
512 and 1024 asks thinking at the default.

Run, at this head, on mote:
- packages/workbuddy: bun test, 315 pass, 0 fail.
- bun scripts/check.mjs workbuddy: ok.
- Broken by hand (the SMALL_BUDGET line removed): the new test is red,
  8 pass, 1 fail.

Real, on the owner's workbuddy-ai account (www.workbuddy.ai, sandbox HOME,
no token renewal), deepseek-v4.1-flash-sg, default effort high:
- main, max_tokens 64, no effort: finish "length", 64 reasoning tokens,
  empty content (#643's pattern). This head: "stop", 0 reasoning, the
  title answered.
- main, max_tokens 1024: 76 reasoning tokens. This head: 0, answered.
- This head, max_tokens 2048: 65 reasoning tokens (the default still goes).
- An explicit "high" at 64 still ends "length"; "low" answers. An effort
  the client names goes as it came.

Not tried: the China site (copilot.tencent.com), deepseek-v4-pro (11102 on
the AI site), kimi-k3.1-pro (11158, not for free users).
This commit is contained in:
yetone
2026-11-03 02:25:46 +08:00
parent 8d8b108e67
commit d51bd50cf6
4 changed files with 45 additions and 14 deletions
+5 -1
View File
@@ -286,7 +286,11 @@ that names no level goes at the model's own default from the config
(`reasoning.defaultEffort`, "high" for DeepSeek-V4.1-Flash), as WorkBuddy's
client sends it: WorkBuddy doesn't think when a chat names none, so
OpenCode's default variant got answers without thinking. An effort the
client names, `none` too, goes as it came.
client names, `none` too, goes as it came. A chat whose `max_tokens` is
1024 or less gets no default (since 0.2.15, #643): a title or a
classification asked at 64 tokens spent all 64 on reasoning and answered
nothing. Anthropic's API takes no thinking under a 1024-token budget, so
no client means to think in one that small.
One value differs from the config, measured with real requests:
DeepSeek-V4.1-Flash (and its paid `-sg` id) lists `none`, though the
+22 -9
View File
@@ -12,6 +12,8 @@ import { afterEach, expect, test } from "bun:test"
import { WorkBuddyAuthPlugin, WorkBuddyAIAuthPlugin, _internal } from "./index.mjs"
import { unz } from "./testdata/unz.mjs"
const { SMALL_BUDGET } = _internal
const real = globalThis.fetch
afterEach(() => (globalThis.fetch = real))
@@ -150,20 +152,31 @@ test("defaultEffortOf reads defaultEffort, else effort, held to the model's leve
expect(defaultEffortOf({}, ["low"])).toBeUndefined()
})
test("a chat with small max_tokens (<= 256) is not given a default reasoning effort", async () => {
test("a chat with a small max_tokens is not given a default reasoning effort", async () => {
// itspig (#643): title requests at max_tokens 64 spent all 64 on reasoning
// at the default high and answered no text. Anthropic's API takes no
// thinking budget under 1024, so a budget of SMALL_BUDGET or less was
// never one to think in; a larger one, or none, still goes at the default
expect(SMALL_BUDGET).toBe(1024)
const sent = serve()
const opts = await loader()
for (const max_tokens of [64, 100, 256]) {
for (const max_tokens of [64, 100, 256, 1000, 1024]) {
await ask(opts, "deepseek-v4.1-flash", { max_tokens })
}
await ask(opts, "deepseek-v4.1-flash", { max_completion_tokens: 64 })
await ask(opts, "deepseek-v4.1-flash", { max_tokens: 64, reasoning_effort: "low" })
await ask(opts, "deepseek-v4.1-flash", { max_tokens: 1000 })
await ask(opts, "deepseek-v4.1-flash", { max_tokens: 1025 })
await ask(opts, "deepseek-v4.1-flash", { max_completion_tokens: 32000 })
await ask(opts, "deepseek-v4.1-flash", { max_tokens: 0 })
const chats = chatsOf(sent).map((c) => JSON.parse(c.text))
expect(chats[0].reasoning_effort).toBeUndefined()
expect(chats[1].reasoning_effort).toBeUndefined()
expect(chats[2].reasoning_effort).toBeUndefined()
expect(chats[3].reasoning_effort).toBeUndefined()
expect(chats[4].reasoning_effort).toBe("low")
expect(chats[5].reasoning_effort).toBe("high")
for (let i = 0; i < 6; i++) expect(chats[i].reasoning_effort).toBeUndefined()
expect(chats[6].reasoning_effort).toBe("low")
expect(chats[7].reasoning_effort).toBe("high")
expect(chats[8].reasoning_effort).toBe("high")
expect(chats[9].reasoning_effort).toBe("high")
// the WorkBuddy AI build alike
const sent2 = serve()
const ai = await loader(WorkBuddyAIAuthPlugin)
await ask(ai, "deepseek-v4.1-flash", { max_tokens: 64 }, "https://www.workbuddy.ai/v2/chat/completions")
expect(JSON.parse(chatsOf(sent2)[0].text).reasoning_effort).toBeUndefined()
})
+17 -3
View File
@@ -3259,13 +3259,27 @@ function defaultEffortOf(d, efforts) {
return typeof own === "string" && efforts.includes(own) ? own : undefined
}
// SMALL_BUDGET is the largest output budget a chat can name and still be
// one no client meant to think in: Anthropic's API takes thinking only with
// a budget of at least 1024 tokens and a max_tokens above it, so a request
// of 1024 or less can't have asked for thinking there, and a client's own
// short asks (a session title, a classification) name such budgets. A
// default effort spends them on reasoning: itspig (#643) saw 230+ title
// requests at max_tokens 64 on deepseek-v4-pro end out=64, reasoning=64,
// no text. Measured 2026-11-03 on www.workbuddy.ai, deepseek-v4.1-flash-sg
// at its default high: max_tokens 64 ended "length" with 64 reasoning
// tokens and no text; without an effort it answered the title.
const SMALL_BUDGET = 1024
// withDefaultEffort gives a chat that names no effort the model's default
// (defaultEffortOf), as WorkBuddy's client sends it; true when it did. An
// effort the client named, "none" too, goes as it came.
// effort the client named, "none" too, goes as it came. A chat whose
// max_tokens is SMALL_BUDGET or less is given none: WorkBuddy doesn't
// think without one, so its budget goes to the answer.
function withDefaultEffort(chat, list) {
if (!chat || typeof chat !== "object" || namesEffort(chat)) return false
const limit = chat.max_tokens ?? chat.max_completion_tokens
if (typeof limit === "number" && limit > 0 && limit <= 256) return false
if (typeof limit === "number" && limit > 0 && limit <= SMALL_BUDGET) return false
const m = list?.find((x) => x.id === chat.model)
if (!m?.effort) return false
chat.reasoning_effort = m.effort
@@ -3954,4 +3968,4 @@ export const WorkBuddyAuthPlugin = makePlugin(SITES.workbuddy)
export const WorkBuddyAIAuthPlugin = makePlugin(SITES["workbuddy-ai"])
// for tests
export const _internal = { planCodes, idFor, OFF_TAKEN, replyAfterToolsOn, withDefaultEffort, defaultEffortOf, gzipped, FREE_ONLY, PRICE_TTL, keyAccount, remoteConfig, cycleOf, typeUnions, systemAsUser, systemKey, DEFAULT_SYSTEM, EDGE_READS, fitShape, replyAfterTools, AFTER_TOOLS_REFUSED, enterpriseUsageOf, accountName, notDesktop, textOnly, runsOutOf, packagesOf, endOf, enterpriseHeaders, enterpriseOf, liveModels, browserSignIn, withSystem, asReasoning, normalizeToolChoice, fitTools, fitted, renamed, unsaid, FILTER_SAYS, unflagged, usageOf, desktopHeld, explained, REFUSED_HINT, RESTRICTED_HINT, EXHAUSTED_HINT, REFUSED_DOC, commaPaused, commaPausedOn, opened, freeCredits, creditsOf, priceOf, fresh, SITES, renewing, renewed, SESSION, attend, scopeOf, turnKey, conversationKey, signatureOf, isMessages, withoutUnsigned, withoutSignedThinking, prepared, answeredBefore, nativeOf, modelOf, configModels, freeWindowOf, tokensShort, freeWindowRows, freeWindowLedger, readLedgerTail, pinned, pinning, rowTime, rowAccount, ofAccount, windowOffset, windowReset, FREE_WINDOW_MODELS, FREE_WINDOW_CN, FREE_WINDOW_AI, FREE_WINDOW_SPAN, FREE_WINDOW_GAP, FREE_WINDOW_LEAD, checkinOf, API_MESSAGES: NPM_MESSAGES, API_CHAT: NPM }
export const _internal = { planCodes, idFor, OFF_TAKEN, replyAfterToolsOn, withDefaultEffort, SMALL_BUDGET, defaultEffortOf, gzipped, FREE_ONLY, PRICE_TTL, keyAccount, remoteConfig, cycleOf, typeUnions, systemAsUser, systemKey, DEFAULT_SYSTEM, EDGE_READS, fitShape, replyAfterTools, AFTER_TOOLS_REFUSED, enterpriseUsageOf, accountName, notDesktop, textOnly, runsOutOf, packagesOf, endOf, enterpriseHeaders, enterpriseOf, liveModels, browserSignIn, withSystem, asReasoning, normalizeToolChoice, fitTools, fitted, renamed, unsaid, FILTER_SAYS, unflagged, usageOf, desktopHeld, explained, REFUSED_HINT, RESTRICTED_HINT, EXHAUSTED_HINT, REFUSED_DOC, commaPaused, commaPausedOn, opened, freeCredits, creditsOf, priceOf, fresh, SITES, renewing, renewed, SESSION, attend, scopeOf, turnKey, conversationKey, signatureOf, isMessages, withoutUnsigned, withoutSignedThinking, prepared, answeredBefore, nativeOf, modelOf, configModels, freeWindowOf, tokensShort, freeWindowRows, freeWindowLedger, readLedgerTail, pinned, pinning, rowTime, rowAccount, ofAccount, windowOffset, windowReset, FREE_WINDOW_MODELS, FREE_WINDOW_CN, FREE_WINDOW_AI, FREE_WINDOW_SPAN, FREE_WINDOW_GAP, FREE_WINDOW_LEAD, checkinOf, API_MESSAGES: NPM_MESSAGES, API_CHAT: NPM }
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-workbuddy-auth",
"version": "0.2.14",
"version": "0.2.15",
"description": "OpenCode provider plugins for WorkBuddy's plans: WorkBuddy (CodeBuddy, copilot.tencent.com) and WorkBuddy AI (www.workbuddy.ai)",
"type": "module",
"main": "./index.mjs",