Skip to content

Preserve separate OpenAI LLM selections for API key and ChatGPT login - #1092

Closed
fqf555 wants to merge 1 commit into
TypeWhisper:mainfrom
fqf555:fix/openai-chatgpt-model-selection
Closed

Preserve separate OpenAI LLM selections for API key and ChatGPT login#1092
fqf555 wants to merge 1 commit into
TypeWhisper:mainfrom
fqf555:fix/openai-chatgpt-model-selection

Conversation

@fqf555

@fqf555 fqf555 commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Context

The OpenAI plugin currently uses one selectedLLMModel preference for both API-key and ChatGPT-login modes. When the authentication mode changes, that shared value is normalized against the newly active model catalog and may be replaced by its fallback. Switching back can therefore lose the user's previous model choice.

This builds on the dynamic ChatGPT model catalog introduced in #1016 by keeping a selection for each authentication mode.

Changes

  • Store independent API-key and ChatGPT-login LLM selections.
  • Migrate the legacy shared preference into the currently active authentication mode.
  • Keep the legacy preference synchronized for compatibility.
  • Restore each mode's previous selection when switching modes.

User impact

Users can switch between API-key and ChatGPT authentication without having to reselect their preferred model each time.

Test plan

  • cd TypeWhisperPluginSDK && swift test --filter OpenAIPluginTests

Summary by CodeRabbit

  • New Features
    • Model selections are now maintained separately for ChatGPT and API-key authentication modes.
    • Each mode’s selected model is saved and restored when switching between authentication methods.
    • Existing model preferences are migrated automatically based on the active authentication mode.

@fqf555
fqf555 requested a review from SeoFood as a code owner August 11, 2026 20:58
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The OpenAI plugin now stores separate LLM model selections for API-key and ChatGPT authentication modes. Activation migrates legacy state, selection updates persist the active mode, and normalization validates fallback models. Tests cover switching and restoring selections.

Changes

OpenAI model selection

Layer / File(s) Summary
Mode-specific selection state
TypeWhisperPluginSDK/Plugins/OpenAIPlugin/OpenAIPlugin.swift
The plugin adds separate persisted selections and storage keys for API-key and ChatGPT modes. OpenAIAuthMode and setAuthMode are module-visible.
Selection activation and persistence
TypeWhisperPluginSDK/Plugins/OpenAIPlugin/OpenAIPlugin.swift
Activation loads mode-specific selections and migrates legacy state. Selection updates persist the active mode. Normalization validates selections and synchronizes mode-specific and legacy defaults.
Mode switching persistence test
TypeWhisperPluginSDK/Plugins/OpenAIPlugin/Tests/OpenAIPluginTests.swift
Tests verify independent model persistence and restoration when authentication modes change.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant OpenAIPlugin
  participant PersistentStorage
  participant AvailableModels
  OpenAIPlugin->>PersistentStorage: Load mode-specific and legacy selections
  OpenAIPlugin->>OpenAIPlugin: Resolve selection for active authentication mode
  OpenAIPlugin->>AvailableModels: Validate selected model
  AvailableModels-->>OpenAIPlugin: Return available models
  OpenAIPlugin->>PersistentStorage: Persist normalized selection
Loading

Possibly related PRs

Suggested labels: enhancement

Suggested reviewers: seofood

Poem

A rabbit hops through models bright,
Saving each mode just right.
ChatGPT keeps one, keys keep two,
Switching brings the choice back true.
The plugin stores what rabbits know. 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes preserving separate OpenAI model selections for API-key and ChatGPT authentication.
Description check ✅ Passed The description explains the problem, changes, user impact, and test command, but it does not use the template headings or checklist.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot added the enhancement New feature or request label Aug 11, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
TypeWhisperPluginSDK/Plugins/OpenAIPlugin/Tests/OpenAIPluginTests.swift (1)

599-600: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Cover restoration after a new plugin activation.

Lines 599-600 verify the in-memory selection after setAuthMode. They do not verify that activate(host:) reloads both new storage keys. Create a second OpenAIPlugin after both selections are stored. Activate it, then assert the ChatGPT selection and the API-key selection after switching mode.

Proposed test update
-        plugin.setAuthMode(.apiKey)
-        XCTAssertEqual(plugin.selectedLLMModelId, "gpt-4.1-mini")
+        let restoredPlugin = OpenAIPlugin()
+        restoredPlugin.activate(host: host)
+        XCTAssertEqual(restoredPlugin.selectedLLMModelId, "gpt-5.3-codex-spark")
+
+        restoredPlugin.setAuthMode(.apiKey)
+        XCTAssertEqual(restoredPlugin.selectedLLMModelId, "gpt-4.1-mini")
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@TypeWhisperPluginSDK/Plugins/OpenAIPlugin/Tests/OpenAIPluginTests.swift`
around lines 599 - 600, Extend the test around OpenAIPlugin activation to
persist both ChatGPT and API-key model selections, then create a second
OpenAIPlugin instance and call activate(host:). After switching authentication
mode, assert that the restored ChatGPT and API-key selections match their stored
values, covering reload of both storage keys rather than only the in-memory
setAuthMode result.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@TypeWhisperPluginSDK/Plugins/OpenAIPlugin/Tests/OpenAIPluginTests.swift`:
- Around line 599-600: Extend the test around OpenAIPlugin activation to persist
both ChatGPT and API-key model selections, then create a second OpenAIPlugin
instance and call activate(host:). After switching authentication mode, assert
that the restored ChatGPT and API-key selections match their stored values,
covering reload of both storage keys rather than only the in-memory setAuthMode
result.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a5090503-dada-4034-9fe7-46806bb402fc

📥 Commits

Reviewing files that changed from the base of the PR and between 28f8cfd and 9c3092e.

📒 Files selected for processing (2)
  • TypeWhisperPluginSDK/Plugins/OpenAIPlugin/OpenAIPlugin.swift
  • TypeWhisperPluginSDK/Plugins/OpenAIPlugin/Tests/OpenAIPluginTests.swift

@fqf555

fqf555 commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

Closing this for now so the higher-impact startup responsiveness PR can proceed within the repository's one-open-PR policy. The branch will remain available if this fix is useful to revisit later. Thank you for taking a look.

@fqf555 fqf555 closed this Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant