Gateway: disconnect revoked device sessions#55952
Gateway: disconnect revoked device sessions#55952jacobtomlinson merged 4 commits intoopenclaw:mainfrom
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4886ec8e01
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Greptile SummaryThis PR adds live-session disconnect logic to the gateway device handlers: when a paired device is removed or a device token is revoked, all active WebSocket clients matching that Confidence Score: 5/5Safe to merge; the core logic is correct and well-tested, with only a P2 design question about role-scoped vs. device-scoped disconnection on token revoke. All findings are P2 or lower. The implementation is straightforward, errors are properly guarded with optional chaining, the try/catch prevents iterator errors from propagating, and four new tests cover the critical happy-path and failure-path branches. src/gateway/server.impl.ts — the
|
| Filename | Overview |
|---|---|
| src/gateway/server-methods/devices.ts | Added context.disconnectClientsForDevice?.(deviceId) after successful device.pair.remove and device.token.revoke operations. Both paths correctly guard on a truthy result before calling the hook. |
| src/gateway/server-methods/types.ts | Added optional disconnectClientsForDevice?: (deviceId: string) => void field to GatewayRequestContext, consistent with the existing optional hasExecApprovalClients. |
| src/gateway/server.impl.ts | Implements disconnectClientsForDevice by iterating the clients Set and closing matching sockets. The same close code (4001) and reason ('device removed') is used for both removal and revocation. |
| src/gateway/server-methods/devices.test.ts | New test file covering all four relevant paths: successful and failed remove/revoke. Mocks are correctly hoisted and all key assertions are present. |
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/gateway/server.impl.ts
Line: 1199-1210
Comment:
**Token revoke disconnects all device sessions regardless of role**
`device.token.revoke` revokes a token for a *specific* role (e.g., "operator"), but `disconnectClientsForDevice` closes every active socket for the entire `deviceId`. If a device has simultaneous connections for different roles (e.g., one session as "operator" and another as "admin"), revoking the "operator" token will also drop the still-valid "admin" session.
`device.pair.remove` disconnecting all sessions for the device is correct — the whole device is de-paired. But for `device.token.revoke`, the intent is presumably to invalidate a single role's token. The implementation in `devices.ts` calls the same broad helper for both operations, so there is no per-role filtering.
If the correct behaviour really is "revoke any one token → disconnect every session for the device", that should be documented. If not, consider adding a `role?: string` parameter to `disconnectClientsForDevice` so the iterator can additionally check `gatewayClient.connect.role === role` before closing.
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "Gateway: disconnect revoked device sessi..." | Re-trigger Greptile
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d13c5bdde9
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
* Gateway: disconnect revoked device sessions * Gateway: normalize device disconnect targets * Gateway: scope token revoke disconnects by role * Gateway: respond before disconnecting sessions
* Gateway: disconnect revoked device sessions * Gateway: normalize device disconnect targets * Gateway: scope token revoke disconnects by role * Gateway: respond before disconnecting sessions
* Gateway: disconnect revoked device sessions * Gateway: normalize device disconnect targets * Gateway: scope token revoke disconnects by role * Gateway: respond before disconnecting sessions
* Gateway: disconnect revoked device sessions * Gateway: normalize device disconnect targets * Gateway: scope token revoke disconnects by role * Gateway: respond before disconnecting sessions
Summary
Changes
disconnectClientsForDevicehook to the gateway request contextValidation
pnpm test -- src/gateway/server-methods/devices.test.tspnpm test -- src/gateway/server-methods/server-methods.test.ts -t "exec approval handlers"pnpm checkpnpm buildclaude -p "/review"; it requested a PR number or open-PR context, so there was no actionable feedback to apply locallyNotes