Skip to content

Commit 5d6f211

Browse files
steipetePeter Steinberger
andauthored
fix(ui): canonical plugin settings, reconnect, and freshness ownership (#117047)
* fix(ui): unify memory and plugin config mutation ownership * test(ui): prove committed memory refresh failures in Chromium * fix(ui): preserve concurrent memory mutation outcomes * test(ui): prove model setup reloads after reconnect * test(ui): await mocked reconnect handshake before restoring model * fix(ui): own model setup connection generations * test(ui): use valid setup gateway hello fixtures * test(ui): synchronize memory mutation owner regressions * fix(ui): bind memory restart notices to executing gateway process * fix(ui): scope setup and memory state to gateway connections * fix(ui): prevent stale memory restart notice ownership * fix(ui): separate gateway refresh warnings from restart notices * test(ui): await current memory catalog before reconnect actions * fix(ui): clear shared memory refresh warnings after authoritative updates * test(ui): click the visible memory add-on switch host * test(ui): assert canonical gateway refresh error text * test(ui): align gateway fixtures and dead-code ownership --------- Co-authored-by: Peter Steinberger <[email protected]>
1 parent e8d546c commit 5d6f211

19 files changed

Lines changed: 1869 additions & 484 deletions

‎ui/src/app/bootstrap.test.ts‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -338,11 +338,16 @@ describe("normalizeInitialApplicationLocation", () => {
338338
return () => undefined;
339339
});
340340
const replaceRoute = vi.fn();
341+
const gateway = {
342+
snapshot: {
343+
phase: "connecting",
344+
client: null,
345+
hello: null,
346+
} as Parameters<GatewayListener>[0],
347+
subscribe,
348+
};
341349
const context = {
342-
gateway: {
343-
snapshot: { phase: "connecting", client: null, hello: null },
344-
subscribe,
345-
},
350+
gateway,
346351
replace: replaceRoute,
347352
} as unknown as ApplicationContext<RouteId>;
348353

@@ -363,14 +368,15 @@ describe("normalizeInitialApplicationLocation", () => {
363368
if (!connectedListener) {
364369
throw new Error("expected first-run gateway listener");
365370
}
366-
connectedListener({
371+
gateway.snapshot = {
367372
phase: "connected",
368373
client,
369374
hello: {
370375
auth: { role: "operator", scopes: ["operator.admin"] },
371376
features: { methods: ["openclaw.setup.detect"] },
372377
},
373-
} as Parameters<GatewayListener>[0]);
378+
} as Parameters<GatewayListener>[0];
379+
connectedListener(gateway.snapshot);
374380
await vi.waitFor(() => expect(replaceRoute).toHaveBeenCalledOnce(), STARTUP_STEP_WAIT);
375381
expect(replaceRoute).toHaveBeenCalledWith("model-setup", { search: "?firstRun=1" });
376382
});

‎ui/src/e2e/memory-settings-engine.e2e.test.ts‎

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,93 @@ describeControlUiE2e("Control UI memory engine settings mocked Gateway E2E", ()
157157
}
158158
});
159159

160+
it("keeps a committed add-on enabled and makes a failed config refresh visible", async () => {
161+
const context = await browser.newContext({
162+
colorScheme: "dark",
163+
locale: "en-US",
164+
serviceWorkers: "block",
165+
viewport: { height: 900, width: 1440 },
166+
});
167+
const page = await context.newPage();
168+
const pageErrors: string[] = [];
169+
page.on("pageerror", (error) => pageErrors.push(String(error)));
170+
const activeMemory = {
171+
id: "active-memory",
172+
name: "Active memory",
173+
installed: true,
174+
enabled: false,
175+
state: "disabled",
176+
};
177+
const gateway = await installMockGateway(page, {
178+
methodResponses: {
179+
"config.get": configResponse("memory-lancedb", "memory-refresh-hash-1"),
180+
"plugins.list": {
181+
plugins: [...memoryPlugins, activeMemory],
182+
diagnostics: [],
183+
mutationAllowed: true,
184+
},
185+
},
186+
});
187+
188+
try {
189+
await page.goto(`${server.baseUrl}settings/memory/settings`);
190+
const toggle = page.getByRole("switch", { name: "Enable or disable Active memory" });
191+
await toggle.waitFor();
192+
const initialConfigReads = (await gateway.getRequests("config.get")).length;
193+
const initialCatalogReads = (await gateway.getRequests("plugins.list")).length;
194+
await gateway.deferNext("plugins.setEnabled");
195+
await gateway.deferNext("config.get");
196+
await page
197+
.locator("wa-switch.settings-toggle")
198+
.filter({ hasText: "Enable or disable Active memory" })
199+
.click();
200+
201+
const mutation = await gateway.waitForRequest("plugins.setEnabled");
202+
expect(mutation.params).toEqual({ pluginId: "active-memory", enabled: true });
203+
const committed = { ...activeMemory, enabled: true, state: "enabled" };
204+
await gateway.setMethodResponse("plugins.list", {
205+
plugins: [...memoryPlugins, committed],
206+
diagnostics: [],
207+
mutationAllowed: true,
208+
});
209+
await gateway.resolveDeferred("plugins.setEnabled", {
210+
ok: true,
211+
plugin: committed,
212+
restartRequired: false,
213+
});
214+
await expect
215+
.poll(async () => (await gateway.getRequests("config.get")).length)
216+
.toBeGreaterThan(initialConfigReads);
217+
await gateway.rejectDeferred("config.get", {
218+
code: "UNAVAILABLE",
219+
message: "authoritative snapshot unavailable",
220+
});
221+
222+
await expect
223+
.poll(async () => (await gateway.getRequests("plugins.list")).length)
224+
.toBeGreaterThan(initialCatalogReads);
225+
await expect.poll(() => toggle.getAttribute("aria-checked")).toBe("true");
226+
await page.getByText("Needs attention", { exact: true }).first().waitFor();
227+
await page
228+
.getByText(
229+
"Could not refresh Control UI configuration: GatewayRequestError: authoritative snapshot unavailable",
230+
)
231+
.waitFor();
232+
expect(await page.getByText("Could not update Active memory").count()).toBe(0);
233+
expect(pageErrors).toEqual([]);
234+
235+
if (captureUiProofEnabled) {
236+
await mkdir(uiProofArtifactDir, { recursive: true });
237+
await page.locator("openclaw-memory-settings").screenshot({
238+
animations: "disabled",
239+
path: path.join(uiProofArtifactDir, "03-addon-committed-refresh-warning.png"),
240+
});
241+
}
242+
} finally {
243+
await context.close();
244+
}
245+
});
246+
160247
it("keeps a missing default engine labelled, first, and selected as unavailable", async () => {
161248
const context = await browser.newContext({
162249
colorScheme: "dark",
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// Browser proof that model setup reloads after a same-client Gateway reconnect.
2+
import { mkdir } from "node:fs/promises";
3+
import path from "node:path";
4+
import { chromium, type Browser } from "playwright";
5+
import { afterAll, beforeAll, describe, expect, it } from "vitest";
6+
import {
7+
canRunPlaywrightChromium,
8+
installMockGateway,
9+
resolvePlaywrightChromiumExecutablePath,
10+
startControlUiE2eServer,
11+
type ControlUiE2eServer,
12+
} from "../test-helpers/control-ui-e2e.ts";
13+
14+
const chromiumExecutablePath = resolvePlaywrightChromiumExecutablePath(chromium.executablePath());
15+
const chromiumAvailable = canRunPlaywrightChromium(chromiumExecutablePath);
16+
const allowMissingChromium = process.env.OPENCLAW_UI_E2E_ALLOW_MISSING_CHROMIUM === "1";
17+
const describeControlUiE2e = chromiumAvailable || !allowMissingChromium ? describe : describe.skip;
18+
const captureUiProofEnabled = process.env.OPENCLAW_CAPTURE_UI_PROOF === "1";
19+
const artifactDir = path.join(
20+
process.cwd(),
21+
".artifacts",
22+
"control-ui-e2e",
23+
"model-setup-reconnect",
24+
);
25+
26+
function detection(modelRef: string) {
27+
return {
28+
candidates: [],
29+
manualProviders: [],
30+
configuredModel: modelRef,
31+
setupComplete: true,
32+
workspace: "/tmp/openclaw-e2e",
33+
};
34+
}
35+
36+
let browser: Browser;
37+
let server: ControlUiE2eServer;
38+
39+
describeControlUiE2e("Control UI model setup same-client reconnect", () => {
40+
beforeAll(async () => {
41+
if (!chromiumAvailable) {
42+
throw new Error(`Playwright Chromium is unavailable at ${chromiumExecutablePath}`);
43+
}
44+
server = await startControlUiE2eServer();
45+
browser = await chromium.launch({ executablePath: chromiumExecutablePath });
46+
});
47+
48+
afterAll(async () => {
49+
await browser?.close();
50+
await server?.close();
51+
});
52+
53+
it("re-detects once and replaces stale visible model state after reconnect", async () => {
54+
const context = await browser.newContext({
55+
locale: "en-US",
56+
serviceWorkers: "block",
57+
viewport: { height: 900, width: 1280 },
58+
});
59+
const page = await context.newPage();
60+
const pageErrors: string[] = [];
61+
page.on("pageerror", (error) => pageErrors.push(String(error)));
62+
const gateway = await installMockGateway(page, {
63+
featureMethods: ["openclaw.setup.detect"],
64+
methodResponses: { "openclaw.setup.detect": detection("provider/original-model") },
65+
});
66+
67+
try {
68+
const response = await page.goto(`${server.baseUrl}settings/model-setup`);
69+
expect(response?.status()).toBe(200);
70+
await page.getByText("provider/original-model").waitFor();
71+
const initialDetections = (await gateway.getRequests("openclaw.setup.detect")).length;
72+
const initialConnections = (await gateway.getRequests("connect")).length;
73+
await gateway.setMethodResponse(
74+
"openclaw.setup.detect",
75+
detection("provider/reconnected-model"),
76+
);
77+
await gateway.deferNext("connect");
78+
await gateway.closeLatest(1012, "model setup reconnect proof");
79+
await expect.poll(async () => page.getByText("provider/original-model").count()).toBe(0);
80+
await expect
81+
.poll(async () => (await gateway.getRequests("connect")).length)
82+
.toBeGreaterThan(initialConnections);
83+
await gateway.resolveDeferred("connect");
84+
await expect
85+
.poll(async () => (await gateway.getRequests("openclaw.setup.detect")).length)
86+
.toBe(initialDetections + 1);
87+
await page.getByText("provider/reconnected-model").waitFor();
88+
expect(pageErrors).toEqual([]);
89+
90+
if (captureUiProofEnabled) {
91+
await mkdir(artifactDir, { recursive: true });
92+
await page.locator("openclaw-model-setup-page").screenshot({
93+
animations: "disabled",
94+
path: path.join(artifactDir, "00-reconnected-model-visible.png"),
95+
});
96+
}
97+
} finally {
98+
await context.close();
99+
}
100+
});
101+
});

‎ui/src/lib/plugins/index.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type {
1414
PluginsUninstallResult,
1515
} from "../../../../packages/gateway-protocol/src/schema/plugins.js";
1616
import { GatewayRequestError, type GatewayBrowserClient } from "../../api/gateway.ts";
17+
import type { RuntimeConfigCapability } from "../config/index.ts";
1718

1819
export type PluginCatalogItem = PluginCatalogEntry;
1920
export type PluginListResult = ProtocolPluginsListResult;
@@ -50,6 +51,34 @@ export function setPluginEnabled(
5051
return client.request<PluginMutationResult>("plugins.setEnabled", { pluginId, enabled });
5152
}
5253

54+
/** Serialize every plugin config write without discarding structured Gateway failures. */
55+
export async function runPluginConfigMutation<T>(
56+
runtimeConfig: Pick<RuntimeConfigCapability, "runExternalMutation">,
57+
expectedClient: GatewayBrowserClient,
58+
task: (client: GatewayBrowserClient) => Promise<T>,
59+
): Promise<{ value: T; refreshError: string | null }> {
60+
let taskError: Error | undefined;
61+
const mutation = await runtimeConfig.runExternalMutation(async (client) => {
62+
if (client !== expectedClient) {
63+
throw new Error("Connection changed before the plugin update started.");
64+
}
65+
try {
66+
return await task(client);
67+
} catch (error) {
68+
// ClawHub risk acknowledgment requires the original structured Gateway error.
69+
taskError = error instanceof Error ? error : new Error(String(error));
70+
throw taskError;
71+
}
72+
});
73+
if (!mutation.ok) {
74+
throw taskError ?? new Error(mutation.error);
75+
}
76+
return {
77+
value: mutation.value,
78+
refreshError: mutation.refresh.ok ? null : mutation.refresh.error,
79+
};
80+
}
81+
5382
export function readPluginInstallTrustError(error: unknown): ClawHubTrustErrorDetails | undefined {
5483
if (!(error instanceof GatewayRequestError)) {
5584
return undefined;

0 commit comments

Comments
 (0)