Skip to content

perf: add backoff delay to empty response retries (#35230) - #38002

Closed
SandroHub013 wants to merge 2 commits into
NousResearch:mainfrom
SandroHub013:fix/empty-response-backoff
Closed

perf: add backoff delay to empty response retries (#35230)#38002
SandroHub013 wants to merge 2 commits into
NousResearch:mainfrom
SandroHub013:fix/empty-response-backoff

Conversation

@SandroHub013

Copy link
Copy Markdown

Summary

Adds jittered exponential backoff between empty response retries in the conversation loop, preventing rapid-fire retries that waste API calls.

Problem

When the model returns an empty response (no content, no reasoning), the agent retries up to 3 times with zero delay. All retries fire back-to-back within seconds. If the model is temporarily degraded, all 3 retries are wasted. Worst case: 6 rapid-fire calls (3 primary + 3 fallback).

This is inconsistent with the existing jittered_backoff() mechanism used for API-level errors (rate limits, timeouts, 5xx), which properly waits between attempts.

Fix

Added time.sleep(jittered_backoff(...)) with base_delay=0.5s, max_delay=4s to the empty-response retry path in agent/conversation_loop.py. This produces delays of approximately:

  • Retry 1: ~0.5s
  • Retry 2: ~1.0s
  • Retry 3: ~2.0s

Consistent with the existing API error retry mechanism using the same jittered_backoff() utility.

Files Changed

  • agent/conversation_loop.py — Added backoff delay before continue in empty response retry block (~line 4163)

Testing

Existing tests in test_run_agent.py cover empty response retry paths. The test conftest already patches jittered_backoff to return 0.0 for fast test execution, so no test changes needed.

Fixes #35230

SandroHub013 and others added 2 commits June 3, 2026 09:24
…ch#29590)

Read max_tokens from auxiliary.vision config section instead of using
hardcoded values (2000 for vision_analyze, 4000 for video_analyze).

- Add max_tokens to auxiliary.vision config defaults (4000)
- vision_analyze: read config, fallback to 2000
- video_analyze: read config, fallback to 8192
- Update existing config tests to verify max_tokens behavior
When the model returns an empty response (no content, no reasoning),
the agent previously retried up to 3 times with zero delay. All retries
fired back-to-back within seconds, wasting API calls.

Add jittered exponential backoff (base=0.5s, max=4s) between empty
response retries, consistent with the existing API error retry
mechanism using jittered_backoff(). This prevents rapid-fire retries
when the model is temporarily degraded.

Co-authored-by: SandroHub013 <SandroHub013@users.noreply.github.com>
@SandroHub013

Copy link
Copy Markdown
Author

Duplicate of #35296 — same fix already open. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint duplicate This issue or pull request already exists P3 Low — cosmetic, nice to have type/perf Performance improvement or optimization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Enhancement] Empty response retries have no backoff delay — immediate retry wastes API calls

2 participants