Pre-submission checklist
Bug Description
Thinking models share one max_tokens budget between reasoning and the final answer, so a truncated completion arrives as 200 OK with finish_reason="length" — not as an error. completeJson() in apps/memos-local-plugin/core/llm/client.ts treats it like any malformed output and retries with the same max_tokens budget. The retry truncates at the same point: it can never succeed, and both attempts are wasted on what is a budget problem, not a formatting problem.
On our local deployment this hit L3-abstraction calls routinely (P95 useful output ≈ 4.2k tokens, with reasoning frequently pushing past the configured budget), surfacing as LLM_OUTPUT_MALFORMED.
How to Reproduce
- Configure a thinking model (reasoning + answer share
max_tokens) with a modest maxTokens
- Call
completeJson() with a task whose reasoning + JSON answer exceeds the budget
- Observe
finish_reason="length" on the 200 response, followed by a retry at the identical budget — which truncates identically
Environment
- memos-local-plugin: 2.0.18 (
apps/memos-local-plugin)
- Node.js: 26
- OS: macOS
Willingness to Implement
Pre-submission checklist
Bug Description
Thinking models share one
max_tokensbudget between reasoning and the final answer, so a truncated completion arrives as 200 OK withfinish_reason="length"— not as an error.completeJson()inapps/memos-local-plugin/core/llm/client.tstreats it like any malformed output and retries with the samemax_tokensbudget. The retry truncates at the same point: it can never succeed, and both attempts are wasted on what is a budget problem, not a formatting problem.On our local deployment this hit L3-abstraction calls routinely (P95 useful output ≈ 4.2k tokens, with reasoning frequently pushing past the configured budget), surfacing as
LLM_OUTPUT_MALFORMED.How to Reproduce
max_tokens) with a modestmaxTokenscompleteJson()with a task whose reasoning + JSON answer exceeds the budgetfinish_reason="length"on the 200 response, followed by a retry at the identical budget — which truncates identicallyEnvironment
apps/memos-local-plugin)Willingness to Implement