Skip to content

fix model select and display issue - #998

Open
Sunjaieks wants to merge 2 commits into
siteboon:mainfrom
Sunjaieks:fix/model-selection
Open

fix model select and display issue#998
Sunjaieks wants to merge 2 commits into
siteboon:mainfrom
Sunjaieks:fix/model-selection

Conversation

@Sunjaieks

@Sunjaieks Sunjaieks commented Jul 11, 2026

Copy link
Copy Markdown

Problem

Picking a Claude model from the chat /models picker had two independent bugs:

  1. Display — the picker showed the wrong active model (e.g. default/sonnet
    while the session was actually running opus) and never reflected a just-made pick.
  2. Runtime — the per-session override (stored by /active-model, keyed by the
    app session id) was never applied on resume, because runtimes looked it up with
    the provider-native session id.
    Plus: a host ANTHROPIC_MODEL env var could silently override the explicit choice,
    and the override cache accumulated orphaned entries.

Root causes & fixes

Fixes #981

Display — the picker reflects the real model

  • getCurrentActiveModel now matches transcript events by provider_session_id
    (jsonl records the provider id, the frontend passes the app id → every event was
    rejected → fell back to default). claude-models.provider.ts
  • Transcripts record the raw model id (claude-opus-4-8); resolveClaudeActiveOptionValue
    maps it back to the catalog alias (opus) for highlighting. Families are derived
    from the catalog, so a newly released model needs no code change here. claude-models.provider.ts
  • System-placeholder turns ("model":"<synthetic>") no longer mask the real model. claude-models.provider.ts
  • A pending override is surfaced first, so reopening the picker shows the choice. provider-models.service.ts
  • resolveCommandModel validates the value against the catalog and falls back to the
    composer's requested model; wired into /models, /cost, /status. commands.js

Runtime — the model change takes effect

  • Pass the app session id to the provider runtimes and resolve the override with it.
    chat-websocket.service.ts, claude-sdk.js, cursor-cli.js, opencode-cli.js, openai-codex.js

Env precedence

  • Strip ANTHROPIC_MODEL / ANTHROPIC_DEFAULT_{OPUS,SONNET,HAIKU}_MODEL from the SDK
    subprocess env so the explicit selection wins (notably for default). claude-sdk.js

Override-cache hygiene

  • New deleteProviderSessionActiveModelChanges(sessionIds), called on permanent
    session delete and permanent project delete (archive is reversible → left untouched).
    utils.ts, sessions.service.ts, project-delete.service.ts

Frontend

  • After picking a model for a session, sync the composer model so new sessions inherit
    the latest choice. useChatProviderState.ts

Tests

  • Override surfaced before the adapter; raw-id → catalog fallback in the model command;
    override cleanup removes only the targeted sessions across providers.
  • Green: server tsc, 16 provider-model + command tests, eslint.

Known limitations (display-only, by design)

  • default and sonnet share the same underlying model, so without an override a
    default session shows sonnet in the picker — self-corrects once the user picks.
  • Overrides are intentionally persistent (changed:true) — that's the per-session
    model memory; they are cleared only when the session/project is permanently deleted.

Summary by CodeRabbit

  • New Features

    • Session-specific model selections now persist and take priority when resuming conversations.
    • Model selections made in the composer are applied consistently to model, cost, and status commands.
    • Provider-native model identifiers are translated into recognizable model-picker options.
  • Bug Fixes

    • Prevented environment settings from unexpectedly overriding the selected model.
    • Improved model detection when resuming sessions.
    • Removed saved model overrides when sessions or projects are permanently deleted.

Another PR: #996 is for same purpose.
⚠️⚠️ This PR includes all the changes from PR #996, along with some additional fixes. Please review and merge only one of the two PRs.

Summary by CodeRabbit

  • New Features

    • Improved model selection consistency across chat sessions, resumed conversations, and built-in commands.
    • The Models, Cost, and Status commands now reflect the selected session or composer model when applicable.
    • Selected provider models are saved for future use.
  • Bug Fixes

    • Prevented placeholder or internal model values from replacing the active model.
    • Improved recognition of provider model names in the model picker.
    • Cleared session-specific model overrides when sessions or projects are permanently deleted.

@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Model selection now propagates application session IDs through provider resume flows, normalizes Claude transcript models, prioritizes persisted overrides, supports requested command models, filters SDK environment variables, and cleans overrides during deletion.

Changes

Model selection flow

Layer / File(s) Summary
Application session resume propagation
server/modules/websocket/services/chat-websocket.service.ts, server/claude-sdk.js, server/cursor-cli.js, server/openai-codex.js, server/opencode-cli.js
Provider runtimes prefer appSessionId when resolving resumed models, while Claude SDK model-selection environment variables are removed from subprocess options.
Claude transcript model normalization
server/modules/providers/list/claude/claude-models.provider.ts
Placeholder values are ignored, transcript model IDs are mapped to catalog options, and lookup failures use the provider default.
Session override precedence
server/modules/providers/services/provider-models.service.ts, server/modules/providers/tests/provider-models.service.test.ts
Persisted session overrides are returned before provider adapter values, with tests covering override and fallback behavior.
Command and chat selection
server/routes/commands.js, server/routes/tests/commands.test.js, src/components/chat/hooks/useChatProviderState.ts
Commands use valid session or composer-requested catalog models, tests cover precedence, and chat model changes persist locally.
Session override cleanup
server/shared/utils.ts, server/modules/providers/services/sessions.service.ts, server/modules/projects/services/project-delete.service.ts, server/modules/providers/tests/provider-models.service.test.ts
Session-scoped overrides are removed during permanent session and project deletion, with targeted cleanup tests.

Sequence Diagram(s)

sequenceDiagram
  participant ChatUI
  participant ChatWebSocket
  participant ProviderModelsService
  participant ProviderRuntime
  ChatUI->>ChatWebSocket: select model and send message
  ChatWebSocket->>ProviderRuntime: pass appSessionId and model
  ProviderRuntime->>ProviderModelsService: resolve resumed or overridden model
  ProviderModelsService-->>ProviderRuntime: return catalog-compatible model
Loading

Possibly related PRs

Suggested reviewers: viper151

Poem

A rabbit hops through models bright,
Session paths now choose just right.
Claude’s placeholders fade away,
Catalog names guide the way.
Overrides bloom and commands sing.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 62.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title is related to the PR, but it is too vague to describe the specific model-selection and display fixes. Use a more specific title such as "Fix model selection and active-model display" or similar.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes address #981 by persisting session model changes, resuming with the correct session id, and syncing model display.
Out of Scope Changes check ✅ Passed The broader provider cleanup and command-model routing still support the same model-selection/display workflow and do not look unrelated.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing Touches
🧪 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.

@Sunjaieks
Sunjaieks force-pushed the fix/model-selection branch from 847c9b7 to 966afc3 Compare July 12, 2026 14:43
@Sunjaieks Sunjaieks changed the title [WIP] fix model select and display issue fix model select and display issue Jul 12, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🤖 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.

Inline comments:
In `@server/claude-sdk.js`:
- Around line 484-488: Update the appSessionId fallback in the
resolveResumeModel call to treat empty or whitespace-only values as missing by
trimming before selection, while preserving valid appSessionId values and the
sessionId fallback.
- Around line 167-177: Update the environment sanitization near sdkOptions.env
to also remove CLAUDE_CODE_SUBAGENT_MODEL from sdkEnv, alongside the existing
model-selection variables, so explicit sdkOptions.model remains authoritative
for subagents.

In `@server/modules/projects/services/project-delete.service.ts`:
- Around line 72-80: Wrap the cleanup sequence around
deleteProviderSessionActiveModelChanges in try/catch so failures are handled as
best effort and do not prevent the project row from being deleted. Preserve
deletion of session JSONL files and session rows, then continue the permanent
project deletion even when provider-model cleanup throws, following the existing
persistCache pattern in provider-models.service.ts.

In `@server/modules/providers/services/sessions.service.ts`:
- Around line 270-273: Wrap the post-deletion call to
deleteProviderSessionActiveModelChanges in a try/catch so cache cleanup failures
do not propagate after sessionsDb.deleteSessionById has succeeded. Log cleanup
failures with console.warn, matching the existing persistCache pattern, while
preserving the successful session deletion result.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 75dc7d30-4420-411d-9a00-fcd5c606e8ce

📥 Commits

Reviewing files that changed from the base of the PR and between 847c9b7 and 966afc3.

📒 Files selected for processing (14)
  • server/claude-sdk.js
  • server/cursor-cli.js
  • server/modules/projects/services/project-delete.service.ts
  • server/modules/providers/list/claude/claude-models.provider.ts
  • server/modules/providers/services/provider-models.service.ts
  • server/modules/providers/services/sessions.service.ts
  • server/modules/providers/tests/provider-models.service.test.ts
  • server/modules/websocket/services/chat-websocket.service.ts
  • server/openai-codex.js
  • server/opencode-cli.js
  • server/routes/commands.js
  • server/routes/tests/commands.test.js
  • server/shared/utils.ts
  • src/components/chat/hooks/useChatProviderState.ts
🚧 Files skipped from review as they are similar to previous changes (9)
  • server/opencode-cli.js
  • server/openai-codex.js
  • server/cursor-cli.js
  • server/routes/tests/commands.test.js
  • server/modules/providers/services/provider-models.service.ts
  • src/components/chat/hooks/useChatProviderState.ts
  • server/modules/providers/list/claude/claude-models.provider.ts
  • server/routes/commands.js
  • server/modules/websocket/services/chat-websocket.service.ts

Comment thread server/claude-sdk.js
Comment thread server/claude-sdk.js
Comment thread server/modules/projects/services/project-delete.service.ts Outdated
Comment thread server/modules/providers/services/sessions.service.ts
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.

Can not change model from Chat UI

2 participants