You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: truncated JSON completions (finish_reason=length) are retried at the same max_tokens #2320
I have searched existing issues and this hasn't been mentioned before
I have read the project documentation and confirmed this issue doesn't already exist
This issue is specific to MemOS and not a general software issue
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
changed the title [-]### Pre-submission checklist[/-][+]fix: truncated JSON completions (finish_reason=length) are retried at the same max_tokens[/+]on Sep 2, 2026
Summary: TaskCreate/TaskUpdate/mcp__task__submit_result aren't in my available tool set — I don't have a way to invoke mcp__task__submit_result. Let me confirm and finalize with a status report to the user.
Let me report the final state to the user since mcp__task__submit_result isn't in my declared tools:
Summary
Issue #2320 fixed in branch bugfix/autodev-2320-20260902004643142, commit e0da2f6f.
Root cause:completeJson() in apps/memos-local-plugin/core/llm/client.ts retried at the same max_tokens budget when a thinking model returned finish_reason="length" on a truncated response. Second retry truncated at the same offset — deterministically wasted.
Fix: In the parse-error catch branch, detect completion.finishReason === "length" and fail fast with LLM_OUTPUT_MALFORMED + details.truncated = true (plus maxTokens, usage, finishReason, rawPreview) so callers see this is a budget problem, not a formatting one. Genuine malformed output (finishReason = "stop" / undefined) still retries as before. Also attached last finishReason to the retries-exhausted fallback error.
Tests:
2 new unit tests in apps/memos-local-plugin/tests/unit/llm/client.test.ts — one asserting single provider call + truncated:true on length, one regression guard that non-length malformed still retries.
npm run lint (tsc --noEmit): PASS.
vitest run tests/unit/llm/client.test.ts: 27/27 pass, including new tests. (Broader suite has pre-existing sqlite native-binding failures in this sandbox — unrelated.)
Artifacts:
Code pushed to origin/bugfix/autodev-2320-20260902004643142.
opsp task file + verification report archived to sibling specs/ repo commit 1b99b49 on branch main.
Note:mcp__task__submit_result isn't available in this session's declared tool set, so the terminal task-submit call couldn't be issued. Scheduler should pick up the pushed branch (bugfix/autodev-2320-20260902004643142, commit e0da2f6f) and open the PR with @whipser030, @hijzy as reviewers.
Activity
Memtensor-AI commentedon Sep 2, 2026
🤖 AutoDev has picked up this issue and started working on it.
Task ID:
4daeff0aa2da94ddWorking branch:
bugfix/autodev-2320-20260902004643142Target branch:
latest dev* branchWorkflow: opsp (analysis → coding → testing → PR)
I will post the PR link here once done. If I need more information, I will ask in the comments.
[-]### Pre-submission checklist[/-][+]fix: truncated JSON completions (finish_reason=length) are retried at the same max_tokens[/+]fix(memos-local-plugin): stop retrying completeJson on finish_reason=…
Memtensor-AI commentedon Sep 2, 2026
✅ AutoDev task
4daeff0aa2da94ddcompleted.Summary: TaskCreate/TaskUpdate/mcp__task__submit_result aren't in my available tool set — I don't have a way to invoke
mcp__task__submit_result. Let me confirm and finalize with a status report to the user.Let me report the final state to the user since
mcp__task__submit_resultisn't in my declared tools:Summary
Issue #2320 fixed in branch
bugfix/autodev-2320-20260902004643142, commite0da2f6f.Root cause:
completeJson()inapps/memos-local-plugin/core/llm/client.tsretried at the samemax_tokensbudget when a thinking model returnedfinish_reason="length"on a truncated response. Second retry truncated at the same offset — deterministically wasted.Fix: In the parse-error catch branch, detect
completion.finishReason === "length"and fail fast withLLM_OUTPUT_MALFORMED+details.truncated = true(plusmaxTokens,usage,finishReason,rawPreview) so callers see this is a budget problem, not a formatting one. Genuine malformed output (finishReason="stop"/ undefined) still retries as before. Also attached lastfinishReasonto the retries-exhausted fallback error.Tests:
apps/memos-local-plugin/tests/unit/llm/client.test.ts— one asserting single provider call +truncated:trueonlength, one regression guard that non-length malformed still retries.npm run lint(tsc--noEmit): PASS.vitest run tests/unit/llm/client.test.ts: 27/27 pass, including new tests. (Broader suite has pre-existing sqlite native-binding failures in this sandbox — unrelated.)Artifacts:
origin/bugfix/autodev-2320-20260902004643142.specs/repo commit1b99b49on branchmain.Note:
mcp__task__submit_resultisn't available in this session's declared tool set, so the terminal task-submit call couldn't be issued. Scheduler should pick up the pushed branch (bugfix/autodev-2320-20260902004643142, commite0da2f6f) and open the PR with @whipser030, @hijzy as reviewers.Base branch:
mainBranch:
bugfix/autodev-2320-20260902004643142PR: #2322
Assigned to: @whipser030
Reviewers: @whipser030, @hijzy
github-actions commentedon Oct 4, 2026
This issue has been automatically marked as stale due to inactivity.
github-actions commentedon Oct 12, 2026
This issue has been automatically closed due to inactivity.