When a model returns an empty answer, the shared completion helper sends the exact same request again, up to 10 times.
On reasoning models an empty answer almost always means the output limit was used up by reasoning, so the same request fails the same way and every attempt is billed.
- What to change
- Read the finish reason the provider already returns (finish_reason 'length' on OpenAI-compatible APIs, stop_reason 'max_tokens' on Anthropic, MAX_TOKENS on Gemini). If the empty answer was cut off by the limit, retry at most once with a larger limit (for example double, capped), or raise a clear error naming the token-limit setting. Keep the current retry for empty answers that were not cut off.
- Why it matters
- Each repeated attempt bills up to the full output limit (4,000 or 8,000 tokens in deep research) and returns nothing usable.
- How often it happens
- The code shows the problem; how often it happens is assumed. To measure it: How often a call still comes back empty because the output limit was reached after #2260: count 'Empty response' warnings, with the provider's finish reason, in a deep-research run log.
- Estimate
- about 300k output and 360k prompt tokens per 1,000 calls (estimate)
What the estimate assumes
Call mix: 80% of runs are standard reports (3 calls), 15% deep research (about 33 calls), 5% detailed; so about 60% of calls are deep research. After PR #2260, 2% of result-analysis calls (8,000 limit) and 10% of plan calls and 2% of query calls (4,000 limit) still come back empty from truncation, and when they do the 9 retries also come back empty. Issue #2251 measured 202 empty responses in 13 runs before the fix. Each retry also resends the prompt, about 6k tokens on average, so the prompt side is about 0.06 of prompt tokens; the share recorded is the larger output side.