Skip to content

fix(native-chat): never adopt an unlisted model as the launch default - #19854

Merged
brennanb2025 merged 2 commits into
mainfrom
brennanb2025/native-chat-unlisted-model-not-default
Sep 10, 2026
Merged

brennanb2025 merged 2 commits into
mainfrom
brennanb2025/native-chat-unlisted-model-not-default

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

The bug

modelIsAdoptableAsLaunchDefault in native-chat-pty-session-options.ts is the sole gate on whether a model id may become the persisted -m launch flag for future native chats with an agent:

const modelIsAdoptableAsLaunchDefault = (modelId: string): boolean =>
  modelsAreDiscovered
    ? !catalog.discoveredModelsAreAuthoritative || models.some((model) => model.id === modelId)
    : record.model !== undefined

Claude and Codex do not set discoveredModelsAreAuthoritative, so !catalog.discoveredModelsAreAuthoritative is true and the discovered branch short-circuits to true for any id once a host model list has arrived.

How an unlisted id gets into the record

Two paths write a model id verbatim, with no catalog matching:

  • A raw launch flag. worker-start --model claude-opus-5 flows through seedNativeChatAppliedSessionOptions, which stores values.model as-is.
  • An agent report. applyNativeChatReportedSessionOptions (native-chat-session-option-state.ts:132-138) likewise stores values.model as-is, so an agent reporting a model name Orca does not carry lands one too.

A typed /model is not a third path: matchNativeChatCatalogModelId only ever returns ids drawn from the list it is handed, so a never-seen id either collapses to a catalog id (claude /model claude-opus-5 → opus) or matches nothing (codex /model gpt-6-turbo → no persist). It can only re-assert an id one of the two paths above already tracked.

User-visible consequence

Once such an id is in the record, the first option write or model re-pick in that chat persists it as the durable default, and every future native chat with that agent launches -m claude-opus-5 — an id that neither the host CLI's list nor the catalog seed carries. The same holds for the pre-discovery branch, where a tracked model is treated as proof enough; tracking only says the id was written, not that it names a real model.

The fix

Both branches now sit behind one precondition: the active models list or the catalog.models seed must carry the id. An id no list carries is not evidence of anything and never becomes durable state.

Ids that are carried keep every existing behaviour — the change is a pure && narrowing:

  • authoritative catalogs (grok) are unaffected: that branch already required models.some(...), and the precondition is implied by it.
  • a seeded alias the host CLI has stopped listing (opus when the CLI lists only opus[1m]) is still adopted — it is a real model the seed vouches for.
  • a model only the host catalog lists (opus[1m], unseeded) is still adopted.
  • the record.model !== undefined branch is otherwise untouched.

The gate reads the raw models and catalog.models lists, never the reconciled activeModels(), so it does not depend on the fabricated row and is correct both before and after #19852.

Tests

New file native-chat-launch-default-adoption.test.ts (5 tests). The new tests went in their own file because native-chat-pty-session-options.test.ts is already near the 800-line max-lines cap and adding to it broke the rule; no suppression was added, and that file is restored to a verified-empty diff.

Ablation — production change reverted by hand, restored by hand, re-proven at the final commit:

test ablated
unlisted launch-flag id not adopted (discovered) RED
unlisted launch-flag id not adopted (pre-discovery) RED
model only the host catalog lists is still adopted green (no-regression guard)
seeded alias the CLI stopped listing is still adopted green (no-regression guard)
tracked seed model before discovery is still adopted green (no-regression guard)

The three no-regression guards cannot go red against this change by construction, so each was also proven load-bearing against an over-reaching variant of the fix: dropping the seed fallback reddens the seeded-alias test; a seed-only precondition reddens the host-catalog test and an existing grok test; neutering the pre-discovery branch reddens the tracked-seed test and two existing tests.

Not in this PR

  • The model name shown in the chat and the fabricated { id, label: id, options: [] } catalog row — that is Name a native-chat model only when it is available or agent-reported #19852, already open.
  • The effort picker for an unlisted model, and the empty-dropdown explanatory text — separate follow-ups.
  • worker-start --model itself behaves exactly as on main; nothing under src/main/runtime/rpc/methods/orchestration/ is touched.

`modelIsAdoptableAsLaunchDefault` is the sole gate on whether a model id may
become the persisted `-m` launch flag for future native chats. For a catalog
that does not set `discoveredModelsAreAuthoritative` — Claude and Codex —
`!catalog.discoveredModelsAreAuthoritative` short-circuited the discovered
branch to `true` for any id at all.

So a raw launch flag (`worker-start --model claude-opus-5`) is seeded verbatim
into the session record, and the first option write or model re-pick adopted it
as the durable default. Every later native chat with that agent then launched
`-m claude-opus-5` — an id neither the host CLI's list nor the catalog seed
carries.

Both branches now sit behind one precondition: the active model list or the
catalog seed must carry the id. Ids that are carried keep their existing
behaviour, including the authoritative-retirement and tracked-model rules.
@coderabbitai

coderabbitai Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 46670096-930c-4bc8-8920-bf4e2b752f07

📥 Commits

Reviewing files that changed from the base of the PR and between 2bbdc8e and 715a3bb.

