Skip to content

fix(gateway): tolerate legacy paired metadata in ws upgrade checks#21447

Merged
BunsDev merged 5 commits intoopenclaw:mainfrom
joshavant:joshavant/fix-21236-legacy-paired-metadata
Feb 19, 2026
Merged

fix(gateway): tolerate legacy paired metadata in ws upgrade checks#21447
BunsDev merged 5 commits intoopenclaw:mainfrom
joshavant:joshavant/fix-21236-legacy-paired-metadata

Conversation

@joshavant
Copy link
Copy Markdown
Contributor

@joshavant joshavant commented Feb 19, 2026

Summary

Fixes the pairing required regression from #21236 for legacy paired devices that were created without roles / scopes metadata.

This PR includes two separate commits:

  1. Repro regression test (server.auth.e2e.test.ts) that models legacy paired metadata.
  2. Handshake fix in message-handler.ts to tolerate legacy metadata and backfill it in place.

Related maintainer draft: #21347 (used as reference/inspiration).

Problem

After handshake hardening, a previously paired device could be treated as a scope/role upgrade if its persisted paired record lacked roles/scopes, causing:

  • gateway closed (1008): pairing required
  • failed CLI/gateway commands after upgrade

What changed

1) Repro test

  • Added allows legacy paired devices missing role/scope metadata in src/gateway/server.auth.e2e.test.ts.
  • Test flow:
    1. Pair device normally.
    2. Remove roles and scopes from persisted paired record.
    3. Reconnect with same device and scope.
    4. Assert connect succeeds and metadata is backfilled.

2) Handshake fix

  • In src/gateway/server/ws-connection/message-handler.ts:
    • detect legacy paired metadata shape (roles === undefined && scopes === undefined)
    • skip upgrade-pairing enforcement only for that legacy shape
    • still call updatePairedDeviceMetadata(...) so metadata is repaired in-place

Why this is safe

  • Existing strict upgrade checks remain unchanged for non-legacy paired records.
  • Existing paired entry is preserved; metadata is merged/backfilled in-place.
  • Existing token entries are not dropped by this change.

Verification evidence

Repro was red pre-fix

Command:

pnpm exec vitest run --config vitest.e2e.config.ts src/gateway/server.auth.e2e.test.ts --testNamePattern "allows legacy paired devices missing role/scope metadata" --maxWorkers=1

Observed pre-fix failure:

  • AssertionError: expected false to be true
  • at src/gateway/server.auth.e2e.test.ts (expect(reconnect.ok).toBe(true))

Post-fix targeted checks

Command:

pnpm exec vitest run --config vitest.e2e.config.ts src/gateway/server.auth.e2e.test.ts --testNamePattern "allows legacy paired devices missing role/scope metadata|requires pairing for scope upgrades" --maxWorkers=1

Result:

  • 1 passed, 2 passed | 29 skipped

Post-fix auth file checks

Command:

pnpm exec vitest run --config vitest.e2e.config.ts src/gateway/server.auth.e2e.test.ts --maxWorkers=1

Result:

  • 1 passed, 31 passed

Manual single-host install validation

Using a normal local install pattern with an isolated state dir:

  1. Start gateway locally, pair once (openclaw health passes).
  2. Remove roles/scopes from devices/paired.json for the paired device.
  3. Before fix: openclaw health returns gateway closed (1008): pairing required.
  4. After fix: openclaw health succeeds, and devices/paired.json shows roles/scopes backfilled.

