Skip to content

fix(pairing): avoid stale full config overwrite during origin patch#325

Draft
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-investigation-767f
Draft

fix(pairing): avoid stale full config overwrite during origin patch#325
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-investigation-767f

Conversation

@cursor

@cursor cursor Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Bug and impact

auto_pair_device() always calls patch_gateway_origins() on WebSocket reconnect (common on Windows pairing/origin failures). The previous implementation read openclaw.json, patched allowedOrigins, then wrote the entire stale snapshot back to disk.

If the user saved config concurrently (gateway auth/token, models, channels, etc.), the stale snapshot could overwrite those edits — silent config loss.

Root cause

patch_gateway_origins / patchGatewayOrigins treated the read-time config as the full source of truth instead of issuing a targeted update. Even on Tauri, save_openclaw_json merges shallowly, so a full stale gateway object could revert freshly saved gateway.auth and other nested fields.

This risk increased after the recent pairing stabilization work (e16ff2b), which made origin patching run on every auto-pair attempt.

Fix

  • Rust (pairing.rs): compute merged allowedOrigins, then call save_openclaw_json with only { gateway: { controlUi: { allowedOrigins } } } so merge preserves unrelated fields.
  • Web dev API (dev-api.js): same partial patch, merged via mergeConfigsPreservingFields before write.

Validation

  • Added tests/patch-gateway-origins.test.js (source-level regression guard)
  • Added partial_gateway_patch_preserves_auth_token merge test in config.rs
  • node --test tests/patch-gateway-origins.test.js → 2/2 pass
Open in Web View Automation 

auto_pair_device always patches gateway.controlUi.allowedOrigins. The
previous implementation saved the entire config snapshot captured at read
time, which could clobber concurrent user edits to gateway auth, models,
or channels when WebSocket auto-pair ran during reconnect.

Write only the allowedOrigins delta through the existing merge path so
other fields on disk are preserved.

Co-authored-by: 晴天 <1186258278@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant