Skip to content

fix(agent-server): propagate out-of-band run failures as ConversationErrorEvent (#16686) - #4535

Merged
VascoSch92 merged 5 commits into
mainfrom
fix/16686-propagate-backstop-llm-error
Aug 20, 2026
Merged

VascoSch92 merged 5 commits into
mainfrom
fix/16686-propagate-backstop-llm-error

Conversation

@VascoSch92

@VascoSch92 VascoSch92 commented Aug 18, 2026 •

Copy link
Copy Markdown
Member

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 a
typed ConversationErrorEvent (with code/detail) for exceptions raised
inside their try-block, and the agent-canvas frontend already renders that event
(store + ErrorMessageBanner, shipped in v1.14.0). The gap is failures that
escape outside that try-block — e.g. a cold-start error in init_state via
_ensure_agent_ready(). Those land in EventService._run_and_publish's
backstop, which only forced the status to ERROR and emitted no typed error
event. The frontend then has nothing but a bare ERROR status to show → the
generic "error" from the issue.

Summary

  • Run backstop (agent-server): EventService._run_and_publish's exception
    backstop 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 WebSocket
    subscribers so the UI can render the detail. Skips emission when the exception
    is a ConversationRunError, since run()/arun() already emitted their own
    (possibly agent-supplied) typed event for that path — avoids duplicating the
    error in the UI.
  • Auto-title generation: generate_title_with_llm previously swallowed LLM
    failures with only a logger.warning (the "Error generating conversation
    title with LLM" line in the issue). The SDK title utils gain a pure, opt-in
    on_error hook; the agent-server's AutoTitleSubscriber (the path that
    actually auto-titles, via _generate_title_traced) passes a callback that
    reuses EventService._publish_error_event_sync — the same helper the
    run-loop backstop uses — to emit a ConversationErrorEvent with 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 a
    plain RuntimeError (the out-of-band / cold-start path) now produces exactly
    one ConversationErrorEvent through _on_event, with
    code == "RuntimeError", the exception message as detail, and
    source == "environment"; status still flips to ERROR.
  • test_run_conversation_run_error_does_not_double_emit — a run that raises
    ConversationRunError produces no backstop event (no duplication).
  • test_generate_title_with_llm_invokes_on_error
    (tests/sdk/conversation/test_generate_title.py) — the util reports the
    swallowed LLM error via on_error while still returning None (fallback).
  • test_autotitle_surfaces_llm_error_to_ui
    (tests/agent_server/test_conversation_service.py) — when the title LLM call
    fails, AutoTitleSubscriber surfaces it through
    EventService._publish_error_event_sync; auto-titling stays non-fatal.

Run:

uv run pytest tests/agent_server/test_event_service.py tests/agent_server/test_conversation_service.py -k "run_exception or double_emit or autotitle" tests/sdk/conversation/test_generate_title.py -q

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 existing
title-fallback tests, confirming behavior for the unchanged paths. ruff check
and ruff format --check are 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 ErrorMessageBanner renders the emitted event unchanged.

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

Notes

  • The title-generation error is surfaced as a ConversationErrorEvent (the
    event 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

Variant Architectures Base Image Docs / Tags
java amd64, arm64 eclipse-temurin:17-jdk Link
python amd64, arm64 nikolaik/python-nodejs:python3.13-nodejs22-slim Link
golang amd64, arm64 golang:1.21-bookworm Link

Pull (multi-arch manifest)

# Each variant is a multi-arch manifest supporting both amd64 and arm64
docker pull ghcr.io/openhands/agent-server:e9c6587-python

Run

docker run -it --rm \
  -p 8000:8000 \
  --name agent-server-e9c6587-python \
  ghcr.io/openhands/agent-server:e9c6587-python

All tags pushed for this build

ghcr.io/openhands/agent-server:e9c6587-golang-amd64
ghcr.io/openhands/agent-server:e9c6587ed7f6b8e31f30f9b2714faaf7e4c0ddb7-golang-amd64
ghcr.io/openhands/agent-server:fix-16686-propagate-backstop-llm-error-golang-amd64
ghcr.io/openhands/agent-server:e9c6587-golang_tag_1.21-bookworm-amd64
ghcr.io/openhands/agent-server:e9c6587-golang-arm64
ghcr.io/openhands/agent-server:e9c6587ed7f6b8e31f30f9b2714faaf7e4c0ddb7-golang-arm64
ghcr.io/openhands/agent-server:fix-16686-propagate-backstop-llm-error-golang-arm64
ghcr.io/openhands/agent-server:e9c6587-golang_tag_1.21-bookworm-arm64
ghcr.io/openhands/agent-server:e9c6587-java-amd64
ghcr.io/openhands/agent-server:e9c6587ed7f6b8e31f30f9b2714faaf7e4c0ddb7-java-amd64
ghcr.io/openhands/agent-server:fix-16686-propagate-backstop-llm-error-java-amd64
ghcr.io/openhands/agent-server:e9c6587-eclipse-temurin_tag_17-jdk-amd64
ghcr.io/openhands/agent-server:e9c6587-java-arm64
ghcr.io/openhands/agent-server:e9c6587ed7f6b8e31f30f9b2714faaf7e4c0ddb7-java-arm64
ghcr.io/openhands/agent-server:fix-16686-propagate-backstop-llm-error-java-arm64
ghcr.io/openhands/agent-server:e9c6587-eclipse-temurin_tag_17-jdk-arm64
ghcr.io/openhands/agent-server:e9c6587-python-amd64
ghcr.io/openhands/agent-server:e9c6587ed7f6b8e31f30f9b2714faaf7e4c0ddb7-python-amd64
ghcr.io/openhands/agent-server:fix-16686-propagate-backstop-llm-error-python-amd64
ghcr.io/openhands/agent-server:e9c6587-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim-amd64
ghcr.io/openhands/agent-server:e9c6587-python-arm64
ghcr.io/openhands/agent-server:e9c6587ed7f6b8e31f30f9b2714faaf7e4c0ddb7-python-arm64
ghcr.io/openhands/agent-server:fix-16686-propagate-backstop-llm-error-python-arm64
ghcr.io/openhands/agent-server:e9c6587-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim-arm64
ghcr.io/openhands/agent-server:e9c6587-golang
ghcr.io/openhands/agent-server:e9c6587ed7f6b8e31f30f9b2714faaf7e4c0ddb7-golang
ghcr.io/openhands/agent-server:fix-16686-propagate-backstop-llm-error-golang
ghcr.io/openhands/agent-server:e9c6587-golang_tag_1.21-bookworm
ghcr.io/openhands/agent-server:e9c6587-java
ghcr.io/openhands/agent-server:e9c6587ed7f6b8e31f30f9b2714faaf7e4c0ddb7-java
ghcr.io/openhands/agent-server:fix-16686-propagate-backstop-llm-error-java
ghcr.io/openhands/agent-server:e9c6587-eclipse-temurin_tag_17-jdk
ghcr.io/openhands/agent-server:e9c6587-python
ghcr.io/openhands/agent-server:e9c6587ed7f6b8e31f30f9b2714faaf7e4c0ddb7-python
ghcr.io/openhands/agent-server:fix-16686-propagate-backstop-llm-error-python
ghcr.io/openhands/agent-server:e9c6587-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim

About Multi-Architecture Support

  • Each variant tag (e.g., e9c6587-python) is a multi-arch manifest supporting both amd64 and arm64
  • Docker automatically pulls the correct architecture for your platform
  • Individual architecture tags (e.g., e9c6587-python-amd64) are also available if needed

@github-actions

github-actions Bot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Python API breakage checks — ✅ PASSED

Result: ✅ PASSED

Action log

@github-actions

github-actions Bot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

REST API breakage checks (OpenAPI) — ✅ PASSED

Result: ✅ PASSED

Action log

@github-actions

github-actions Bot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Coverage

Coverage Report •
FileStmtsMissCoverMissing
openhands-agent-server/openhands/agent_server
   conversation_service.py114612689%181–182, 191, 218–219, 223–224, 229, 332–333, 336–337, 349–350, 364, 537–538, 599, 663, 685, 692–693, 776, 852, 903–904, 911, 943–944, 960, 991, 995, 1012, 1024–1027, 1033–1034, 1043, 1045, 1100, 1106–1107, 1111–1112, 1120, 1147, 1153, 1247, 1253, 1258, 1264, 1272–1273, 1282–1285, 1294, 1306, 1314, 1343, 1349–1350, 1353–1355, 1382, 1434, 1527–1528, 1599, 1654–1656, 1658–1659, 1662–1663, 1683, 1769–1770, 1801–1803, 1806–1807, 1811–1813, 1816–1817, 1821–1823, 1826–1827, 1856, 1865, 1908, 1918–1920, 1980, 1983, 2010, 2020, 2025–2028, 2042, 2053, 2065–2066, 2098, 2192, 2249, 2307, 2322–2323, 2455, 2701, 2754, 2757
   event_service.py88212786%169–170, 292, 296, 301, 328, 335, 369, 372–373, 377–378, 389, 395, 405–409, 412–415, 486, 507–508, 582, 636, 656, 683, 707–708, 712, 720, 723, 739, 771, 782, 789, 795, 860–861, 939, 969, 972, 1010, 1050, 1071, 1206, 1326–1329, 1333, 1362, 1366, 1373, 1387, 1402, 1449–1451, 1531, 1556, 1562, 1564, 1574, 1576, 1583, 1593, 1595–1596, 1600, 1614–1619, 1621, 1648, 1653–1659, 1663–1666, 1674–1677, 1719–1721, 1775–1776, 1778–1785, 1787–1788, 1797–1798, 1800–1801, 1808–1809, 1811–1812, 1823, 1848, 1854, 1860, 1869–1870, 1892, 1902
openhands-sdk/openhands/sdk/conversation
   title_utils.py60297%35, 83
TOTAL41372758582% 

…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.
@VascoSch92
VascoSch92 force-pushed the fix/16686-propagate-backstop-llm-error branch from 9e80959 to 3dfdae0 Compare August 19, 2026 05:09
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.
@VascoSch92
VascoSch92 marked this pull request as ready for review August 19, 2026 09:23
@all-hands-bot

Copy link
Copy Markdown
Collaborator

🚦 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 @all-hands-bot as a reviewer to have it reviewed regardless of CI status.)

This is an automated check - no AI was used to generate this comment.

all-hands-bot commented Aug 19, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Review complete.

This review was performed through OpenHands Cloud Automation. You can log in and view the conversation here.

@all-hands-bot

Copy link
Copy Markdown
Collaborator

🤖 OpenHands is reviewing this PR.

Head commit: 007b2a574d82aef3524488fea17d5bb009d3e803
View the conversation: https://oss-agent-canvas.ngrok.dev/conversations/798d3277-4c00-4a95-8414-14ee0ffcbdb1

This comment was posted by an AI agent (OpenHands).

@all-hands-bot all-hands-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 have None defaults 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:

  1. Add a .agents/skills/custom-codereview-guide.md file to your branch (or edit it if one already exists) with the /codereview trigger and the context the reviewer is missing. See the customization docs for the required frontmatter format.
  2. Re-request a review - the reviewer reads guidelines from the PR branch, so your changes take effect immediately.
  3. 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 /iterate to 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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

@juanmichelini juanmichelini left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@VascoSch92
VascoSch92 enabled auto-merge (squash) August 20, 2026 11:42
@github-actions

Copy link
Copy Markdown
Contributor

📁 PR Artifacts Notice

This PR contains a .pr/ directory with temporary PR-specific documents. The directory will be automatically removed when the PR is approved.

@VascoSch92
VascoSch92 merged commit 1de2e6d into main Aug 20, 2026
28 of 31 checks passed
@VascoSch92
VascoSch92 deleted the fix/16686-propagate-backstop-llm-error branch August 20, 2026 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants