fix(agent): log outer-loop exceptions at ERROR with traceback (#32264)

The outer 'except Exception' guard in run_conversation() captures
exceptions raised inside the agent loop (during streaming, tool
dispatch, message construction, etc.) and prints a one-line summary
to the screen.  The traceback was only logged at DEBUG, so it never
landed in errors.log (WARNING+) and was lost.

For intermittent failures — the most important kind to debug — users
saw 'Error during OpenAI-compatible API call #N: <message>' on
screen with no way to recover the call site.  Switching to
logger.exception() emits the full traceback at ERROR so it goes to
both agent.log and errors.log automatically.

This is a pure logging change; control flow is unchanged.
This commit is contained in:
Teknium 2026-05-25 15:16:54 -07:00 committed by GitHub
parent 30928f945f
commit c2aa235328
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -3945,8 +3945,14 @@ def run_conversation(
print(f"{error_msg}")
except (OSError, ValueError):
logger.error(error_msg)
logger.debug("Outer loop error in API call #%d", api_call_count, exc_info=True)
# Emit the full traceback at ERROR level so it lands in both
# agent.log AND errors.log. Previously this was logged at DEBUG,
# which meant intermittent outer-loop failures were unreproducible
# — users would see a one-line summary on screen with no way to
# recover the call site. logger.exception() includes the
# traceback automatically and emits at ERROR.
logger.exception("Outer loop error in API call #%d", api_call_count)
# If an assistant message with tool_calls was already appended,
# the API expects a role="tool" result for every tool_call_id.