Skip to content

feat: add retry with exponential backoff for transient API failures - #63

Merged
molly554 merged 2 commits into
lynote-ai:mainfrom
MoonWindow:feat/retry-backoff
Sep 16, 2026
Merged

molly554 merged 2 commits into
lynote-ai:mainfrom
MoonWindow:feat/retry-backoff

Conversation

@MoonWindow

Copy link
Copy Markdown

Problem

The pipeline calls each API exactly once per step. If DeepSeek returns a 429 (rate limit) or Google Translate has a momentary network blip, the entire pipeline fails — even though the error is transient and would likely succeed on retry. This is especially painful because Steps 1-2 consume LLM API credits. If Step 3 or 4 fails transiently, the LLM spend is wasted.

Solution

Add a retry_with_backoff() helper in a new src/standard/retry.py module that retries on transient errors (429, 502, 503, 504, timeout) with exponential backoff (1s → 2s → 4s by default).

  • Client errors (401, 400, 422) fail immediately without retry
  • Wraps both chat_completions() in llm_client.py and niutrans_translate() in translators.py
  • Includes unit tests in tests/test_retry.py

Files changed

  • src/standard/retry.py (new) — retry_with_backoff() helper + TRANSIENT_STATUS set
  • src/standard/llm_client.py — wrap httpx.post() call
  • src/standard/translators.py — wrap Niutrans httpx.post() call
  • tests/test_retry.py (new) — 6 unit tests covering success, transient retry, client error, timeout, and exhaustion

Developer and others added 2 commits September 15, 2026 22:58
Wrap LLM and Niutrans HTTP calls with retry_with_backoff() that
retries on
429503/503,). Client errors
 (401, 400 422) fail immediately without retry.

Saves LLM API credits when a later pipeline step fails transiently
—transiently the—spend on Steps 1-2 is—.
test_llm_client.py loaded llm_client.py standalone via spec_from_file_location,
which breaks now that llm_client imports `from .retry`. Import through the
package instead (consistent with test_smoke.py). Fixes test collection.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@molly554
molly554 merged commit 51eb2bb into lynote-ai:main Sep 16, 2026
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.

2 participants