[loop-generated] [optimization] Agent retry uses fixed 1s delay instead of exponential backoff #174

Closed
opened 2026-03-15 15:42:10 +00:00 by hermes · 0 comments
Collaborator

Problem

src/timmy/agents/base.py lines 131-152: The SubAgent retry loop uses a fixed asyncio.sleep(1) between retries. This is suboptimal when Ollama is overloaded — fixed delays cause thundering herd.

Current code

for attempt in range(1, max_retries + 1):
    try:
        result = self.agent.run(message, stream=False)
        ...
    except Exception as exc:
        if attempt < max_retries:
            await asyncio.sleep(1)  # Fixed 1s delay

Proposed fix

Use exponential backoff: await asyncio.sleep(2 ** (attempt - 1)) which gives 1s, 2s, 4s delays. This is gentler on Ollama when it is under load and reduces contention.

Optionally add jitter: await asyncio.sleep(2 ** (attempt - 1) + random.uniform(0, 0.5))

Files

  • src/timmy/agents/base.py lines 131-152
## Problem `src/timmy/agents/base.py` lines 131-152: The SubAgent retry loop uses a fixed `asyncio.sleep(1)` between retries. This is suboptimal when Ollama is overloaded — fixed delays cause thundering herd. ## Current code ```python for attempt in range(1, max_retries + 1): try: result = self.agent.run(message, stream=False) ... except Exception as exc: if attempt < max_retries: await asyncio.sleep(1) # Fixed 1s delay ``` ## Proposed fix Use exponential backoff: `await asyncio.sleep(2 ** (attempt - 1))` which gives 1s, 2s, 4s delays. This is gentler on Ollama when it is under load and reduces contention. Optionally add jitter: `await asyncio.sleep(2 ** (attempt - 1) + random.uniform(0, 0.5))` ## Files - `src/timmy/agents/base.py` lines 131-152
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Rockachopa/Timmy-time-dashboard#174