Repository navigation
fix(agent-server): keep sockets and /v1 closed until deferred init completes - #5661
Merged
Merged
Conversation
…mpletes In deferred-init (warm-pool) mode the dormant gate was only attached to the /api router. The /sockets/* WebSocket routes and the /v1 OpenAI-compatible routes were mounted without it, so they were reachable before POST /api/init delivered the per-user config and session keys. Attach require_initialized to both routers. The dependency now takes an HTTPConnection so it also resolves on WebSocket routes, and for those it raises WebSocketException(1013 Try Again Later), which closes the socket before the handshake is accepted. HTTP requests keep getting a 503. Initialized and non-deferred servers are unaffected: the gate is a no-op once the server is ready or when no InitService is registered. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01W9qxyUBKhzmbLrTK2wi7D7
Contributor
REST API breakage checks (OpenAPI) — ✅ PASSEDResult: ✅ PASSED |
Contributor
14 tasks
enyst
marked this pull request as ready for review
October 10, 2026 16:16
all-hands-bot
approved these changes
Oct 10, 2026
all-hands-bot
left a comment
Collaborator
There was a problem hiding this comment.
LGTM — reviewed the diff and the surrounding router wiring.
The fix is correct and well-scoped. A few notes:
What I verified
- Switching
require_initializedtoHTTPConnectionis the right call: the same dependency now resolves on both HTTP and WebSocket routes, and raisingWebSocketException(1013)(instead ofHTTPException) avoids the app-level exception handler that readsrequest.method— good catch. - Applying the gate at the router mount points (
openai_routerandconversation_registry.sockets_router) means the events / session / bash sockets are all covered for both the local and Docker registries, not just the individual routes. - The dependency ordering matches the existing
/apigroup (check_openai_api_keybeforerequire_initialized), so a dormant pod without the key still gets 401 rather than leaking 503 semantics. Consistent. - No-op behavior for non-deferred / already-ready servers is preserved.
Tests
- The two added end-to-end tests exercise the real
create_applifespan viaTestClientand assert both the 1013 refusal (with the side-effectmarkerproving no command ran) and the post-init success path. That's exactly the right level.
Non-blocking follow-ups (I agree with keeping this diff small)
/app-backends/*(HTTP + WebSocket proxy) and the/apiworkspace static-file routes are still reachable while dormant. The app-backends HTTP/WS proxies are especially worth gating since they forward arbitrary requests/upgrades to an owned backend — happy to see that tracked as its own issue.- Gating
/v1is clearly correct: init delivers the LLM profile store, so there is nothing to serve while dormant. - #5660 touches
_build_initialized_configininit_router.pyin a different hunk, so merge order looks safe.
Approving. Solid hardening.
This review was generated by an AI agent (OpenHands) on behalf of the user.
1 of 5 tasks
enyst
added a commit
that referenced
this pull request
Oct 11, 2026
Deferred init (F03): document the dormant gate as merged in #5661 and #5700. Every socket, the /v1 gateway, the workspace static-file routes and /app-backends are now closed until POST /api/init, and readiness is checked before authentication. - F03.dormant-gates-api: the workspace route now answers with the gate's own reason instead of the missing conversation service. - New F03.dormant-gates-sockets (bash-events, events and session sockets refuse the handshake, seen as HTTP 403), F03.dormant-gates-v1 (/v1/models, /v1/chat/completions and /app-backends answer 503) and F03.init-opens-events-socket-and-v1 (positive control after init). - F03.auth-before-gate is retired; F03.gate-before-auth asserts the new order (missing, wrong or valid key all get 503, socket bad key 403). - F03.dormant-boot also checks /server_info and GET / stay open. - F01 and F16 gotchas no longer claim /ready is 503 while dormant or that the workspace routes sit outside the gate. Drift from main and from the harness change in 2f1aa08: - F09, F19: add --unsafe-unredacted to the --field reads whose encrypted values are fed back (including both F19 oauth_state reads), and let the F19 HTTP MCP fixtures call os.setsid() so map run's per-bullet process group cleanup does not stop them after Preconditions. - F07: saved captures now start with an `opened` entry; shift every frames.N index by one and say so in the gotcha. - F24: the subscription models route returns OPENAI_CODEX_MODELS, which #5436 extended past the codex ACP registry; derive the expectation from the allowlist. - F18: #5682 fixed F18.secret-empty-value (baseline before it xfail twice, this checkout xpass twice); drop the known-bug markers, assert the 422, and declare its Requires. Fix the stale gotcha about --field redaction. - launch: accept readiness only from this run's own listener, so a parallel launch handed the same port fails instead of driving another run's server. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01W9qxyUBKhzmbLrTK2wi7D7
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
HUMAN:
This PR fixes a bug found during a full agentic run of agent-server.
AGENT:
I'm an AI agent based on Opus 5.5, helping Engel Nyst (@enyst) with project maintenance.
Why
Hardening for deferred-init (warm-pool) Agent Servers. While a pod is dormant, waiting for
POST /api/init, the dormant gaterequire_initializedis attached only to the/apirouter. The/sockets/*WebSocket routes and the/v1OpenAI-compatible routes are mounted without it, so they are reachable before init. A dormant pod normally has no session keys yet (they arrive in the init body), so these surfaces should stay closed until the pod has its per-user configuration. It was found while building the Agent Server feature map in #5621 (F03.dormant-ws-bash-bypass,F13.ws-dormant-gate,F30.dormant-models-gated).Summary
require_initializedtakes anHTTPConnection, so the same dependency resolves on HTTP and WebSocket routes. HTTP requests still get a 503 while dormant; WebSockets getWebSocketException(1013 Try Again Later), which closes the socket before the handshake is accepted. (RaisingHTTPExceptionfrom a WebSocket dependency would reach the app's HTTP exception handler, which readsrequest.methodand fails.)/v1router (aftercheck_openai_api_key, the same order as/api) and to the sockets router at its mount point, covering the events, session and bash sockets for both the local and Docker registries.readyor when noInitServiceis registered.Issue Number
Related to #5688.
How to Test
Two new end-to-end tests drive the real
create_applifespan throughTestClient: a dormant server refuses/sockets/bash-eventswith 1013 and runs no command, then accepts it afterPOST /api/init;/v1/modelsanswers 503 while dormant and 200 after init. Both fail onmain(the socket is accepted;/v1/modelsanswers 200) and pass with this change. Fulltests/agent_server: 2510 passed;tests/cross/test_remote_conversation_live_server.py: 24 passed. ruff, pyright and pre-commit are clean.Type
Notes
TestClient).BashEventService/ConversationServicefallbacks insockets.py(unreachable on a dormant server now, but several tests patch them), and deciding whether the/apiworkspace static-file routes and/app-backends/*should also be gated before init.init_router.py(_build_initialized_config), in a different hunk.🤖 Generated with Claude Code
https://claude.ai/code/session_01W9qxyUBKhzmbLrTK2wi7D7
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:0aa3782-pythonRun
All tags pushed for this build
About Multi-Architecture Support
0aa3782-python) is a multi-arch manifest supporting both amd64 and arm640aa3782-python-amd64) are also available if neededGenerated by Claude Code