From 8d8b108e67ccabe1f64cd42ff33dcf0b162e0863 Mon Sep 17 00:00:00 2001 From: itspig <1708360+itspig@users.noreply.github.com> Date: Mon, 2 Nov 2026 23:18:50 +0800 Subject: [PATCH] fix(workbuddy): omit default reasoning effort when max_tokens <= 256 When a chat does not explicitly name reasoning_effort, withDefaultEffort injects the model's default reasoning effort (e.g. 'high'). However, for lightweight tasks specifying small output limits (e.g. max_tokens <= 256 like title generation or short classification), forcing a high reasoning effort consumes the entire completion token budget on reasoning alone, producing 0 text tokens before hitting finish_reason=length. Skip default reasoning effort injection when max_tokens <= 256 while preserving explicit client-specified efforts and normal-sized chats. Issue #643, PR #644. --- packages/workbuddy/default-effort.test.mjs | 18 ++++++++++++++++++ packages/workbuddy/index.mjs | 2 ++ 2 files changed, 20 insertions(+) diff --git a/packages/workbuddy/default-effort.test.mjs b/packages/workbuddy/default-effort.test.mjs index a4d8f35..f42a1fa 100644 --- a/packages/workbuddy/default-effort.test.mjs +++ b/packages/workbuddy/default-effort.test.mjs @@ -149,3 +149,21 @@ test("defaultEffortOf reads defaultEffort, else effort, held to the model's leve expect(defaultEffortOf({ reasoning: { defaultEffort: "medium" } }, ["low", "high"])).toBeUndefined() expect(defaultEffortOf({}, ["low"])).toBeUndefined() }) + +test("a chat with small max_tokens (<= 256) is not given a default reasoning effort", async () => { + const sent = serve() + const opts = await loader() + for (const max_tokens of [64, 100, 256]) { + 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 }) + 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") +}) diff --git a/packages/workbuddy/index.mjs b/packages/workbuddy/index.mjs index f7b8505..a3f10aa 100644 --- a/packages/workbuddy/index.mjs +++ b/packages/workbuddy/index.mjs @@ -3264,6 +3264,8 @@ function defaultEffortOf(d, efforts) { // effort the client named, "none" too, goes as it came. 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 const m = list?.find((x) => x.id === chat.model) if (!m?.effort) return false chat.reasoning_effort = m.effort