Skip to content

fix: truncated JSON completions (finish_reason=length) are retried at the same max_tokens #2320

Description

@smoryan

Pre-submission checklist

  • 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

  1. Configure a thinking model (reasoning + answer share max_tokens) with a modest maxTokens
  2. Call completeJson() with a task whose reasoning + JSON answer exceeds the budget
  3. 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

  • I'm willing to implement this myself

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

ai:pr-readyAI-created PR is ready for review | AI 生成的 PR 已等待评审area:pluginOpenClaw & Hermesstatus:in-progressSomeone or AI is working on it | 人工或 AI 正在处理types:bugSomething isn't working | 功能异常

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions