Skip to content

Commit 389b83f

Browse files
author
ObitaBot
committed
fix: scope localStorage settings key by basePath to prevent cross-deployment conflicts
- Add settingsKeyForGateway() function similar to tokenSessionKeyForGateway() - Use scoped key format: openclaw.control.settings.v1:https://example.com/gateway-a - Add migration from legacy static key on load - Fixes #47481
1 parent ad97c58 commit 389b83f

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

ui/src/ui/storage.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
const KEY = "openclaw.control.settings.v1";
1+
const SETTINGS_KEY_PREFIX = "openclaw.control.settings.v1:";
22
const LEGACY_TOKEN_SESSION_KEY = "openclaw.control.token.v1";
33
const TOKEN_SESSION_KEY_PREFIX = "openclaw.control.token.v1:";
44
const MAX_SCOPED_SESSION_ENTRIES = 10;
55

6+
function settingsKeyForGateway(gatewayUrl: string): string {
7+
return `${SETTINGS_KEY_PREFIX}${normalizeGatewayTokenScope(gatewayUrl)}`;
8+
}
9+
610
type ScopedSessionSelection = {
711
sessionKey: string;
812
lastActiveSessionKey: string;
@@ -188,7 +192,9 @@ export function loadSettings(): UiSettings {
188192
};
189193

190194
try {
191-
const raw = storage?.getItem(KEY);
195+
// First check for legacy key (no scope), then check for scoped key
196+
const scopedKey = settingsKeyForGateway(defaults.gatewayUrl);
197+
const raw = storage?.getItem(scopedKey) ?? storage?.getItem(SETTINGS_KEY_PREFIX + "default") ?? storage?.getItem("openclaw.control.settings.v1");
192198
if (!raw) {
193199
return defaults;
194200
}
@@ -256,9 +262,11 @@ function persistSettings(next: UiSettings) {
256262
persistSessionToken(next.gatewayUrl, next.token);
257263
const storage = getSafeLocalStorage();
258264
const scope = normalizeGatewayTokenScope(next.gatewayUrl);
265+
const scopedKey = settingsKeyForGateway(next.gatewayUrl);
259266
let existingSessionsByGateway: Record<string, ScopedSessionSelection> = {};
260267
try {
261-
const raw = storage?.getItem(KEY);
268+
// Try to migrate from legacy key or other scopes
269+
const raw = storage?.getItem(scopedKey) ?? storage?.getItem(SETTINGS_KEY_PREFIX + "default") ?? storage?.getItem("openclaw.control.settings.v1");
262270
if (raw) {
263271
const parsed = JSON.parse(raw) as PersistedUiSettings;
264272
if (parsed.sessionsByGateway && typeof parsed.sessionsByGateway === "object") {
@@ -294,5 +302,5 @@ function persistSettings(next: UiSettings) {
294302
sessionsByGateway,
295303
...(next.locale ? { locale: next.locale } : {}),
296304
};
297-
storage?.setItem(KEY, JSON.stringify(persisted));
305+
storage?.setItem(scopedKey, JSON.stringify(persisted));
298306
}

0 commit comments

Comments
 (0)