Skip to content

fix(ui): stabilize agent primary model selection on switch - #46275

Closed
thegoldenflow wants to merge 1 commit into
openclaw:mainfrom
thegoldenflow:fix/41344-agents-keyed-clean
Closed

thegoldenflow wants to merge 1 commit into
openclaw:mainfrom
thegoldenflow:fix/41344-agents-keyed-clean

Conversation

@thegoldenflow

Copy link
Copy Markdown
Contributor

Summary

Describe the problem and fix in 2–5 bullets:

  • Problem: In the Agents UI, the Primary Model control for non-default agents could temporarily show the default model, or drift to the wrong selected option, when switching between agents.
  • Why it matters: This made the UI inconsistent with the actual saved config and with the Overview panel, which was confusing and made agent model editing unreliable.
  • What changed: Remounted selected-agent details on agent switch, stabilized non-default primary-model select binding around the explicit entry model only, and corrected native <select> DOM drift when a matching option exists.
  • What did NOT change (scope boundary): No backend config persistence, validation, redaction, or gateway save-path behavior was changed.

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

User-visible / Behavior Changes

  • For non-default agents, the Primary Model control now stays aligned with the actual explicit model override when switching between agents.
  • The control no longer temporarily shows the default model before correcting itself.
  • Switching a non-default agent back to inherit default no longer leaves the control blank.

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:

Repro + Verification

Environment

  • OS: Windows 10
  • Runtime/container: Local dev run from source
  • Model/provider: OpenAI + Anthropic model identifiers in local config
  • Integration/channel (if any): None (channels disabled in local dev)
  • Relevant config (redacted):
    • agents.defaults.model = 'openai/gpt-4.1-mini'
    • non-default agent qa.model = 'anthropic/claude-opus-4-6'
    • non-default agent ops.model = 'openai/gpt-4.1'

Steps

  1. Start local gateway and Control UI on latest main-based branch.
  2. Configure multiple agents where defaults and non-default explicit models differ.
  3. Open Agents and switch between dev, qa, and ops.
  4. For a non-default agent, also switch Primary Model back to inherit default.

Expected

  • Non-default agents should immediately show their explicit model override in the Primary Model control.
  • The control should remain consistent with the Overview panel and actual config.
  • Switching back to inherit default should show the inherit/default state cleanly.

Actual

  • Before this fix, the Primary Model control could initially show the default model for a non-default agent, then correct itself after a delay.
  • In some cases the native <select> selected state drifted away from the intended bound value.
  • Switching back to inherit default could temporarily leave the control blank.

Evidence

Attach at least one:

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Human Verification (required)

What you personally verified (not just CI), and how:

  • Verified scenarios:
    • Switched dev -> qa
    • Switched dev -> ops
    • Switched back and forth repeatedly between agents
    • Switched a non-default agent back to inherit default
  • Edge cases checked:
    • Non-default agents with explicit model overrides different from defaults
    • Default agent behavior remained correct
    • Unsaved UI state no longer produced the temporary wrong selected option during agent switching
  • What you did not verify:
    • Automated UI/browser tests were not added in this PR
    • Other unrelated agent panels beyond the Primary Model control were not revalidated exhaustively

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

If a bot review conversation is addressed by this PR, resolve that conversation yourself. Do not leave bot review conversation cleanup for maintainers.

Compatibility / Migration

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

Failure Recovery (if this breaks)

  • How to disable/revert this change quickly: Revert this PR or restore the previous UI files from main.
  • Files/config to restore:
    • ui/src/ui/views/agents.ts
    • ui/src/ui/views/agents-panels-overview.ts
  • Known bad symptoms reviewers should watch for:
    • Primary Model control shows the wrong selected option after agent switch
    • Non-default agents temporarily display defaults instead of explicit overrides
    • Switching back to inherit default leaves the control blank

Risks and Mitigations

List only real risks for this PR. Add/remove entries as needed. If none, write None.

  • Risk: The fix touches native <select> synchronization logic and selected-agent remount behavior in the Agents UI.
    • Mitigation: Kept the patch localized to the relevant UI files, preserved backend/save-path behavior, and manually verified agent switching and inherit-default scenarios on a latest-main-based branch.

@greptile-apps

greptile-apps Bot commented Mar 14, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR stabilises the Primary Model <select> control in the Agents UI so it always reflects the correct explicit model override when switching between agents, rather than momentarily drifting to the default model or going blank.

The fix uses three complementary Lit techniques:

  • keyed(selectedAgent.id, …) in agents.ts forces a full remount of all agent-panel content on agent switch, eliminating carry-over DOM state.
  • live(selectValue) on the <select> in agents-panels-overview.ts ensures Lit compares against the real DOM value on every render rather than its stale cache, so late option-list updates always re-sync the selected option.
  • A ref + queueMicrotask callback handles the mount-time race where the native <select> value may be set before <option> elements are committed to the DOM.

