Skip to content

Commit 289b81d

Browse files
fix(ui): preserve source config for Control UI saves
Co-authored-by: clawsweeper[bot] <274271284+clawsweeper[bot]@users.noreply.github.com>
1 parent acf265d commit 289b81d

4 files changed

Lines changed: 98 additions & 23 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ Docs: https://docs.openclaw.ai
6363
### Fixes
6464

6565
- Agents/compaction: skip agent-harness preflight for provider-owned CLI runtime sessions so over-threshold Claude CLI sessions continue through normal compaction instead of failing on a missing harness. Fixes #84857. (#84878) Thanks @zhangguiping-xydt.
66+
- Control UI/config: save form-mode edits from the source config snapshot so runtime-only provider defaults like empty `models.providers.<id>.baseUrl` are not written back and rejected. Fixes #85831. Thanks @garyd9.
6667
- Telegram: normalize legacy durable group retry targets before retry sends, polls, and pins so group retries keep using the real chat id. (#85656) Thanks @luoyanglang.
6768
- WebChat: summarize internal message-tool source replies so tool cards no longer duplicate the visible reply body. (#84773) Thanks @jason-allen-oneal.
6869
- WebChat: scope the visible attachment button to its own composer file input so clicking Upload reliably opens the file picker. (#83952, fixes #47983) Thanks @jason-allen-oneal.

‎ui/src/ui/controllers/config.test.ts‎

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,17 @@ describe("applyConfigSnapshot", () => {
8686
it("updates config form when clean", () => {
8787
const state = createState();
8888
applyConfigSnapshot(state, {
89-
config: { gateway: { mode: "local" } },
89+
sourceConfig: { gateway: { mode: "local" } },
90+
config: { gateway: { mode: "local", runtimeOnly: true } },
9091
valid: true,
9192
issues: [],
9293
raw: "{}",
9394
});
9495

9596
expect(state.configForm).toEqual({ gateway: { mode: "local" } });
97+
expect(state.configSnapshot?.config).toEqual({
98+
gateway: { mode: "local", runtimeOnly: true },
99+
});
96100
});
97101

98102
it("sets configRawOriginal when clean for change detection", () => {
@@ -184,7 +188,8 @@ describe("applyConfigSnapshot", () => {
184188
state.configFormMode = "raw";
185189

186190
applyConfigSnapshot(state, {
187-
config: { gateway: { mode: "local" } },
191+
sourceConfig: { gateway: { mode: "local" } },
192+
config: { gateway: { mode: "local", runtimeOnly: true } },
188193
valid: true,
189194
issues: [],
190195
raw: null,
@@ -221,7 +226,11 @@ describe("updateConfigFormValue", () => {
221226
it("seeds from snapshot when form is null", () => {
222227
const state = createState();
223228
state.configSnapshot = {
224-
config: { channels: { telegram: { botToken: "t" } }, gateway: { mode: "local" } },
229+
sourceConfig: { channels: { telegram: { botToken: "t" } }, gateway: { mode: "local" } },
230+
config: {
231+
channels: { telegram: { botToken: "t" } },
232+
gateway: { mode: "local", runtimeOnly: true },
233+
},
225234
valid: true,
226235
issues: [],
227236
raw: "{}",
@@ -830,6 +839,56 @@ describe("saveConfig", () => {
830839
expect(params.baseHash).toBe("hash-save-redacted");
831840
});
832841

842+
it("submits source config instead of runtime-materialized provider defaults", async () => {
843+
const request = createRequestWithConfigGet();
844+
const state = createState();
845+
state.connected = true;
846+
state.client = { request } as unknown as ConfigState["client"];
847+
state.configFormMode = "form";
848+
applyConfigSnapshot(state, {
849+
hash: "hash-source-provider",
850+
sourceConfig: {
851+
models: {
852+
providers: {
853+
openai: {
854+
agentRuntime: { id: "openai" },
855+
},
856+
},
857+
},
858+
ui: { theme: "light" },
859+
},
860+
config: {
861+
models: {
862+
providers: {
863+
openai: {
864+
agentRuntime: { id: "openai" },
865+
baseUrl: "",
866+
},
867+
},
868+
},
869+
ui: { theme: "light" },
870+
},
871+
valid: true,
872+
issues: [],
873+
raw: '{\n "models": {\n "providers": {\n "openai": {\n "agentRuntime": { "id": "openai" }\n }\n }\n },\n "ui": { "theme": "light" }\n}\n',
874+
});
875+
876+
updateConfigFormValue(state, ["ui", "theme"], "dark");
877+
await saveConfig(state);
878+
879+
const call = requireRequestCall(request);
880+
expect(call[0]).toBe("config.set");
881+
const params = call[1] as { raw: string; baseHash: string };
882+
const parsed = JSON.parse(params.raw) as {
883+
models: { providers: { openai: { agentRuntime: { id: string }; baseUrl?: string } } };
884+
ui: { theme: string };
885+
};
886+
expect(parsed.models.providers.openai.agentRuntime.id).toBe("openai");
887+
expect(parsed.models.providers.openai).not.toHaveProperty("baseUrl");
888+
expect(parsed.ui.theme).toBe("dark");
889+
expect(params.baseHash).toBe("hash-source-provider");
890+
});
891+
833892
it("drops stale loaded redacted placeholders before config.apply and keeps session key", async () => {
834893
const request = createRequestWithConfigGet();
835894
const state = createState();

‎ui/src/ui/controllers/config.ts‎

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,23 @@ function applyConfigSchema(state: ConfigState, res: ConfigSchemaResponse) {
8787
state.configSchemaVersion = res.version ?? null;
8888
}
8989

90+
function asConfigRecord(value: unknown): Record<string, unknown> | null {
91+
if (!value || typeof value !== "object" || Array.isArray(value)) {
92+
return null;
93+
}
94+
return value as Record<string, unknown>;
95+
}
96+
97+
function resolveEditableSnapshotConfig(
98+
snapshot: ConfigSnapshot | null | undefined,
99+
): Record<string, unknown> | null {
100+
return (
101+
asConfigRecord(snapshot?.sourceConfig) ??
102+
asConfigRecord(snapshot?.resolved) ??
103+
asConfigRecord(snapshot?.config)
104+
);
105+
}
106+
90107
export function applyConfigSnapshot(
91108
state: ConfigState,
92109
snapshot: ConfigSnapshot,
@@ -95,15 +112,16 @@ export function applyConfigSnapshot(
95112
const preservePendingChanges = state.configFormDirty && options.discardPendingChanges !== true;
96113
const draftBaseHash = state.configDraftBaseHash ?? state.configSnapshot?.hash ?? null;
97114
state.configSnapshot = snapshot;
115+
const editableConfig = resolveEditableSnapshotConfig(snapshot);
98116
const rawAvailable = typeof snapshot.raw === "string";
99117
if (!rawAvailable && state.configFormMode === "raw") {
100118
state.configFormMode = "form";
101119
}
102120
const rawFromSnapshot: string =
103121
typeof snapshot.raw === "string"
104122
? snapshot.raw
105-
: snapshot.config && typeof snapshot.config === "object"
106-
? serializeConfigForm(snapshot.config)
123+
: editableConfig
124+
? serializeConfigForm(editableConfig)
107125
: state.configRaw;
108126
if (!preservePendingChanges || state.configFormMode === "raw") {
109127
state.configRaw = rawFromSnapshot;
@@ -116,8 +134,8 @@ export function applyConfigSnapshot(
116134
state.configIssues = Array.isArray(snapshot.issues) ? snapshot.issues : [];
117135

118136
if (!preservePendingChanges) {
119-
state.configForm = cloneConfigObject(snapshot.config ?? {});
120-
state.configFormOriginal = cloneConfigObject(snapshot.config ?? {});
137+
state.configForm = cloneConfigObject(editableConfig ?? {});
138+
state.configFormOriginal = cloneConfigObject(editableConfig ?? {});
121139
state.configRawOriginal = rawFromSnapshot;
122140
state.configFormDirty = false;
123141
state.configDraftBaseHash = snapshot.hash ?? null;
@@ -232,7 +250,7 @@ async function submitConfigChange(
232250

233251
function syncConfigDraft(state: ConfigState, nextForm: Record<string, unknown>) {
234252
const original = cloneConfigObject(
235-
state.configFormOriginal ?? state.configSnapshot?.config ?? {},
253+
state.configFormOriginal ?? resolveEditableSnapshotConfig(state.configSnapshot) ?? {},
236254
);
237255
const nextRaw = serializeConfigForm(nextForm);
238256
const originalRaw = serializeConfigForm(original);
@@ -284,7 +302,9 @@ export async function runUpdate(state: ConfigState) {
284302
}
285303

286304
function mutateConfigForm(state: ConfigState, mutate: (draft: Record<string, unknown>) => void) {
287-
const base = cloneConfigObject(state.configForm ?? state.configSnapshot?.config ?? {});
305+
const base = cloneConfigObject(
306+
state.configForm ?? resolveEditableSnapshotConfig(state.configSnapshot) ?? {},
307+
);
288308
mutate(base);
289309
syncConfigDraft(state, base);
290310
}
@@ -374,12 +394,7 @@ export function updateConfigFormValue(
374394
}
375395

376396
export function stageConfigPreset(state: ConfigState, patch: Record<string, unknown>) {
377-
const snapshotConfig =
378-
state.configSnapshot?.config &&
379-
typeof state.configSnapshot.config === "object" &&
380-
!Array.isArray(state.configSnapshot.config)
381-
? state.configSnapshot.config
382-
: null;
397+
const snapshotConfig = resolveEditableSnapshotConfig(state.configSnapshot);
383398
const baseSource = state.configForm ?? snapshotConfig;
384399
if (!baseSource || (!state.configForm && !state.configSnapshot?.hash)) {
385400
return;
@@ -393,12 +408,11 @@ export function stageConfigPreset(state: ConfigState, patch: Record<string, unkn
393408
}
394409

395410
export function resetConfigPendingChanges(state: ConfigState) {
396-
state.configForm = cloneConfigObject(
397-
state.configFormOriginal ?? state.configSnapshot?.config ?? {},
398-
);
411+
const editableConfig = resolveEditableSnapshotConfig(state.configSnapshot);
412+
state.configForm = cloneConfigObject(state.configFormOriginal ?? editableConfig ?? {});
399413
state.configRaw =
400414
state.configRawOriginal ??
401-
serializeConfigForm(state.configFormOriginal ?? state.configSnapshot?.config ?? {});
415+
serializeConfigForm(state.configFormOriginal ?? editableConfig ?? {});
402416
state.configFormDirty = false;
403417
state.configDraftBaseHash = state.configSnapshot?.hash ?? null;
404418
autoAllowlistedPluginIdsByState.delete(state);
@@ -434,8 +448,7 @@ export function ensureAgentConfigEntry(state: ConfigState, agentId: string): num
434448
if (!normalizedAgentId) {
435449
return -1;
436450
}
437-
const source =
438-
state.configForm ?? (state.configSnapshot?.config as Record<string, unknown> | null);
451+
const source = state.configForm ?? resolveEditableSnapshotConfig(state.configSnapshot);
439452
const existingIndex = findAgentConfigEntryIndex(source, normalizedAgentId);
440453
if (existingIndex >= 0) {
441454
return existingIndex;
@@ -451,8 +464,7 @@ export function stageDefaultAgentConfigEntry(state: ConfigState, agentId: string
451464
if (!normalizedAgentId) {
452465
return false;
453466
}
454-
const source =
455-
state.configForm ?? (state.configSnapshot?.config as Record<string, unknown> | null);
467+
const source = state.configForm ?? resolveEditableSnapshotConfig(state.configSnapshot);
456468
const targetIndex = findAgentConfigEntryIndex(source, normalizedAgentId);
457469
if (targetIndex < 0) {
458470
return false;

‎ui/src/ui/types.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,9 @@ export type ConfigSnapshot = {
290290
hash?: string | null;
291291
parsed?: unknown;
292292
valid?: boolean | null;
293+
sourceConfig?: Record<string, unknown> | null;
294+
resolved?: Record<string, unknown> | null;
295+
runtimeConfig?: Record<string, unknown> | null;
293296
config?: Record<string, unknown> | null;
294297
issues?: ConfigSnapshotIssue[] | null;
295298
};

0 commit comments

Comments
 (0)