Skip to content

fix(ui): select dropdowns show stale value on page load - #52948

Closed
xiaoquanidea wants to merge 4 commits into
openclaw:mainfrom
xiaoquanidea:fix/ui-agent-model-select-stale
Closed

xiaoquanidea wants to merge 4 commits into
openclaw:mainfrom
xiaoquanidea:fix/ui-agent-model-select-stale

Conversation

@xiaoquanidea

@xiaoquanidea xiaoquanidea commented Mar 23, 2026 •

Copy link
Copy Markdown

Summary

  • Fix <select> dropdowns showing stale/wrong values on page load across the Control UI, caused by Lit's .value property binding firing before child <option> elements are in the DOM.

Affected Components

  1. Agent model dropdown (agents-utils.ts → buildModelOptions): The Primary model select in Agents → Overview always showed the first model in the catalog instead of the configured model after page refresh.

  2. Config form enum selects (config-form.node.ts → renderSelect): All schema-driven enum dropdowns (e.g., Model Provider API Adapter) showed "Select..." instead of the configured value after page refresh.

Root Cause

Both components use Lit's .value property binding on <select> elements. On initial render, .value fires before the child <option> elements are in the DOM. The browser cannot find a matching option, so it falls back to the first option — regardless of what the actual configured value is.

Fix

Add ?selected attribute binding to each <option> so the correct option is marked directly in the HTML at render time, independent of .value property timing.

agents-utils.ts — Before:

html`<option value=${option.value}>${option.label}</option>`

After:

html`<option value=${option.value} ?selected=${option.value === current}>${option.label}</option>`

config-form.node.ts — Before:

<option value=${unset}>Select...</option>
<option value=${String(idx)}>${String(opt)}</option>

After:

<option value=${unset} ?selected=${currentIndex < 0}>Select...</option>
<option value=${String(idx)} ?selected=${idx === currentIndex}>${String(opt)}</option>

Testing

  • Lightly tested — verified locally on macOS with OpenClaw 2026.3.23
  • vitest run ui/src/ui/views/agents-utils.test.ts — 11/11 tests pass
  • Pre-commit hooks (lint, format, typecheck) all pass on both commits
  • Confirmed agent model dropdown shows correct configured model on page load
  • Confirmed config form API Adapter dropdown shows correct value on page load

AI Disclosure

🤖 This PR was AI-assisted (Claude Code). I understand the changes and have verified them locally.

Closes #40352

@xiaoquanidea

xiaoquanidea commented Mar 23, 2026 •

Copy link
Copy Markdown
Author

Screenshots

Before (bug): Model dropdown shows MiniMax instead of configured Gemini after page refresh

before

The <select> falls back to the first <option> (MiniMax) because Lit's .value property binding fires before child <option> elements are in the DOM.

After (fix): Correct model (Gemini) is selected on page load

after

Added ?selected attribute binding to each <option> so the browser marks the correct option at render time.

@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: 0b8fc364fd

ℹ️ 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-utils.ts Resolved
@greptile-apps

greptile-apps Bot commented Mar 23, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a well-documented Lit rendering timing issue where the .value property binding on <select> fires before child <option> elements are in the DOM, causing the dropdown to fall back to the first option instead of the configured model. The fix is minimal and correct: adding ?selected=${option.value === current} to each <option> in buildModelOptions so the selection state is encoded directly in the HTML at render time.

  • The fix correctly handles all edge cases — current being null/undefined (no option selected), a stale model not in the current list (the prepended "Current (…)" option is also marked selected), and the normal matching case.
  • No new unit tests were added for buildModelOptions specifically around the ?selected behavior. Given the simplicity of the change this is low risk, but a test asserting that the returned TemplateResult contains a selected attribute for the matching option would improve regression coverage.

Confidence Score: 5/5

  • Safe to merge — minimal, targeted fix with no side effects on existing behaviour.
  • The change is a single-expression addition that relies on standard Lit boolean-attribute binding (?selected). It does not modify any data-flow, event handling, or component state — only the initial rendered HTML of the <option> elements. All edge cases are handled correctly by the existing logic that prepends a "Current" option when the value is absent from the list.
  • No files require special attention.

Reviews (1): Last reviewed commit: "fix(ui): agent model dropdown shows stal..." | Re-trigger Greptile

@xiaoquanidea xiaoquanidea changed the title fix(ui): agent model dropdown shows stale value on page load fix(ui): select dropdowns show stale value on page load Mar 23, 2026
@xiaoquanidea

Copy link
Copy Markdown
Author

Addressed in b3923ed: added an optional selected parameter to buildModelOptions. The caller now passes the actual <select> value — for non-default agents without an override, selected is null so no model option is preselected, preserving the "Inherit default" behaviour.

@xiaoquanidea

xiaoquanidea commented Mar 24, 2026 •

Copy link
Copy Markdown
Author

Screenshots for config form fix (commit 2)

Before: Config form enum selects show "Select..." instead of configured value

config-form-before

The Model Provider API Adapter dropdown shows "Select..." even though openai-completions is configured in openclaw.json. This affects all schema-driven enum <select> elements in the config editor.

After: Config form enum selects correctly show the configured value

config-form-after

The Model Provider API Adapter now correctly displays openai-completions on page load.

xiaoquanidea and others added 4 commits April 28, 2026 18:23
The `<select>` element in the agent overview panel uses Lit's `.value`
property binding to set the active model.  On initial render the binding
fires before the child `<option>` elements are in the DOM, so the
browser falls back to the first option (whichever model appears first in
the catalog) instead of the configured primary model.