📒 Files selected for processing (1)
  • src/renderer/src/components/native-chat/native-chat-pty-session-options.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/renderer/src/components/native-chat/native-chat-pty-session-options.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review.


📝 Walkthrough

Walkthrough

modelIsAdoptableAsLaunchDefault now requires a model ID to exist in an available model list or an existing tracked record. Authoritative catalogs must also contain discovered models. New tests cover unlisted launch-flag models, catalog-only models, removed aliases, and tracked models before discovery.

Merge Risk: ⚪ Minimal · up to 715a3

Launch-default model adoption now avoids persisting unlisted model IDs while retaining the documented valid catalog and discovery cases. No current merge-blocking risk is identified.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description provides detailed bug, fix, scope, and test information, but it does not follow the repository template. It omits the required ELI5, Linked Issue, Visual Proof, Testing checklist, AI D… Add all required template sections. Include the linked issue after “Fixes #”, write N/A with a reason for Visual Proof if appropriate, document manual and automated testing with platforms, complete the required checklists, and state appli…
✅ Passed checks (3 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly and concisely describes the primary change: preventing unlisted models from becoming launch defaults.
Full details: Description check

Explanation

The description provides detailed bug, fix, scope, and test information, but it does not follow the repository template. It omits the required ELI5, Linked Issue, Visual Proof, Testing checklist, AI Disclosure, Review, boundary, Notes, and Checklist sections.

Resolution

Add all required template sections. Include the linked issue after “Fixes #”, write N/A with a reason for Visual Proof if appropriate, document manual and automated testing with platforms, complete the required checklists, and state applicable AI disclosure and compatibility considerations.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

…y vector

A typed `/model` cannot introduce an unlisted id: matchNativeChatCatalogModelId
returns only ids drawn from the list it is handed, so a never-seen id either
collapses to a catalog id (claude `/model claude-opus-5` -> `opus`) or matches
nothing (codex). It can only re-assert an id already in the record.

The origins that do enter verbatim are the launch flag and an agent report --
applyNativeChatReportedSessionOptions writes `values.model` with no catalog
matching. Say that instead, so the comment is true of the code as written and
does not lean on the reconciled row that #19852 removes.

Comment only; no behaviour change.

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

  • Launch-default adoption gate narrowed — modelIsAdoptableAsLaunchDefault now requires the id to be carried by the active models list or the catalog.models seed before either branch may adopt it, so an id only a raw launch flag or typed /model named can no longer become the persisted -m default.
  • Regression and no-regression coverage added — five tests in native-chat-launch-default-adoption.test.ts pin the two unlisted-id negatives (both RED under the old code) and the three seed/host-catalog still-adopted guards.

The narrowing is a pure && gate on top of the existing branches: grok's authoritative path still requires listedIn(models), and codex/gemini never reach persist (their options are all agent-picker), so neither the authoritative retirement flow nor codex's "unknown persisted ids pass through" seed contract regresses. The new and existing suites pass (38 passed).

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

  • Precondition doc comment corrected — commit 715a3bb rewrites the modelIsAdoptableAsLaunchDefault comment to state the two verbatim entry paths accurately (raw launch flag and agent report) and drops the misleading "typed /model" wording, which the PR body correctly notes is not a third path.

The only change since the prior review is this comment edit; the gate logic and the five tests are unchanged. Verified against the updated PR body: matchNativeChatCatalogModelId only returns ids drawn from the list it is handed, so a typed /model can only re-assert an id already tracked by a launch flag or an agent report — the revised comment matches that contract.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status: land

No in-scope issues remain at 715a3bb9833c3c645d180a3ec91f4497920944f6. The same-model review loop and closing readiness pass are clean; no code changes were needed during review.

  • Functional/root-cause: durable model adoption is now gated at the sole PTY persistence funnel by membership in the live or seeded catalog. This covers both picker and typed-command persistence without changing valid seeded aliases or host-discovered models.
  • Architecture: validation stays with the layer that owns catalog context and runs at commit time, preserving discovery-race handling. Existing historical opaque settings are intentionally not destructively migrated, and broader host-scoped settings provenance remains separate pre-existing work.
  • Performance/compatibility: only bounded catalog scans occur on explicit persistence actions. No timers, polling, subprocesses, retained state, wire/RPC schemas, platform paths, or mobile/SSH behavior changed.
  • Validation: 124 expanded tests passed in the main review loop; an independent closing pass reran 61 relevant tests. pnpm tc, changed-code quality checks, and git diff --check passed. PR CI is green, including Windows packaging and all eight test shards.
  • Electron: exercised the native-chat model picker in an isolated background CDP instance. After an unlisted claude-opus-5 launch value was rendered, clearing the stored default and re-selecting that row left nativeChatSessionOptions as {}. A subsequent Claude launch contained no --model flag.
  • QA note: the requested Grok validation lane could not start because its weekly quota was exhausted; the coordinator-run Electron/CDP proof above was used instead. Mobile, Windows-host, and SSH-specific harnesses were not applicable to this renderer-only persistence change.

Native chat unlisted-model regression scenario

@brennanb2025
brennanb2025 merged commit a933843 into main Sep 10, 2026
27 checks passed
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