Skip to content

Conversation

@ibetitsmike
Copy link
Contributor

@ibetitsmike ibetitsmike commented Nov 29, 2025

There were two issues causing the wrong model to be used when creating workspaces:

  1. Stale React state: The handleSend callback in useCreationWorkspace captured sendMessageOptions from useSendMessageOptions, but that hook's state updates were delayed by requestAnimationFrame batching in usePersistedState. If the user selected a model and clicked send before the next animation frame, the old model value would be used.

  2. Effect overwriting selection: The useEffect that initialized the model to the default when entering creation mode could re-run and overwrite the user's selection if defaultModel changed for any reason.

Fixes:

  • Read send options fresh from localStorage at send time using getSendOptionsFromStorage instead of relying on potentially-stale React state
  • Track initialization state with a ref so the model is only set once per entry into creation mode, not on every defaultModel change

Also added mode field to getSendOptionsFromStorage return value for parity with useSendMessageOptions.

Generated with mux

There were two issues causing the wrong model to be used when creating workspaces:

1. **Stale React state**: The `handleSend` callback in `useCreationWorkspace`
   captured `sendMessageOptions` from `useSendMessageOptions`, but that hook's
   state updates were delayed by `requestAnimationFrame` batching in
   `usePersistedState`. If the user selected a model and clicked send before
   the next animation frame, the old model value would be used.

2. **Effect overwriting selection**: The useEffect that initialized the model
   to the default when entering creation mode could re-run and overwrite the
   user's selection if `defaultModel` changed for any reason.

**Fixes:**
- Read send options fresh from localStorage at send time using
  `getSendOptionsFromStorage` instead of relying on potentially-stale
  React state
- Track initialization state with a ref so the model is only set once
  per entry into creation mode, not on every `defaultModel` change

Also added `mode` field to `getSendOptionsFromStorage` return value for
parity with `useSendMessageOptions`.

_Generated with `mux`_
@ibetitsmike ibetitsmike force-pushed the fix-mux-model-selection-bug branch from 04d56ec to 7feb2df Compare November 30, 2025 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant