Skip to content

feat: Implement Exponential Backoff Retry Handler for LLM and External Service Calls#44

Open
Yashaswini-ds wants to merge 1 commit into
devloperdevesh:mainfrom
Yashaswini-ds:feat/exponential-backoff-retry-handler
Open

feat: Implement Exponential Backoff Retry Handler for LLM and External Service Calls#44
Yashaswini-ds wants to merge 1 commit into
devloperdevesh:mainfrom
Yashaswini-ds:feat/exponential-backoff-retry-handler

Conversation

@Yashaswini-ds

Copy link
Copy Markdown

Description

Implements a reusable exponential backoff retry decorator in app/reliability/retry_handler.py and applies it to the Ollama LLM client in app/rag/llm.py.

Currently, when the Ollama LLM server is unavailable or times out, the application immediately returns an error with no retry logic. This PR adds production-grade resilience to handle transient failures.

Type of Change

  • New Feature
  • Bug Fix (handles transient connection failures)

Related Issue

Closes #29

What Was Implemented

app/reliability/retry_handler.py (was empty stub)

  • RetryConfig dataclass for clean, type-safe configuration
  • with_retry decorator supporting both sync and async functions
  • Exponential backoff: delay = min(base_delay * (backoff_factor ** attempt), max_delay)
  • Jitter support to prevent the thundering herd problem
  • Custom exception filtering (only retries on specified exception types)
  • Structured JSON retry logs via existing app/observability/logging.py

app/rag/llm.py

  • Applied @with_retry decorator to generate_answer() with max_retries=3, base_delay=1.0s, max_delay=8.0s
  • Only retries on ConnectionError and Timeout, not HTTP 4xx/5xx errors

Checklist

  • Code tested locally (both sync and async retry paths verified)
  • No unnecessary files added
  • Full docstrings and type annotations added
  • No breaking changes to existing API contracts

- Add RetryConfig dataclass for clean configuration
- Implement with_retry decorator supporting both sync and async functions
- Apply exponential backoff: delay = base_delay * (backoff_factor ** attempt)
- Add jitter to prevent thundering herd problem
- Integrate structured retry logs via app/observability/logging.py
- Apply decorator to app/rag/llm.py generate_answer() for Ollama resilience

Closes devloperdevesh#29
@vercel

vercel Bot commented May 23, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the devloperdevesh's projects Team on Vercel.

A member of the Team first needs to authorize it.

@Karanjot786

Copy link
Copy Markdown

Hey @Yashaswini-ds! Saw your work on GSSoC 2026.

We are building TermUI, a TypeScript terminal UI framework with React-style hooks and JSX, rendered entirely in the terminal.

We have 67 unassigned GSSoC issues open. 19 are marked good first issue. Your TypeScript background transfers directly.

Karanjot, TermUI maintainer

@Yashaswini-ds

Copy link
Copy Markdown
Author

Hi @Karanjot786, Thank you for reaching out and for the invitation. I'll definitely take a look at TermUI and the open GSSoC issues. The project sounds interesting, especially since it uses TypeScript and React-style concepts. Looking forward to exploring it!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Implement Exponential Backoff Retry Handler for LLM and External Service Calls

2 participants