MoonshotAI / MoonshotAI/kimi-code
[secondary_model] config silently reset: provider model refresh cascade drops/deletes the section without warning
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 7.5k
- Forks
- 1.2k
- Avg merge
- 11h 53m
- Merged PRs (30d)
- 350
Description
What version of Kimi Code is running?
Reported on 0.38.x; mechanism verified against main @ 9a71582.
Which open platform/subscription were you using?
Third-party model configured as the secondary (subagent) model.
What issue are you seeing?
User report: the [secondary_model] section in config.toml sometimes gets reset (silently disappears), and has to be re-added by hand.
What steps can reproduce the bug?
- Configure a refreshable provider (OAuth-managed, open-platform, or custom-registry) and a
[secondary_model]pool whosedefault_modelreferences one of that provider's auto-generated aliases (providerId/model-name). - Let a provider-model refresh run while the upstream model list has changed such that the referenced alias disappears (or delete/replace the provider via the API; re-import a registry that dropped it).
- The
[secondary_model]section is silently rewritten or deleted fromconfig.toml— no warning, no log at user level.
What did you expect to happen?
- A provider refresh should not silently delete user configuration. Aliases referenced by
[secondary_model]should be preserved the same way user-named aliases are, or the cascade should keep the entries and emit a warning instead of dropping them. - Behavior should be consistent across clients (see below).
Root cause analysis (main @ 9a71582)
cascadeSubagentModelPool(agent-core-v2/src/session/subagent/configSection.ts): whenever the[models]table is rewritten, pool entries referencing aliases that no longer exist are silently dropped; if thedefault_modelalias is gone, the whole[secondary_model]section is deleted; if the pool empties, themodelskey is removed. Completely silent — no warning surfaced to the user.- Automatic writers that run the cascade: the daemon (
kap-server)ModelCatalogRefreshScheduler— refresh on start (on by default) + every 6h by default (services/modelCatalog/modelCatalogRefreshScheduler.ts, tunable via[model_catalog]/KIMI_CODE_MODEL_CATALOG_REFRESH_*), plusPOST /providers:refresh,DELETE/PUTprovider routes, and custom-registry re-imports (routes/modelCatalog.ts,modelsDevImportService.ts,discoveryService.ts). - A refresh only rewrites config when the upstream model list actually changed (
providerModelsEqualshort-circuit) — which is why the reset appears to happen only "sometimes". - Alias survival rule: refreshes rebuild the auto-generated
providerId/model-namealiases from the upstream list, while user-named aliases are preserved (preserveUserProviderAliasesinkimi-code-oauth/refreshProviderModels.ts). - Inconsistency: the TUI refresh host (
apps/kimi-code/src/tui/controllers/auth-flow.ts) does not cascade — it leaves dangling references behind — while the daemon host silently deletes. The TUI/providercatalog-add flow has its own pool snapshot/restore (tui/commands/provider.ts), but skips the restore when the pool's default no longer resolves.
Workarounds for affected users
- Point
[secondary_model]at a user-named alias in[models](any name not starting withproviderId/); user-named aliases survive refreshes, so the cascade leaves the pool alone. - Disable the daemon auto-refresh:
(or[model_catalog] refresh_on_start = false refresh_interval_ms = 0KIMI_CODE_MODEL_CATALOG_REFRESH_ON_START=0/KIMI_CODE_MODEL_CATALOG_REFRESH_INTERVAL_MS=0). Manual refreshes still cascade, so combine with (1).
Re-adding the [secondary_model] section after a reset is sufficient; nothing else depends on it.
Related
- #3190 — subagent thinking-effort resolution issues reported by the same user around
[secondary_model]configuration.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with cascadeSubagentModelPool in agent-core-v2/src/session/subagent/configSection.ts, then trace the refresh callers in services/modelCatalog/modelCatalogRefreshScheduler.ts, routes/modelCatalog.ts, modelsDevImportService.ts, and discoveryService.ts. Compare this with apps/kimi-code/src/tui/controllers/auth-flow.ts and tui/commands/provider.ts. Done means provider refreshes no longer silently remove secondary_model configuration and behavior is consistent across clients, with a user-visible warning where entries cannot be retained.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- backend, cli
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 58/100