Repository navigation
Description
I'm an AI agent based on Opus 5.5, helping Engel Nyst (@enyst) with project maintenance.
Is there an existing issue for the same bug?
- I have searched existing issues and this is not a duplicate.
Bug Description
When a conversation run fails, EventService._run_and_publish logs it with logger.exception(...) on the server's event loop. With default console logging (Rich, LOG_RICH_TRACEBACKS defaults to true), rendering the chained traceback of an ordinary LLM connection error (about 1,000 lines) takes about 5 s, and every request, socket and run on the server waits meanwhile. Any server without LOG_JSON=true (e.g. run from a checkout) hits this on every failed run.
Expected Behavior
GET /alive keeps answering 200 in about 100 ms (never over 1.5 s) while a run fails, and the ConversationErrorEvent reaches socket subscribers without delay.
Actual Behavior
A request sent while the failure is logged waits 4.8-6.6 s before its 200. The ConversationErrorEvent is already stored and the conversation ends execution_status: "error", but the socket's error frames arrive late by the same amount. With LOG_RICH_TRACEBACKS=false or LOG_JSON=true the slowest probe is under 200 ms.
Steps to Reproduce
- With
LOG_JSON,CIandGITHUB_ACTIONSunset and no session API key:uv run agent-server --host 127.0.0.1 --port 8000 - Create a conversation whose LLM points at a closed port, and queue a message:
WS=$(mktemp -d) CID=$(curl -s -X POST localhost:8000/api/conversations -H 'Content-Type: application/json' \ -d '{"agent":{"llm":{"model":"openai/offline","api_key":"x","base_url":"http://127.0.0.1:9/v1","num_retries":0},"tools":[]},"workspace":{"working_dir":"'"$WS"'"}}' | jq -r .id) curl -s -X POST localhost:8000/api/conversations/$CID/events -H 'Content-Type: application/json' \ -d '{"role":"user","content":[{"type":"text","text":"hi"}],"run":false}'
- Run it and probe
/alive:One probe takes about 5 s while stderr prints the traceback for "Error during conversation run".curl -s -X POST localhost:8000/api/conversations/$CID/run for i in $(seq 30); do curl -s -o /dev/null -w '%{http_code} %{time_total}\n' localhost:8000/alive; done
- Restart with
LOG_RICH_TRACEBACKS=falseand repeat: every probe is well under 200 ms.
With the verify-agent-server skill (#5621): control-agent-server map run --file F05 --only F05.run-error-responsive --fresh reports the known-bug bullet as an expected failure while the bug lasts.
Acceptance Criteria
- With default console logging, no
/aliveprobe takes over 1.5 s while a run fails, and socket error frames are not delayed. - The run failure is still logged with enough detail to diagnose it.
- A regression test fails a run on a live server and bounds the latency of a concurrent request.
- The map bullet
F05.run-error-responsivepasses; its known-bug marker is removed.
Installation Method
uv sync in a checkout of main
Version
main at 2804c12
Additional Context
openhands-agent-server/openhands/agent_server/event_service.py:1546:logger.exception("Error during conversation run")in_run_and_publish, a task on the server loop. Here the exception is aConversationRunErrorchained through litellm, openai, httpx and httpcore errors.openhands-sdk/openhands/sdk/logger/logger.py:45defaultsLOG_RICH_TRACEBACKSto true; lines 134-137 installRichHandler(rich_tracebacks=...)as the root console handler unlessLOG_JSONor CI is set.RichHandler.emitrenders the whole chain with source context synchronously in the caller, here the loop.LocalConversation.arunhas already stored theConversationErrorEventand setERRORbefore raising (openhands-sdk/openhands/sdk/conversation/impl/local_conversation.py:2582-2608), so only the log line and everything else on the loop are delayed.
Suggested fix: keep console rendering off the loop, either with a QueueHandler/QueueListener around the console handler in setup_logging (covers every logger.exception on the loop) or, here, a one-line error (the event already has code and detail) with the traceback rendered via asyncio.to_thread or at DEBUG.
Related: #5373 (same mechanism in sockets.py, a cyclic chain whose render never returns). Its draft fix #5489 bounds traversal but still renders on the loop, so a finite chain like this one would still stall.
OpenHands AI triage
The following comments and acceptance criteria were added by the OpenHands AI agent.
Triage
Ownership: this repository owns the Agent Server and SDK, and the fix is here. The
reported defect is real and reproduced in the product: while _run_and_publish
logs a failed run via logger.exception(...) on the server event loop
(openhands-agent-server/openhands/agent_server/event_service.py:1546), the
default root RichHandler (installed when neither LOG_JSON nor CI is set,
LOG_RICH_TRACEBACKS defaulting true — openhands-sdk/openhands/sdk/logger/logger.py)
renders the full chained traceback synchronously in the caller, so /alive and
socket delivery stall 4.8-6.6 s on every failed run. Scope: stop that one log
call from blocking the loop while keeping enough diagnostic detail to find the
cause. Non-goals: reworking the rest of the run-error path; changing the
ConversationErrorEvent/status behavior (already correct before the raise);
changing default handling of unbounded/cyclic tracebacks (that is the separate
#5373/#5489 mechanism, which bounds traversal but still renders on the loop).
The fix approach is deliberately not prescribed: two supported shapes (a
QueueHandler/QueueListener around the console handler, or a bounded inline
message with off-loop/DEBUG traceback) both satisfy the criteria.
Acceptance Criteria
- With default console logging (
LOG_JSONunset,LOG_RICH_TRACEBACKSunset/true), a run fails on a live agent server pointed at an unreachable LLM endpoint and every concurrentGET /aliveprobe returns 200 within 1.5 s; no probe stalls on the run-error log. - The same scenario with
LOG_RICH_TRACEBACKS=falseorLOG_JSON=trueremains under the same bound. - The
ConversationErrorEventfor the failed run reaches subscribers without the log-induced delay (conversation endsexecution_status: "error"). - The run failure is still recorded with the exception type and message at normal log level, and the full traceback remains retrievable off the loop (or at DEBUG) for diagnosis; with
LOG_TO_FILE=truethe file handler still receives the record. - A regression test fails a run on a live server and bounds the latency of a concurrent request, so the stall cannot return unnoticed.
- The verify-agent-server map bullet
F05.run-error-responsivepasses and its known-bug marker is removed. - The fix does not alter the OpenAPI/REST contract or serialized event shapes and stays compatible with
LOG_JSON/CI JSON logging.
Activity
xxwtiancai commentedon Oct 11, 2026
I’m working on this with Codex assistance. I’ll first reproduce the failed-run stall on a real CLI server with default Rich and access logging, using an unreachable local provider. The intended scope is the run-error log call: retain useful ERROR diagnostics and a DEBUG traceback, with HTTP/WebSocket responsiveness and shutdown coverage. I’ll leave the cyclic-traceback work in #5489 and the shared logger architecture unchanged.
enyst commentedon Oct 11, 2026
Related to #5373: both involve Rich traceback rendering synchronously on the server event loop, but the triggers and acceptance cases differ.
This issue reproduces an ordinary finite LLM error chain taking about 5 seconds to render in
_run_and_publish. #5373 covers a cyclic/pathological chain on the events-WebSocket error path that never returns and grows memory. Bounding cyclic traversal alone does not address the finite-chain latency here.Keeping both reports open with this cross-link; they can share work on the logging path, but both reproductions should remain covered. The relationship is also tracked in #5653.
Posted by Codex on behalf of @enyst.
enyst commentedon Oct 13, 2026
I'm an AI agent (Claude Code) helping Engel Nyst (@enyst) with project maintenance.
An independent fix is in #5780. At the maintainer's request, it was written for comparison with #5709 without reading it. Notes on the triage points:
Decision needed (fix shape). The triage leaves the approach open, so a maintainer should choose. #5780 logs the failure at ERROR with the traceback formatted by
traceback.format_exceptionas plain text in the message, and noexc_info. That keeps the full chain at the normal level, including inLOG_JSONproduction logs and withLOG_TO_FILE(same record, same level). It costs milliseconds instead of seconds. Trade-offs: the console shows a plain traceback instead of Rich's panel, and in JSON logs the traceback is inmessageinstead ofexc_info.Alternatives: a one-line ERROR plus a DEBUG traceback (keeps the
exc_infofield, but production INFO logs lose the traceback), or aQueueHandler/QueueListenerinsetup_logging(keeps Rich output for every log call, but changes logging for all SDK users).One finding that rules out the simplest variant: moving
logger.exceptionto a worker thread does not fix it. I measured about 5 s probes on a live server, because every log call on the loop (e.g. the access log) waits for the console handler's lock while the thread renders.Answers to the acceptance criteria:
/aliveor events-count probe while the run failed was 4540 and 4791 ms on main, and 142 and 93 ms with the fix.LOG_JSON/LOG_RICH_TRACEBACKS=falsewere already fast, and the change only makes their formatting cheaper.ConversationErrorEventand theerrorstatus are unchanged, and the final state update is no longer held up by the log call.exc_infoand carries the whole chain. The live latency bound is the map bulletF05.run-error-responsive, whose known-bug marker is removed in the same PR (Add verify-agent-server: an executable feature map and control CLI for the Agent Server API #5621 is merged). It now passes.sockets.py(agent-server: a logging call can wedge the event loop and amplify memory (rich traceback render) #5373) is left alone, as scoped.Generated by Claude Code
xxwtiancai commentedon Oct 13, 2026
Thanks @enyst. Keeping the full traceback available at the normal production log level makes sense. #5709 followed the DEBUG-traceback option in the issue, but #5780 avoids needing to enable DEBUG to diagnose a failed run.
There may be useful test coverage to carry over from #5709. Its live-server regression test covers Rich, plain, and JSON logging, concurrent /alive and /server_info requests, WebSocket error-delivery latency, terminal ERROR state, and file diagnostics.
Would you be open to combining that coverage with #5780? The test checks externally visible behavior rather than the DEBUG implementation, although I have not run it against #5780 yet. That seems more useful than maintaining two competing fixes.