Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
apply a composed route's model and effort only after the caller reflects its provider id (#7566)
[._.]/ Adam Eivy683ba9f31962
diff --git a/client/src/components/ProviderModelSelector.jsx b/client/src/components/ProviderModelSelector.jsxindex ffc6a67032..035a3a7219 100644--- a/client/src/components/ProviderModelSelector.jsx+++ b/client/src/components/ProviderModelSelector.jsx@@ -45,6 +45,8 @@* @param {string} [props.id] - Id for the provider `<select>`, when the caller* owns the `<label htmlFor>` (`FormField` injects one onto its first child).* Defaults to a generated id.+ * @param {string} [props.aria-describedby] - Forwarded to the provider+ * `<select>` (`FormField` injects its hint's id the same way).* @param {string} [props.label] - Label text (default: "Provider")* @param {boolean} [props.disabled] - Disable both selectors* @param {boolean} [props.loading] - The caller's provider list hasn't settled@@ -100,7 +102,7 @@* flow may offer (`['tui']` for a shell launcher, `['api']` for a streaming* caller). Defaults to `selectionPolicy.modes`; omit both for no restriction.*/-import { useId, useState } from 'react';+import { useEffect, useId, useRef, useState } from 'react';import {COMPOSE_OPTION_VALUE,effectiveModelFor,@@ -144,6 +146,7 @@ export default function ProviderModelSelector({onProviderChange,onModelChange,id: idProp,+ 'aria-describedby': describedBy,label = 'Provider',disabled = false,loading = false,@@ -171,6 +174,11 @@ export default function ProviderModelSelector({// the caller refetches — otherwise the freshly selected id would render as// an unknown value the moment the popover closed.const [savedPresets, setSavedPresets] = useState([]);+ // A composed/minted route's model and effort, waiting for the caller to+ // reflect its provider id (see `selectRoute`).+ const [pendingRoute, setPendingRoute] = useState(null);+ const callbacksRef = useRef({ onModelChange, onEffortChange });+ callbacksRef.current = { onModelChange, onEffortChange };const providerAllowed = selectionPolicy?.provider;const modelAllowed = selectionPolicy?.model;const effortAllowed = selectionPolicy?.effort;@@ -300,18 +308,30 @@ export default function ProviderModelSelector({}onProviderChange(value);};- // A composed route lands in the caller's existing provider field; the- // model/effort follow through the same callbacks a pick in the sibling- // selects would use, so the caller's own clearing rules (a provider change- // resetting the model) run first and are then overridden by the explicit- // choice. "Use once" passes the composite id; "Save as preset" passes the- // minted preset (whose defaults are the composed model and effort) after- // carrying it locally until the caller's list catches up.+ // A composed route lands in the caller's existing provider field through+ // `onProviderChange`; its model and effort follow through the same+ // callbacks a pick in the sibling selects would use — but only AFTER the+ // caller reflects the new id. Firing all three in one tick would hand+ // `onModelChange` to a handler that merges over the caller's CURRENT+ // provider (`onChange({ ...draft, model })`, `persist(providerId, m)`),+ // which is still the old one until it re-renders, silently putting the+ // previous provider back. Waiting for `selectedProviderId` to catch up also+ // lets the caller's own clearing rule (a provider change resetting the+ // model) run first and then be overridden by the explicit choice. A caller+ // that never reflects the id simply never gets the model/effort.const selectRoute = (id, model, routeEffort) => {+ setPendingRoute({ id, model: model || '', effort: routeEffort || '' });onProviderChange(id);- onModelChange?.(model || '');- onEffortChange?.(routeEffort || '');};+ useEffect(() => {+ if (!pendingRoute || pendingRoute.id !== selectedProviderId) return;+ callbacksRef.current.onModelChange?.(pendingRoute.model);+ callbacksRef.current.onEffortChange?.(pendingRoute.effort);+ setPendingRoute(null);+ }, [pendingRoute, selectedProviderId]);+ // "Use once" passes the composite id; "Save as preset" passes the minted+ // preset (whose defaults are the composed model and effort) after carrying+ // it locally until the caller's list catches up.const handleCompose = (compositeId, { model, effort: composedEffort }) => selectRoute(compositeId, model, composedEffort);const handlePresetSaved = (preset) => {setSavedPresets((prev) => [...prev.filter((p) => p.id !== preset.id), preset]);@@ -348,6 +368,7 @@ export default function ProviderModelSelector({disabled={disabled || loading}title={compact ? label : undefined}aria-label={compact ? label : undefined}+ aria-describedby={describedBy}className={SELECT_CLASS}>{/* Rendered even when the caller forces a selection: mid-fetch therediff --git a/client/src/components/ProviderModelSelector.presetFirst.test.jsx b/client/src/components/ProviderModelSelector.presetFirst.test.jsxindex 5579e47375..0eceb7d240 100644--- a/client/src/components/ProviderModelSelector.presetFirst.test.jsx+++ b/client/src/components/ProviderModelSelector.presetFirst.test.jsx@@ -90,13 +90,19 @@ describe('ProviderModelSelector — preset-first', () => {});it('opens the compose popover from the compose entry without emitting the sentinel, and emits the composed selection on "Use once"', async () => {- const handlers = renderSelector();+ const { rerender, ...handlers } = renderSelector();await composeVia({ harness: 'pi', method: 'tui', service: 'nvidia-nim-free', model: 'nvidia/other', effort: 'high' });expect(handlers.onProviderChange).not.toHaveBeenCalled();expect(providerSelect().value).toBe('claude-code');fireEvent.click(screen.getByRole('button', { name: 'Use once' }));expect(handlers.onProviderChange).toHaveBeenCalledWith('pi.tui@nvidia-nim-free');- expect(handlers.onModelChange).toHaveBeenCalledWith('nvidia/other');+ // The model/effort wait for the caller to reflect the new id — a handler+ // that merges over the caller's current provider would otherwise put the+ // old provider back (regression: a composed route reverting to the preset).+ expect(handlers.onModelChange).not.toHaveBeenCalled();+ expect(handlers.onEffortChange).not.toHaveBeenCalled();+ rerender({ selectedProviderId: 'pi.tui@nvidia-nim-free' });+ await waitFor(() => expect(handlers.onModelChange).toHaveBeenCalledWith('nvidia/other'));expect(handlers.onEffortChange).toHaveBeenCalledWith('high');await waitFor(() => expect(screen.queryByRole('combobox', { name: 'Harness' })).toBeNull());});@@ -135,14 +141,15 @@ describe('ProviderModelSelector — preset-first', () => {id: 'pi-nim', name: 'Pi on NIM', type: 'tui', harnessId: 'pi', enabled: true,defaultModel: 'nvidia/other', effort: 'high', models: ['nvidia/example', 'nvidia/other'],});- const handlers = renderSelector();+ const { rerender, ...handlers } = renderSelector();await composeVia({ harness: 'pi', method: 'tui', service: 'nvidia-nim-free', model: 'nvidia/other', effort: 'high' });fireEvent.click(screen.getByRole('button', { name: 'Save as preset…' }));fireEvent.change(screen.getByRole('textbox', { name: 'Preset name' }), { target: { value: 'Pi on NIM' } });fireEvent.click(screen.getByRole('button', { name: 'Confirm save' }));await waitFor(() => expect(handlers.onProviderChange).toHaveBeenCalledWith('pi-nim'));expect(api.createProviderPreset).toHaveBeenCalledWith({ compositeId: 'pi.tui@nvidia-nim-free', name: 'Pi on NIM', model: 'nvidia/other', effort: 'high' });- expect(handlers.onModelChange).toHaveBeenCalledWith('nvidia/other');+ rerender({ selectedProviderId: 'pi-nim' });+ await waitFor(() => expect(handlers.onModelChange).toHaveBeenCalledWith('nvidia/other'));expect(handlers.onEffortChange).toHaveBeenCalledWith('high');});diff --git a/client/src/components/models/ComparisonResearch.jsx b/client/src/components/models/ComparisonResearch.jsxindex b143be940b..f14c8e6b62 100644--- a/client/src/components/models/ComparisonResearch.jsx+++ b/client/src/components/models/ComparisonResearch.jsx@@ -43,7 +43,8 @@ export default function ComparisonResearch() {<h3 className="font-semibold text-lg">Refresh model research with CoS</h3><p className="text-sm text-port-text-muted leading-relaxed">Choose a browsing-capable provider and model. Running research uses that provider’s quota or API budget. The task checks current sources and configured model gaps; it never runs model benchmarks. New providers and local models are considered on the next research run.</p><div className="flex flex-wrap gap-3 items-end">- <div className="text-sm min-w-0 max-w-full"><ProviderModelSelector label="Research provider" providers={providers} selectedProviderId={draft.providerId} disabled={busy || !saved} onProviderChange={providerId => setDraft({ providerId, model: '' })} emptyProviderOption="Choose provider" /></div>+ <div className="text-sm min-w-0 max-w-full">{/* Compose is off: the save gate below validates the model against a STORED record's list, which a composed route has none of. */}+ <ProviderModelSelector label="Research provider" compose={false} providers={providers} selectedProviderId={draft.providerId} disabled={busy || !saved} onProviderChange={providerId => setDraft({ providerId, model: '' })} emptyProviderOption="Choose provider" /></div><label className="text-sm min-w-0 max-w-full" htmlFor="research-model">Research model<br /><select id="research-model" className="bg-port-bg border border-port-border rounded-lg p-2.5 mt-2 max-w-full" value={draft.model} disabled={busy || !saved} onChange={e => setDraft(previous => ({ ...previous, model: e.target.value }))}><option value="">Choose model</option>{provider?.models?.map(model => <option key={model} value={model}>{model}</option>)}</select></label><button className="px-4 py-2.5 text-sm rounded-lg border border-port-border disabled:opacity-50" onClick={save} disabled={busy || !valid || (!dirty && saved?.enabled)}>Save research settings</button><button className="px-4 py-2.5 text-sm rounded-lg bg-port-accent text-port-on-accent disabled:opacity-50" onClick={run} disabled={busy || dirty || !valid || !saved?.enabled}>Run research now</button>