Skip to content

fix: continue session loop when response is truncated by length (problem with local, smaller LLMs) - #39397

Open
erkkiat wants to merge 2 commits into
anomalyco:devfrom
erkkiat:fix/continue-on-length-truncation
Open

fix: continue session loop when response is truncated by length (problem with local, smaller LLMs)#39397
erkkiat wants to merge 2 commits into
anomalyco:devfrom
erkkiat:fix/continue-on-length-truncation

Conversation

@erkkiat

@erkkiat erkkiat commented Jul 28, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #17471

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

When using local models such as qwen3.6:35b, the context window limitations will break the flow on a regular basis. When a model's finish reason is "length" (hit the output token cap mid-turn) and no tool call was started, the session loop currently ends and goes idle, requiring the user to manually type "continue". This treats "length" like "tool-calls" so the loop keeps going automatically instead. The fix suggested in #17471 can work, but here is an alternate, perhaps cleaner solution.

How did you verify your code works?

I have used a version with this fix for a couple of weeks, and it works continuously without requiring manual intervention. I want to share a working solution.

Screenshots / recordings

No UI changes.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

When a model's finish reason is "length" (hit the output token cap
mid-turn) and no tool call was started, the session loop currently
ends and goes idle, requiring the user to manually type "continue".
This treats "length" like "tool-calls" so the loop keeps going
automatically instead.
@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Related PR Found

PR #26167 - fix(session): retry empty stream truncations and discard partial parts
#26167

This appears to be related as it also handles stream truncations in sessions, though the approach differs (retrying vs continuing). This PR may be worth reviewing to understand any overlapping concerns or previous solutions.

The current PR (#39397) is specifically addressing truncations caused by output token limits with local models, while #26167 appears to focus on empty stream truncations.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: Auto-continue when model hits output token limit (finish_reason: "length")

1 participant