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:
26
cli.py
26
cli.py
@@ -5508,13 +5508,25 @@ class HermesCLI:
|
||||
def run_agent():
|
||||
nonlocal result
|
||||
agent_message = _voice_prefix + message if _voice_prefix else message
|
||||
result = self.agent.run_conversation(
|
||||
user_message=agent_message,
|
||||
conversation_history=self.conversation_history[:-1], # Exclude the message we just added
|
||||
stream_callback=stream_callback,
|
||||
task_id=self.session_id,
|
||||
persist_user_message=message if _voice_prefix else None,
|
||||
)
|
||||
try:
|
||||
result = self.agent.run_conversation(
|
||||
user_message=agent_message,
|
||||
conversation_history=self.conversation_history[:-1], # Exclude the message we just added
|
||||
stream_callback=stream_callback,
|
||||
task_id=self.session_id,
|
||||
persist_user_message=message if _voice_prefix else None,
|
||||
)
|
||||
except Exception as exc:
|
||||
logging.error("run_conversation raised: %s", exc, exc_info=True)
|
||||
_summary = getattr(self.agent, '_summarize_api_error', lambda e: str(e)[:300])(exc)
|
||||
result = {
|
||||
"final_response": f"Error: {_summary}",
|
||||
"messages": [],
|
||||
"api_calls": 0,
|
||||
"completed": False,
|
||||
"failed": True,
|
||||
"error": _summary,
|
||||
}
|
||||
|
||||
# Start agent in background thread
|
||||
agent_thread = threading.Thread(target=run_agent)
|
||||
|
||||
Reference in New Issue
Block a user