Skip to content

fix: track last error across retries in _call_with_retry#234

Open
dennis-lynch-nv wants to merge 1 commit intoaiming-lab:mainfrom
dennis-lynch-nv:fix/retry-error-tracking-bugs-v2
Open

fix: track last error across retries in _call_with_retry#234
dennis-lynch-nv wants to merge 1 commit intoaiming-lab:mainfrom
dennis-lynch-nv:fix/retry-error-tracking-bugs-v2

Conversation

@dennis-lynch-nv
Copy link
Copy Markdown

Problem

When all retries are exhausted in _call_with_retry(), the final RuntimeError only says:

LLM call failed after N retries for model X

...with no indication of what went wrong (rate limit? timeout? connection refused?).

Additionally, URLError exceptions are caught but not captured as a variable, so their details are lost.

Fix

  • Add last_err tracking across all three exception handlers (HTTPError, URLError, TimeoutError/OSError)
  • Capture URLError as e so the error details are available
  • Include last_err in the final RuntimeError message
  • Truncate HTTP body to 200 chars to keep error messages manageable

After

LLM call failed after 8 retries for model gpt-4o. Last error: HTTP 429: {"error":{"message":"Rate limit exceeded"...}}

Testing

Import-tested; no new dependencies. Change is limited to the retry loop in researchclaw/llm/client.py.

When all retries are exhausted, the RuntimeError message only says
'LLM call failed after N retries for model X' with no indication of
what went wrong. Additionally, URLError exceptions are not captured
as a variable, losing diagnostic info.

Fixes:
- Add last_err tracking across all three exception handlers
  (HTTPError, URLError, TimeoutError/OSError)
- Capture URLError as 'e' so the error details are available
- Include last_err in the final RuntimeError message
- Truncate HTTP body to 200 chars to avoid massive error messages
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