User-facing guidance (for #21236)

  • Users should update to a release containing this fix, restart gateway, and run openclaw health.
  • Existing pairings should continue working; legacy metadata is repaired automatically on reconnect.
  • Users who already applied workaround steps that moved/deleted pairing files may still need re-approval/reconnect (expected when pairing state was reset).

Fixes #21236

Greptile Summary

Fixes regression where legacy paired devices without roles/scopes metadata were incorrectly rejected as upgrade attempts. The fix detects the legacy metadata shape (roles === undefined && scopes === undefined) and skips upgrade enforcement while still backfilling metadata via updatePairedDeviceMetadata(). Includes comprehensive test that validates the backfill behavior.

Confidence Score: 5/5

  • Safe to merge with minimal risk
  • The fix is narrowly scoped to detect and handle legacy metadata (both roles and scopes undefined) while preserving all existing upgrade checks for non-legacy paired devices. The test comprehensively validates the backfill behavior, and the updatePairedDeviceMetadata function properly merges metadata to repair legacy entries.
  • No files require special attention

Last reviewed commit: fda21f1

@joshavant
Copy link
Copy Markdown
Contributor Author

Verification evidence (focused):

  1. Regression repro was red before fix
    Command:
    pnpm exec vitest run --config vitest.e2e.config.ts src/gateway/server.auth.e2e.test.ts --testNamePattern "allows legacy paired devices missing role/scope metadata" --maxWorkers=1
    Observed failure before fix:
  • AssertionError: expected false to be true
  • failing assertion: expect(reconnect.ok).toBe(true)
  1. Targeted guard checks are green after fix
    Command:
    pnpm exec vitest run --config vitest.e2e.config.ts src/gateway/server.auth.e2e.test.ts --testNamePattern "allows legacy paired devices missing role/scope metadata|requires pairing for scope upgrades" --maxWorkers=1
    Observed result:
  • test file passed
  • 2 passed | 29 skipped
  1. Full auth/connect file is green after fix
    Command:
    pnpm exec vitest run --config vitest.e2e.config.ts src/gateway/server.auth.e2e.test.ts --maxWorkers=1
    Observed result:
  • test file passed
  • 31 passed
  1. Manual single-host behavior check
    Using a normal local install pattern with isolated state:
  • pair once, then remove roles/scopes from paired device metadata
  • before fix: openclaw health fails with pairing required
  • after fix: openclaw health succeeds and metadata is backfilled (roles/scopes)

User impact/remediation notes:

  • Users on affected versions should update to a release containing this fix, restart gateway, and run openclaw health.
  • Existing pairs are preserved and repaired in-place on reconnect.
  • Users who manually reset pairing files during workaround may still need re-approval/reconnect (expected after state reset).

References:

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

Follow-up for CI failure in check job:

  • Cause: TypeScript strict-null check flagged ws2 as possibly undefined in the new repro test (TS18048).
  • Fix: replaced direct use with a local wsReconnect const, then assigned ws2 = wsReconnect for cleanup.
  • Commit: a612c6cc5 (test(gateway): satisfy strict null checks in legacy repro)

Re-verified locally with:
pnpm check

Result: pass (format check + tsgo + lint).

@BunsDev BunsDev self-assigned this Feb 19, 2026
@BunsDev BunsDev merged commit 29ad073 into openclaw:main Feb 19, 2026
19 checks passed
@BunsDev
Copy link
Copy Markdown
Member

BunsDev commented Feb 19, 2026

Merged via squash.

  • Prepared head SHA: 55415504434bca28370ec05ae0697f24fcdaacea
  • Merge commit: 29ad0736f44566fcbc955a1f642a84c16d20f43f

Thanks @joshavant 🦞

@joshavant joshavant deleted the joshavant/fix-21236-legacy-paired-metadata branch February 19, 2026 23:47
BunsDev added a commit that referenced this pull request Feb 19, 2026
cursor bot pushed a commit to Parcosta/openclaw that referenced this pull request Feb 20, 2026
vignesh07 pushed a commit to pahdo/openclaw that referenced this pull request Feb 20, 2026
…penclaw#21447)

Fixes the pairing required regression from openclaw#21236 for legacy paired devices
created without roles/scopes metadata. Detects legacy paired metadata shape
and skips upgrade enforcement while backfilling metadata in place on reconnect.

Co-authored-by: Josh Avant <[email protected]>
Co-authored-by: Val Alexander <[email protected]>
vignesh07 pushed a commit to pahdo/openclaw that referenced this pull request Feb 20, 2026
anisoptera pushed a commit to anisoptera/openclaw that referenced this pull request Feb 20, 2026
…penclaw#21447)

Fixes the pairing required regression from openclaw#21236 for legacy paired devices
created without roles/scopes metadata. Detects legacy paired metadata shape
and skips upgrade enforcement while backfilling metadata in place on reconnect.

Co-authored-by: Josh Avant <[email protected]>
Co-authored-by: Val Alexander <[email protected]>
anisoptera pushed a commit to anisoptera/openclaw that referenced this pull request Feb 20, 2026
@khanmubaris
Copy link
Copy Markdown

IS this released yet?

@elmariachi111
Copy link
Copy Markdown

my Opus 4.6 session could boil the solution down to

openclaw gateway stop
mkdir -p "${OPENCLAW_STATE_DIR:-$HOME/.openclaw}/devices"
[ -f "$HOME/.openclaw/devices/paired.json" ] && mv "$HOME/.openclaw/devices/paired.json" "$HOME/.openclaw/devices/paired.json.bak"
[ -f "$HOME/.openclaw/devices/pending.json" ] && mv "$HOME/.openclaw/devices/pending.json" "$HOME/.openclaw/devices/pending.json.bak"
openclaw gateway start

(I did an openclaw gateway install)

guess that's the solution buried in the thread, but if you can't wait for the new version to roll out, this might help you too ❤️

rodrigogs pushed a commit to rodrigogs/openclaw that referenced this pull request Feb 20, 2026
…penclaw#21447)

Fixes the pairing required regression from openclaw#21236 for legacy paired devices
created without roles/scopes metadata. Detects legacy paired metadata shape
and skips upgrade enforcement while backfilling metadata in place on reconnect.

Co-authored-by: Josh Avant <[email protected]>
Co-authored-by: Val Alexander <[email protected]>
rodrigogs pushed a commit to rodrigogs/openclaw that referenced this pull request Feb 20, 2026
@khanmubaris
Copy link
Copy Markdown

I downgraded to 2026.2.15 and its working now for me

Hansen1018 added a commit to Hansen1018/openclaw that referenced this pull request Feb 21, 2026
…penclaw#21447)

Fixes the pairing required regression from openclaw#21236 for legacy paired devices
created without roles/scopes metadata. Detects legacy paired metadata shape
and skips upgrade enforcement while backfilling metadata in place on reconnect.

Co-authored-by: Josh Avant <[email protected]>
Co-authored-by: Val Alexander <[email protected]>
Hansen1018 added a commit to Hansen1018/openclaw that referenced this pull request Feb 21, 2026
vincentkoc pushed a commit that referenced this pull request Feb 21, 2026
…21447)

Fixes the pairing required regression from #21236 for legacy paired devices
created without roles/scopes metadata. Detects legacy paired metadata shape
and skips upgrade enforcement while backfilling metadata in place on reconnect.

Co-authored-by: Josh Avant <[email protected]>
Co-authored-by: Val Alexander <[email protected]>
vincentkoc pushed a commit that referenced this pull request Feb 21, 2026
vincentkoc pushed a commit that referenced this pull request Feb 21, 2026
…21447)

Fixes the pairing required regression from #21236 for legacy paired devices
created without roles/scopes metadata. Detects legacy paired metadata shape
and skips upgrade enforcement while backfilling metadata in place on reconnect.

Co-authored-by: Josh Avant <[email protected]>
Co-authored-by: Val Alexander <[email protected]>
vincentkoc pushed a commit that referenced this pull request Feb 21, 2026
mmyyfirstb pushed a commit to mmyyfirstb/openclaw that referenced this pull request Feb 21, 2026
…penclaw#21447)

Fixes the pairing required regression from openclaw#21236 for legacy paired devices
created without roles/scopes metadata. Detects legacy paired metadata shape
and skips upgrade enforcement while backfilling metadata in place on reconnect.

Co-authored-by: Josh Avant <[email protected]>
Co-authored-by: Val Alexander <[email protected]>
mmyyfirstb pushed a commit to mmyyfirstb/openclaw that referenced this pull request Feb 21, 2026
obviyus pushed a commit to guirguispierre/openclaw that referenced this pull request Feb 22, 2026
…penclaw#21447)

Fixes the pairing required regression from openclaw#21236 for legacy paired devices
created without roles/scopes metadata. Detects legacy paired metadata shape
and skips upgrade enforcement while backfilling metadata in place on reconnect.

Co-authored-by: Josh Avant <[email protected]>
Co-authored-by: Val Alexander <[email protected]>
obviyus pushed a commit to guirguispierre/openclaw that referenced this pull request Feb 22, 2026
hughdidit pushed a commit to hughdidit/DAISy-Agency that referenced this pull request Mar 1, 2026
(cherry picked from commit 6bc9824)

# Conflicts:
#	README.md
hughdidit pushed a commit to hughdidit/DAISy-Agency that referenced this pull request Mar 3, 2026
(cherry picked from commit 6bc9824)

# Conflicts:
#	README.md
zooqueen pushed a commit to hanzoai/bot that referenced this pull request Mar 6, 2026
…penclaw#21447)

Fixes the pairing required regression from openclaw#21236 for legacy paired devices
created without roles/scopes metadata. Detects legacy paired metadata shape
and skips upgrade enforcement while backfilling metadata in place on reconnect.

Co-authored-by: Josh Avant <[email protected]>
Co-authored-by: Val Alexander <[email protected]>
zooqueen pushed a commit to hanzoai/bot that referenced this pull request Mar 6, 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.

[Bug]: Gateway returns "pairing required" after update to 2026.2.19-2

4 participants