fix(tui): provision managed WebSearch services on provider refresh#781
fix(tui): provision managed WebSearch services on provider refresh#781Rish-it wants to merge 4 commits into
Conversation
🦋 Changeset detectedLatest commit: 003b42f The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Provision managed Moonshot search/fetch services during provider refresh so WebSearch/URL fetch works after login without requiring manual config.toml edits.
Changes:
- Backfill
services.moonshotSearch/services.moonshotFetchon managed (OAuth) refresh even when models are unchanged. - Persist managed services along with managed model refresh updates.
- Add/extend tests and a changeset documenting the behavior change.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| apps/kimi-code/src/tui/utils/refresh-providers.ts | Adds logic to detect missing managed services and persist them during refresh. |
| apps/kimi-code/test/tui/utils/refresh-providers.test.ts | Adds coverage for backfilling services on unchanged refresh and ensuring existing services aren’t clobbered. |
| .changeset/websearch-services-on-refresh.md | Documents the patch change for release notes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // the WebSearch tool disabled. Backfill the services so the refresh | ||
| // repairs it, without emitting a spurious model-change report. | ||
| if (managedServicesMissing(config)) { | ||
| config = await host.setConfig({ services: next.services }); |
| config = await host.setConfig({ | ||
| providers: next.providers, | ||
| models: next.models, | ||
| defaultModel: next.defaultModel, | ||
| defaultThinking: next.defaultThinking, | ||
| // Persist the managed search/fetch services alongside the model | ||
| // refresh; omitting them here is what left upgraded clients with a | ||
| // non-functional WebSearch tool. | ||
| services: next.services, | ||
| }); |
| // The managed Kimi Code login provisions `services.moonshot_search` / | ||
| // `services.moonshot_fetch` — the endpoints behind the WebSearch and URL-fetch |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: eba592f834
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // the WebSearch tool disabled. Backfill the services so the refresh | ||
| // repairs it, without emitting a spurious model-change report. | ||
| if (managedServicesMissing(config)) { | ||
| config = await host.setConfig({ services: next.services }); |
There was a problem hiding this comment.
Backfill only missing managed service entries
When only one managed service is missing, this patches both generated services from applyManagedKimiCodeConfig, whose defaults include apiKey: ''. Because setConfig merges object patches, a config with services.moonshot_search.base_url plus a user api_key but no fetch service will have the existing search key overwritten while trying to backfill fetch; build the patch per missing service or preserve existing service fields.
Useful? React with 👍 / 👎.
| // Persist the managed search/fetch services alongside the model | ||
| // refresh; omitting them here is what left upgraded clients with a | ||
| // non-functional WebSearch tool. | ||
| services: next.services, |
There was a problem hiding this comment.
Preserve service credentials on model refresh
In the model-changing path, every managed model refresh now sends the freshly generated next.services, which resets service fields to the managed defaults (apiKey: '' and no custom headers). For users who already configured services.moonshot_search or services.moonshot_fetch with a manual key/header fallback, the next model-list change will silently clobber those settings; merge only missing/generated endpoint data while carrying over existing service credentials.
Useful? React with 👍 / 👎.
eba592f to
733ca05
Compare
The managed Kimi Code login writes `services.moonshot_search` and `services.moonshot_fetch` (the endpoints behind the WebSearch and URL-fetch tools), but the background provider refresh never persisted them: the model-change branch omitted `services` from the setConfig patch, and the unchanged-models branch skipped persistence entirely. A client that logged in before service provisioning existed (or had the block dropped) therefore kept an empty `services` config, so core-impl built `webSearcher: undefined` and WebSearch stayed silently disabled until the user hand-added an api_key to config.toml. Persist the services alongside model changes, and backfill them on an unchanged-models refresh when they are missing, without rewriting a block the user already has (so a manually set api_key is preserved). Fixes MoonshotAI#696
Assert the refresh backfills the managed services on an unchanged-models refresh, persists them alongside a model change, and leaves an already-provisioned services block (with a user-set api_key) untouched.
733ca05 to
381753b
Compare
Problem
Fixes #696. After logging in with a managed Kimi Code (OAuth) account, the WebSearch tool is silently unavailable. It only starts working after the user manually adds an
api_keyto both[services.moonshot_search]and[services.moonshot_fetch]inconfig.toml.Root cause
The managed login provisions the search/fetch services and writes the whole config:
applyManagedKimiCodeConfigsetsconfig.services = { moonshotSearch, moonshotFetch }(each with anoauthref and an emptyapiKey) —packages/oauth/src/managed-kimi-code.ts.MoonshotWebSearchProviderprefers the OAuthtokenProvideroverapiKey, so with the services present no manual key is needed.But the background provider refresh (
refreshAllProviderModels, run on startup / before the model picker) never persisted the services:apps/kimi-code/src/tui/utils/refresh-providers.ts: the model-change branch'ssetConfigpatch includedproviders,models,defaultModel,defaultThinking— but notservices.So any client that logged in on a build predating service provisioning (or that lost the block) keeps an empty
servicesconfig.createRuntimeConfigthen buildswebSearcher: undefined(packages/agent-core/src/rpc/core-impl.ts), disabling WebSearch until the user editsconfig.tomlby hand.Fix
In the managed-provider path of
refreshAllProviderModels:services: next.servicesalongside model changes.managedServicesMissing), so a refresh repairs the config without a spurious model-change report — and without rewriting a block the user already has, preserving any manually setapi_key.Testing
apps/kimi-code/test/tui/utils/refresh-providers.test.ts:api_key) untouched.