Skip to content

fix(agent-server): stop bridging to a crashed Canvas backend - #5920

Merged
enyst merged 1 commit into
mainfrom
claude/umbrella-bug-fixes-tgz9ai-backend-crash-ready
Oct 14, 2026
Merged

enyst merged 1 commit into
mainfrom
claude/umbrella-bug-fixes-tgz9ai-backend-crash-ready

Conversation

@enyst

@enyst enyst commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

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

  1. How the bridge learns about a crash. Implemented: ready_endpoint also requires the backend process to be alive (returncode is None), so the bridge answers 503 Canvas App backend is not ready right after a crash. The stored state stays ready until the next F28 status/start/stop call reports unhealthy and reaps the process group; I kept ready_endpoint synchronous and side-effect free rather than mutating state from a read path. Alternative: a per-backend watcher task that awaits process.wait() and flips the state to unhealthy (and reaps) on exit, so GET .../backend would also be accurate without a poll; more moving parts and a new background task to cancel on stop/shutdown.
  2. Wording/status when a live backend refuses the connection. Implemented: 502 with detail Canvas App backend unreachable (only connection-level httpx failures are renamed; the redirect 502 and the Docker runtime proxy's own message are unchanged). Alternative: answer 503 Canvas App backend is not ready there 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_endpoint returns None once the backend process has exited, so the HTTP proxy, WebSocket bridge and bootstrap answer 503 not ready without a status poll.
  • proxy_app_backend_http renames a connection failure to 502 Canvas App backend unreachable.
  • F29 map: F29.backend-crash-detected drops its # bug marker; its prose and the Gotchas line now describe the fixed behaviour.

Issue Number

Fixes #5912

How to Test

  • New unit tests: test_ready_endpoint_closes_when_ready_backend_exits (backend exits via /exit; with no status poll the stored state is still ready but ready_endpoint is None; status then reports unhealthy, restart works) and test_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's backend.py (it is not touched by this change); CI is the reference.
  • Map proof with AGENT_SERVER_VERIFY_HOME isolated:
    • main (--checkout at origin/main 6e7a853): control-agent-server map run --file F29 --only F29.backend-crash-detected --fresh --repeat 2 -> xfail, xfail.
    • this branch: same command -> xpass, xpass.
    • after dropping the marker: map check ok (34 files, 935 ids, no problems); map run --file F29 --only F29.backend-lifecycle-revokes,F29.backend-crash-detected --fresh -> all pass.
  • uv run pre-commit run --files <changed files>: all hooks pass.

Video/Screenshots

n/a

Type

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

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 bullet F29.backend-crash-detected). Other umbrella fixes touch the bridge's proxy request body and response headers; this PR only wraps the proxy_http call in proxy_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

Variant Architectures Base Image Docs / Tags
java amd64, arm64 eclipse-temurin:17-jdk Link
python-slim amd64, arm64 python-node-runtime Link
python-minimal amd64, arm64 python-node-runtime Link
python amd64, arm64 python-node-runtime 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:0ee038d-python

Run

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

All tags pushed for this build