Add `?selected` attribute binding to each `<option>` inside
`buildModelOptions` so the correct option is marked at render time,
independent of `.value` timing.

Closes openclaw#40352

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Apply the same `?selected` attribute fix to the generic config form
`renderSelect` helper.  The `<select>` in config-form.node.ts uses
Lit's `.value` property binding which can fire before child `<option>`
elements are in the DOM, causing the browser to fall back to the first
option ("Select...") instead of the configured value.

This affects all schema-driven enum selects in the config editor,
including the Model Provider API Adapter dropdown.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
The previous commit marked the effectivePrimary option as selected
in buildModelOptions, but for non-default agents the <select> binds
to entryPrimary (empty when inheriting).  This caused inherited
agents to appear as if they had an explicit model override on page
load.

Add an optional `selected` parameter to buildModelOptions so the
caller can pass the actual <select> value.  For non-default agents
without an override, no model option is preselected, preserving the
"Inherit default" behaviour.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@vincentkoc

Copy link
Copy Markdown
Member

ProjectClownfish pushed a narrow repair to this branch so the original contributor path can stay canonical.

Source PR: #52948
Validation: pnpm check:changed
Contributor credit is preserved in the branch history and PR context.

@clawsweeper

clawsweeper Bot commented Apr 28, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve.

Keep this PR open. Current main still lacks the selected-option repair for both affected Control UI paths: the Agents primary model select still renders model options without selected state and the schema-driven config enum select still renders unset/enum options without selected state. The PR remains an active implementation candidate, with maintainer branch work and focused UI/test/changelog changes, while the related merged reload-state fix does not cover this page-load selected-option path.

Best possible solution:

Keep this PR open for maintainer review and landing, or land an equivalent patch on current main. The final fix should mark matching option elements selected for both the Agents primary model select and schema-driven enum selects, preserve inherited non-default agents on the inherit-default option, keep selectedOptions/value regression coverage, and then use the merged result to resolve the remaining #40352 page-load selected-option path if maintainers agree it covers it.

What I checked:

  • Current main checked: Checkout is on current main at a820a30 and remained clean after read-only inspection. (a820a307dfeb)
  • Agent model options lack selected state on main: buildModelOptions still accepts configForm/current/catalog only and returns <option value=...> without .selected or ?selected, so the PR's core option-state repair is not present on main. (ui/src/ui/views/agents-utils.ts:657, a820a307dfeb)
  • Agent overview still has no separate selected value: The Agents overview select still binds the parent select value from effectivePrimary/entryPrimary and calls buildModelOptions without the PR's selected argument, leaving the inherited non-default-agent distinction unimplemented on main. (ui/src/ui/views/agents-panels-overview.ts:143, a820a307dfeb)
  • Config enum select lacks selected state on main: renderSelect computes currentIndex and binds <select>.value, but the unset and enum option elements are still rendered without selected state. (ui/src/ui/views/config-form.node.ts:846, a820a307dfeb)
  • Regression coverage is still missing on main: The current Agents test only checks that options exist/remount across agent switches and does not assert select.value/selectedOptions; the config-form browser test has no large-enum selectedOptions case from this PR. (ui/src/ui/views/agents.test.ts:158, a820a307dfeb)
  • PR is open and not merged: Public PR API reports this PR open, unmerged, head 6a9b00a, with mergeable=false. The remote pull ref also resolves to that head SHA. (6a9b00a61846)

Likely related people:

  • steipete: Local blame for the affected current-main lines resolves to Peter Steinberger in this compact checkout, and public path history shows recent Control UI commits/refactors by steipete on the affected agents/config files. (role: current-main maintainer / recent UI path maintainer; confidence: medium; commits: 74fb6be71680, e0b4f3b995cc, f665da8dbcf3; files: ui/src/ui/views/agents-utils.ts, ui/src/ui/views/agents-panels-overview.ts, ui/src/ui/views/config-form.node.ts)
  • vincentkoc: vincentkoc pushed the latest narrow repair commit to this PR branch, merged the adjacent [Bug]: Control UI Model Selection dropdown shows stale model after config reload #40352 explicit-reload repair, and appears in recent public path history for the affected Control UI config/agents files. (role: recent maintainer repair / adjacent Control UI owner; confidence: medium; commits: 6a9b00a61846, 045f1e8a3a00, 01058162bebb; files: ui/src/ui/views/agents-panels-overview.ts, ui/src/ui/views/config-form.node.ts, ui/src/ui/views/agents-utils.ts)
  • vignesh07: Public path history shows Vignesh Natarajan authored the Agents UI effective model/file hydration work, which is directly adjacent to the primary-model selection behavior this PR repairs. (role: adjacent feature-history owner; confidence: medium; commits: 384a590e54e6; files: ui/src/ui/views/agents-utils.ts, ui/src/ui/views/agents-panels-overview.ts)

Remaining risk / open question:

  • Closing this PR now would discard a focused, active implementation candidate while current main still lacks the selected-option repair.
  • The public PR API reports mergeable=false, so maintainers should rebase or resolve conflicts before landing.
  • Before landing, maintainers should re-check the Lit option binding choice and the inherited non-default-agent path, because an earlier review correctly identified that as the main regression risk.

Codex review notes: model gpt-5.5, reasoning high; reviewed against a820a307dfeb.

@openclaw-clownfish

Copy link
Copy Markdown
Contributor

ProjectClownfish could not safely update this branch, so it opened a narrow replacement PR instead.

Replacement PR: #74000
Source PR: #52948
Contributor credit is preserved in the replacement PR body and changelog plan.

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 clawsweeper Tracked by ClawSweeper automation size: S

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

2 participants