Skip to content

test: cover generic_call_api_with_retries branches and backoff - #31

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1789677967-retry-driver-tests
Open

devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1789677967-retry-driver-tests

Conversation

@devin-ai-integration

Copy link
Copy Markdown

Summary

generic_call_api_with_retries in src/agentlab/llm/llm_utils.py is the resilience layer every LLM call funnels through, and none of its branches had a direct test (the only rate-limit tests in the suite are commented out). A code scan flagged this; this PR adds tests in tests/llm/test_llm_utils.py locking in the classification, retry, and backoff behavior. No production code changed.

Tests use fake exception classes (FakeRateLimitError, FakeAPIError(status_code)) plus a sleep_calls fixture that monkeypatches llm_utils.time.sleep to record delays instead of sleeping, so the suite stays fast and offline.

Behavior pinned:

  • retriable: FakeRateLimitError, and status 429/500/503 → loop then succeed
  • non-retriable: status 400/401/404, and a get_status_code_fn that itself raises → re-raise immediately, no sleep
  • unexpected exception (KeyError) → re-raised immediately
  • invalid response content → retries until valid
  • exhaustion on each path (invalid content, rate limit, API error) → RuntimeError, with client_function.call_count == max_retries
  • backoff sequence asserted exactly, including the cap:
    initial=10, max_delay=100, max_retries=6, always rate-limited
    sleeps == [20, 40, 80, 100, 100]     # exception path: initial * 2**attempt, attempt from 1
    invalid-content path: initial * 2**(attempt-1)  -> [1, 2] for initial=1
    
    These assertions encode the current formula (exception retries start at 2 * initial, invalid-content retries start at 1 * initial) so an off-by-one on the exponent fails the suite.

pytest tests/llm/test_llm_utils.py → 26 passed; black --check clean.

Devin-Org: engineering

Link to Devin session: https://app.devin.ai/sessions/072cbc22fb6c41dea481065ec77d7489
Open in Devin Desktop: https://app.devin.ai/desktop/session/072cbc22fb6c41dea481065ec77d7489?variant=devin

@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

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.

0 participants