Skip to content

fix(tui): provision managed WebSearch services on provider refresh#781

Open
Rish-it wants to merge 4 commits into
MoonshotAI:mainfrom
Rish-it:fix/696-websearch-services-on-refresh
Open

fix(tui): provision managed WebSearch services on provider refresh#781
Rish-it wants to merge 4 commits into
MoonshotAI:mainfrom
Rish-it:fix/696-websearch-services-on-refresh

Conversation

@Rish-it

@Rish-it Rish-it commented Jun 15, 2026

Copy link
Copy Markdown

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_key to both [services.moonshot_search] and [services.moonshot_fetch] in config.toml.

Root cause

The managed login provisions the search/fetch services and writes the whole config:

  • applyManagedKimiCodeConfig sets config.services = { moonshotSearch, moonshotFetch } (each with an oauth ref and an empty apiKey) — packages/oauth/src/managed-kimi-code.ts.
  • MoonshotWebSearchProvider prefers the OAuth tokenProvider over apiKey, 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's setConfig patch included providers, models, defaultModel, defaultThinkingbut not services.
  • The unchanged-models branch (the common case for an upgrader) short-circuited and persisted nothing at all.

So any client that logged in on a build predating service provisioning (or that lost the block) keeps an empty services config. createRuntimeConfig then builds webSearcher: undefined (packages/agent-core/src/rpc/core-impl.ts), disabling WebSearch until the user edits config.toml by hand.

Fix

In the managed-provider path of refreshAllProviderModels:

  • Persist services: next.services alongside model changes.
  • Backfill the services on an unchanged-models refresh when they are missing (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 set api_key.

Testing

apps/kimi-code/test/tui/utils/refresh-providers.test.ts:

  • Backfills managed search/fetch services on an unchanged-models refresh.
  • Persists services alongside a model-changing refresh.
  • Leaves an already-provisioned services block (with a user-set api_key) untouched.
vitest run test/tui/utils/refresh-providers.test.ts   # 10 passed
pnpm --filter @moonshot-ai/kimi-code run typecheck     # clean
pnpm run lint                                          # 0 errors

Copilot AI review requested due to automatic review settings June 15, 2026 11:24
@changeset-bot

changeset-bot Bot commented Jun 15, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 003b42f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

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

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.

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.moonshotFetch on 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 });
Comment on lines 354 to 363
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,
});
Comment on lines +95 to +96
// The managed Kimi Code login provisions `services.moonshot_search` /
// `services.moonshot_fetch` — the endpoints behind the WebSearch and URL-fetch

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 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 });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@Rish-it Rish-it force-pushed the fix/696-websearch-services-on-refresh branch from eba592f to 733ca05 Compare June 15, 2026 11:29
Rish-it added 3 commits June 15, 2026 17:11
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.
@Rish-it Rish-it force-pushed the fix/696-websearch-services-on-refresh branch from 733ca05 to 381753b Compare June 15, 2026 11:41
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.

WebSearch tool unavailable after login until API key is manually configured

2 participants