Skip to content

fix(llm): make ProviderClient.chat attempt count match MAX_RETRIES#6

Open
Arvuno wants to merge 1 commit into
OpenNSWM-Lab:mainfrom
Arvuno:fix/provider-client-retry-attempt-count
Open

fix(llm): make ProviderClient.chat attempt count match MAX_RETRIES#6
Arvuno wants to merge 1 commit into
OpenNSWM-Lab:mainfrom
Arvuno:fix/provider-client-retry-attempt-count

Conversation

@Arvuno
Copy link
Copy Markdown

@Arvuno Arvuno commented Jun 5, 2026

fix(llm): make ProviderClient.chat attempt count match MAX_RETRIES

ProviderClient.chat used while retries <= MAX_RETRIES: with
retries = 0, so an operator setting MAX_RETRIES=3 actually triggered
four LLM calls. The final log line printed MAX_RETRIES rather than the
attempt count, hiding the off-by-one behind a misleading number.

Replace the while loop with for attempt in range(1, MAX_RETRIES + 1):.
The body no longer carries a manual retries counter and the
last_error variable is properly typed. The final error log now reports
the actual number of attempts ("after N attempt(s)") and the
ProviderError that gets raised still carries status_code 502.

Adds backend/tests/test_provider_client_retry.py with two cases:

  • litellm.completion fails once then succeeds → exactly 2 calls.
  • litellm.completion always fails → exactly MAX_RETRIES calls, the
    final error log contains "attempt" and no longer contains "retries".

`ProviderClient.chat` used `while retries <= MAX_RETRIES:` with
`retries = 0`, so an operator setting `MAX_RETRIES=3` actually triggered
four LLM calls. The final log line printed `MAX_RETRIES` rather than the
attempt count, hiding the off-by-one behind a misleading number.

Replace the `while` loop with `for attempt in range(1, MAX_RETRIES + 1):`.
The body no longer carries a manual `retries` counter and the
`last_error` variable is properly typed. The final error log now reports
the actual number of attempts (`"after N attempt(s)"`) and the
ProviderError that gets raised still carries status_code 502.

Adds `backend/tests/test_provider_client_retry.py` with two cases:
- `litellm.completion` fails once then succeeds → exactly 2 calls.
- `litellm.completion` always fails → exactly MAX_RETRIES calls, the
  final error log contains "attempt" and no longer contains "retries".
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.

1 participant