Repository navigation
fix(agent-server): offload blocking subprocess calls in DesktopService.start() - #3810
Conversation
…e.start() DesktopService.start() is async and already launches the managed noVNC process via "await asyncio.create_subprocess_exec", but the surrounding readiness checks and the TigerVNC launch ran synchronously on the event loop: - is_running() (two calls, each a pgrep subprocess), - the Xvnc / novnc_proxy pgrep probes, - the vncserver launch (which has no timeout). Each blocks the server's event loop for the duration of the subprocess - the vncserver spawn in particular is unbounded - stalling other concurrent work while the desktop starts. Dispatch each synchronous call via asyncio.to_thread, consistent with the already-async noVNC launch. Adds a regression test asserting start() offloads its blocking subprocess work via asyncio.to_thread.
|
Verified locally — these VNC startup subprocess calls block the event loop during desktop boot; offloading them keeps the agent-server responsive. |
|
[Automatic Post]: It has been a while since there was any activity on this PR. @ly-wang19, are you still working on it? If so, please go ahead, if not then please request review, close it, or request that someone else follow up. This comment was created by an AI agent (OpenHands) on behalf of the repository maintainers. |
|
[Automatic Post]: I have assigned @enyst as a reviewer based on git blame information. Thanks in advance for the help! This comment was created by an AI agent (OpenHands) on behalf of the user. |
|
@OpenHands Take a look at this PR and the issue it's solving. You are an agent, you are free to install yourself software you need. Do a /codereview and post your feedback with gh api here. |
|
I'm on it! enyst can track my progress at all-hands.dev |
enyst
left a comment
There was a problem hiding this comment.
🟢 Good taste - This is a small, behavior-preserving fix for a real event-loop blocking problem.
The implementation keeps the existing subprocess commands and return-code handling intact while moving the blocking subprocess.run / is_running() paths out of the event loop with asyncio.to_thread. That is the right level of change: no new abstraction, no lifecycle rewrite, and no user-visible contract change.
Validation I ran locally on the PR head:
uv run pytest tests/agent_server/test_desktop_service.py::TestDesktopService::test_start_offloads_blocking_calls_to_thread -q
# 1 passed
uv run pytest tests/agent_server/test_desktop_service.py -q
# 27 passed
uv run ruff check openhands-agent-server/openhands/agent_server/desktop_service.py tests/agent_server/test_desktop_service.py
# All checks passed!
uv run ruff format --check openhands-agent-server/openhands/agent_server/desktop_service.py tests/agent_server/test_desktop_service.py
# 2 files already formatted
[RISK ASSESSMENT]
- [Overall PR]
⚠️ Risk Assessment: 🟢 LOW
The blast radius is limited to DesktopService.start() and a focused regression test. It does not change public APIs, dependencies, security-sensitive code, or the actual desktop startup commands. The main operational caveat remains pre-existing: vncserver can still run unbounded, but it no longer blocks the agent-server event loop while it does so.
VERDICT:
✅ Worth merging: Core logic is sound and the targeted regression coverage catches the important failure mode.
KEY INSIGHT:
The PR fixes the bad async boundary without redesigning the desktop lifecycle, which is exactly the pragmatic shape this bug needs.
This review was created by an AI agent (OpenHands) on behalf of the user.
|
Done — I reviewed PR #3810 and submitted an approval via the GitHub REST API: Validation run locally on the PR head:
Workspace is clean. |
|
Thank you for this! |
HUMAN:
Verified locally — these VNC startup subprocess calls block the event loop during desktop boot; offloading them keeps the agent-server responsive.
AGENT:
Why
DesktopService.start()(openhands-agent-server) is anasync def, and it already launches the long-running noVNC proxy correctly viaawait asyncio.create_subprocess_exec(...). But the surrounding steps still ran synchronously on the event loop:is_running()— called at entry and at the final health check; each invocation runs apgrepsubprocess;Xvncandnovnc_proxyreadinesspgrepprobes;vncserverlaunch, which is passed notimeout(unbounded).While the desktop starts, these calls block the agent server's event loop and stall every other concurrent task. The
vncserverspawn is the worst case since it has no timeout.Summary
subprocess.run(...)calls and theself.is_running()calls insidestart()throughasyncio.to_thread(...), matching the already-async noVNC launch. Same commands, same return-code handling — only the event loop is no longer blocked.test_start_offloads_blocking_calls_to_thread) assertingstart()routes its blockingsubprocess.runwork throughasyncio.to_thread.Evidence
Commands run from the repo root:
Red→green proof the new test guards the fix:
uv run ruff checkandruff format --checkare clean on both changed files. The change is behavior-preserving (the executed commands and their semantics are unchanged), so the existing 26DesktopServicetests pass unmodified. Full VNC end-to-end startup needs a host withvncserver/novncinstalled and is not reproducible here; the change is a mechanical, semantics-preserving offload of already-existing calls.How to Test
From the repo root:
The targeted test passes with this change. To confirm it actually guards the fix, revert just the source file and re-run — it goes red:
A full VNC end-to-end boot needs a host with
vncserver/novncinstalled and isn't reproducible in CI; this change is a semantics-preserving offload of already-existing subprocess calls, so the full 27-testDesktopServicesuite passes unmodified.