diff --git a/packages/workbuddy/README.md b/packages/workbuddy/README.md index b3d6278..904f10d 100644 --- a/packages/workbuddy/README.md +++ b/packages/workbuddy/README.md @@ -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 diff --git a/packages/workbuddy/default-effort.test.mjs b/packages/workbuddy/default-effort.test.mjs index f42a1fa..98a5657 100644 --- a/packages/workbuddy/default-effort.test.mjs +++ b/packages/workbuddy/default-effort.test.mjs @@ -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() }) diff --git a/packages/workbuddy/index.mjs b/packages/workbuddy/index.mjs index a3f10aa..4e7082e 100644 --- a/packages/workbuddy/index.mjs +++ b/packages/workbuddy/index.mjs @@ -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 } diff --git a/packages/workbuddy/package.json b/packages/workbuddy/package.json index 7682b92..2f34123 100644 --- a/packages/workbuddy/package.json +++ b/packages/workbuddy/package.json @@ -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",