Skip to content

The agent that grows with you

fix(desktop): stop runtime model/provider heartbeats from overwriting the composer selection

chelsealongb6b003c14f6a
diff --git a/apps/desktop/src/app/session/hooks/use-session-state-cache.test.tsx b/apps/desktop/src/app/session/hooks/use-session-state-cache.test.tsx
index d92b29323d3..1b041e5e857 100644
--- a/apps/desktop/src/app/session/hooks/use-session-state-cache.test.tsx
+++ b/apps/desktop/src/app/session/hooks/use-session-state-cache.test.tsx
@@ -551,6 +551,34 @@ describe('useSessionStateCache — per-session timers', () => {
expect($currentServiceTier.get()).toBe('')
expect($currentFastMode.get()).toBe(false)
})
+
+ it('mirrors runtime model/provider into the view without persisting over the composer selection (#102793)', () => {
+ // A real user pick: persisted to localStorage, the same as picking a
+ // provider in the model menu.
+ setCurrentModel('claude-opus-5')
+ setCurrentProvider('anthropic')
+ expect(window.localStorage.getItem('hermes.desktop.composer.provider')).toBe('anthropic')
+
+ let cache!: Cache
+
+ render(<Harness activeSessionId="fg-runtime" onReady={c => (cache = c)} selectedStoredSessionId="fg-stored" />)
+
+ // A session.info heartbeat reports the resolved runtime class — `custom`
+ // for a named custom provider — for the same foreground session.
+ act(() => {
+ cache.updateSessionState(
+ 'fg-runtime',
+ state => ({ ...state, model: 'claude-opus-5', provider: 'custom' }),
+ 'fg-stored'
+ )
+ })
+
+ // The visible status area follows the runtime...
+ expect($currentProvider.get()).toBe('custom')
+ // ...but the user's persisted composer selection must survive the
+ // heartbeat, so a fresh chat still follows it instead of `custom`.
+ expect(window.localStorage.getItem('hermes.desktop.composer.provider')).toBe('anthropic')
+ })
})
interface LayoutProbeHarnessProps {
diff --git a/apps/desktop/src/app/session/hooks/use-session-state-cache.ts b/apps/desktop/src/app/session/hooks/use-session-state-cache.ts
index 4ccc6318104..a8dc799a26a 100644
--- a/apps/desktop/src/app/session/hooks/use-session-state-cache.ts
+++ b/apps/desktop/src/app/session/hooks/use-session-state-cache.ts
@@ -12,9 +12,9 @@ import {
$messages,
setActiveSessionStoredIdRotation,
setCurrentFastMode,
- setCurrentModel,
+ setCurrentModelTransient,
setCurrentPersonality,
- setCurrentProvider,
+ setCurrentProviderTransient,
setCurrentReasoningEffort,
setCurrentReasoningEffortWire,
setCurrentServiceTier,
@@ -61,8 +61,13 @@ interface SessionStateCacheOptions {
}
function syncRuntimeMetadataToView(state: ClientSessionState) {
- setCurrentModel(state.model ?? '')
- setCurrentProvider(state.provider ?? '')
+ // Transient: this runs on every session-state sync, including the periodic
+ // session.info heartbeat, whose reported model/provider is the runtime's
+ // resolved identity (e.g. the generic `custom` billing class), not a user
+ // pick. The persisting setters would silently overwrite the composer's
+ // sticky localStorage selection with that runtime value (#102793).
+ setCurrentModelTransient(state.model ?? '')
+ setCurrentProviderTransient(state.provider ?? '')
setCurrentReasoningEffort(state.reasoningEffort ?? '')
setCurrentReasoningEffortWire(state.reasoningEffortWire ?? '')
setCurrentServiceTier(state.serviceTier ?? '')
diff --git a/apps/desktop/src/store/session.ts b/apps/desktop/src/store/session.ts
index e65d7321a3b..1058b2af9d6 100644
--- a/apps/desktop/src/store/session.ts
+++ b/apps/desktop/src/store/session.ts
@@ -1579,6 +1579,19 @@ export const setCurrentProvider = (next: Updater<string>) => {
}
}
+/** Move the visible model/provider without claiming it as the composer's sticky
+ * selection.
+ *
+ * For values that come from the RUNTIME rather than the user: the periodic
+ * `session.info` heartbeat's resolved model/provider (e.g. the generic `custom`
+ * billing class a named provider resolves to). Persisting those through
+ * `setCurrentModel`/`setCurrentProvider` overwrote the user's actual composer
+ * pick in localStorage on every heartbeat, so a later new chat followed the
+ * last-seen runtime class instead of the selection or the Settings default.
+ */
+export const setCurrentModelTransient = (next: Updater<string>) => updateAtom($currentModel, next)
+export const setCurrentProviderTransient = (next: Updater<string>) => updateAtom($currentProvider, next)
+
export const getCurrentModelSource = (): ComposerModelSource => {
const source = storedComposerString(COMPOSER_MODEL_SOURCE_KEY)