Skip to content

bug: Selected model from /model command not persisted to settings.json #1222

@benzntech

Description

@benzntech

What happened?

When users select a model via the /model command in the multi-model support feature, the selection is only stored in-memory for the current session. When the CLI is restarted, the selected model is lost and defaults back to the hardcoded settings.model?.name from settings.json.

Current Behavior

Flow:

  1. User runs /model command
  2. ModelDialog displays available models
  3. User selects a model → config.setModel(model) is called (in-memory only)
  4. Model is used for current session ✓
  5. CLI is closed/restarted
  6. Selected model is lost ✗ - defaults back to old hardcoded model or environment variables

Code Location: packages/cli/src/ui/components/ModelDialog.tsx (lines 119-129)

const handleSelect = useCallback(
  (model: string) => {
    if (config) {
      config.setModel(model);  // ✓ Updates in-memory config only
      const event = new ModelSlashCommandEvent(model);
      logModelSlashCommand(config, event);  // ✓ Logs telemetry
      // ✗ MISSING: settings.setValue() to persist to settings.json
    }
    onClose();
  },
  [config, onClose],
);

Expected Behavior

The selected model should be persisted to ~/.qwen/settings.json so that:

  • User's latest model selection is remembered across sessions
  • Next time CLI starts, it uses the last selected model
  • Consistent with how other settings (theme, approval mode, editor) work

Solution

Update ModelDialog.tsx handleSelect function to persist the selected model to settings:

const handleSelect = useCallback(
  (model: string) => {
    if (config) {
      config.setModel(model);
      const event = new ModelSlashCommandEvent(model);
      logModelSlashCommand(config, event);
      
      // Add this: Persist the selected model to settings.json
      if (loadedSettings) {
        const scope = isWorkspaceSettings ? SettingScope.Workspace : SettingScope.User;
        await loadedSettings.setValue(scope, 'model.name', model);
      }
    }
    onClose();
  },
  [config, loadedSettings, isWorkspaceSettings, onClose],
);

Files to Update

  1. packages/cli/src/ui/components/ModelDialog.tsx

    • Update handleSelect callback to call settings.setValue()
    • Add LoadedSettings to component props/context if needed
    • Handle async save operation
  2. Settings Schema (if needed)

    • Verify model.name is properly defined in settings schema
    • Ensure migration path for existing settings

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions