Skip to content

fix(gateway): disconnect active sessions after device token rotation#57646

Merged
vincentkoc merged 2 commits intomainfrom
fix/device-token-rotate-session-revoke
Mar 31, 2026
Merged

fix(gateway): disconnect active sessions after device token rotation#57646
vincentkoc merged 2 commits intomainfrom
fix/device-token-rotate-session-revoke

Conversation

@vincentkoc
Copy link
Copy Markdown
Member

Summary

  • disconnect active device sessions after a successful token rotation
  • keep the existing rotate response shape unchanged for callers
  • add coverage for the disconnect-on-rotate behavior alongside existing device token authz tests

Testing

  • pnpm test -- src/gateway/server-methods/devices.test.ts src/gateway/server.device-token-rotate-authz.test.ts

@vincentkoc vincentkoc self-assigned this Mar 30, 2026
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S maintainer Maintainer-authored PR labels Mar 30, 2026
@vincentkoc vincentkoc marked this pull request as ready for review March 30, 2026 23:57
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Mar 30, 2026

Greptile Summary

This PR extends the gateway's device token rotation handler (device.token.rotate) to disconnect any active sessions that are authenticated with the rotated token immediately after rotation succeeds, rather than waiting for those sockets to close naturally. The change follows the exact same queueMicrotask + optional-chaining pattern already in place for device.pair.remove and device.token.revoke, making the three mutation paths consistent. The implementation is straightforward and low-risk.

Key changes:

  • devices.ts: adds a queueMicrotask call to context.disconnectClientsForDevice?.(deviceId.trim(), { role: entry.role }) after a successful rotateDeviceToken, mirroring the revoke and remove patterns.
  • devices.test.ts: adds mocks for getPairedDevice and rotateDeviceToken, and a new test asserting that disconnectClientsForDevice is invoked with the trimmed device ID and correct role after successful rotation.
  • CHANGELOG.md: records the new behavior.

One minor gap: a failure-path test (rotation denied → disconnectClientsForDevice not called) is absent, while the revoke handler does have this symmetrical test.

Confidence Score: 5/5

  • Safe to merge — no logic, security, or data integrity issues introduced.
  • The implementation is a one-liner that exactly mirrors two already-reviewed patterns in the same file. The only finding is a P2 suggestion to add a symmetrical failure-path test, which does not affect correctness or merge readiness.
  • No files require special attention; the missing failure-path test in devices.test.ts is a nice-to-have, not a blocker.

Comments Outside Diff (1)

  1. src/gateway/server-methods/devices.test.ts, line 176-191 (link)

    P2 Missing failure-path test for token rotation

    The PR adds a success-path test for disconnecting clients after rotation, but there is no corresponding test asserting that disconnectClientsForDevice is not called when rotation fails (e.g. rotateDeviceToken returns { ok: false }). The revoke handler has exactly this symmetrical test ("does not disconnect clients when token revocation fails"), so a parallel test for the rotate failure path would keep coverage consistent and guard against future regressions in the early-return branches.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: src/gateway/server-methods/devices.test.ts
    Line: 176-191
    
    Comment:
    **Missing failure-path test for token rotation**
    
    The PR adds a success-path test for disconnecting clients after rotation, but there is no corresponding test asserting that `disconnectClientsForDevice` is **not** called when rotation fails (e.g. `rotateDeviceToken` returns `{ ok: false }`). The revoke handler has exactly this symmetrical test ("does not disconnect clients when token revocation fails"), so a parallel test for the rotate failure path would keep coverage consistent and guard against future regressions in the early-return branches.
    
    How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/gateway/server-methods/devices.test.ts
Line: 176-191

Comment:
**Missing failure-path test for token rotation**

The PR adds a success-path test for disconnecting clients after rotation, but there is no corresponding test asserting that `disconnectClientsForDevice` is **not** called when rotation fails (e.g. `rotateDeviceToken` returns `{ ok: false }`). The revoke handler has exactly this symmetrical test ("does not disconnect clients when token revocation fails"), so a parallel test for the rotate failure path would keep coverage consistent and guard against future regressions in the early-return branches.

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "fix(gateway): revoke active sessions on ..." | Re-trigger Greptile

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9b77d0eadf

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread CHANGELOG.md
@vincentkoc vincentkoc merged commit 91f7a6b into main Mar 31, 2026
32 of 36 checks passed
@vincentkoc vincentkoc deleted the fix/device-token-rotate-session-revoke branch March 31, 2026 00:05
pgondhi987 pushed a commit to pgondhi987/openclaw that referenced this pull request Mar 31, 2026
pgondhi987 pushed a commit to pgondhi987/openclaw that referenced this pull request Mar 31, 2026
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
Tardisyuan pushed a commit to Tardisyuan/openclaw that referenced this pull request Apr 30, 2026
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime maintainer Maintainer-authored PR size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant