Repository navigation
fix(agent-server): propagate out-of-band run failures as ConversationErrorEvent (#16686) - #4535
Conversation
Python API breakage checks — ✅ PASSEDResult: ✅ PASSED |
REST API breakage checks (OpenAPI) — ✅ PASSEDResult: ✅ PASSED |
Coverage Report •
|
|||||||||||||||||||||||||||||||||||
…ilures Failures raised outside run()/arun()'s try-block (e.g. a cold-start error in init_state) never reach the SDK's own ConversationErrorEvent emission, so the _run_and_publish backstop only forced ERROR status and the frontend showed a bare "error" with no detail (issue #16686). The backstop now emits a ConversationErrorEvent carrying the exception type and message, which _on_event() both persists and fans out to WebSocket subscribers so the UI can render the detail. ConversationRunError is skipped because run()/arun() already emitted its own typed event for that path.
9e80959 to
3dfdae0
Compare
generate_title_with_llm swallowed LLM failures with only a logger.warning, so a bad model/credential surfaced during auto-title generation was invisible to the UI (the "Error generating conversation title with LLM" line in issue #16686). Thread an optional on_error callback through the title utils and have LocalConversation.generate_title emit a ConversationErrorEvent with the exception detail. Title generation stays non-fatal — it still falls back to truncation and does not change the conversation's execution status — but the error detail now reaches clients. All existing callers pass no callback and behave exactly as before.
…versation Addresses review: emitting a ConversationErrorEvent on title-generation failure does not belong in LocalConversation.generate_title, a general SDK method used by direct/CLI callers. It also missed the actual auto-title path, which runs via AutoTitleSubscriber -> _generate_title_traced, not LocalConversation. - Revert the LocalConversation.generate_title change; keep only the pure, opt-in on_error hook on the title utils. - Wire on_error through _generate_title_traced and have AutoTitleSubscriber surface the failure by reusing EventService._publish_error_event_sync (the same helper the run-loop backstop uses, renamed from _publish_backstop_error_event_sync now that it serves both paths). Net effect for the UI is unchanged; the SDK footprint shrinks to the util hook.
|
🚦 CI is currently failing on this PR's latest commit. Please fix the failing checks before OpenHands reviews it - this is re-checked automatically once you push a new commit. (A maintainer can also request This is an automated check - no AI was used to generate this comment. |
|
✅ Review complete. This review was performed through OpenHands Cloud Automation. You can log in and view the conversation here. |
|
🤖 OpenHands is reviewing this PR. Head commit: This comment was posted by an AI agent (OpenHands). |
all-hands-bot
left a comment
There was a problem hiding this comment.
🟡 Acceptable — clean fix for a real production pain point.
The core logic is sound: the run-loop backstop now emits a ConversationErrorEvent for out-of-band failures, and generate_title_with_llm gets an opt-in on_error hook that the agent-server uses to surface title-LLM failures. Both paths are additive and backward-compatible. The test suite covers the key invariants (no double-emission on ConversationRunError, correct event fields, the on_error callback fires). Two minor comment issues are called out inline.
[RISK ASSESSMENT]
- [Overall PR]
⚠️ Risk Assessment: 🟢 LOW
Backend-only; all new parameters haveNonedefaults so existing call-sites are unaffected. The run-loop change adds one conditional emit before the already-present_mark_error_status_sync, with a best-effort wrapper that swallows its own failures. No API surface changes.
VERDICT:
✅ Worth merging — closes a real observability gap with minimal, well-tested code.
KEY INSIGHT:
The ConversationRunError carve-out in the backstop is the most subtle part; the existing tests that verify it don't double-emit are exactly the right regression proof for future refactors.
This review was generated by an AI agent (OpenHands) on behalf of the user through OpenHands Automation. View conversation
Improve this review? If any feedback above seems incorrect or irrelevant to this repository, you can teach the reviewer to do better:
- Add a
.agents/skills/custom-codereview-guide.mdfile to your branch (or edit it if one already exists) with the/codereviewtrigger and the context the reviewer is missing. See the customization docs for the required frontmatter format.- Re-request a review - the reviewer reads guidelines from the PR branch, so your changes take effect immediately.
- When your PR is merged, the guideline file goes through normal code review by repository maintainers.
Resolve with AI? Install the iterate skill in your agent and run
/iterateto automatically drive this PR through CI, review, and QA until it's merge-ready.Was this review helpful? React with 👍 or 👎 to give feedback.
|
|
||
| except Exception as e: | ||
| logger.warning(f"Error generating conversation title with LLM: {e}") | ||
| # Non-fatal (we fall back to truncation), but let callers surface the |
There was a problem hiding this comment.
🟡 Suggestion: This comment restates information already in the docstring (on_error: Optional callback invoked with the exception when the LLM call fails) and narrates the PR change history via the issue reference. The parameter name and the guard if on_error is not None are self-explanatory. Consider dropping these two lines — the docstring is the right place for the 'why'.
| if title_llm is None: | ||
| title_llm = conversation.agent.llm if conversation else None | ||
|
|
||
| # Surface an LLM failure during auto-titling to the UI (issue #16686); |
There was a problem hiding this comment.
🟡 Suggestion: Same pattern — the comment restates what the function name _on_title_error and the surrounding AutoTitleSubscriber context already make clear, and pulls in an issue reference that belongs in the commit message. The two-line comment block can be dropped without loss of clarity.
|
📁 PR Artifacts Notice This PR contains a |
HUMAN:
Propagate errors from agent-server.
AGENT:
Why
OpenHands/OpenHands#16686: when an LLM call fails (e.g. Nebius + a non-existent
deepseek-ai/DeepSeek-V3, which raises a 404), the UI shows only a generic"error" while the real detail lives only in the server logs, leaving users with
no way to understand or fix the misconfiguration.
Tracing the path: the SDK's
LocalConversation.run()/arun()already emit atyped
ConversationErrorEvent(withcode/detail) for exceptions raisedinside their try-block, and the agent-canvas frontend already renders that event
(store +
ErrorMessageBanner, shipped in v1.14.0). The gap is failures thatescape outside that try-block — e.g. a cold-start error in
init_statevia_ensure_agent_ready(). Those land inEventService._run_and_publish'sbackstop, which only forced the status to
ERRORand emitted no typed errorevent. The frontend then has nothing but a bare
ERRORstatus to show → thegeneric "error" from the issue.
Summary
EventService._run_and_publish's exceptionbackstop now emits a
ConversationErrorEvent(source="environment", code=type(exc).__name__, detail=str(exc))via
_on_event(), which both persists it and fans it out to WebSocketsubscribers so the UI can render the detail. Skips emission when the exception
is a
ConversationRunError, sincerun()/arun()already emitted their own(possibly agent-supplied) typed event for that path — avoids duplicating the
error in the UI.
generate_title_with_llmpreviously swallowed LLMfailures with only a
logger.warning(the "Error generating conversationtitle with LLM" line in the issue). The SDK title utils gain a pure, opt-in
on_errorhook; the agent-server'sAutoTitleSubscriber(the path thatactually auto-titles, via
_generate_title_traced) passes a callback thatreuses
EventService._publish_error_event_sync— the same helper therun-loop backstop uses — to emit a
ConversationErrorEventwith the detail.Auto-titling stays non-fatal (still falls back to truncation, execution status
untouched). The only SDK change is the opt-in util hook; all existing callers
pass no callback and are unchanged.
Issue Number
OpenHands/OpenHands#16686
How to Test
Automated (added, mirroring the existing backstop tests in
tests/agent_server/test_event_service.py):test_run_exception_emits_conversation_error_event— a run that raises aplain
RuntimeError(the out-of-band / cold-start path) now produces exactlyone
ConversationErrorEventthrough_on_event, withcode == "RuntimeError", the exception message asdetail, andsource == "environment"; status still flips toERROR.test_run_conversation_run_error_does_not_double_emit— a run that raisesConversationRunErrorproduces no backstop event (no duplication).test_generate_title_with_llm_invokes_on_error(
tests/sdk/conversation/test_generate_title.py) — the util reports theswallowed LLM error via
on_errorwhile still returningNone(fallback).test_autotitle_surfaces_llm_error_to_ui(
tests/agent_server/test_conversation_service.py) — when the title LLM callfails,
AutoTitleSubscribersurfaces it throughEventService._publish_error_event_sync; auto-titling stays non-fatal.Run:
Result: all pass — the new tests plus the pre-existing backstop tests
(
test_run_exception_forces_error_status/test_run_exception_preserves_existing_error_status) and the existingtitle-fallback tests, confirming behavior for the unchanged paths.
ruff checkand
ruff format --checkare clean on all changed files.End-to-end note: I could not run the live Nebius/DeepSeek-404 repro from this
environment (no provider credentials), so the runtime confirmation of which
path the reporter hit is still worth doing — open DevTools → WS inspector and
check whether a
"kind":"ConversationErrorEvent"frame arrives. If it does(in-loop failure), the SDK already handled it and the remaining work is
frontend-side; if it does not (out-of-band failure), this PR is the fix. Either
way this change is strictly additive: it closes the out-of-band hole and cannot
double-emit for the already-handled path.
Video/Screenshots
N/A — backend-only change; behavior is covered by the unit tests above. The
existing frontend
ErrorMessageBannerrenders the emitted event unchanged.Type
Notes
ConversationErrorEvent(theevent the FE already renders) even though it is non-fatal; auto-classification
maps e.g. a model-not-found to a config outcome. If a lighter, non-error
notification surface is preferred for transient title failures, that can be
swapped in without changing the callback plumbing.
🐳 Agent Server images for this PR — GHCR package, pull/run commands, and all pushed tags (click to expand)
• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server
Variants & Base Images
eclipse-temurin:17-jdknikolaik/python-nodejs:python3.13-nodejs22-slimgolang:1.21-bookwormPull (multi-arch manifest)
# Each variant is a multi-arch manifest supporting both amd64 and arm64 docker pull ghcr.io/openhands/agent-server:e9c6587-pythonRun
All tags pushed for this build
About Multi-Architecture Support
e9c6587-python) is a multi-arch manifest supporting both amd64 and arm64e9c6587-python-amd64) are also available if needed