Repository navigation
fix(kap-server): turn the global search index off by default - #4516
Conversation
🦋 Changeset detectedLatest commit: 572223f 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.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
commit: |
The behaviour of MoonshotAI#4421 has been in the requester since 94397aa, but its suite still asserted only that the lowered system message lost its `tools` field, which a message kept in place would also satisfy. Assert instead that no system message survives and the history keeps its length, and rename the case after what it protects. Also settle ten ledger rows that were already implemented here: MoonshotAI#3733, MoonshotAI#4413, MoonshotAI#4418, MoonshotAI#4421, MoonshotAI#4435, MoonshotAI#4460, MoonshotAI#4465, MoonshotAI#4516, MoonshotAI#4523, MoonshotAI#4532 and the MoonshotAI#4558 test calibration, each with a probe over the suite that pins it. Two rows carried a probe without a test-name selector (MoonshotAI#4557, MoonshotAI#4558), which aborted `--verify` for every other row; MoonshotAI#4557 is a changelog sync and now carries a manual probe.
Ports the docs half of upstream MoonshotAI/kimi-code 8b6a003 (MoonshotAI#4673): the 2.5.0 section from the upstream release notes lands in both changelogs, en and zh, word for word. Every feature the section names is in this tree - busy /model and /effort (MoonshotAI#4621), merged project-level skills (MoonshotAI#4520), remote sessions in SSH, Docker and custom-command environments (MoonshotAI#4062), [workspace] require_trust (MoonshotAI#4517), web search off by default (MoonshotAI#4516), and the subagent model pool (MoonshotAI#4418) - so the notes describe what the fork actually does. Deliberately not touched: apps/kimi-code/CHANGELOG.md still tops out at 2.4.1 and package.json still says 2.4.1. That file is generated by `changeset version`, this tree has 377 pending changesets, and AGENTS.md forbids running version or publish from this repository, so the entry is written on the docs side only. Whoever next cuts a release here should reconcile this section with what changeset version generates rather than re-deriving it by hand.
Requirement or Bug
全局全文搜索索引没有任何第一方消费者,却在每次启动时后台扫描全部历史会话,重度用户的搜索 worker 因此 OOM 并带崩整个进程;改为默认关闭,会话索引保持开启。
Bug Reproduction Steps
kimi web,~/.kimi-code/sessions下积累数 GB 的wire.jsonl(用户现场:3239 个文件共 10.8 GiB,其中 10 个超过 50 MiB,最大 400 MiB)。kimi-search-worker,栈顶为node::OOMErrorHandler,用 Electron 43.1.1 的符号重新解析后为Runtime_MapGrow → OrderedHashMap::Rehash → HeapAllocator::AllocateRawSlowPath → V8::FatalProcessOutOfMemory("CALL_AND_RETRY_LAST")。Root Cause
搜索 worker 以
resourceLimits.maxOldGenerationSizeMb = 1024创建,minidb 的全文索引把写缓冲delta(term → Map)、deltaDocs和整个词典常驻内存;同步每轮摄入最多 64 MiB、轮间只去抖 2 秒,而能清空 delta 的 generation 构建最多每 60 秒踢一次、失败后退避 5 分钟,delta 相对 1 GB 实际无界。Node 对 worker 的 near-heap-limit 回调只放宽 16 MiB,一次装不下的大分配(百万级条目的Map扩容)直接走CALL_AND_RETRY_LAST致命路径,abort()掉整个进程。已用同版本 Electron 复现:worker 限 256 MiB、数字键Map增长,进程以 134 退出,堆仅用到约 114 MiB。本 PR 是绕过而非根本修复:既然没有消费者,默认不启动索引;内存收敛(背压、词典表示)与进程隔离另行处理。
Code Changes
GlobalSearchService constructor requestSync runSync + enabled() # await config.ready; [database] global_search ?? false + -> false: log once, return (no backend, no sync, search-index untouched) ensureBackend + -> throws GlobalSearchError('index_unavailable', how-to-enable) when off search normalizeQuery # invalid bodies still fail with 40001 + enabled() -> false: throw GlobalSearchError('index_unavailable', how-to-enable) status + enabled() -> false: { sessions: 0, ..., lifecycle: { state: 'stopped', detail } } dispose - await backendPromise + await backendPromise?.catch(() => undefined)原有
[database] search键的语义不变:它只决定开启后索引跑在 worker 线程还是服务器进程内,从来不是关闭开关。Behavior Changes and Affected Users
SearchService构造即requestSync()global_search = truekimi web、desktop 与 web,三者共用 kap-server[database] global_search = true或KIMI_CODE_GLOBAL_SEARCH=1POST /api/v1/searchbuilding页50001,msg说明如何开启;请求体校验仍先返回40001~/.kimi-code/search-index目录与db.lockkimi-search-workerstatus()lifecycle.state = 'stopped'并带说明global search: worker started等global search: global search is disabled; ...[database] search、search_sync_session_cap、search_sync_debounce_ms受影响模块与测试覆盖:
packages/kap-server/src/search/searchService.ts:test/search/searchService.test.ts原有套件通过globalSearch: true显式开启,钉住开启人群的旧行为;新增global search switched off套件覆盖默认关闭与显式false两种配置下的status()、search()、reindex()、lifecycleReport()与索引目录不存在。packages/kap-server/src/routes/search.ts(未改):test/search/searchRoute.test.ts原有套件通过 env 开启;新增套件钉住默认关闭时/api/v1/search返回50001、GET /api/v1/sessions正常、不生成search-index。packages/agent-core-v2/src/persistence/configSection.ts:test/app/config/configManifest.test.ts钉住 manifest 中的新键与 env 绑定。验证:agent-core-v2 与 kap-server 类型检查通过;kap-server 全量 1431 个用例通过,另有
plugins.test.ts远端回退与telemetry.test.ts云端 appender 两个用例在本机环境于未改动的基线上同样失败,与本 PR 无关。合入后需要在 code-app 仓 bump submodule 并附处理过的 changeset。
Checklist
/approve). 无关联 issue,来源于用户崩溃报告分析。gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.