Skip to content

fix(gateway): clear pairing state on device token mismatch#22071

Merged
mbelinky merged 3 commits intomainfrom
lane4/19562-salvage-minimal
Feb 20, 2026
Merged

fix(gateway): clear pairing state on device token mismatch#22071
mbelinky merged 3 commits intomainfrom
lane4/19562-salvage-minimal

Conversation

@mbelinky
Copy link
Contributor

@mbelinky mbelinky commented Feb 20, 2026

Summary

  • clear paired-device state when gateway client receives close code 1008 with a device token mismatch reason
  • keep token-clear behavior and add explicit async error handling for pairing-state clear
  • add focused tests for close-handling and clearDevicePairing behavior

Why

This is the minimal safe salvage of #19562. It keeps only the pairing-recovery behavior needed for re-pairing after token mismatch and drops unrelated changes.

Changes

  • src/gateway/client.ts
  • src/infra/device-pairing.ts
  • src/gateway/client.test.ts
  • src/infra/device-pairing.test.ts

Validation run locally

  • pnpm exec vitest run src/gateway/client.test.ts -t "GatewayClient close handling"
  • pnpm exec vitest run src/infra/device-pairing.test.ts -t "clears paired device state by device id"

Supersedes #19562 for this fix scope.

Greptile Summary

Added device pairing state cleanup alongside token cleanup when gateway receives close code 1008 with device token mismatch. The new clearDevicePairing function removes paired device state by device ID.

  • Added clearDevicePairing to remove paired device state by device ID
  • Gateway client now calls clearDevicePairing (fire-and-forget) when clearing stale tokens
  • Tests cover both successful pairing clear and error handling when pairing clear fails
  • One issue found: log message prematurely claims pairing is cleared before the async operation completes

Confidence Score: 4/5

  • Safe to merge with one minor logging inaccuracy that doesn't affect functionality
  • The implementation correctly adds pairing state cleanup when device token mismatch occurs, with proper error handling and comprehensive tests. The only issue is a premature log message that claims pairing is cleared before the async operation completes, but this is a logging cosmetic issue that doesn't affect the actual cleanup behavior.
  • No files require special attention

Last reviewed commit: 4423f6e

@openclaw-barnacle openclaw-barnacle bot added gateway Gateway runtime size: S maintainer Maintainer-authored PR labels Feb 20, 2026
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

4 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

void clearDevicePairing(deviceId).catch((err) => {
logDebug(`failed clearing stale device pairing for device ${deviceId}: ${String(err)}`);
});
logDebug(`cleared stale device-auth token and pairing for device ${deviceId}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

log message claims pairing is cleared, but clearDevicePairing is async and fire-and-forget (voided promise), so pairing might not be cleared when this logs

Suggested change
logDebug(`cleared stale device-auth token and pairing for device ${deviceId}`);
logDebug(`cleared stale device-auth token for device ${deviceId}`);
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/gateway/client.ts
Line: 192

Comment:
log message claims pairing is cleared, but `clearDevicePairing` is async and fire-and-forget (voided promise), so pairing might not be cleared when this logs

```suggestion
          logDebug(`cleared stale device-auth token for device ${deviceId}`);
```

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

@mbelinky mbelinky force-pushed the lane4/19562-salvage-minimal branch from 05948a4 to 3546adc Compare February 20, 2026 18:02
@mbelinky mbelinky force-pushed the lane4/19562-salvage-minimal branch from 3546adc to ad38d1a Compare February 20, 2026 18:11
@mbelinky mbelinky merged commit 5dd304d into main Feb 20, 2026
24 checks passed
@mbelinky mbelinky deleted the lane4/19562-salvage-minimal branch February 20, 2026 18:21
rodrigogs pushed a commit to rodrigogs/openclaw that referenced this pull request Feb 20, 2026
…22071)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: ad38d1a
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Reviewed-by: @mbelinky
Hansen1018 added a commit to Hansen1018/openclaw that referenced this pull request Feb 21, 2026
…22071)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: ad38d1a
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Reviewed-by: @mbelinky
vincentkoc pushed a commit that referenced this pull request Feb 21, 2026
Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: ad38d1a
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Reviewed-by: @mbelinky
dgarson pushed a commit to dgarson/clawdbot that referenced this pull request Feb 21, 2026
…22071)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: ad38d1a
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Reviewed-by: @mbelinky
mmyyfirstb pushed a commit to mmyyfirstb/openclaw that referenced this pull request Feb 21, 2026
…22071)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: ad38d1a
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Reviewed-by: @mbelinky
@guokewuming guokewuming mentioned this pull request Feb 21, 2026
obviyus pushed a commit to guirguispierre/openclaw that referenced this pull request Feb 22, 2026
…22071)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: ad38d1a
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Reviewed-by: @mbelinky
mreedr pushed a commit to mreedr/openclaw-custom that referenced this pull request Feb 24, 2026
…22071)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: ad38d1a
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Reviewed-by: @mbelinky
zooqueen pushed a commit to hanzoai/bot that referenced this pull request Mar 6, 2026
…22071)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: ad38d1a
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Reviewed-by: @mbelinky
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