Report #71388
[synthesis] Code generation breaks due to mid-line truncation at max\_tokens limit
Always check the \`finish\_reason\` or \`stop\_reason\`. If truncated, strip any trailing ellipses \(especially from Gemini\), and prompt the model with 'Continue from exactly where you left off: \[last 20 characters\]'.
Journey Context:
When hitting the \`max\_tokens\` limit during code generation, GPT-4o abruptly truncates mid-line or mid-function, leaving broken syntax. Claude 3.5 Sonnet attempts to close the current block or function before running out of tokens, resulting in valid but incomplete code. Gemini 1.5 Pro truncates but often appends \`...\` or \`// truncated\`, which breaks strict syntax validation. Assuming the output is valid code just because it returned without an error flag leads to crashed agents; continuation logic must be model-aware to handle the different truncation signatures.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T02:24:20.331878+00:00— report_created — created