fix(clients): honor project default models in new threads #6011
Mergedanirudhsama(GitHub profile, opens in a new tab)merged 6 commits into
main fromrefs/pull/6011/headmerged by shivamhwp(GitHub profile, opens in a new tab) View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
anirudhsama(GitHub profile, opens in a new tab) changed the title
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:M
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/mobile/src/lib/modelOptions.ts line 107Resolvedby shivamhwp(GitHub profile, opens in a new tab)@@ -104,3 +104,4 @@104104 return model?.isLegacy === true ? null : usable;105105 }106106107+export function resolveNewTaskModelSelection(input: {
- apps/mobile/src/state/use-composer-drafts.ts line 330Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -225,7 +257,17 @@225257 if (loadPromise !== null) {226258 return;227259 }228- loadPromise = loadPersistedComposerDrafts()229- .then((persistedDrafts) => {230- if (Object.keys(persistedDrafts).length === 0) {231- return;260+ loadPromise = loadPersistedComposerState()261+ .then((persisted) => {262+ if (Object.keys(persisted.drafts).length > 0) {263+ const current = appAtomRegistry.get(composerDraftsAtom);264+ appAtomRegistry.set(composerDraftsAtom, {265+ ...persisted.drafts,266+ ...current,267+ });268+ }269+ if (270+ persisted.stickyModelSelection !== null &&271+ appAtomRegistry.get(stickyComposerModelSelectionAtom) === null272+ ) {273+ appAtomRegistry.set(stickyComposerModelSelectionAtom, persisted.stickyModelSelection);
- apps/mobile/src/state/use-composer-drafts.ts lines 174 to 179OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -143,0 +159,21 @@159+ ([key, draft]) =>160+ [161+ key,162+ // Stale new-task drafts left on disk by builds before the163+ // model-precedence fix carry a bare modelSelection with no164+ // other selector settings. Strip it so the next compose pass165+ // re-resolves project → sticky → provider defaults. Drafts166+ // with runtime/interaction/workspace settings or actual text /167+ // attachments were deliberately configured and are left alone.168+ key.startsWith("new-task:") &&169+ draft.modelSelection &&170+ draft.text.length === 0 &&171+ draft.attachments.length === 0 &&172+ draft.runtimeMode === undefined &&173+ draft.interactionMode === undefined &&174+ draft.workspaceSelection === undefined175+ ? { ...draft, modelSelection: undefined }176+ : draft,177+ ] as const,178+ )179+ .filter(([, draft]) => !isEmptyDraft(draft)),apps/mobile/src/state/use-composer-drafts.ts line 295OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -225,14 +278,18 @@225- writePersistedComposerDrafts(appAtomRegistry.get(composerDraftsAtom)),278+ writePersistedComposerState(279+ appAtomRegistry.get(composerDraftsAtom),280+ appAtomRegistry.get(stickyComposerModelSelectionAtom),281+ ),226282 );227283 }228284 await persistenceQueue.run(() => Promise.resolve());229285 } while (persistTimer !== null);230286 }231287232-function schedulePersistComposerDrafts(drafts: Record<string, ComposerDraft>): void {288+function schedulePersistComposerState(): void {233289 if (persistTimer !== null) {234290 clearTimeout(persistTimer);235291 }236292 persistTimer = setTimeout(() => {237293 persistTimer = null;238- void savePersistedComposerDrafts(drafts);294+ ensureComposerDraftsLoaded();295+ void loadPromise?.then(() =>
- apps/web/src/hooks/useHandleNewThread.ts line 285OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -276,8 +276,10 @@276276 ...(carryRuntimeMode ? { runtimeMode: carryRuntimeMode } : {}),277277 ...(carryInteractionMode ? { interactionMode: carryInteractionMode } : {}),278278 });279- if (carryModelSelection) {280- // The carried selection is a complete snapshot of the viewed281- // thread's model state: absent options mean "no options", not282- // "keep the stale draft's options".283- setModelSelection(emptyStoredDraftThread.draftId, carryModelSelection, {279+ // A stored draft that already carries a model selection keeps it:280+ // the v9 storage migration strips stale legacy picks, so anything281+ // remaining was chosen deliberately (model + reasoning effort) and282+ // must not be overridden by the project default. Only a bare draft283+ // gets seeded.284+ const storedDraft = getComposerDraft(emptyStoredDraftThread.draftId);285+ const storedDraftHasModelSelection = Boolean(
- apps/web/src/hooks/useHandleNewThread.ts line 313Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -277,7 +277,16 @@277277 ...(carryInteractionMode ? { interactionMode: carryInteractionMode } : {}),278278 });279- if (carryModelSelection) {280- // The carried selection is a complete snapshot of the viewed281- // thread's model state: absent options mean "no options", not282- // "keep the stale draft's options".283- setModelSelection(emptyStoredDraftThread.draftId, carryModelSelection, {279+ // A stored draft that already carries a model selection keeps it:280+ // the v9 storage migration strips stale legacy picks, so anything281+ // remaining was chosen deliberately (model + reasoning effort) and282+ // must not be overridden by the project default. Only a bare draft283+ // gets seeded.284+ const storedDraft = getComposerDraft(emptyStoredDraftThread.draftId);285+ const storedDraftHasModelSelection = Boolean(286+ storedDraft.activeProvider &&287+ storedDraft.modelSelectionByProvider[storedDraft.activeProvider],288+ );289+ if (modelSelectionOverride && !storedDraftHasModelSelection) {290+ // This is a complete snapshot: absent options mean "no options",291+ // not "keep the stale draft's options".292+ setModelSelection(emptyStoredDraftThread.draftId, modelSelectionOverride, {apps/mobile/src/state/use-composer-drafts.ts line 300OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -226,13 +282,19 @@226282 );227283 }228284 await persistenceQueue.run(() => Promise.resolve());229285 } while (persistTimer !== null);230286 }231287232-function schedulePersistComposerDrafts(drafts: Record<string, ComposerDraft>): void {288+function schedulePersistComposerState(): void {233289 if (persistTimer !== null) {234290 clearTimeout(persistTimer);235291 }236292 persistTimer = setTimeout(() => {237293 persistTimer = null;238- void savePersistedComposerDrafts(drafts);294+ ensureComposerDraftsLoaded();295+ void loadPromise?.then(() =>296+ savePersistedComposerState(297+ appAtomRegistry.get(composerDraftsAtom),298+ appAtomRegistry.get(stickyComposerModelSelectionAtom),299+ ),300+ );
- apps/web/src/composerDraftStore.ts line 1824Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1802,3 +1815,4 @@18021815 ? {18031816 modelSelectionByProvider: compactModelSelectionByProvider(modelSelectionByProvider),18041817 activeProvider,1818+ ...(modelSelectionExplicit ? { modelSelectionExplicit: true } : {}),apps/web/src/hooks/useHandleNewThread.ts line 313Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -278,6 +278,16 @@278278 });279- if (carryModelSelection) {280- // The carried selection is a complete snapshot of the viewed281- // thread's model state: absent options mean "no options", not282- // "keep the stale draft's options".283- setModelSelection(emptyStoredDraftThread.draftId, carryModelSelection, {279+ // A stored draft keeps its model selection only when a human280+ // picked it (`modelSelectionExplicit`). Seeded selections — and281+ // legacy entries, which predate the flag — are re-resolved here:282+ // the override (project default ?? carry) replaces them so stale283+ // seeds never beat newer configuration.284+ const storedDraft = getComposerDraft(emptyStoredDraftThread.draftId);285+ const storedActiveSelection = storedDraft?.activeProvider286+ ? storedDraft.modelSelectionByProvider[storedDraft.activeProvider]287+ : undefined;288+ const storedDraftHasExplicitModelPick =289+ Boolean(storedActiveSelection) && storedDraft?.modelSelectionExplicit === true;290+ if (modelSelectionOverride && !storedDraftHasExplicitModelPick) {291+ // This is a complete snapshot: absent options mean "no options",292+ // not "keep the stale draft's options".293+ setModelSelection(emptyStoredDraftThread.draftId, modelSelectionOverride, {
- apps/web/src/hooks/useHandleNewThread.ts line 313Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -283 +281,20 @@283- setModelSelection(emptyStoredDraftThread.draftId, carryModelSelection, {281+ }282+ // Model intent: an explicit human pick always stands. Seeds and283+ // legacy entries alike re-resolve here — sticky first, mirroring284+ // the mint-fresh path, then the project default or carried285+ // selection on top. This runs even when the draft is already open:286+ // without it, a changed pin could never reach the draft the user287+ // is looking at, because explicit picks are the only thing the288+ // flag protects.289+ const storedDraft = getComposerDraft(emptyStoredDraftThread.draftId);290+ const storedActiveSelection = storedDraft?.activeProvider291+ ? storedDraft.modelSelectionByProvider[storedDraft.activeProvider]292+ : undefined;293+ const storedDraftHasExplicitModelPick =294+ Boolean(storedActiveSelection) && storedDraft?.modelSelectionExplicit === true;295+ if (!storedDraftHasExplicitModelPick) {296+ applyStickyState(emptyStoredDraftThread.draftId);297+ if (modelSelectionOverride) {298+ // This is a complete snapshot: absent options mean "no options",299+ // not "keep the stale draft's options".300+ setModelSelection(emptyStoredDraftThread.draftId, modelSelectionOverride, {
- apps/web/src/composerDraftStore.ts line 1874Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1857 +1854,21 @@1854+ draft.modelSelectionExplicit === true ||1855+ persistedComposerDraftHasUserContent(draft)1856+ ) {1857+ return [[threadKey, draft]];1858+ }1859+1860+ const {1861+ activeProvider: _activeProvider,1862+ modelSelectionByProvider: _modelSelectionByProvider,1863+ modelSelectionExplicit: _modelSelectionExplicit,1864+ ...retained1865+ } = draft;1866+ return retained.runtimeMode || retained.interactionMode ? [[threadKey, retained]] : [];1867+ }),18571868 );1869+}1870+1871+function migratePersistedComposerDraftStoreState(1872+ persistedState: unknown,1873+): PersistedComposerDraftStoreState {1874+ const normalized = normalizeCurrentPersistedComposerDraftStoreState(persistedState);
shivamhwp(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.


Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
9de7e8b9-1856-4286-8468-5d74454bfd45You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share