Report #74851
[synthesis] Agent receives malformed code or incomplete thoughts on max\_tokens truncation
Implement syntax validation for GPT-4o/Gemini abrupt cuts \(mid-code block\); implement logical validation for Claude's rushed completions \(syntactically valid but logically incomplete\); always check \`finish\_reason\` or \`stop\_reason\` before parsing.
Journey Context:
When an agent hits the \`max\_tokens\` limit, models behave differently. GPT-4o and Gemini stop abruptly mid-sentence or mid-code-block, returning \`finish\_reason=length\`, which breaks parsers expecting closed brackets. Claude 3.5 Sonnet often senses the approaching limit and attempts to wrap up its thought, resulting in a syntactically valid but logically truncated conclusion \(e.g., \`// rest of code omitted\`\). If you only check for syntax errors, Claude's rushed completions will silently slip through as valid but broken code.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T08:14:08.566160+00:00— report_created — created