Issues found:

  • The ⋯ and … Unicode characters in agents.ts have been corrupted to mojibake sequences (鈰? / 鈥?), most likely due to a GBK/UTF-8 encoding mismatch during editing on Windows. This introduces a visible text regression in the actions-menu toggle button and the "Loading…" label — needs fixing before merge.
  • effectivePrimary in agents-panels-overview.ts is now a dead variable (computed but never used after the refactor) — minor cleanup opportunity.

Confidence Score: 3/5

  • The core bug-fix logic is sound and well-scoped, but a character-encoding regression in agents.ts must be corrected before merging.
  • The keyed + live() + ref/queueMicrotask approach correctly addresses the stated race conditions and is idiomatic Lit. No backend or persistence code is touched. However, two visible UI strings (⋯ and …) were corrupted to mojibake characters during editing, which would be immediately noticeable to users. This is a blocker for merging as-is.
  • ui/src/ui/views/agents.ts — encoding-corrupted strings on lines 178 and 219 must be restored to proper Unicode characters before merge.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: ui/src/ui/views/agents.ts
Line: 178-219

Comment:
**Encoding corruption introduced on two strings**

The Unicode characters `⋯` (U+22EF, midline horizontal ellipsis — used for the actions toggle button) and `…` (U+2026, horizontal ellipsis — used in the loading label) have been corrupted to mojibake sequences (`鈰?` and `鈥?` respectively). This appears to be a file-encoding mismatch during editing (e.g., the file was saved as GBK/GB2312 on a Windows machine instead of UTF-8).

Both strings need to be restored to their original Unicode characters:

Line 178 — actions button label:
```suggestion
                        >⋯</button>
```

Line 219 — loading text:
```suggestion
                ${props.loading ? "Loading…" : "Refresh"}
```

These will otherwise render as garbage characters in every user's browser.

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

---

This is a comment left during a code review.
Path: ui/src/ui/views/agents-panels-overview.ts
Line: 60

Comment:
**`effectivePrimary` is now a dead variable**

After this refactor, `effectivePrimary` is computed on this line but is no longer referenced anywhere in the template — `selectValue` and `optionCurrent` replaced all of its previous uses. Consider removing this line to avoid confusion for future readers.

```suggestion
  // effectivePrimary removed — selectValue / optionCurrent used directly
```
Or simply delete the line.

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

Last reviewed commit: ee6dd70

Comment thread ui/src/ui/views/agents.ts Resolved

@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: ee6dd7095f

ℹ️ 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".

Comment thread ui/src/ui/views/agents.ts Resolved
@thegoldenflow
thegoldenflow force-pushed the fix/41344-agents-keyed-clean branch 2 times, most recently from 24e7186 to e23c841 Compare March 14, 2026 15:45

@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: e23c841d73

ℹ️ 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".

@thegoldenflow
thegoldenflow force-pushed the fix/41344-agents-keyed-clean branch from e23c841 to 0ae0a89 Compare March 14, 2026 18:03
@thegoldenflow
thegoldenflow force-pushed the fix/41344-agents-keyed-clean branch from 0ae0a89 to 3983033 Compare March 14, 2026 18:48
@thegoldenflow

Copy link
Copy Markdown
Contributor Author

Local verification on this branch:

  • pnpm --dir ui exec vitest run --environment jsdom src/ui/views/agents.browser.test.ts ✅
  • pnpm format:check ✅

This PR only changes:

  • ui/src/ui/views/agents.ts
  • ui/src/ui/views/agents-panels-overview.ts
  • ui/src/ui/views/agents.browser.test.ts

I also restored the existing actions-toggle button text/markup after a merge-time encoding/corruption issue; no actions-menu behavior was intentionally changed.

This issue is user-visible and has been reproducible across both the older and newer Agents UI structure: when switching between agents, the Primary Model control could temporarily show the wrong default value or drift from the actual saved explicit override. Since this behavior has persisted across refactors, I wanted to get a focused fix and regression test in place.

The currently failing format-check job points to src/gateway/server/ws-connection/message-handler.ts, which is not modified by this PR, so that failure appears unrelated from my branch state.

If someone with permissions is able to re-run that failing job, that would help confirm whether it is an unrelated CI issue. If so, I’d appreciate this PR being considered on its own UI/test changes.

@clawsweeper

clawsweeper Bot commented Apr 26, 2026

Copy link
Copy Markdown
Contributor

Closing this as duplicate or superseded after Codex automated review.

Close #46275 as superseded by the later open PR #54724. Current main does not appear to contain this select-state stabilization, but #54724 is by the same author, explicitly references #46275, and tracks the same Agents Overview Primary Model switching bug plus the related model-catalog hydration gap with broader tests.

Best possible solution:

Close #46275 as the older overlapping PR and keep review focused on the canonical follow-up, preferably #54724 or a reconciled newer PR, so the final landed change includes selected-agent remount/select synchronization, model-catalog hydration, and targeted browser/controller regression tests.

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 8bbb143ab87e.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Control UI Agent form shows wrong Primary model and Save fails with GatewayRequestError: invalid config

1 participant