When a turn is cut off at the 50,000-token output limit, nothing reads why it stopped.
On OpenAI the cut-off tool call arrives as broken JSON and the whole broken text is sent back to the model as the tool result. The model is told to try again with the same limit, so it writes the whole file again.
- What to change
- Read the stop reason on each provider (OpenAI status incomplete, Anthropic stop_reason max_tokens, Gemini finishReason MAX_TOKENS). On a cut-off, do not echo the broken arguments back: end the variant with a clear 'output limit reached' error, or continue from the saved file with a higher limit.
- Why it matters
- Each cut-off turn bills up to 50,000 output tokens, the retry bills them again, and the echoed broken arguments stay in the history and are re-read on every later turn.
- How often it happens
- The code shows the problem; how often it happens is assumed. To measure it: how often a turn ends at the 50,000-token output limit (OpenAI status incomplete, Anthropic stop_reason max_tokens, Gemini MAX_TOKENS), from the run records the app already writes
- Who reaches this
- OpenAI models; Anthropic and Gemini see the cut-off as a silent partial file instead
- Estimate
- about 225k output and 675k prompt tokens per 1,000 calls
What the estimate assumes
half a percent of turns end at the limit (guess; only high-effort reasoning models or very large pages should); each wasted turn is about 45k output tokens; the echoed text is carried by about 3 later turns; average turn is 30k prompt and 5k output tokens. Applies mostly to OpenAI, where arguments arrive as broken JSON; on Anthropic the cut-off call is accepted as complete (see the notes).