Repository navigation
refactor(gateway): consolidate chat abort authorization - #119642
Conversation
|
Codex review: needs maintainer review before merge. Reviewed August 5, 2026, 12:11 PM ET / 16:11 UTC. ClawSweeper reviewWhat this changesThis PR routes active and queued Gateway chat cancellations through one shared authorization decision and removes duplicate queue-map wrappers and validators. Merge readinessNo blocking findings. Current main still has the split authorization paths, while this PR retains the existing access rules through one canonical check and supplies exact-head production WebSocket evidence. Likely related people: steipete (high) and Masato Hoshino (medium). Priority: P3 Review scores
Verification
How this fits togetherGateway clients send chat-abort requests to the server, which checks session, agent, connection, and device ownership before cancelling active or queued work. The result controls whether the requested chat run is stopped or rejected without changing its state. flowchart LR
A[Gateway client] --> B[Chat abort request]
B --> C[Shared authorization]
C --> D{Authorized target?}
D -->|Yes| E[Active or queued run]
D -->|No| F[Rejected request]
E --> G[Cancellation result]
Before merge
Agent review detailsSecurityNone. PR surfaceSource -111. Total -111 across 4 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep one authorization owner for active and queued targets, then merge through the normal exact-head checks once GitHub’s clean merge result is available. Do we have a high-confidence way to reproduce the issue? Not applicable as a reported defect: this is a behavior-preserving refactor, and the PR supplies an exact-head production GatewayClient/WebSocket trace for the preserved authorization outcomes. Is this the best way to solve the issue? Yes. The shared owner-level decision removes duplicate active and queued policies while retaining the stricter cross-session check at the authorization boundary. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 21bc2c43f2a5. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
|
Merged via squash.
|
What Problem This Solves
Gateway chat cancellation maintained separate authorization and lifecycle paths for active, queued, and preregistered runs, making connection/device ownership and agent-scoped session checks harder to keep consistent.
Why This Change Was Made
Route active and queued cancellation through one canonical owner-level authorization decision, reuse the lifecycle-owned queue map and pending ownership metadata, and remove duplicate exact-run validators, obsolete wrappers, and synthetic pending-run controllers. The shared target explicitly models
ChatAbortControllerEntry | QueuedChatTurnEntry, preserving the existing queue-entry production contract.User Impact
No intended behavior change. Administrator privileges, same-device reconnect and connection ownership, ownerless same-session access with fail-closed cross-session rejection, selected global-agent isolation, canonical/session aliases, hidden/internal/side-run exclusion, partial persistence, and queued-before-active cancellation order remain unchanged. Production change: 69 additions, 180 deletions; net -111 lines across four files.
Evidence
tbx_01kz92dt9nvd6bh3xpj8d4bagx: 19 gateway test files and 341 tests passed, including authorization (32), abort persistence (28), selected-agent scope (29), queued turns (14), chat abort (46), full gateway chat integration (96), and sibling ownership/dispatch coverage.pnpm check:changedpassed: production and full-tree dead-export scans, public Plugin SDK API manifest, core and core-test TypeScript checks, formatting, lint with zero warnings/errors, import-cycle checks, and security guards..agents/skills/autoreview/scripts/autoreview --mode local --engine codex --model gpt-5.6-sol --thinking xhighpassed with no actionable findings and 0.97 confidence.completed.Exact-head redacted Gateway client trace
Observed by executing the committed
chat.abortRPC handler, authorization owner, cancellation runtime, active-run abort owner, and queued-turn abort owner at8d1afa5395b821e3013f558100e08d6c7c11ff07. The fixture uses synthetic client/device IDs and isolated in-memory session registries; it does not start a listener or access the network, credentials, or operator state.[ { "scenario": "same-connection-active", "request": { "sessionKey": "main", "connection": "conn-owner", "device": "device-other", "scopes": [ "operator.write" ] }, "response": { "ok": true, "aborted": true, "runIds": [ "same-connection-active" ] }, "stateAfter": { "registry": "active", "runRegistered": false, "signalAborted": true } }, { "scenario": "same-device-reconnected-active", "request": { "sessionKey": "main", "connection": "conn-new", "device": "device-owner", "scopes": [ "operator.write" ] }, "response": { "ok": true, "aborted": true, "runIds": [ "same-device-reconnected-active" ] }, "stateAfter": { "registry": "active", "runRegistered": false, "signalAborted": true } }, { "scenario": "foreign-active", "request": { "sessionKey": "main", "connection": "conn-foreign", "device": "device-foreign", "scopes": [ "operator.write" ] }, "response": { "ok": false, "code": "INVALID_REQUEST", "error": "unauthorized" }, "stateAfter": { "registry": "active", "runRegistered": true, "signalAborted": false } }, { "scenario": "ownerless-cross-session-active", "request": { "sessionKey": "other", "connection": "conn-foreign", "device": "device-foreign", "scopes": [ "operator.write" ] }, "response": { "ok": false, "code": "INVALID_REQUEST", "error": "runId does not match sessionKey" }, "stateAfter": { "registry": "active", "runRegistered": true, "signalAborted": false } }, { "scenario": "same-device-reconnected-queued", "request": { "sessionKey": "main", "connection": "conn-new", "device": "device-owner", "scopes": [ "operator.write" ] }, "response": { "ok": true, "aborted": true, "runIds": [ "same-device-reconnected-queued" ] }, "stateAfter": { "registry": "queued", "runRegistered": false, "signalAborted": true } }, { "scenario": "foreign-queued", "request": { "sessionKey": "main", "connection": "conn-foreign", "device": "device-foreign", "scopes": [ "operator.write" ] }, "response": { "ok": false, "code": "INVALID_REQUEST", "error": "unauthorized" }, "stateAfter": { "registry": "queued", "runRegistered": true, "signalAborted": false } }, { "scenario": "ownerless-cross-session-queued", "request": { "sessionKey": "other", "connection": "conn-foreign", "device": "device-foreign", "scopes": [ "operator.write" ] }, "response": { "ok": false, "code": "INVALID_REQUEST", "error": "runId does not match sessionKey" }, "stateAfter": { "registry": "queued", "runRegistered": true, "signalAborted": false } }, { "scenario": "admin-cross-session-active", "request": { "sessionKey": "other", "connection": "conn-admin", "device": "device-admin", "scopes": [ "operator.admin" ] }, "response": { "ok": true, "aborted": true, "runIds": [ "admin-cross-session-active" ] }, "stateAfter": { "registry": "active", "runRegistered": false, "signalAborted": true } }, { "scenario": "global-agent-mismatch", "request": { "sessionKey": "global", "connection": "conn-owner", "device": "device-owner", "scopes": [ "operator.write" ] }, "response": { "ok": false, "code": "INVALID_REQUEST", "error": "runId does not match agentId" }, "stateAfter": { "registry": "active", "runRegistered": true, "signalAborted": false } } ]Foreign and ownerless cross-session requests leave their original active/queued run registered and unaborted; the same connection, a reconnected paired device, and the authorized administrator cancel successfully. The global-session agent mismatch remains rejected. This adds observed evidence to the PR body only: the reviewed commit SHA is unchanged, so the existing exact-head review remains valid and no re-review is requested.
Genuine production Gateway listener + GatewayClient WebSocket verdict (exact head)
The existing
setupGatewaySessionsTestHarnessstarted the actual productionstartGatewayServerlistener on isolated loopback port 63000. Three independent productionGatewayClientinstances completed realhello-okWebSocket handshakes (protocol 4); they then sent six actualchat.abortRPCs over their WebSocket connections to the committed production listener, request dispatch, authorization owner, runtime owner, and queued-turn owner. The fixture used only synthetic isolated temporary session state; the real listener, network transport, Gateway clients, RPC dispatch, authorization, and cancellation handlers were not mocked. A passive in-memory runtime observer inspected the real Gateway-owned maps, and queued entries were registered through productionregisterQueuedChatTurn.{ "head": "8d1afa5395b821e3013f558100e08d6c7c11ff07", "productionClient": "src/gateway/client.ts:GatewayClient", "productionListener": "src/gateway/server-start.ts:startGatewayServer", "productionOwners": [ "src/gateway/server-methods/chat-abort-handler.ts", "src/gateway/server-methods/chat-abort-authorization.ts", "src/gateway/server-methods/chat-abort-runtime.ts", "src/gateway/chat-queued-turns.ts" ], "transport": { "scheme": "ws", "host": "127.0.0.1", "listenerPort": 63000, "connectedProductionGatewayClients": 3, "hello": [ "hello-ok", "hello-ok", "hello-ok" ], "protocol": 4, "websocketRequests": 6 }, "state": "synthetic isolated temporary Gateway session state; no operator data", "cases": [ { "kind": "queued", "requester": "foreign", "websocketRequest": { "method": "chat.abort", "sessionKey": "main", "runId": "synthetic-owned-queued-turn" }, "productionClientResponse": { "ok": false, "errorClass": "GatewayClientRequestError", "code": "INVALID_REQUEST", "message": "unauthorized" }, "serverStateAfterResponse": { "remainsRegistered": true, "signalAborted": false } }, { "kind": "queued", "requester": "owner", "websocketRequest": { "method": "chat.abort", "sessionKey": "main", "runId": "synthetic-owned-queued-turn" }, "productionClientResponse": { "ok": true, "payload": { "ok": true, "aborted": true, "runIds": [ "synthetic-owned-queued-turn" ] } }, "serverStateAfterResponse": { "remainsRegistered": false, "signalAborted": true } }, { "kind": "queued", "requester": "foreign", "websocketRequest": { "method": "chat.abort", "sessionKey": "other", "runId": "synthetic-ownerless-queued-turn" }, "productionClientResponse": { "ok": false, "errorClass": "GatewayClientRequestError", "code": "INVALID_REQUEST", "message": "runId does not match sessionKey" }, "serverStateAfterResponse": { "remainsRegistered": true, "signalAborted": false } }, { "kind": "queued", "requester": "admin", "websocketRequest": { "method": "chat.abort", "sessionKey": "other", "runId": "synthetic-ownerless-queued-turn" }, "productionClientResponse": { "ok": true, "payload": { "ok": true, "aborted": true, "runIds": [ "synthetic-ownerless-queued-turn" ] } }, "serverStateAfterResponse": { "remainsRegistered": false, "signalAborted": true } }, { "kind": "active", "requester": "foreign", "websocketRequest": { "method": "chat.abort", "sessionKey": "main", "runId": "synthetic-owned-active-turn" }, "productionClientResponse": { "ok": false, "errorClass": "GatewayClientRequestError", "code": "INVALID_REQUEST", "message": "unauthorized" }, "serverStateAfterResponse": { "remainsRegistered": true, "signalAborted": false } }, { "kind": "active", "requester": "owner", "websocketRequest": { "method": "chat.abort", "sessionKey": "main", "runId": "synthetic-owned-active-turn" }, "productionClientResponse": { "ok": true, "payload": { "ok": true, "aborted": true, "runIds": [ "synthetic-owned-active-turn" ] } }, "serverStateAfterResponse": { "remainsRegistered": true, "signalAborted": true, "registrationLifecycle": "terminal-persistence-pending" } } ] }Observed outcomes: a foreign non-admin client cannot cancel another connection's queued or active run; both remain registered and unaborted. The owning connection successfully cancels both. An ownerless queued run rejects a foreign cross-session request and remains queued; an admin can explicitly authorize its cross-session cancellation. The successful active cancellation intentionally retains its aborted registration while terminal persistence is pending, preserving the existing lifecycle-ordering contract.
Focused real-listener result: 1 passed, 7 unrelated existing cases skipped by the explicit name filter. All production clients and the isolated listener were shut down; the temporary dependency link was removed and the source worktree remained clean. Reviewed head remains
8d1afa5395b821e3013f558100e08d6c7c11ff07; this is additional exact-head evidence only, so the existing exact-head review remains valid and no re-review is requested.