Repository navigation
fix(agent-server): stop bridging to a crashed Canvas backend - #5920
Conversation
ready_endpoint trusted the stored 'ready' state, which only the F28 status/start/stop routes reconcile, so the bridge kept dialing a backend whose process had exited and answered 502 with the Docker-runtime proxy's 'Conversation container unreachable'. ready_endpoint now also requires a live process, so the bridge answers 503 'Canvas App backend is not ready' right after a crash, and a live backend that refuses the connection answers 502 'Canvas App backend unreachable'. The F29 map bullet backend-crash-detected drops its known-bug marker. Fixes #5912 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014MKndVj7XWvRQmvW9w2bDg
REST API breakage checks (OpenAPI) — ✅ PASSEDResult: ✅ PASSED |
Coverage Report •
|
|||||||||||||||||||||||||
all-hands-bot
left a comment
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
Scope: this is Agent Server Python behavior (Canvas App backend lifecycle and the /app-backends bridge), which this repository owns; no cross-repo move is warranted. The linked issue #5912 is open with bug, priority:low, ready-for-dev, and its acceptance criteria are addressed by the current head.
Findings: no material correctness, security, compatibility, or acceptance-criterion defect.
What I verified on 0ee038dd61abcfc94798c92ad1c5224d8b155ed2:
- Core fix.
CanvasExtensionBackendManager.ready_endpoint(canvas_extensions/backend.py:814-824) now returnsNonewhenruntime.process is Noneorruntime.process.returncode is not None, so all three bridge consumers — the HTTP proxy, the WebSocket bridge, and the session bootstrap, which all route through_ready_endpoint(canvas_extensions/bridge.py:346-364) — answer503 Canvas App backend is not readyfor a crashed backend without a prior status poll. The storedruntime.stateis deliberately left alone (reconciled later bystatus()/start()/stop()), and the added comment states that trade-off accurately. - Error rename.
proxy_app_backend_http(canvas_extensions/bridge.py:465-484) renames only the connection-level502whose__cause__is anhttpx.HTTPError. I confirmed againstdocker_runtime/proxy.py:145-161that the redirect502raises with no__cause__, and the Docker-runtime path is a separate caller (docker_runtime/routers.py:102), so both keep their existing wording. - Base-vs-head behavior. I ran the two new tests against a worktree of
origin/main(6e7a853) and against this head.test_ready_endpoint_closes_when_ready_backend_exitsfails on base exactly atassert manager.ready_endpoint(...) is None(test line 201) and passes on head;test_unreachable_backend_error_names_the_canvas_backendfails on base on the detail string and passes on head. - Existing suite and CI.
uv run pytest -q tests/agent_server/canvas_extensions tests/agent_server/test_canvas_extensions_router.pyfails 11 backend tests in this sandbox, but they fail identically on base and the cause is environmental: the test fixtures use a#!/usr/bin/python3shebang and this container has no/usr/bin/python3. Patching the fixture interpreter at runtime makes the new test pass, so the failures are not attributable to this change.uv run pre-commit run --files <changed files>passes (ruff, pyright, import-dependency, etc.), and all check runs for this head aresuccess(includingRun tests,Agent Server,Pre-commit checks,REST API breakage checks). - Live evidence. For this runtime-lifecycle bug the PR supplies authentic before/after evidence via the
verify-agent-servermap recipe (F29.backend-crash-detected:xfailon base,xpasson head, andpassafter the# bugmarker is dropped), which satisfies the live-evidence checkpoint rather than relying on constructed test state alone. The F29 doc prose and Gotchas line were updated consistently with the new behavior.
The httpx import is already an established Agent Server dependency (docker_runtime/proxy.py imports it) and is pulled in transitively via openhands-sdk, so the new direct import introduces no packaging change.
No inline comments: no actionable findings.
✅ APPROVED
HUMAN:
This PR proposes a fix for a bug uncovered during the first full agentic run of
verify-agent-server.AGENT:
I'm an AI agent (Claude Code) helping Engel Nyst (@enyst) with project maintenance.
Requested by Engel · project thread
Decision needed
ready_endpointalso requires the backend process to be alive (returncode is None), so the bridge answers503 Canvas App backend is not readyright after a crash. The stored state staysreadyuntil the next F28 status/start/stop call reportsunhealthyand reaps the process group; I keptready_endpointsynchronous and side-effect free rather than mutating state from a read path. Alternative: a per-backend watcher task that awaitsprocess.wait()and flips the state tounhealthy(and reaps) on exit, soGET .../backendwould also be accurate without a poll; more moving parts and a new background task to cancel on stop/shutdown.502with detailCanvas App backend unreachable(only connection-levelhttpxfailures are renamed; the redirect 502 and the Docker runtime proxy's own message are unchanged). Alternative: answer503 Canvas App backend is not readythere too, which hides the difference between "not running" and "running but not answering".Why
When a ready Canvas App backend's process died, the app-backend bridge kept dialing its dead port until someone polled the backend's status: proxied requests answered
502 Conversation container unreachable(the Docker runtime proxy's wording, naming a container that does not exist here) and new session bootstraps still succeeded.Summary
CanvasExtensionBackendManager.ready_endpointreturnsNoneonce the backend process has exited, so the HTTP proxy, WebSocket bridge and bootstrap answer 503 not ready without a status poll.proxy_app_backend_httprenames a connection failure to502 Canvas App backend unreachable.F29.backend-crash-detecteddrops its# bugmarker; its prose and the Gotchas line now describe the fixed behaviour.Issue Number
Fixes #5912
How to Test
test_ready_endpoint_closes_when_ready_backend_exits(backend exits via/exit; with no status poll the stored state is stillreadybutready_endpointisNone; status then reportsunhealthy, restart works) andtest_unreachable_backend_error_names_the_canvas_backend. Both fail on main's code and pass here.uv run pytest -q tests/agent_server/canvas_extensions tests/agent_server/test_canvas_extensions_router.py: 188 passed, 1 failed. The failure,test_exited_leader_descendant_does_not_block_recovery[status], also fails in this sandbox with main'sbackend.py(it is not touched by this change); CI is the reference.AGENT_SERVER_VERIFY_HOMEisolated:--checkoutat origin/main 6e7a853):control-agent-server map run --file F29 --only F29.backend-crash-detected --fresh --repeat 2->xfail,xfail.xpass,xpass.map checkok (34 files, 935 ids, no problems);map run --file F29 --only F29.backend-lifecycle-revokes,F29.backend-crash-detected --fresh-> allpass.uv run pre-commit run --files <changed files>: all hooks pass.Video/Screenshots
n/a
Type
Notes
Found by the first full agentic run of verify-agent-server (umbrella #5653, listed there as
F29.backend-lifecycle-revokes; the crash case has its own bulletF29.backend-crash-detected). Other umbrella fixes touch the bridge's proxy request body and response headers; this PR only wraps theproxy_httpcall inproxy_app_backend_http.🤖 Generated with Claude Code
https://claude.ai/code/session_014MKndVj7XWvRQmvW9w2bDg
Generated by Claude Code
🐳 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-jdkpython-node-runtimepython-node-runtimepython-node-runtimegolang: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:0ee038d-pythonRun
All tags pushed for this build
About Multi-Architecture Support
0ee038d-python) is a multi-arch manifest supporting both amd64 and arm640ee038d-python-amd64) are also available if needed