ghcr.io/openhands/agent-server:0ee038d-golang-amd64
ghcr.io/openhands/agent-server:0ee038dd61abcfc94798c92ad1c5224d8b155ed2-golang-amd64
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-backend-crash-ready-golang-amd64
ghcr.io/openhands/agent-server:0ee038d-golang_tag_1.21-bookworm-amd64
ghcr.io/openhands/agent-server:0ee038d-golang-arm64
ghcr.io/openhands/agent-server:0ee038dd61abcfc94798c92ad1c5224d8b155ed2-golang-arm64
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-backend-crash-ready-golang-arm64
ghcr.io/openhands/agent-server:0ee038d-golang_tag_1.21-bookworm-arm64
ghcr.io/openhands/agent-server:0ee038d-java-amd64
ghcr.io/openhands/agent-server:0ee038dd61abcfc94798c92ad1c5224d8b155ed2-java-amd64
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-backend-crash-ready-java-amd64
ghcr.io/openhands/agent-server:0ee038d-eclipse-temurin_tag_17-jdk-amd64
ghcr.io/openhands/agent-server:0ee038d-java-arm64
ghcr.io/openhands/agent-server:0ee038dd61abcfc94798c92ad1c5224d8b155ed2-java-arm64
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-backend-crash-ready-java-arm64
ghcr.io/openhands/agent-server:0ee038d-eclipse-temurin_tag_17-jdk-arm64
ghcr.io/openhands/agent-server:0ee038d-python-amd64
ghcr.io/openhands/agent-server:0ee038dd61abcfc94798c92ad1c5224d8b155ed2-python-amd64
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-backend-crash-ready-python-amd64
ghcr.io/openhands/agent-server:0ee038d-python-node-runtime-amd64
ghcr.io/openhands/agent-server:0ee038d-python-arm64
ghcr.io/openhands/agent-server:0ee038dd61abcfc94798c92ad1c5224d8b155ed2-python-arm64
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-backend-crash-ready-python-arm64
ghcr.io/openhands/agent-server:0ee038d-python-node-runtime-arm64
ghcr.io/openhands/agent-server:0ee038d-python-minimal-amd64
ghcr.io/openhands/agent-server:0ee038dd61abcfc94798c92ad1c5224d8b155ed2-python-minimal-amd64
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-backend-crash-ready-python-minimal-amd64
ghcr.io/openhands/agent-server:0ee038d-python-node-runtime-minimal-amd64
ghcr.io/openhands/agent-server:0ee038d-python-minimal-arm64
ghcr.io/openhands/agent-server:0ee038dd61abcfc94798c92ad1c5224d8b155ed2-python-minimal-arm64
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-backend-crash-ready-python-minimal-arm64
ghcr.io/openhands/agent-server:0ee038d-python-node-runtime-minimal-arm64
ghcr.io/openhands/agent-server:0ee038d-python-slim-amd64
ghcr.io/openhands/agent-server:0ee038dd61abcfc94798c92ad1c5224d8b155ed2-python-slim-amd64
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-backend-crash-ready-python-slim-amd64
ghcr.io/openhands/agent-server:0ee038d-python-node-runtime-slim-amd64
ghcr.io/openhands/agent-server:0ee038d-python-slim-arm64
ghcr.io/openhands/agent-server:0ee038dd61abcfc94798c92ad1c5224d8b155ed2-python-slim-arm64
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-backend-crash-ready-python-slim-arm64
ghcr.io/openhands/agent-server:0ee038d-python-node-runtime-slim-arm64
ghcr.io/openhands/agent-server:0ee038d-golang
ghcr.io/openhands/agent-server:0ee038dd61abcfc94798c92ad1c5224d8b155ed2-golang
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-backend-crash-ready-golang
ghcr.io/openhands/agent-server:0ee038d-golang_tag_1.21-bookworm
ghcr.io/openhands/agent-server:0ee038d-java
ghcr.io/openhands/agent-server:0ee038dd61abcfc94798c92ad1c5224d8b155ed2-java
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-backend-crash-ready-java
ghcr.io/openhands/agent-server:0ee038d-eclipse-temurin_tag_17-jdk
ghcr.io/openhands/agent-server:0ee038d-python-minimal
ghcr.io/openhands/agent-server:0ee038dd61abcfc94798c92ad1c5224d8b155ed2-python-minimal
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-backend-crash-ready-python-minimal
ghcr.io/openhands/agent-server:0ee038d-python-node-runtime-minimal
ghcr.io/openhands/agent-server:0ee038d-python-slim
ghcr.io/openhands/agent-server:0ee038dd61abcfc94798c92ad1c5224d8b155ed2-python-slim
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-backend-crash-ready-python-slim
ghcr.io/openhands/agent-server:0ee038d-python-node-runtime-slim
ghcr.io/openhands/agent-server:0ee038d-python
ghcr.io/openhands/agent-server:0ee038dd61abcfc94798c92ad1c5224d8b155ed2-python
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-backend-crash-ready-python
ghcr.io/openhands/agent-server:0ee038d-python-node-runtime

About Multi-Architecture Support

  • Each variant tag (e.g., 0ee038d-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., 0ee038d-python-amd64) are also available if needed

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
@github-actions

Copy link
Copy Markdown
Contributor

REST API breakage checks (OpenAPI) — ✅ PASSED

Result: ✅ PASSED

Action log

@github-actions

Copy link
Copy Markdown
Contributor

Coverage

Coverage Report •
FileStmtsMissCoverMissing
openhands-agent-server/openhands/agent_server/canvas_extensions
   backend.py5285989%52–53, 146, 153, 157–159, 174, 177, 206, 228, 256–258, 261–263, 266–267, 271, 278, 284, 289–291, 314, 320, 324, 328, 337, 340, 347, 371–372, 375, 394–396, 423–424, 504–505, 554, 560–561, 588, 591–592, 607–608, 617, 622, 629, 637, 650, 713–714, 759, 795
   bridge.py2902791%113, 129, 144, 160–162, 227–228, 235, 241, 251, 260, 263, 266, 312, 320, 341, 354, 360, 386, 390, 401, 456, 509–511, 516
TOTAL497461981860% 

@enyst
enyst marked this pull request as ready for review October 14, 2026 02:08
@enyst
enyst requested a review from all-hands-bot October 14, 2026 02:14

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

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 returns None when runtime.process is None or runtime.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) — answer 503 Canvas App backend is not ready for a crashed backend without a prior status poll. The stored runtime.state is deliberately left alone (reconciled later by status()/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-level 502 whose __cause__ is an httpx.HTTPError. I confirmed against docker_runtime/proxy.py:145-161 that the redirect 502 raises 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_exits fails on base exactly at assert manager.ready_endpoint(...) is None (test line 201) and passes on head; test_unreachable_backend_error_names_the_canvas_backend fails 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.py fails 11 backend tests in this sandbox, but they fail identically on base and the cause is environmental: the test fixtures use a #!/usr/bin/python3 shebang 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 are success (including Run 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-server map recipe (F29.backend-crash-detected: xfail on base, xpass on head, and pass after the # bug marker 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

@enyst
enyst merged commit 1c34a84 into main Oct 14, 2026
56 of 57 checks passed
@enyst
enyst deleted the claude/umbrella-bug-fixes-tgz9ai-backend-crash-ready branch October 14, 2026 15:45
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.

[Bug]: Canvas bridge keeps dialing a crashed backend still marked 'ready' and answers 502 'Conversation container unreachable' until a status poll

3 participants