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

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>
This commit is contained in:
Cursor Agent
2026-06-09 11:13:58 +00:00
parent 5aa09f4bb7
commit 8230066c2b
4 changed files with 102 additions and 33 deletions

View File

@@ -2687,10 +2687,17 @@ function patchGatewayOrigins() {
const merged = [...new Set([...existing, ...origins])]
// 幂等:已包含所有需要的 origin 时跳过写入
if (origins.every(o => existing.includes(o))) return false
if (!config.gateway) config.gateway = {}
if (!config.gateway.controlUi) config.gateway.controlUi = {}
config.gateway.controlUi.allowedOrigins = merged
writeOpenclawConfigFile(config)
// 只写入 allowedOrigins 增量,避免用陈旧全量快照覆盖并发保存的其它配置字段。
const existingOnDisk = fs.existsSync(CONFIG_PATH) ? JSON.parse(fs.readFileSync(CONFIG_PATH, 'utf8')) : null
const partial = {
gateway: {
controlUi: {
allowedOrigins: merged,
},
},
}
const mergedConfig = existingOnDisk ? mergeConfigsPreservingFields(existingOnDisk, partial) : partial
writeOpenclawConfigFile(mergedConfig)
return true
}