Skip to content

The agent that grows with you

fix(gateway): say which write the restart wait lets through, next to the reads it does

unsupportedpastelsdba39a09f5ac
diff --git a/gateway/drain_control.py b/gateway/drain_control.py
index 3ac3efbab9d..e005b948679 100644
--- a/gateway/drain_control.py
+++ b/gateway/drain_control.py
@@ -47,10 +47,12 @@ def restart_wait_open(runner) -> bool:
and descriptor.get("drain_reason") == RESTART_WAIT_REASON)
-# The reads a client needs during that wait to find and open the conversation parked on
-# approval/clarify: Desktop's session picker, the session detail and its transcript pages, and the
-# health probes. GET only and still authenticated; every write and every other route keeps the
-# drain's refusal. The prompt itself (approval.pending / *.respond) rides the WebSocket.
+# The requests a client needs during that wait to find, open and answer the conversation parked on
+# approval/clarify: the GET reads below (Desktop's session picker, the session detail and its
+# transcript pages, and the health probes) and one write, a Webapp tab's mint of the one-use ticket
+# its /api/ws dial-back needs (restart_wait_socket_ticket). Both only pass the drain's refusal; the
+# listener's auth gate still runs on them. Every other write and route keeps that refusal. The
+# prompt itself (approval.pending / *.respond) rides the WebSocket.
_RESTART_WAIT_READS = re.compile(
r"/api/(?:health|status|profiles/sessions(?:/sidebar)?"
r"|sessions/[^/]+(?:/messages(?:/around)?|/timeline)?)")
@@ -61,6 +63,16 @@ def restart_wait_read(runner, method, path) -> bool:
return (method == "GET" and bool(_RESTART_WAIT_READS.fullmatch(path or ""))
and restart_wait_open(runner))
+
+def restart_wait_socket_ticket(runner, method, path, query) -> bool:
+ """True for a gateway-socket ticket mint while *runner* is in a restart's after-turn wait.
+
+ Exempts the request from the drain's refusal only: it does not authenticate it."""
+ from urllib.parse import parse_qs
+ from hermes_cli.web_session_sockets import GATEWAY_SOCKET
+ return (method == "POST" and path == "/api/webapp/socket-ticket"
+ and parse_qs(query or "").get("socket") == [GATEWAY_SOCKET] and restart_wait_open(runner))
+
# The WebSocket verbs an interactive client may still call during that wait: attach to and read the
# parked session, answer its prompt (or interrupt the turn so the restart can finish) and commit
# queued input for the next owner. Every other verb (config.set, session.save, rollback.restore,
diff --git a/gateway/run_api.py b/gateway/run_api.py
index 3742ee6a720..4ba3e799950 100644
--- a/gateway/run_api.py
+++ b/gateway/run_api.py
@@ -338,14 +338,9 @@ def _restart_wait_read(runner, scope) -> bool:
def _restart_wait_socket_ticket(runner, scope) -> bool:
- """Allow authenticated gateway-ticket minting during restart wait."""
- from urllib.parse import parse_qs
- from gateway.drain_control import restart_wait_open
- from hermes_cli.web_session_sockets import GATEWAY_SOCKET
- return (scope['type'] == 'http' and scope.get('method') == 'POST'
- and scope.get('path') == '/api/webapp/socket-ticket'
- and parse_qs(scope.get('query_string', b'').decode('latin-1')).get('socket') == [GATEWAY_SOCKET]
- and restart_wait_open(runner))
+ from gateway.drain_control import restart_wait_socket_ticket
+ return scope['type'] == 'http' and restart_wait_socket_ticket(
+ runner, scope.get('method'), scope.get('path'), scope.get('query_string', b'').decode('latin-1'))
class GatewayRuntimeAPI: