Skip to content

fix(agent-core-v2): temporarily disable skill-root directory watches and add detailed startup tracing - #3690

Open
liruifengv wants to merge 2 commits into
mainfrom
fix/windows-startup-trace-and-skill-watch
Open

fix(agent-core-v2): temporarily disable skill-root directory watches and add detailed startup tracing#3690
liruifengv wants to merge 2 commits into
mainfrom
fix/windows-startup-trace-and-skill-watch

Conversation

@liruifengv

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue — the problem is explained below (reported by Windows users on 0.42.0).

Problem

Windows users report that the latest CLI (0.42.0) starts very slowly and feels laggy throughout the session. A KIMI_STARTUP_TRACE=1 capture from an affected machine shows ~2.5s in the win32-only Git Bash probe and 15.3s inside getWorkspaceTrustInfo (workspace materialization) before the first screen.

One of the 0.42.0 changes in this area is #3608, which added recursive file watches on the entire OS home directory and the whole project root to keep the skill catalog fresh. On Windows these run through the native recursive fs.watch leg (#3502), which delivers every subtree event to the main thread with no OS-level filtering — the home directory is one of the most active trees on a Windows machine (Defender, search indexer, browser caches, OneDrive), so the main thread is continuously interrupted. There is currently no config, env var, or flag to turn these watches off.

What changed

  • Temporarily disable the skill-root directory watches by default. Both watch sites (UserFileSkillSource — user-level roots under the OS home directory, and WorkspaceRootSkillSource — the project root) are now gated behind KIMI_CODE_SKILL_ROOT_WATCH (default off) until the watches are redesigned to cover only the skill candidate directories instead of the whole home/project tree. Skill catalogs still load normally at startup; newly added or changed skills are picked up on restart. Set KIMI_CODE_SKILL_ROOT_WATCH=1 to re-enable live refresh.
  • Add fine-grained startupTrace points along the workspace-trust path so the remaining startup cost can be split precisely on the affected machine: workspaceTrust:getOrCreate:* / workspaceTrust:read:* (SDK), workspace:catalog:* / workspace:materialize:* (engine). The engine-side tracer lives in agent-core-v2 and shares the same env vars (KIMI_STARTUP_TRACE / KIMI_STARTUP_TRACE_LOG), the same log file, and the same process-start clock as the app-side tracer (the app tracer now uses raw performance.now() so app and engine labels are directly comparable).
  • Tests: existing watch-dependent tests opt in via KIMI_CODE_SKILL_ROOT_WATCH=1; two new tests cover the default-off behavior for both watch sites.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue — N/A, problem explained above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill.
  • Ran gen-docs skill, or this PR needs no doc update — skill watching was not documented, and the KIMI_CODE_SKILL_ROOT_WATCH kill-switch is temporary.

The skill-root watches added in #3608 register recursive fs.watch roots on
the entire OS home directory and the whole project root. On Windows these
run through the native recursive leg, which delivers every subtree event
to the main thread with no OS-level filtering, and each event costs an
xstate transition (#3502). This is the prime suspect behind the reported
0.42.0 startup and interactive lag on Windows.

Gate both watch sites behind KIMI_CODE_SKILL_ROOT_WATCH (default off)
until the watches are redesigned to cover only the skill candidate
directories. Skill catalogs still load at startup; new or changed skills
are picked up on restart.
@changeset-bot

changeset-bot Bot commented Sep 9, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5c2639a

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

@pkg-pr-new

pkg-pr-new Bot commented Sep 9, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@5c2639a
npx https://pkg.pr.new/@moonshot-ai/kimi-code@5c2639a

commit: 5c2639a

@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: 5c2639a9f6

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

"@moonshot-ai/kimi-code": patch
---

Disable live watching of skill directories; new or changed skills are picked up on restart. Set KIMI_CODE_SKILL_ROOT_WATCH=1 to re-enable live refresh.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep the changeset entry to one sentence

When release tooling publishes this entry, it will include two sentences and expose the temporary environment-variable mechanism, although repository policy requires one short user-facing sentence stating only what changed. Fold the relevant user-visible behavior into a single sentence and omit mechanism-level detail.

AGENTS.md reference: AGENTS.md:L86-L87

Useful? React with 👍 / 👎.

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