Skip to content

fix(kap-server): defer global search activation - #2376

Open
linxule wants to merge 1 commit into
MoonshotAI:mainfrom
linxule:agent/lazy-kap-search-registration
Open

fix(kap-server): defer global search activation#2376
linxule wants to merge 1 commit into
MoonshotAI:mainfrom
linxule:agent/lazy-kap-search-registration

Conversation

@linxule

@linxule linxule commented Jul 29, 2026

Copy link
Copy Markdown

Related Issue

None. This is a focused, reproducible bug fix.

Problem

IGlobalSearchService is registered through the CLI's unconditional web-command
import chain. With OnScopeCreated, experimental-v2 App bootstraps—including
kimi -p and v2 SDK/TUI clients—constructed it without a KAP server and started
cross-session indexing under <KIMI_CODE_HOME>/search-index.

The default v1 engine is unaffected.

What changed

  • Register global search as App-scoped OnDemand.
  • Preserve kimi web behavior through its existing explicit service resolution.
  • Add a behavioral DI test for lazy activation and singleton reuse.
  • Document the server resolution as the activation point before route registration.

Verification

  • KAP server: 917 tests passed; typecheck passed.
  • Type-aware oxlint: 0 errors; 4 pre-existing warnings outside changed lines.
  • Populated-home v2 run: no index with OnDemand; matched OnScopeCreated
    control created the index within 1 second.
  • Test control: OnScopeCreated failed the zero-call assertion; OnDemand passed.

No changeset is needed under gen-changesets Core Rule 6: shipped kimi web
behavior is unchanged, while the corrected behavior is limited to experimental-v2
surfaces with no documented configuration. No user-facing docs cover this feature.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot

changeset-bot Bot commented Jul 29, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: b514266

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@linxule
linxule marked this pull request as ready for review July 29, 2026 16:05
linxule added a commit to linxule/kimi-plugin-cc that referenced this pull request Jul 29, 2026
KIMI_TESTED_MINORS gains {0,30}; the H9 out-of-range warning stops firing.
The substantive change is not the certification -- it is the discovery that
the evidence backing it was worthless.

An exact-0.30.0 smoke:real had already passed 10/0/43. It proved nothing
about the one behavior in question: every isolated KIMI_CODE_HOME is created
empty, kimi-code's cross-session indexer short-circuits on zero sessions, so
the path exited before doing anything. Nothing in the harness checked that
its own premise held. A green test whose precondition never held is worse
than a red one -- it reads as evidence. The new populated-home case asserts
its precondition (wire.jsonl count > 0) and fails loudly instead of passing
quietly. That is now a standing rule in AGENTS.md, because the failure mode
is generic to any smoke whose behavior depends on host state.

The test pins the invariant, not the side effect: writes stay denied under a
populated home, agent-core-v2 genuinely served the run, and no search index
ever appears in the workspace -- while only RECORDING whether
<KIMI_CODE_HOME>/search-index materialized. Asserting its absence would
encode an upstream bug as a plugin failure; asserting its presence would
break the day the upstream fix ships.

Exact-0.30.0 smoke:real GREEN: 11 pass / 0 fail, 49 assertions in 348.05s,
and non-vacuous this time (index PRESENT, wire files=1). Write-swarm stayed
confined (patchBytes=334, userTreeClean=true, worktreeCleaned=true).

The source audit was re-run against 0.30.0 rather than inheriting the daily
monitor's verdict -- monitor reports are continuity-only and do not certify
a version. Every load-bearing contract holds. The deepest check: agent.hooks
is OPTIONAL, so an unwired subagent would silently fail open through policy
index 0; it is wired unconditionally by createAgent's
`config.hookEngine ?? this.hookEngine` fallback, and no production call site
supplies config.hookEngine.

Scope correction worth recording: the audit clone's package.json reads
0.30.0, but origin/main is eight commits ahead of the released tag. Custom
agent files, plugin-contributed agents, plugin systemPrompt, and the
secondary-model flag are all queued for 0.31.0 and are NOT in the shipped
binary. Auditing the wrong tree would have certified behavior users do not
have.

0.30.0 carries one characterized caveat: experimental-v2 App bootstraps
eagerly activate the KAP global-search service, creating
<KIMI_CODE_HOME>/search-index. Engine-internal (never a tool call), confined
to KIMI_CODE_HOME, and the default v1 engine is unaffected -- not a hook
bypass, worktree write, or credential read. Root-caused and fixed upstream
by MoonshotAI/kimi-code#2376, which flips the registration to App-scope
OnDemand.

Residual, stated rather than buried: write-swarm still runs against a
session-less home, so "an un-awaited index sync cannot race the patch
capture" is composed from two tests rather than observed end to end in one.

Before certifying 0.31.0: v1 custom agent files will auto-scan project roots
with no flag gating, and an override:true file can replace the default agent
profile. AgentFileDefinition carries no permission/hook/cwd field, so it
reshapes the system prompt and tool list only and our label allowlist fails
closed -- a prompt-injection surface for repo-scoped rescue/swarm-write, not
a hook bypass. It needs a docs/safety.md paragraph before 0.31 lands.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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