fix(llm): treat an empty length-cut response as truncation - #115
Merged
Conversation
detect_truncation recognized a max-tokens cutoff only when the response carried partial tool calls. A response whose entire budget burns before any deliverable output - observed live with adaptive thinking consuming all 8000 completion tokens, leaving no text and no tool calls - passed as a normal completion, so agent loops ended reporting success with zero work done (a kb import read its document and wrote nothing, twice, deterministically on the same file). A length-cut response now counts as truncated when it has partial tool calls, or no tool calls and no content under either result field name. One that still carries text remains a partial answer returned to the caller. Truncation feeds the existing recovery path: the loop stores the turn, injects the retry guidance, and the agent continues. Claude-Session: https://claude.ai/code/session_011evDbMcxWJxqmRatnQ8g4W
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.
Defect
output.detect_truncationflags afinish_reason: lengthresponse as truncated only when it carries partial tool calls. A response that hits the cap having produced nothing — no text, no tool calls — passes as a normal completion.Observed live (WMU instance,
kb_importeronclaude-sonnet-5,class:balanced): iteration 2 consumed exactly 8000 completion tokens entirely inside an adaptive-thinking block, returned{"result":"","tool_calls":[]}withfinish_reason: "length", and the agent workload completed "successfully" having written zero KB entries — deterministically, twice, on the same document.Fix
A length-cut response is truncated when it has partial tool calls, or no tool calls and no content (checked under both
contentandresultfield names). A length-cut response that still carries text stays a partial answer returned to the caller — chat semantics unchanged.This routes the empty case into the existing truncation recovery (store turn → inject retry guidance → continue), which is functional as of #114.
Tests
Two tests that pinned the defective behavior (
LENGTHwithout tool calls → never truncation) are split into correct pairs: with text → false, with nothing → true, under both field names. llm suite 1208 green, agent suite 313 green, lint clean.https://claude.ai/code/session_011evDbMcxWJxqmRatnQ8g4W