Repository navigation
Let a controller send its agents' operations on its socket, not over HTTP (CHOO-3667) - #1275
Closed
abeldantas wants to merge 2 commits into
Closed
abeldantas wants to merge 2 commits into
abeldantas wants to merge 2 commits into
Conversation
…HTTP (CHOO-3667) A controller relays every operation its agents' sessions call, and each was an HTTP request of its own: parsed, routed and authenticated with the controller's token, though the controller already holds an authenticated WebSocket to the same server. The socket now takes them as `call` frames and answers each with the status and body the HTTP route would have (`management/socket_calls.py`). A call is authorized as the HTTP request is: the controller checked against its row, the agent's binding against presence. The socket's first frame says it takes calls, so a controller from before this keeps using HTTP.
…667)
The relay sends `POST /agents/{id}/ops/{operation}` as a call on the
controller's socket while Switch offers calls, and over HTTP otherwise
(`socket-calls.ts`, `relay-forward.ts`). A call the socket closes on is
answered 502, as a request whose connection drops. The server answers
every call, a failure with 500, so a controller is never left waiting
on one until its socket closes.
abeldantas
requested review from
agent-runner353,
amaudruz,
christian-mcdermott,
lbangalosbt,
massimo-sandboxaq,
niall-sandboxaq,
petr-sandbox,
raullopez-sandbox and
simonflk-sb
as code owners
November 1, 2026 15:15
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Critical unresolved issues remain in relay response typing, per-connection answer-queue bounds, and socket authorization after agent removal.
3 open issues
What changed in this PR
This PR adds a WebSocket call channel for controller-relayed agent operations, reducing per-operation HTTP overhead while preserving HTTP-compatible status and response bodies. It also adds authorization parity, capacity negotiation, fallback behavior, and protocol coverage across the Python service and TypeScript controller.
Changes:
- Adds authenticated
callandcall.resultframes to controller WebSockets, including concurrency limits and disconnect handling. - Updates the controller relay to use socket calls for JSON operation requests, falling back to HTTP when unsupported or at capacity.
- Adds shared refusal-status handling, request-ID sanitization, contract fixtures, and extensive Python/TypeScript tests.
| File | Description |
|---|---|
| core/tests/switch_core/management/test_stream.py | Updated as part of this pull request. |
| core/tests/switch_core/management/test_socket_calls.py | Updated as part of this pull request. |
| core/tests/switch_core/management/test_contract_fixtures.py | Updated as part of this pull request. |
| core/tests/switch_core/management/test_connection_socket.py | Updated as part of this pull request. |
| core/tests/switch_core/fixtures/agent_controllers/stream_frames.json | Updated as part of this pull request. |
| core/switch_core/request_context.py | Updated as part of this pull request. |
| core/switch_core/management/socket_calls.py | Updated as part of this pull request. |
| core/switch_core/management/controller_routes.py | Updated as part of this pull request. |
| core/switch_core/management/auth.py | Updated as part of this pull request. |
| core/switch_core/bridges/agent/api/operations.py | Updated as part of this pull request. |
| console/packages/agent-controller/src/stream.ts | Updated as part of this pull request. |
| console/packages/agent-controller/src/stream.test.ts | Updated as part of this pull request. |
| console/packages/agent-controller/src/socket-calls.ts | Updated as part of this pull request. |
| console/packages/agent-controller/src/socket-calls.test.ts | Updated as part of this pull request. |
| console/packages/agent-controller/src/schemas.ts | Updated as part of this pull request. |
| console/packages/agent-controller/src/schemas.test.ts | Updated as part of this pull request. |
| console/packages/agent-controller/src/relay.test.ts | Updated as part of this pull request. |
| console/packages/agent-controller/src/relay-forward.ts | Updated as part of this pull request. |
| console/packages/agent-controller/src/controller.ts | Updated as part of this pull request. |
| CHANGELOG.md | Updated as part of this pull request. |
Review effort: Lite
Comment on lines
+103
to
+106
| const text = JSON.stringify(answer.body); | ||
| res.writeHead(answer.status, { | ||
| 'Content-Type': 'application/json', | ||
| 'Content-Length': Buffer.byteLength(text), |
Comment on lines
+770
to
+775
| if len(in_flight) >= socket_calls.MAX_CALLS_IN_FLIGHT: | ||
| outbox.put_answer(socket_calls.capacity_exceeded(id_)) | ||
| return | ||
|
|
||
| async def run() -> None: | ||
| outbox.put_answer( |
Comment on lines
+155
to
+159
| binding = authenticator.presence.binding(call.agent_id) | ||
| if ( | ||
| binding is None | ||
| or binding.controller_id != controller.controller_id | ||
| or binding.tenant_id != controller.tenant_id |
Collaborator
Author
|
Combined into #1307 with the other scaling PRs. |
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.

A controller relays every operation its agents' sessions call (
post_message,read_contextand the rest of/agents/{id}/ops/*), and each one was an HTTP request of its own, authenticated with the controller's token. The controller already holds an authenticated WebSocket to the same server for its agents' events, so in this PR the socket carries the operations too.We ran the same build both ways on 12 pods (four shared m5.xlarge nodes, Aurora), with 10,000 agents behind 498 controllers posting and reading through operations, as the controller relays them:
In this PR we:
callframes on the controller's socket and answer each with acall.resultframe carrying the status and body the HTTP route would have answered with (management/socket_calls.py). A call is authorized as the HTTP request is: the controller is checked against its row, and the agent's binding against presence.calls.max_in_flight, 64), so a controller from before this keeps using HTTP. A call over the limit is answered 429capacity_exceededwithout running.POST /agents/{id}/ops/{operation}as a call while the socket offers them, and over HTTP otherwise (socket-calls.ts,relay-forward.ts). A call the socket closes on is answered 502, as a request whose connection drops.test_socket_calls.pysends each outcome of an operation through both doors and compares the answers.