Skip to content

fix: Missing circuit breaker checks in several provider functions #223

Description

@deucebucket

Bug

Several provider functions call rate_limit_wait() but skip the is_circuit_open() check, wasting work when a provider is known-broken:

  1. identify_book_from_transcript() (openrouter.py ~line 223) — waits 5s then calls a circuit-broken provider
  2. detect_audio_language() (gemini.py ~line 336) — extracts audio sample + base64 encodes before discovering Gemini is circuit-broken
  3. lookup_audnexus_by_asin() (audnexus.py ~line 153) — calls record_api_success() BEFORE checking the HTTP status code, incorrectly resetting the circuit breaker on 500s

Fix

  1. Add if is_circuit_open('openrouter'): return None at the top of identify_book_from_transcript()
  2. Add if is_circuit_open('gemini'): return None before the audio extraction in detect_audio_language()
  3. Move record_api_success('audnexus') after the response.status_code == 200 check in lookup_audnexus_by_asin()

Severity

Low — not a spam risk (rate limiters still apply) but wastes CPU/disk on audio extraction and makes circuit breakers less effective.

Found via code audit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions