Skip to content

Commit ee9a658

Browse files
authored
fix(ui): persist per-agent settings changes (#117107)
Closes #117046 Per-agent model, tool, skill, and node-binding edits in the Control UI were written to the retired `agents.list` shape, so the strict Gateway schema rejected them. Save failures could then be hidden by an immediate roster refresh. Route all affected writers through the canonical keyed `agents.entries` resolver, preserve authored keys, reject unsafe keys, align adjacent cron and swarm readers, and keep failed saves dirty with the Gateway error visible in the active panel. Validated with the exact Testbox changed gate, full CI, 314 focused UI tests, 11 Playwright scenarios, 42 Gateway config tests, clean autoreview, and ClawSweeper review.
1 parent 9ec20c4 commit ee9a658

29 files changed

Lines changed: 624 additions & 212 deletions

‎ui/src/e2e/agent-channel-runtime-status.e2e.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ describeControlUiE2e("Control UI Agents channel status", () => {
8585
channelDefaultAccountId: { discord: "default" },
8686
},
8787
"config.get": {
88-
config: { agents: { list: [{ id: "main" }] } },
88+
config: { agents: { entries: { main: { default: true } } } },
8989
hash: "hash-1",
9090
issues: [],
9191
raw: '{"agents":{"list":[{"id":"main"}]}}',
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
// Control UI E2E proves per-agent config writes use the canonical keyed shape.
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 captureUiProof = process.env.OPENCLAW_CAPTURE_UI_PROOF === "1";
19+
const proofDir = path.join(process.cwd(), ".artifacts", "control-ui-e2e", "agent-config-save");
20+
21+
let browser: Browser;
22+
let server: ControlUiE2eServer;
23+
24+
function requireRecord(value: unknown): Record<string, unknown> {
25+
if (!value || typeof value !== "object" || Array.isArray(value)) {
26+
throw new Error("Expected object value");
27+
}
28+
return value as Record<string, unknown>;
29+
}
30+
31+
describeControlUiE2e("Control UI agent config save", () => {
32+
beforeAll(async () => {
33+
if (!chromiumAvailable) {
34+
throw new Error(`Playwright Chromium is unavailable at ${chromiumExecutablePath}`);
35+
}
36+
server = await startControlUiE2eServer();
37+
browser = await chromium.launch({ executablePath: chromiumExecutablePath });
38+
});
39+
40+
afterAll(async () => {
41+
await browser?.close();
42+
await server?.close();
43+
});
44+
45+
it("submits keyed entries and surfaces Gateway validation failures", async () => {
46+
const context = await browser.newContext({
47+
locale: "en-US",
48+
serviceWorkers: "block",
49+
viewport: { height: 900, width: 1280 },
50+
});
51+
const page = await context.newPage();
52+
const config = {
53+
agents: {
54+
entries: {
55+
main: {
56+
default: true,
57+
tools: { profile: "full" },
58+
},
59+
},
60+
},
61+
};
62+
const gateway = await installMockGateway(page, {
63+
assistantName: "Main agent",
64+
defaultAgentId: "main",
65+
methodResponses: {
66+
"agents.list": {
67+
agents: [{ id: "main", name: "Main agent" }],
68+
defaultId: "main",
69+
mainKey: "main",
70+
scope: "agent",
71+
},
72+
"config.get": {
73+
config,
74+
sourceConfig: config,
75+
runtimeConfig: config,
76+
hash: "agent-config-hash-1",
77+
issues: [],
78+
raw: JSON.stringify(config),
79+
valid: true,
80+
},
81+
"tools.catalog": {
82+
agentId: "main",
83+
profiles: [{ id: "full", label: "Full" }],
84+
groups: [
85+
{
86+
id: "fs",
87+
label: "Files",
88+
source: "core",
89+
tools: [
90+
{
91+
id: "read",
92+
label: "read",
93+
description: "Read files",
94+
source: "core",
95+
defaultProfiles: ["full"],
96+
},
97+
],
98+
},
99+
],
100+
},
101+
"tools.effective": {
102+
agentId: "main",
103+
profile: "full",
104+
groups: [],
105+
notices: [],
106+
},
107+
},
108+
});
109+
110+
try {
111+
const response = await page.goto(`${server.baseUrl}settings/agents/main/tools`);
112+
expect(response?.status()).toBe(200);
113+
await gateway.waitForRequest("agents.list");
114+
await gateway.waitForRequest("config.get");
115+
await gateway.waitForRequest("tools.catalog");
116+
117+
await page
118+
.locator(".agent-tools-group")
119+
.filter({ hasText: "Files" })
120+
.locator(".agent-tools-group__summary")
121+
.click();
122+
await gateway.deferNext("config.set");
123+
await page.locator("#agent-tool-read wa-switch").click();
124+
125+
const request = await gateway.waitForRequest("config.set");
126+
const params = requireRecord(request.params);
127+
const raw = requireRecord(JSON.parse(String(params.raw)));
128+
expect(raw).toEqual({
129+
agents: {
130+
entries: {
131+
main: {
132+
default: true,
133+
tools: { profile: "full", deny: ["read"] },
134+
},
135+
},
136+
},
137+
});
138+
expect(requireRecord(raw.agents)).not.toHaveProperty("list");
139+
expect(params.baseHash).toBe("agent-config-hash-1");
140+
141+
await gateway.rejectDeferred("config.set", {
142+
code: "INVALID_REQUEST",
143+
message: "mock validation failure",
144+
});
145+
await page.getByRole("alert").filter({ hasText: "mock validation failure" }).waitFor();
146+
147+
if (captureUiProof) {
148+
await mkdir(proofDir, { recursive: true });
149+
await page.screenshot({
150+
animations: "disabled",
151+
fullPage: true,
152+
path: path.join(proofDir, "01-save-error.png"),
153+
});
154+
}
155+
} finally {
156+
await context.close();
157+
}
158+
});
159+
});

‎ui/src/e2e/agent-model-fallback-ownership.e2e.test.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,13 @@ describeControlUiE2e("Control UI agent model fallback ownership", () => {
6767
viewport: { height: 900, width: 1280 },
6868
});
6969
const page = await context.newPage();
70-
const writer = { id: "writer", ...(model === undefined ? {} : { model }) };
7170
const config = {
7271
agents: {
7372
defaults: { model: { primary: primaryModel, fallbacks: [inheritedFallback] } },
74-
list: [{ id: "main" }, writer],
73+
entries: {
74+
main: { default: true },
75+
writer: model === undefined ? {} : { model },
76+
},
7577
},
7678
};
7779
const gateway = await installMockGateway(page, {

‎ui/src/e2e/agents-set-default-persistence.e2e.test.ts‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ describeControlUiE2e("Control UI agents Set Default mocked Gateway E2E", () => {
5252
viewport: { height: 900, width: 1280 },
5353
});
5454
const page = await context.newPage();
55+
const initialConfig = {
56+
agents: { entries: { main: { default: true }, kimi: {} } },
57+
};
58+
const savedConfig = {
59+
agents: { entries: { main: {}, kimi: { default: true } } },
60+
};
5561
const gateway = await installMockGateway(page, {
5662
assistantName: "Main agent",
5763
defaultAgentId: "main",
@@ -66,17 +72,19 @@ describeControlUiE2e("Control UI agents Set Default mocked Gateway E2E", () => {
6672
scope: "agent",
6773
},
6874
"config.get": {
69-
config: { agents: { list: [{ id: "main" }, { id: "kimi" }] } },
75+
config: initialConfig,
76+
sourceConfig: initialConfig,
7077
hash: "hash-1",
7178
issues: [],
72-
raw: '{"agents":{"list":[{"id":"main"},{"id":"kimi"}]}}',
79+
raw: JSON.stringify(initialConfig),
7380
valid: true,
7481
},
7582
"config.set": {
76-
config: { agents: { list: [{ id: "main" }, { id: "kimi", default: true }] } },
83+
config: savedConfig,
84+
sourceConfig: savedConfig,
7785
hash: "hash-2",
7886
issues: [],
79-
raw: '{"agents":{"list":[{"id":"main"},{"id":"kimi","default":true}]}}',
87+
raw: JSON.stringify(savedConfig),
8088
valid: true,
8189
},
8290
},
@@ -98,9 +106,8 @@ describeControlUiE2e("Control UI agents Set Default mocked Gateway E2E", () => {
98106
// only stages a form draft and never emits config.set, so this request never arrives.
99107
const setRequest = await gateway.waitForRequest("config.set");
100108
const raw = requestParams(setRequest).raw;
101-
expect(JSON.parse(String(raw))).toEqual({
102-
agents: { list: [{ id: "main" }, { id: "kimi", default: true }] },
103-
});
109+
expect(JSON.parse(String(raw))).toEqual(savedConfig);
110+
expect(requireRecord(JSON.parse(String(raw))).agents).not.toHaveProperty("list");
104111
} finally {
105112
await context.close();
106113
}

‎ui/src/e2e/model-alias-display.e2e.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ suite.define(() => {
114114
"nvidia/moonshotai/kimi-k2.5": { alias: "Kimi K2.5 (NVIDIA)" },
115115
},
116116
},
117-
list: [{ id: "main" }],
117+
entries: { main: { default: true } },
118118
},
119119
};
120120
const gateway = await installMockGateway(page, {

‎ui/src/e2e/plugins-config-mutation.e2e.test.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ function configResponse(fallback: string | undefined, workboardEnabled: boolean,
3131
const config = {
3232
agents: {
3333
defaults: { model: { primary: "openai/gpt-5" } },
34-
list: [
35-
{
36-
id: "main",
34+
entries: {
35+
main: {
36+
default: true,
3737
model: {
3838
primary: "openai/gpt-5",
3939
...(fallback ? { fallbacks: [fallback] } : {}),
4040
},
4141
},
42-
],
42+
},
4343
},
4444
plugins: {
4545
entries: { workboard: { enabled: workboardEnabled } },

‎ui/src/lib/agents/display.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ describe("buildAgentContext", () => {
213213
fallbacks: ["openai/gpt-5.2-codex"],
214214
},
215215
},
216-
list: [{ id: "main" }],
216+
entries: { main: { default: true } },
217217
},
218218
},
219219
null,

‎ui/src/lib/agents/display.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import type {
1717
import { t } from "../../i18n/index.ts";
1818
import { resolveAgentAvatarUrl, resolveAssistantTextAvatar } from "../avatar.ts";
1919
import { buildCatalogDisplayLookup, buildChatModelOptionFromLookup } from "../chat/model-ref.ts";
20+
import { resolveAgentConfigEntryTarget } from "../config/index.ts";
2021
import { normalizeLowercaseStringOrEmpty, normalizeOptionalString } from "../string-coerce.ts";
2122

2223
type AgentRosterEntry = {
@@ -274,7 +275,6 @@ type ToolPolicy = {
274275
};
275276

276277
type AgentConfigEntry = {
277-
id: string;
278278
name?: string;
279279
workspace?: string;
280280
agentDir?: string;
@@ -292,7 +292,7 @@ type AgentConfigEntry = {
292292
type ConfigSnapshot = {
293293
agents?: {
294294
defaults?: { workspace?: string; model?: unknown; models?: Record<string, { alias?: string }> };
295-
list?: AgentConfigEntry[];
295+
entries?: Record<string, AgentConfigEntry>;
296296
};
297297
tools?: {
298298
profile?: string;
@@ -349,8 +349,9 @@ export function formatBytes(bytes?: number) {
349349

350350
export function resolveAgentConfig(config: Record<string, unknown> | null, agentId: string) {
351351
const cfg = config as ConfigSnapshot | null;
352-
const list = cfg?.agents?.list ?? [];
353-
const entry = list.find((agent) => agent?.id === agentId);
352+
const entry = resolveAgentConfigEntryTarget(config, agentId)?.entry as
353+
| AgentConfigEntry
354+
| undefined;
354355
return {
355356
entry,
356357
defaults: cfg?.agents?.defaults,

‎ui/src/lib/agents/index.test.ts‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ function createSaveState(): {
115115
const { state, request } = createState();
116116
const configState = {
117117
configFormDirty: true,
118-
configForm: { agents: { list: [{ id: "main" }] } },
119-
configFormOriginal: { agents: { list: [{ id: "main" }] } },
118+
configForm: { agents: { entries: { main: {} } } },
119+
configFormOriginal: { agents: { entries: { main: {} } } },
120120
};
121121
const config = {
122122
state: configState,
@@ -546,8 +546,8 @@ describe("setDefaultAgent", () => {
546546
it("stages the default agent and persists a clean draft", async () => {
547547
const { config } = createSaveState();
548548
const refreshAgents = vi.fn(async () => null);
549-
config.state.configForm = { agents: { list: [{ id: "main" }, { id: "kimi" }] } };
550-
config.state.configFormOriginal = { agents: { list: [{ id: "main" }, { id: "kimi" }] } };
549+
config.state.configForm = { agents: { entries: { main: {}, kimi: {} } } };
550+
config.state.configFormOriginal = { agents: { entries: { main: {}, kimi: {} } } };
551551
config.state.configFormDirty = false;
552552
vi.mocked(config.stageDefaultAgent).mockImplementation(() => {
553553
config.state.configFormDirty = true;
@@ -563,7 +563,7 @@ describe("setDefaultAgent", () => {
563563
it("does not persist when the agent is absent from the config list", async () => {
564564
const { config } = createSaveState();
565565
const refreshAgents = vi.fn(async () => null);
566-
config.state.configForm = { agents: { list: [{ id: "main" }] } };
566+
config.state.configForm = { agents: { entries: { main: {} } } };
567567
vi.mocked(config.stageDefaultAgent).mockReturnValue(false);
568568

569569
await setDefaultAgent(config, "ghost", refreshAgents);
@@ -577,19 +577,19 @@ describe("setDefaultAgent", () => {
577577
const { config } = createSaveState();
578578
const refreshAgents = vi.fn(async () => null);
579579
config.state.configFormDirty = true;
580-
config.state.configFormOriginal = { agents: { list: [{ id: "main" }, { id: "kimi" }] } };
580+
config.state.configFormOriginal = { agents: { entries: { main: {}, kimi: {} } } };
581581
config.state.configForm = {
582582
agents: {
583-
list: [{ id: "main", model: "gpt-5.5" }, { id: "kimi" }],
583+
entries: { main: { model: "gpt-5.5" }, kimi: {} },
584584
},
585585
};
586586
vi.mocked(config.stageDefaultAgent).mockImplementation(() => {
587587
config.state.configForm = {
588588
agents: {
589-
list: [
590-
{ id: "main", model: "gpt-5.5" },
591-
{ id: "kimi", default: true },
592-
],
589+
entries: {
590+
main: { model: "gpt-5.5" },
591+
kimi: { default: true },
592+
},
593593
},
594594
};
595595
config.state.configFormDirty = true;
@@ -603,10 +603,10 @@ describe("setDefaultAgent", () => {
603603
expect(refreshAgents).not.toHaveBeenCalled();
604604
expect(config.state.configForm).toEqual({
605605
agents: {
606-
list: [
607-
{ id: "main", model: "gpt-5.5" },
608-
{ id: "kimi", default: true },
609-
],
606+
entries: {
607+
main: { model: "gpt-5.5" },
608+
kimi: { default: true },
609+
},
610610
},
611611
});
612612
expect(config.state.configFormDirty).toBe(true);

0 commit comments

Comments
 (0)