fix(run_agent): surface traceback frame for empty-message errors in retry display - #14733
Open
AndreKurait wants to merge 1 commit into
Open
fix(run_agent): surface traceback frame for empty-message errors in retry display#14733AndreKurait wants to merge 1 commit into
AndreKurait wants to merge 1 commit into
Conversation
…📝 Error:`
## Problem
When the retry loop's `_summarize_api_error()` receives an exception
with an empty `str(error)` (bare `raise AssertionError()`, bare `raise`
without args, or third-party SDK accumulators that discard the original
payload), users see:
📝 Error:
...with nothing after the colon, and no way to diagnose the root cause
without re-running under a debugger.
## Real-world trigger
The anthropic SDK's streaming accumulator raises:
RuntimeError('Unexpected event order, got error before "message_start"')
when Bedrock or Anthropic returns a service-level `error` event as the
first stream event (throttling, overload, 5xx, etc.). The SDK has the
error payload in hand but throws it away before raising — all the user
sees is the cryptic "event order" message with zero context. Even
worse, bare `AssertionError()`s in user-authored code paths often have
empty messages entirely.
## Fix
When the error's string representation is empty or whitespace-only,
walk `error.__traceback__` and format the last frame as:
AssertionError at /path/file.py:123 in some_method() — source line
This gives users an actionable locator without changing the output for
any error with a real message.
## Changes
- `run_agent.py` — `_summarize_api_error()`: added empty-payload guard
at the top of the function before the existing Cloudflare-HTML path.
- `tests/agent/test_summarize_api_error.py` — 4 new tests covering
empty AssertionError, empty-message RuntimeError without traceback,
whitespace-only message, and the fall-through path (non-empty errors
must not be affected).
## Tests
pytest tests/agent/test_summarize_api_error.py -v
# 4 passed in 4.88s
## Risk
- Zero impact on any error with a non-empty message — the new branch
only fires when `str(error).strip()` is falsy.
- `traceback` is a stdlib module; import is lazy (inside the branch).
- `getattr(error, "__traceback__", None)` is the documented API and
handles manually-constructed exceptions that were never raised.
Signed-off-by: Andre Kurait <andrekurait@gmail.com>
Contributor
|
Thanks for addressing an actionable diagnostics gap. The underlying blank-summary behavior is still present on current main: Problems
Suggested changes
This is an automated hermes-sweeper review. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes the retry loop's
📝 Error:display showing a blank line when an exception has an empty string representation. Walks the traceback and surfaces the last frame instead.Motivation — real-world encounter
While running the agent against
bedrock/global.anthropic.claude-opus-4-7, the retry loop logged:The
📝 Error:line was empty. That RuntimeError comes fromanthropic/lib/streaming/_messages.py:454when Bedrock returns anerrorevent as the first stream event — the SDK's accumulator rejects it without forwarding the payload. There are several other paths with the same symptom:raise AssertionError()(no message).raisewith no argument.raise RuntimeError()for flow control.In all cases, today the user sees
📝 Error:followed by nothing — forcing them to attach a debugger to learn where it came from.Fix
In
AIAgent._summarize_api_error(), whenstr(error).strip()is empty, format the last traceback frame:Now the display becomes:
…which is immediately actionable.
Which type of PR is this?
How has this been tested?
New test file
tests/agent/test_summarize_api_error.py:Covers:
AssertionError()— shows frame location + source line."<Type> (no message, no traceback)".Risk
not raw.strip()short-circuits immediately.tracebackis stdlib, imported lazily inside the guarded branch.getattr(error, "__traceback__", None)handles exceptions constructed but never raised.Related
Sibling PRs addressing Bedrock/Anthropic runtime robustness:
"max"reasoning effort level_fallback_chainon partially-constructed agentsA follow-up PR will intercept the specific
"Unexpected event order"RuntimeError at the Bedrock adapter layer and re-raise it with the discarded payload — this PR is the universal safety net that also catches the many other empty-error paths in the codebase.Checklist