feat: turn off filesystem watch by default (#3931)

* feat: turn off filesystem watch by default

* test: enable filesystem watch explicitly in watch-dependent suites
This commit is contained in:
Haozhe 2026-09-19 20:17:47 +08:00 • committed by GitHub
parent 9d07f634be
commit f17a22ebf4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 37 additions and 17 deletions

View file

@ -0,0 +1,5 @@
---
"@moonshot-ai/kimi-code": patch
---
Turn off filesystem watchers for config and workspace files by default. Set `[watch] enabled` to `true` or `KIMI_CODE_WATCH=1` to turn them back on.

View file

@ -474,11 +474,11 @@ Both values must be positive integers. A call's `max_chars` overrides the defaul
## `watch`
`watch` controls filesystem watchers that reload local.toml, AGENTS.md, skills, MCP config, and `config.toml` itself. It defaults to on. Set `enabled` to `false` to start with no watchers; changing the file later will not be picked up until restart.
`watch` controls filesystem watchers that reload local.toml, AGENTS.md, skills, MCP config, and `config.toml` itself. It defaults to off. Set `enabled` to `true` to attach watchers; with watchers off, changing the file later will not be picked up until restart.
| Field | Type | Default | Description |
| --- | --- | --- | --- |
| `enabled` | `boolean` | `true` | Attach filesystem watchers; `false` disables every `watch()` for the process |
| `enabled` | `boolean` | `false` | Attach filesystem watchers; `false` disables every `watch()` for the process |
`enabled` can be overridden by the `KIMI_CODE_WATCH` environment variable, which takes higher priority than `config.toml`.

View file

@ -160,7 +160,7 @@ Switches that control the behavior of subsystems such as telemetry, background t
| `KIMI_CODE_TUI_FULL_SCREEN` | Experimental fullscreen UI: scrollable transcript, mouse selection, clickable links, Ctrl-Shift-F search | `1` enables it; anything else keeps the regular inline UI |
| `KIMI_CODE_EXPERIMENTAL_SUBAGENT_FORK` | Experimental `fork` parameter on `Agent`/`AgentSwarm`: start the subagent from a snapshot of the caller's history instead of an empty context; `KIMI_CODE_EXPERIMENTAL_FLAG=1` also enables it | Truthy: `1`/`true`/`yes`/`on`; falsy: `0`/`false`/`no`/`off` |
| `KIMI_CODE_EXPERIMENTAL_TOOL_SELECT` | Experimental on-demand tool loading: tools of MCP servers marked `deferred: true` stay out of the top-level tool list and are loaded via `select_tools`; also requires the model to declare the `dynamically_loaded_tools` capability — see [MCP](../customization/mcp.md#loading-tools-on-demand) | Truthy: `1`/`true`/`yes`/`on`; falsy: `0`/`false`/`no`/`off` |
| `KIMI_CODE_WATCH` | Attach filesystem watchers that reload config and workspace files; higher priority than `[watch] enabled` (default `true`) | Truthy: `1`/`true`/`yes`/`on`; falsy: `0`/`false`/`no`/`off` |
| `KIMI_CODE_WATCH` | Attach filesystem watchers that reload config and workspace files; higher priority than `[watch] enabled` (default `false`) | Truthy: `1`/`true`/`yes`/`on`; falsy: `0`/`false`/`no`/`off` |
| `KIMI_CODE_SEARCH_WORKER` | Run the global search index in a dedicated worker thread; higher priority than `[database] search` (default `true`) | Truthy: `1`/`true`/`yes`/`on`; falsy: `0`/`false`/`no`/`off` |
| `KIMI_CODE_PERSISTENCE_MINIDB_READMODEL` | Use the minidb-backed read model for session indexing; higher priority than `[database] base` (default `true`) | Truthy: `1`/`true`/`yes`/`on`; falsy: `0`/`false`/`no`/`off` |
| `KIMI_MCP_STARTUP_TIMEOUT_MS` | Global default connection timeout (ms) for MCP servers; overrides the config file, but `mcp.json` `startupTimeoutMs` still wins | Integer from `1` to `2147483647`; invalid values are ignored |

View file

@ -473,11 +473,11 @@ max_chars = 500000
## `watch`
`watch` 控制 local.toml、AGENTS.md、skills、MCP 配置以及 `config.toml` 自身的文件系统热更新。默认开启。把 `enabled` 设为 `false` 后进程内不再挂任何 watcher;之后改文件要重启才会再读。
`watch` 控制 local.toml、AGENTS.md、skills、MCP 配置以及 `config.toml` 自身的文件系统热更新。默认关闭。把 `enabled` 设为 `true` 后进程内才会挂 watcher;关闭时改文件要重启才会再读。
| 字段 | 类型 | 默认值 | 说明 |
| --- | --- | --- | --- |
| `enabled` | `boolean` | `true` | 是否挂文件系统 watch;`false` 关闭进程内全部 `watch()` |
| `enabled` | `boolean` | `false` | 是否挂文件系统 watch;`false` 关闭进程内全部 `watch()` |
`enabled` 可被环境变量 `KIMI_CODE_WATCH` 覆盖,优先级高于配置文件。

View file

@ -160,7 +160,7 @@ kimi
| `KIMI_CODE_TUI_FULL_SCREEN` | 启用实验性的 fullscreen 界面:可滚动 transcript、鼠标选择、可点击链接、Ctrl-Shift-F 搜索 | `1` 开启;其他值保持常规内联界面 |
| `KIMI_CODE_EXPERIMENTAL_SUBAGENT_FORK` | 在 `Agent`/`AgentSwarm` 上启用实验性 `fork` 参数:以调用方对话历史快照而非空上下文启动 subagent | 真值:`1`/`true`/`yes`/`on`;假值:`0`/`false`/`no`/`off` |
| `KIMI_CODE_EXPERIMENTAL_TOOL_SELECT` | 启用实验性按需加载工具:标记 `deferred: true` 的 MCP server 工具不进入顶层工具列表,由模型经 `select_tools` 按需加载;还需模型声明 `dynamically_loaded_tools` 能力,详见 [MCP](../customization/mcp.md#按需加载工具) | 真值:`1`/`true`/`yes`/`on`;假值:`0`/`false`/`no`/`off` |
| `KIMI_CODE_WATCH` | 是否挂文件系统 watch 以热更新配置和工作区文件,优先级高于 `[watch] enabled`(默认 `true`) | 真值:`1`/`true`/`yes`/`on`;假值:`0`/`false`/`no`/`off` |
| `KIMI_CODE_WATCH` | 是否挂文件系统 watch 以热更新配置和工作区文件,优先级高于 `[watch] enabled`(默认 `false`) | 真值:`1`/`true`/`yes`/`on`;假值:`0`/`false`/`no`/`off` |
| `KIMI_CODE_SEARCH_WORKER` | 在独立 worker 线程中运行全局搜索索引,优先级高于 `[database] search`(默认 `true`) | 真值:`1`/`true`/`yes`/`on`;假值:`0`/`false`/`no`/`off` |
| `KIMI_CODE_PERSISTENCE_MINIDB_READMODEL` | 会话索引使用基于 minidb 的读模型,优先级高于 `[database] base`(默认 `true`) | 真值:`1`/`true`/`yes`/`on`;假值:`0`/`false`/`no`/`off` |
| `KIMI_MCP_STARTUP_TIMEOUT_MS` | MCP server 全局默认连接超时(毫秒);优先级高于配置文件,低于 `mcp.json` 的 `startupTimeoutMs` | `1` 到 `2147483647` 的整数;非法值被忽略 |

View file

@ -681,7 +681,7 @@ export class ConfigService extends Disposable implements IConfigService {
}
private applyWatchEnabled(): void {
setWatchEnabled(this.get<WatchConfig | undefined>(WATCH_SECTION)?.enabled ?? true);
setWatchEnabled(this.get<WatchConfig | undefined>(WATCH_SECTION)?.enabled ?? false);
}
private deliveredValue(domain: string): unknown {

View file

@ -4,7 +4,7 @@ import { mkdtemp, mkdir, realpath, rm, symlink, writeFile } from 'node:fs/promis
import { tmpdir } from 'node:os';
import { basename, join } from 'node:path';
import { afterEach, describe, expect, it } from 'vitest';
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
import {
createWatchService,
@ -20,6 +20,14 @@ const wait = (ms: number): Promise<void> => new Promise((r) => setTimeout(r, ms)
const longTempDir = (prefix: string): Promise<string> =>
mkdtemp(join(realpathSync.native(tmpdir()), prefix));
beforeEach(() => {
setWatchEnabled(true);
});
afterEach(() => {
setWatchEnabled(false);
});
class TestNativeWatcher {
private errorListener: ((error: NodeJS.ErrnoException) => void) | undefined;
closed = false;
@ -469,14 +477,10 @@ describe('watch chokidar mode', () => {
it('does not start a filesystem watch when watch is disabled', async () => {
root = await mkdtemp(join(tmpdir(), 'watch-disabled-'));
setWatchEnabled(false);
try {
const events = await start();
await writeFile(join(root, 'a.txt'), 'x');
await wait(300);
expect(events).toHaveLength(0);
} finally {
setWatchEnabled(true);
}
const events = await start();
await writeFile(join(root, 'a.txt'), 'x');
await wait(300);
expect(events).toHaveLength(0);
});
it('stops firing after the handle is disposed', async () => {

View file

@ -513,7 +513,7 @@ export const WATCH_ENV = 'KIMI_CODE_WATCH';
const TRUE_WATCH_ENV = new Set(['1', 'true', 'yes', 'on']);
const FALSE_WATCH_ENV = new Set(['0', 'false', 'no', 'off']);
let watchEnabledFromConfig = true;
let watchEnabledFromConfig = false;
export function setWatchEnabled(enabled: boolean): void {
watchEnabledFromConfig = enabled;

View file

@ -32,6 +32,7 @@ import {
} from '#/app/workspace/workspacePersistence';
import { IWorkspaceAliases } from '#/app/workspaceAliases/workspaceAliases';
import { WorkspaceAliasesService } from '#/app/workspaceAliases/workspaceAliasesService';
import { setWatchEnabled } from '#human/utils/watch';
import { stubBootstrap } from '../bootstrap/stubs';
interface SessionIndexLine {
@ -68,9 +69,11 @@ describe('WorkspaceAliasesService (file-backed)', () => {
'workspaceAliases',
);
homeDir = await fsp.mkdtemp(join(os.tmpdir(), 'ws-aliases-'));
setWatchEnabled(true);
});
afterEach(async () => {
setWatchEnabled(false);
currentHost?.dispose();
currentHost = undefined;
await fsp.rm(homeDir, { recursive: true, force: true });

View file

@ -46,6 +46,8 @@ import { IWorkspaceAgentProfileLoader } from '#/workspace/workspaceAgentProfileL
import { IExtraAgentProfileLoader } from '#/workspace/workspaceAgentProfileLoader/extraAgentProfileLoader';
import { IExplicitAgentProfileLoader } from '#/workspace/workspaceAgentProfileLoader/explicitAgentProfileLoader';
import { setWatchEnabled } from '#human/utils/watch';
import { stubBootstrap } from '../../app/bootstrap/stubs';
const watchMockState = vi.hoisted(() => ({ mode: 'inert' as 'inert' | 'real' }));
@ -334,6 +336,7 @@ async function withStack(
describe('agent profile loaders + session catalog', () => {
beforeEach(() => {
watchMockState.mode = 'inert';
setWatchEnabled(false);
_clearAgentProfileContributionsForTests();
const builtinDefault: AgentProfile = normalizeAgentProfile({
name: DEFAULT_AGENT_PROFILE_NAME,
@ -757,6 +760,7 @@ describe('agent profile loaders + session catalog', () => {
it('rescans the workspace source when a project agent file changes on disk', async () => {
watchMockState.mode = 'real';
setWatchEnabled(true);
await withFixture(async (fixture) => {
await mkdir(join(fixture.workDir, '.kimi-code', 'agents'), { recursive: true });
await withStack(fixture, undefined, async (stack) => {

View file

@ -129,6 +129,7 @@ describe('server-v2 /api/v1 catalog browse + import endpoints', () => {
home = await mkdtemp(join(tmpdir(), 'kimi-server-v2-catalog-'));
process.env['KIMI_CODE_MODEL_CATALOG_REFRESH_ON_START'] = '0';
process.env['KIMI_CODE_MODEL_CATALOG_REFRESH_INTERVAL_MS'] = '0';
process.env['KIMI_CODE_WATCH'] = '1';
server = await startServer({
hostIdentity: TEST_HOST_IDENTITY,
host: '127.0.0.1',
@ -159,6 +160,7 @@ describe('server-v2 /api/v1 catalog browse + import endpoints', () => {
}
delete process.env['KIMI_CODE_MODEL_CATALOG_REFRESH_ON_START'];
delete process.env['KIMI_CODE_MODEL_CATALOG_REFRESH_INTERVAL_MS'];
delete process.env['KIMI_CODE_WATCH'];
});
async function boot(toml?: string): Promise<void> {

View file

@ -45,6 +45,7 @@ describe('server-v2 /api/v1/workspaces', () => {
beforeAll(async () => {
home = await mkdtemp(join(tmpdir(), 'kimi-server-v2-workspaces-'));
process.env['KIMI_CODE_WATCH'] = '1';
server = await startServer({
hostIdentity: TEST_HOST_IDENTITY,
host: '127.0.0.1',
@ -64,6 +65,7 @@ describe('server-v2 /api/v1/workspaces', () => {
await rm(home, { recursive: true, force: true });
home = undefined;
}
delete process.env['KIMI_CODE_WATCH'];
});
async function postJson<T>(