Skip to content

Where agent teams gather. Cross-platform team chat where AI agents are first-class teammates — with cloud or bring-your-own (Claude Code / Codex) brains.

TypeScript

fix(ui): typing a model id in full must pin that model

Xialie Zhuangadecacb16b2e
diff --git a/server/src/__tests__/combobox-highlight.test.ts b/server/src/__tests__/combobox-highlight.test.ts
new file mode 100644
index 0000000..058bb17
--- /dev/null
+++ b/server/src/__tests__/combobox-highlight.test.ts
@@ -0,0 +1,81 @@
+/**
+ * Typing a model id in full and pressing Enter must pin that model.
+ *
+ * The BYOA model picker's first row is the placeholder
+ *
+ * { value: '', label: 'Follow engine default', hint: <catalog default id> }
+ *
+ * and <Combobox>'s filter matches `hint` as well as `label`. For an agent with
+ * no pin (`value === ''`), typing the default model id left both rows in the
+ * list, the highlight stayed on the placeholder because it held the current
+ * value, and Enter committed '' — so the agent was saved UNPINNED while the
+ * trigger showed the typed id as its hint.
+ *
+ * Pinning is what stops a model upgrade in the local CLI from silently changing
+ * an agent's behaviour, so the failure surfaces much later and looks like the
+ * agent changed on its own.
+ *
+ * Run: node --import tsx --test server/src/__tests__/combobox-highlight.test.ts
+ */
+import { test } from 'node:test'
+import assert from 'node:assert/strict'
+import { initialActiveIndex } from '../../../src/lib/combobox-highlight.js'
+
+/** The BYOA model options, in the order AgentEditor builds them. */
+const MODEL_ROWS = [
+ { value: '', label: 'Follow engine default' },
+ { value: 'gpt-5.6-sol', label: 'GPT-5.6 Sol' },
+ { value: 'gpt-5.4-mini', label: 'GPT-5.4 mini' },
+]
+
+// ── the case that lost the pin ─────────────────────────────────────────────
+
+test('typing the default model id in full highlights that model, not the placeholder', () => {
+ // Both rows survive the filter: the placeholder matches through its hint,
+ // which IS this id. The unpinned agent's value is ''.
+ const filtered = [MODEL_ROWS[0], MODEL_ROWS[1]]
+ assert.equal(initialActiveIndex(filtered, '', 'gpt-5.6-sol'), 1)
+})
+
+test('the same holds when the typed id is not the catalog default', () => {
+ const filtered = [MODEL_ROWS[2]]
+ assert.equal(initialActiveIndex(filtered, '', 'gpt-5.4-mini'), 0)
+})
+
+test('an exact label match counts too', () => {
+ // The user can type what they see rather than the id.
+ const filtered = [MODEL_ROWS[0], MODEL_ROWS[1]]
+ assert.equal(initialActiveIndex(filtered, '', 'GPT-5.6 Sol'), 1)
+})
+
+test('matching is case-insensitive, like the filter above it', () => {
+ const filtered = [MODEL_ROWS[0], MODEL_ROWS[1]]
+ assert.equal(initialActiveIndex(filtered, '', 'GPT-5.6-SOL'), 1)
+ assert.equal(initialActiveIndex(filtered, '', ' gpt-5.6-sol '), 1)
+})
+
+// ── and the behaviour that was already right ───────────────────────────────
+
+test('with no query the highlight still follows the current value', () => {
+ assert.equal(initialActiveIndex(MODEL_ROWS, 'gpt-5.4-mini', ''), 2)
+ assert.equal(initialActiveIndex(MODEL_ROWS, '', ''), 0)
+})
+
+test('a partial query is left alone', () => {
+ // Nothing is named exactly, so the old rule applies: the current value, which
+ // here is the pinned model. Changing this would be a different decision.
+ assert.equal(initialActiveIndex(MODEL_ROWS, 'gpt-5.4-mini', 'gpt'), 2)
+})
+
+test('a current value that filtered out falls back to the top', () => {
+ assert.equal(initialActiveIndex([MODEL_ROWS[1]], 'gpt-5.4-mini', 'sol'), 0)
+})
+
+test('an empty list is not an index', () => {
+ assert.equal(initialActiveIndex([], 'gpt-5.6-sol', 'gpt-5.6-sol'), 0)
+})
+
+test('the placeholder is still reachable by naming it', () => {
+ // Pinning must not become impossible to undo from the keyboard.
+ assert.equal(initialActiveIndex(MODEL_ROWS, 'gpt-5.6-sol', 'Follow engine default'), 0)
+})
diff --git a/src/components/Combobox.tsx b/src/components/Combobox.tsx
index 8184528..f1c6afd 100644
--- a/src/components/Combobox.tsx
+++ b/src/components/Combobox.tsx
@@ -1,4 +1,5 @@
import { useEffect, useId, useMemo, useRef, useState } from 'react'
+import { initialActiveIndex } from '@/lib/combobox-highlight'
import { useT } from '@/lib/i18n'
import { cn } from '@/lib/utils'
@@ -77,12 +78,13 @@ export function Combobox<T extends string = string>({
: ''
const resultCount = filtered.length + (customValue ? 1 : 0)
- // Keep the highlight on the current value when the menu (re)opens, else top.
+ // Keep the highlight on the current value when the menu (re)opens, else top —
+ // except when the query names one option exactly, which wins. See
+ // combobox-highlight.ts for the case that made the exception necessary.
useEffect(() => {
if (!open) return
- const idx = filtered.findIndex((o) => o.value === value)
- setActiveIndex(idx >= 0 ? idx : 0)
- }, [open, filtered, value, customValue])
+ setActiveIndex(initialActiveIndex(filtered, value, query))
+ }, [open, filtered, value, query, customValue])
// Close on outside click.
useEffect(() => {
diff --git a/src/lib/combobox-highlight.ts b/src/lib/combobox-highlight.ts
new file mode 100644
index 0000000..b20e251
--- /dev/null
+++ b/src/lib/combobox-highlight.ts
@@ -0,0 +1,43 @@
+/**
+ * Which row a <Combobox> highlights when its menu opens or its filter changes.
+ *
+ * Pure and React-free so the rule can be pinned without rendering — the same
+ * reason recurrence.ts and prompt-surface.ts are split out.
+ *
+ * The rule used to be "whatever row holds the current value, else the first",
+ * which reads well until a row's `hint` collides with another row's `value`.
+ * The BYOA model picker does exactly that: its first row is
+ *
+ * { value: '', label: 'Follow engine default', hint: <the default model id> }
+ *
+ * and the filter matches on `hint` as well as `label`. So for an agent with no
+ * pin (value === ''), typing the default model id in full left BOTH rows in the
+ * list, the highlight stayed on the placeholder because it holds the current
+ * value, and Enter committed '' — "follow engine default" — when the user had
+ * just typed the id they wanted pinned. Pinning exists precisely so a model
+ * upgrade in the underlying CLI cannot silently change an agent's behaviour, so
+ * the failure is quiet and lands later.
+ *
+ * A query that names one option exactly now wins over the current value. With
+ * no query, or with a partial one, nothing changes.
+ */
+export interface HighlightableOption {
+ value: string
+ label: string
+}
+
+export function initialActiveIndex(
+ filtered: readonly HighlightableOption[],
+ currentValue: string,
+ query: string,
+): number {
+ const needle = query.trim().toLowerCase()
+ if (needle) {
+ const exact = filtered.findIndex(
+ (option) => option.value.toLowerCase() === needle || option.label.toLowerCase() === needle,
+ )
+ if (exact >= 0) return exact
+ }
+ const current = filtered.findIndex((option) => option.value === currentValue)
+ return current >= 0 ? current : 0
+}