#21148: fix(gateway): add request-aware pairing recovery hints and docs
docs
gateway
size: S
## Summary
This PR improves the repair path when a gateway client fails handshake with `pairing required` during device scope upgrades.
Closes #21146.
## What changed
### 1) Pairing close reason now includes request id
In handshake pairing rejection, the gateway now closes with:
- `pairing required (requestId: <id>)`
instead of only `pairing required`.
File:
- `src/gateway/server/ws-connection/message-handler.ts`
### 2) CLI close error now prints direct repair commands
Gateway close formatting now detects pairing-required reasons and appends concrete recovery guidance:
- `openclaw devices approve <requestId>` when a request id is present
- fallback `openclaw devices approve --latest`
- `openclaw devices list` verification command
File:
- `src/gateway/call.ts`
### 3) Added tests for request-aware/fallback pairing hints
New assertions verify both:
- request-id aware hint path
- fallback `--latest` hint path
File:
- `src/gateway/call.test.ts`
### 4) Expanded troubleshooting documentation
Added a detailed runbook for:
- pairing-required scope-upgrade loops
- device token mismatch recovery
- service token drift (config token vs service token)
Files:
- `docs/gateway/troubleshooting.md`
- `docs/cli/devices.md`
- `docs/web/control-ui.md`
## Validation
- `pnpm -C /Users/maxime/openclaw exec vitest run src/gateway/call.test.ts`
- `pnpm -C /Users/maxime/openclaw format:check`
## Why this helps
Users now get immediate, actionable output for the most common repair path instead of a generic pairing failure loop. This reduces false “gateway is broken” diagnoses and shortens time-to-recovery.
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
This PR enhances the pairing recovery flow by embedding request IDs in close reasons and providing actionable CLI hints when gateway connections fail due to pairing requirements. The gateway now closes with `pairing required (requestId: <id>)` instead of just `pairing required`, and the CLI formats this into concrete recovery commands like `openclaw devices approve <requestId>` or the fallback `openclaw devices approve --latest`.
- Added request-aware pairing close reason in `message-handler.ts:700`
- Implemented hint formatting logic with regex extraction in `call.ts:318-339`
- Added comprehensive test coverage for both request-id and fallback paths
- Expanded troubleshooting docs with detailed runbooks for pairing loops, token mismatches, and service token drift
The implementation follows existing patterns, uses proper error formatting, and provides immediate value to users experiencing pairing failures.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The changes are well-isolated, focused on improving error messaging and documentation. The code modifications are minimal (3 lines changed in production code), follow existing patterns, include comprehensive test coverage for both code paths, and have been validated by the author. The regex extraction logic was independently verified to work correctly. Documentation additions are helpful and don't modify any behavior.
- No files require special attention
<sub>Last reviewed commit: 5dbabc4</sub>
<!-- greptile_other_comments_section -->
<sub>(4/5) You can add custom instructions or style guidelines for the agent [here](https://app.greptile.com/review/github)!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#22262: fix(gateway): add pairing-repair command hint on 1008 connect failures
by karimnaguib · 2026-02-20
89.7%
#23503: fix: preserve pairing state on device token mismatch + migrate lega...
by dorukardahan · 2026-02-22
84.8%
#22066: fix(cli): add actionable hints for gateway close errors
by pierreeurope · 2026-02-20
83.7%
#6846: fix: bridge node.pair.* tools to device pairing store
by cortexuvula · 2026-02-02
83.3%
#22712: fix(gateway): auto-approve all device pairing for localhost connect...
by NewdlDewdl · 2026-02-21
82.0%
#19088: fix(gateway): allow startup with unset mode and fix pairing for local…
by mdanassaif · 2026-02-17
81.9%
#21651: fix(gateway): token fallback + operator.admin scope superset in pai...
by lan17 · 2026-02-20
81.9%
#17425: fix(gateway): auto-approve scope/role upgrades for already-paired d...
by sauerdaniel · 2026-02-15
81.7%
#22280: fix(gateway): silently auto-approve local paired-device scope upgrades
by abhishekp76 · 2026-02-21
80.8%
#16310: fix(ws-connection): skip device pairing when client authenticates w...
by nawinsharma · 2026-02-14
80.7%