Fix #2320: ### Pre-submission checklist - #2322
Closed
Memtensor-AI wants to merge 1 commit into
Closed
Conversation
…length Thinking models share `max_tokens` between reasoning and the final answer, so a truncated completion arrives as 200 OK with `finish_reason="length"`. `completeJson()` previously treated it as any parse failure and retried at the same budget - the retry truncates at the same offset and both requests are wasted on what is a budget problem, not a formatting problem. Detect `finishReason === "length"` inside the parse-error catch and fail fast with `LLM_OUTPUT_MALFORMED` + `details.truncated=true` (plus `maxTokens`, `usage`, `finishReason`, `rawPreview`) so callers can raise `maxTokens` instead of burning another paid request. Genuine malformed output (finishReason=stop|undefined) still retries as before. Fixes MemTensor#2320
Open
4 tasks
Collaborator
Author
🤖 Open Code ReviewTarget: PR #2322 ✅ OpenCodeReview: Review complete: 0 finding(s) across 1 selected item(s). Generated by cloud-assistant via Open Code Review. |
Collaborator
Author
✅ Automated Test Results: PASSEDAll tests passed (27/27 executed). memos_local_plugin/unit: 27/27. Duration: 3s [advisory, non-gating] AI-generated tests on branch test/auto-gen-4daeff0aa2da94dd-20260902090914: 0/67 passed, 67 failed — these do NOT affect the PR verdict; review the branch manually. Branch: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
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.Related Issue (Required): Fixes #2320
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Not run; documentation-only change.
Checklist
@whipser030, @hijzy please review this PR.
Reviewer Checklist