refactor(gateway): check agent runtime authority once at request start (#201697) Problem: an agent run's Gateway requests re-checked the run's authority many times while one request ran: before the queue, at handler start, inside cron, secrets, sessions.create, message, themes, ui.command and MCP event handlers, and on every response. When the run's authority closed partway through, a started request was refused with "agent runtime authority is no longer active". On WebSocket the client connection was also closed (4001), and a committed effect could be reported as a failure. Fix: run authority is checked once, in the shared pre-dispatch owner `authorizeGatewayRequestPreDispatch`, which WebSocket and in-process requests both pass through. A request from a run that already ended is refused with a message that names the next step. Session authorization inside an already admitted request (`withSessionTurnAuthority`) skips that check. The run guard helpers, the dispatch and response-time re-checks, and the 4001 close are deleted. The message-action turn-capability check and the caller-only message-action fences stay as on base, without the run check; they are separate check-once chains. Gateway computer cleanup after a run ends now has one owner: the Gateway retires the run's desktop execution on run closure, and the tool no longer sends a second close with the ended run's identity. Caller, participant, session-mutation and client-authority assertions are unchanged. User impact: a Gateway request that an agent run has started finishes and returns its real result even if the run's authority closes meanwhile. A new request from a closed run is refused at start. Proof: focused tests for every touched handler and consumer, including the channel read-authority suites; new regressions (a started request keeps its response; an ended run is refused at start but not inside an admitted request); tsgo and test types; the lifetime-check, line-cap, session-identity and mock-export ratchets; a local Gateway run where a subagent's Code Mode crash is followed by a successful Gateway-backed tool call; ocx build --dts plus a packed install smoke on the merged head. Co-authored-by: Ayaan Zaidi <hi@obviy.us>
Current
·
C2
·2026-11
refactor(gateway): check agent runtime authority once at request star…
Find Your Interest
Current
·
C2
·2026-11





