Skip to content

fix(llm): treat an empty length-cut response as truncation - #115

Merged
wolfy-j merged 1 commit into
masterfrom
fix/empty-length-truncation
Sep 4, 2026
Merged

fix(llm): treat an empty length-cut response as truncation#115
wolfy-j merged 1 commit into
masterfrom
fix/empty-length-truncation

Conversation

@wolfy-j

@wolfy-j wolfy-j commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Defect

output.detect_truncation flags a finish_reason: length response 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_importer on claude-sonnet-5, class:balanced): iteration 2 consumed exactly 8000 completion tokens entirely inside an adaptive-thinking block, returned {"result":"","tool_calls":[]} with finish_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 content and result field 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 (LENGTH without 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

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
@wolfy-j
wolfy-j merged commit 665ae1a into master Sep 4, 2026
21 checks passed
@wolfy-j
wolfy-j deleted the fix/empty-length-truncation branch September 4, 2026 21:17
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.

1 participant