Skip to content

Commit 049e0ea

Browse files
committed
fix(ui): serialize settings writes through canonical config owner
1 parent c66ca2f commit 049e0ea

5 files changed

Lines changed: 1950 additions & 229 deletions

File tree

‎ui/src/app/app-host.ts‎

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import { i18n, isSupportedLocale, t } from "../i18n/index.ts";
5454
import { normalizeAgentLabel } from "../lib/agents/display.ts";
5555
import type { BoardFace } from "../lib/board/settings.ts";
5656
import { copyToClipboard } from "../lib/clipboard.ts";
57+
import { hasCurrentConfigSnapshot } from "../lib/config/index.ts";
5758
import { isGatewayMethodAdvertised } from "../lib/gateway-methods.ts";
5859
import { createIdleImport } from "../lib/idle-import.ts";
5960
import { isWorkboardEnabledInConfigSnapshot } from "../lib/plugin-activation.ts";
@@ -523,6 +524,7 @@ class OpenClawShell extends OpenClawLightDomElement {
523524
private sessionKeyClient: GatewayBrowserClient | null = null;
524525
private runtimeConfigClient: GatewayBrowserClient | null = null;
525526
private runtimeConfigSource: ApplicationContext["runtimeConfig"] | null = null;
527+
private runtimeConfigConnectionEpoch: number | null = null;
526528
private sidebarWorkboardSnapshot = EMPTY_SIDEBAR_WORKBOARD_SNAPSHOT;
527529
private sidebarWorkboardRuntime: SidebarWorkboardRuntime | null = null;
528530
private sidebarWorkboardHost: ApplicationContext["workboard"] | null = null;
@@ -655,18 +657,21 @@ class OpenClawShell extends OpenClawLightDomElement {
655657
)
656658
.watch(
657659
() => this.context?.runtimeConfig,
658-
(runtimeConfig, notify) =>
659-
runtimeConfig.subscribe(() => {
660-
this.reconcileServerUiPrefs(runtimeConfig);
661-
this.syncSidebarWorkboard();
662-
notify();
663-
}),
660+
(runtimeConfig, notify) => runtimeConfig.subscribe(notify),
664661
(runtimeConfig) => {
665-
const snapshot = this.context?.gateway.snapshot;
662+
const context = this.context;
663+
if (context?.runtimeConfig !== runtimeConfig) {
664+
return;
665+
}
666+
const snapshot = context.gateway.snapshot;
666667
if (snapshot) {
667668
this.ensureRuntimeConfig(snapshot, runtimeConfig);
668669
}
669-
this.reconcileServerUiPrefs(runtimeConfig);
670+
this.reconcileServerUiPrefs(
671+
runtimeConfig,
672+
runtimeConfig.state.configSnapshot,
673+
runtimeConfig.connectionEpoch,
674+
);
670675
this.syncSidebarWorkboard();
671676
},
672677
);
@@ -677,15 +682,26 @@ class OpenClawShell extends OpenClawLightDomElement {
677682
* apply server-side deltas to the browser mirror whenever a config snapshot
678683
* lands (connect, settings pages, reloads).
679684
*/
680-
private reconcileServerUiPrefs(runtimeConfig: ApplicationContext["runtimeConfig"]) {
681-
const snapshot = runtimeConfig.state.configSnapshot;
685+
private reconcileServerUiPrefs(
686+
runtimeConfig: ApplicationContext["runtimeConfig"],
687+
snapshot = runtimeConfig.state.configSnapshot,
688+
connectionEpoch = runtimeConfig.connectionEpoch,
689+
) {
682690
const context = this.context;
683-
if (!snapshot?.config || !context) {
691+
if (
692+
!snapshot?.config ||
693+
!context ||
694+
(context.runtimeConfig &&
695+
(context.runtimeConfig !== runtimeConfig || !hasCurrentConfigSnapshot(runtimeConfig))) ||
696+
runtimeConfig.connectionEpoch !== connectionEpoch ||
697+
runtimeConfig.state.configSnapshot !== snapshot
698+
) {
684699
return;
685700
}
686701
applyServerUiPrefs(snapshot.config, {
687702
scope: context.gateway.connection.gatewayUrl,
688703
snapshotHash: snapshot.hash ?? undefined,
704+
runtimeConfig,
689705
onApplied: (patch) => {
690706
if (patch.sidebarEntries !== undefined) {
691707
context.navigation.update({ sidebarEntries: patch.sidebarEntries });
@@ -730,8 +746,8 @@ class OpenClawShell extends OpenClawLightDomElement {
730746
}
731747
const prefs = changedServerUiPrefs(previous, next);
732748
const snapshot = this.context?.gateway.snapshot;
733-
if (prefs && snapshot?.phase === "connected" && snapshot.client) {
734-
pushServerUiPrefs(snapshot.client, prefs);
749+
if (prefs && snapshot?.phase === "connected" && snapshot.client && this.context) {
750+
pushServerUiPrefs(this.context.runtimeConfig, prefs);
735751
}
736752
});
737753
}
@@ -784,6 +800,7 @@ class OpenClawShell extends OpenClawLightDomElement {
784800
this.sessionKeyClient = null;
785801
this.runtimeConfigClient = null;
786802
this.runtimeConfigSource = null;
803+
this.runtimeConfigConnectionEpoch = null;
787804
this.disposeSidebarWorkboard();
788805
if (this.agentRosterRefreshTimer !== null) {
789806
globalThis.clearTimeout(this.agentRosterRefreshTimer);
@@ -1524,16 +1541,19 @@ class OpenClawShell extends OpenClawLightDomElement {
15241541
// load eagerly instead of waiting for a page that happens to fetch it.
15251542
if (snapshot.phase !== "connected" || !snapshot.client || !runtimeConfig) {
15261543
this.runtimeConfigClient = null;
1544+
this.runtimeConfigConnectionEpoch = null;
15271545
return;
15281546
}
15291547
if (
15301548
this.runtimeConfigClient === snapshot.client &&
1531-
this.runtimeConfigSource === runtimeConfig
1549+
this.runtimeConfigSource === runtimeConfig &&
1550+
this.runtimeConfigConnectionEpoch === runtimeConfig.connectionEpoch
15321551
) {
15331552
return;
15341553
}
15351554
this.runtimeConfigClient = snapshot.client;
15361555
this.runtimeConfigSource = runtimeConfig;
1556+
this.runtimeConfigConnectionEpoch = runtimeConfig.connectionEpoch;
15371557
void runtimeConfig.ensureLoaded();
15381558
}
15391559

0 commit comments

Comments
 (0)