Skip to content

fix(ui): reset config dirty on reload - #40441

Closed
AaronWander wants to merge 1 commit into
openclaw:mainfrom
AaronWander:fix/ui-reload-clears-dirty-40352
Closed

AaronWander wants to merge 1 commit into
openclaw:mainfrom
AaronWander:fix/ui-reload-clears-dirty-40352

Conversation

@AaronWander

Copy link
Copy Markdown
Contributor

Summary

  • Problem: Control UI "Reload Config" can leave configFormDirty set, so applyConfigSnapshot refuses to refresh configForm, causing the Model Selection dropdown to show stale values.
  • Why it matters: Operators can’t trust the Control UI model selection state after reloading config; this creates confusion and can lead to incorrect model changes.
  • What changed: loadConfig() now resets configFormDirty before fetching/applying the fresh snapshot so the form state reflects the server config on explicit reload.
  • What did NOT change (scope boundary): No server-side config logic; no changes to how dirty state is set during edits or how autosave/apply works.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

Closes #40352

User-visible / Behavior Changes

Clicking "Reload Config" now refreshes the Control UI form state from the latest config snapshot, so the Model Selection dropdown no longer remains stuck on stale values.

Security Impact (required)

  • New permissions/capabilities? (No)
  • Secrets/tokens handling changed? (No)
  • New/changed network calls? (No)
  • Command/tool execution surface changed? (No)
  • Data access scope changed? (No)
  • If any Yes, explain risk + mitigation: N/A

Repro + Verification

Environment

  • OS: N/A (unit-test coverage)
  • Runtime/container: Node + pnpm
  • Model/provider: N/A
  • Integration/channel (if any): N/A
  • Relevant config (redacted): N/A

Steps

  1. Run pnpm test test/ui-config-reload-clears-dirty.test.ts.

Expected

  • When config is explicitly reloaded, the form state updates from the latest snapshot even if it was previously marked dirty.

Actual

  • Before fix: reload could keep dirty state and skip form refresh.
  • After fix: dirty state is cleared for explicit reload, and form refreshes.

Evidence

  • Failing behavior before + passing after (unit test)

Human Verification (required)

  • Verified scenarios: pnpm test test/ui-config-reload-clears-dirty.test.ts
  • Edge cases checked: N/A
  • What you did not verify: Full Control UI manual flow in a running gateway

Compatibility / Migration

  • Backward compatible? (Yes)
  • Config/env changes? (No)
  • Migration needed? (No)
  • If yes, exact upgrade steps: N/A

Failure Recovery (if this breaks)

Revert this commit.

Risks and Mitigations

  • Risk: Reload discards unsaved form edits.
    • Mitigation: This only affects explicit "Reload Config"; save/apply flows are unchanged.

@greptile-apps

greptile-apps Bot commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a Control UI bug where clicking "Reload Config" left configFormDirty set to true, causing applyConfigSnapshot to skip the form refresh and leave the Model Selection dropdown showing stale values. The fix is a single line (state.configFormDirty = false) added to loadConfig before the fetch, with a focused unit test covering the regression scenario.

  • Core fix (ui/src/ui/controllers/config.ts, line 43): resetting configFormDirty to false before the load ensures applyConfigSnapshot always refreshes configForm, configFormOriginal, configRaw, and configRawOriginal on an explicit reload.
  • Scope is correctly bounded: saveConfig and applyConfig already reset configFormDirty before calling loadConfig, so those flows are unaffected (the reset is slightly redundant in those paths but harmless).
  • Test (test/ui-config-reload-clears-dirty.test.ts): covers the primary regression scenario well, but is missing assertions on configFormOriginal and configRawOriginal, which are also updated by applyConfigSnapshot when dirty is cleared — a minor gap worth closing.

Confidence Score: 4/5

  • Safe to merge; the one-line fix is correct, well-scoped, and the regression is covered by the new unit test.
  • The change is minimal and targeted — a single line reset in loadConfig that correctly unblocks applyConfigSnapshot. Existing callers already reset dirty state before calling loadConfig, so no regressions in save/apply flows. The only gap is the test not asserting configFormOriginal/configRawOriginal, which is a minor coverage omission rather than a functional issue.
  • No files require special attention; the minor test coverage gap in test/ui-config-reload-clears-dirty.test.ts is worth addressing but is not a blocker.

