fix: graceful return on max retries instead of crashing thread

run_conversation raised the raw exception after exhausting retries,
which crashed the background thread in cli.py (unhandled exception
in Thread). Now returns a proper error result dict with failed=True
and persists the session, matching the pattern used by other error
paths (invalid responses, empty content, etc.).

Also wraps cli.py's run_agent thread function in try/except as a
safety net against any future unhandled exceptions from
run_conversation.

Made-with: Cursor
This commit is contained in:
Teknium 2026-03-25 19:00:33 -07:00
parent 156b50358b
commit 08d3be0412
No known key found for this signature in database
3 changed files with 35 additions and 12 deletions

View file

@ -6697,7 +6697,15 @@ class AIAgent:
self._dump_api_request_debug(
api_kwargs, reason="max_retries_exhausted", error=api_error,
)
raise api_error
self._persist_session(messages, conversation_history)
return {
"final_response": f"API call failed after {max_retries} retries: {_final_summary}",
"messages": messages,
"api_calls": api_call_count,
"completed": False,
"failed": True,
"error": _final_summary,
}
wait_time = min(2 ** retry_count, 60) # Exponential backoff: 2s, 4s, 8s, 16s, 32s, 60s, 60s
logger.warning(