Skip to content

fix(model-config-import): stop routing pi providers through cc-switch snapshot - #590

Merged
vastsa merged 1 commit into
mainfrom
fix/cc-switch-pi-import
Sep 18, 2026
Merged

vastsa merged 1 commit into
mainfrom
fix/cc-switch-pi-import

Conversation

@vastsa

@vastsa vastsa commented Sep 18, 2026

Copy link
Copy Markdown
Owner

Fixes #588.

What broke

scanModelConfigs treated CC Switch's providers table as the authoritative index for every downstream tool it supports, pi included. But pi has its own native config at ~/.pi/agent/models.json, and CC Switch only holds a one-shot v18 migration snapshot of it — subsequent edits to models.json never flow back. Our importer dedupe key compares (baseUrl, apiStyle, secret) and skips the pi native draft when the same triplet is already in the cc-switch pile, so the fuller pi draft gets silently filtered out and the stale snapshot wins.

Concrete symptom the reporter observed on 0.15.0:

  • opencode-go came in with 9 of 10 models (the default deepseek-flash was dropped).
  • deepseek came in missing two models.
  • Pi providers surfaced under the "CC Switch" group with the snapshot's renamed label (OpenCode Zen Go instead of opencode-go).
  • Nothing showed up in "skipped M" counts, nothing in runtime.log — the models silently disappeared. Root cause matches the issue's own analysis.

Fix

parseCcSwitchProvider now returns [] for app_type='pi'. The pi scanner keeps ownership of ~/.pi/agent/models.json, which is upstream of the cc-switch snapshot. This is the "minimum cost" fix the reporter suggested — it fixes both the silent model loss and the source/name mislabelling at once, without touching the dedupe key or the scan ordering that other appTypes rely on.

If ~/.pi/agent/models.json doesn't exist locally, the pi scanner returns nothing and the cc-switch snapshot is no longer resurrected. That matches how every other source behaves when its native config is missing; the cc-switch snapshot was never a fresh copy anyway.

Tests

  • packages/shared/src/model-config-import.test.ts: new regression test — parseCcSwitchProviders skips app_type='pi' rows even when they carry a plausible model list.
  • apps/desktop/test/model-config-import.test.mjs: new integration test — reproduces the reporter's setup (cc-switch DB row with 9 models + models.json with 10) and asserts the pi source keeps 10 models and no draft lands under cc-switch.

Verification run in the task worktree:

  • pnpm build:js — passes
  • pnpm --filter @pi-desktop/shared test — 392 pass (including the new case)
  • pnpm --filter @pi-desktop/desktop typecheck — passes
  • node --test apps/desktop/test/model-config-import.test.mjs — 5 pass (including the new case)

Not run to green: pnpm lint and the broader pnpm --filter @pi-desktop/desktop test fail on unrelated pre-existing issues (work-panel.test.mjs asserts a minWidth: windowMinWidth string that isn't in apps/desktop/electron/main/index.ts; several CSS token violations under apps/desktop/src/styles/). Both reproduce on unmodified origin/main and are outside this fix's scope.

Compatibility

  • No public API, IPC, or SDK change.
  • No persisted-state change. Users who already imported the stale cc-switch snapshot must re-run "Import → Model config" to pick up the fuller models.json (this issue is about import; existing DB rows are not migrated).
  • User-visible: pi providers now land under the "Pi" group in the import panel with models.json's own name, instead of the CC Switch group with the snapshot's name.

… snapshot

CC Switch only stores a one-shot v18 migration snapshot of
~/.pi/agent/models.json, and our importer dedupe key looks at
endpoint + apiStyle + secret without comparing model coverage. When
scanModelConfigs returned [...ccSwitch, ...extra], any pi provider that
had grown after the sync landed under the cc-switch source with the
snapshot's stale model list, and the fuller pi native draft was silently
filtered out because it matched an earlier candidate. The reporter saw
opencode-go lose deepseek-flash and deepseek lose two models after
import.

parseCcSwitchProvider now returns [] for app_type='pi' so the pi
scanner keeps ownership of that authoritative file. Providers still
missing on disk are simply skipped, which matches every other source
whose native config no longer exists.

fixes #588
Copilot AI lite review requested due to automatic review settings September 18, 2026 10:58

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@vastsa
vastsa merged commit 5efad1d into main Sep 18, 2026
1 of 3 checks passed
@vastsa
vastsa deleted the fix/cc-switch-pi-import branch September 21, 2026 11:16

This branch was previously deployed

1 inactive deployment
Preview — fc2a15af Deployed Sep 18, 2026 by vercel[bot]
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.

[Bug] 模型导入:模型被静默遗漏,pi 的 provider 被归入「CC Switch」组

2 participants