Last reviewed commit: 0e06d63

Comment on lines +57 to +59
expect(state.configFormDirty).toBe(false);
expect(state.configForm).toEqual({ gateway: { mode: "remote" } });
expect(state.configRaw).toBe('{\n "gateway": { "mode": "remote" }\n}\n');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test missing configFormOriginal / configRawOriginal assertions

applyConfigSnapshot also updates configFormOriginal and configRawOriginal when configFormDirty is false (lines 99–101 of config.ts). The test verifies configForm and configRaw are refreshed, but not these two derived fields. Adding assertions for them would guard against future regressions where the "original" baseline diverges from the reloaded snapshot.

Suggested change
expect(state.configFormDirty).toBe(false);
expect(state.configForm).toEqual({ gateway: { mode: "remote" } });
expect(state.configRaw).toBe('{\n "gateway": { "mode": "remote" }\n}\n');
expect(state.configFormDirty).toBe(false);
expect(state.configForm).toEqual({ gateway: { mode: "remote" } });
expect(state.configFormOriginal).toEqual({ gateway: { mode: "remote" } });
expect(state.configRaw).toBe('{\n "gateway": { "mode": "remote" }\n}\n');
expect(state.configRawOriginal).toBe('{\n "gateway": { "mode": "remote" }\n}\n');
Prompt To Fix With AI
This is a comment left during a code review.
Path: test/ui-config-reload-clears-dirty.test.ts
Line: 57-59

Comment:
**Test missing `configFormOriginal` / `configRawOriginal` assertions**

`applyConfigSnapshot` also updates `configFormOriginal` and `configRawOriginal` when `configFormDirty` is `false` (lines 99–101 of `config.ts`). The test verifies `configForm` and `configRaw` are refreshed, but not these two derived fields. Adding assertions for them would guard against future regressions where the "original" baseline diverges from the reloaded snapshot.

```suggestion
    expect(state.configFormDirty).toBe(false);
    expect(state.configForm).toEqual({ gateway: { mode: "remote" } });
    expect(state.configFormOriginal).toEqual({ gateway: { mode: "remote" } });
    expect(state.configRaw).toBe('{\n  "gateway": { "mode": "remote" }\n}\n');
    expect(state.configRawOriginal).toBe('{\n  "gateway": { "mode": "remote" }\n}\n');
```

How can I resolve this? If you propose a fix, please make it concise.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0e06d63ad7

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

if (!state.client || !state.connected) {
return;
}
state.configFormDirty = false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Restrict dirty reset to explicit reload actions

loadConfig now clears configFormDirty unconditionally, but this function is also invoked by automatic refresh paths (for example refreshActiveTab on tab switches in ui/src/ui/app-settings.ts:360-361, config loads for agents/nodes/config in ui/src/ui/app-settings.ts:188-227, and reconnect handling in ui/src/ui/app-gateway.ts:227). In those non-user-initiated cases, applyConfigSnapshot will treat the form as clean and overwrite configForm, so unsaved edits can be silently discarded just by navigating tabs or reconnecting, not only by clicking Reload.

Useful? React with 👍 / 👎.

@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@clawsweeper

clawsweeper Bot commented Apr 26, 2026 •

Copy link
Copy Markdown
Contributor

Closing this as duplicate or superseded after Codex automated review.

#40441 targets a real current-main Control UI reload bug, but its implementation is too broad: it would clear configFormDirty inside the shared loadConfig() path used by both explicit reloads and passive refresh/reconnect flows. Open PR #40443 tracks the same linked bug (#40352) with the safer product shape: explicit reload discards stale local config state while passive refresh preserves unsaved edits.

Best possible solution:

Close #40441 as superseded and keep #40443/#40352 as the canonical path. The best fix is a scoped explicit-reload mechanism, such as a loadConfig option or separate reload handler, with regression coverage proving explicit Reload discards stale local config while passive refresh and reconnect preserve unsaved edits.

What I checked:

So I’m closing this here and keeping the remaining discussion on the canonical linked item.

Codex Review notes: model gpt-5.5, reasoning high; reviewed against 8ba82534e6c9.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui size: S stale Marked as stale due to inactivity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Control UI Model Selection dropdown shows stale model after config reload

1 participant