Skip to content

perf: reduce remote file operation round trips - #4543

Merged
7Sageer merged 20 commits into
MoonshotAI:mainfrom
7Sageer:perf/remote-fs-walk-v2
Nov 2, 2026
Merged

7Sageer merged 20 commits into
MoonshotAI:mainfrom
7Sageer:perf/remote-fs-walk-v2

Conversation

@7Sageer

@7Sageer 7Sageer commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

Requirement or Bug

延续 #4062 的远程执行环境。高 RTT 下,Read、Write 和 Workspace 的 Node 遍历会被串行 RPC 放大。本 PR 合并这些往返,并修复搜索、补全的超时与输出截断边界。

Bug Reproduction Steps

在远程 workspace 读取小文件、写入已有目录,或在无 rg 的环境中搜索 / 补全。即使结果很小,也要等待 stat、内容探测、父目录检查或逐目录 readdir 的多次往返。

Root Cause

控制端逐步执行文件算法,每一步都是独立 RPC。本 PR 将 metadata 与文件头、整棵目录树遍历合并到执行端,直接减少往返,不引入缓存或重试。

Code Changes

优化只落在 IHostFileSystem 和远程协议层,工具层不判断后端能力。本地与 executor 复用 node-local 的 walkDirectoryTree,保持深度优先顺序、ignore 语义和 64 层深度上限一致。

 Read
-  stat → readBytes(探测) → readLines
+  readFileHead(探测) → readLines

 Write
-  stat(父目录) [→ mkdir] → write
+  write [父目录错误 → ensureParentDirectory → write]

 Workspace 的 search / suggest / grep 回退
-  每个目录一次 readdir
+  每个 root 一次 walk

 Glob / Grep 输出
-  达到 10 MiB 后截取,但继续读完 rg 输出
+  达到 10 MiB 即停止 rg
  • Read:远程 fs/readFile 一次返回 metadata 和开头字节,小文件从 3 次 RPC 降为 2 次。正文仍走 readLines,以保留 ACP 客户端未保存内容的编辑器视图。
  • Write:父目录通常已存在,因此先写,遇到 not-found / not-a-directory 再走原有补建与重写。ACP 写入失败时在本地检查父目录并转换错误,以复用同一回退。
  • Workspace:新增 fs/walk,执行端按 8 MiB 响应和 55 秒预算截断,单目录超过 5 万条仍报错。search / suggest / grep 共用截止时间,约束遍历、结果回放和候选评分。
  • Glob / Grep:输出到上限后终止 rg;预期截断导致的非零退出不再误报目录不可读。

重点阅读 hostFileSystem.ts、hostFsService.ts、remoteFileSystem.ts、fsHandler.ts 和 workspaceFs/fsService.ts;其余主要是工具接入、ACP / kap-server 透传与测试。

Screenshots / Recordings

Glob 达到 10 MiB 上限时,不再多出错误的目录警告:

修复前 修复后
[stdout truncated at 10485760 bytes; results may be incomplete — use a more specific pattern]
Glob completed with warnings; some directories could not be read.
[stdout truncated at 10485760 bytes; results may be incomplete — use a more specific pattern]

Behavior Changes and Affected Users

“远程”指 SSH / Docker / command 环境,覆盖 TUI、print、desktop / web、VS Code、ACP 和 SDK 客户端。

行为 原来 现在 依赖原行为的人群 兼容方式 / 退路
远程 Read 小文件 stat、探测、读取共 3 次 RPC 2 次 RPC,输出和错误文案不变 所有远程客户端 无需退路
Write(本地 / 远程 / ACP) 先检查并补建父目录,再写 先写,父目录错误时补建并重写 所有 Write 用户 错误文案不变;常见路径少一次检查,缺父目录时多一次写入尝试
Glob / Grep 达到 10 MiB 截取后继续读完 rg 输出 立即停止 rg,保留部分结果和截断提示 输出极大的用户 缩小 pattern / path / glob 获取完整结果
远程 Workspace 遍历 每个目录一次 readdir 每个 root 一次 fs/walk 无 rg 环境的搜索 / 补全用户 超过 8 MiB 或 55 秒返回部分结果并标记 truncated;单目录超 5 万条仍报错
search / suggest / grep 回退截止时间 suggest 只在 visitor 中止,grep 只检查扫描阶段 rg 尝试、遍历、回放和评分共用截止时间,到期返回部分结果并标记 truncated 本地和远程的 Workspace 搜索 / 补全用户 grep 尚未扫描文件时仍报 FS_GREP_TIMEOUT
远程遍历连接错误 readdir 错误被忽略,可能返回空结果 错误直接抛出 无 rg 环境的搜索 / 补全用户 不再静默返回空结果
全点号文件名 ... 等合法名称可能让 Node 回退失败 search / suggest / grep 均保留这些名称 workspace 含此类文件名的用户 无需开关,ignore 与剪枝语义不变
.git 排除 按名字跳过 .git 文件和目录 通过最后一条 ignore 规则 .git 排除,取反规则不能覆盖 含 .GIT 等大小写变体的仓库 .GIT 现在也会跳过;linked worktree / submodule 的 .git 文件仍被排除
远程协议 — fs/readFile 支持 metadata;新增 fs/walk 手动维护远端 kimi exec-server 的实验功能用户 客户端与 executor 必须同步升级;旧 executor 会直接报错
IHostFileSystem 实现方 — 新增必选 readFileHead 与 walk 仓库内实现与测试替身 接口不从 SDK 公共导出,仓库内实现已同步

配置、环境变量、提示词、CLI 参数、公共 REST / WS / SDK 契约和旧会话格式不变。Grep 的命中文件排序、ACP 正文读取和文件历史持久化路径也不变。

测试覆盖:

  • Read / Write / ACP:read.test.ts、write.test.ts、acp-fs.test.ts、remote/fs.test.ts 覆盖 RPC 次数、父目录回退和错误转换。
  • Glob / Grep:glob.test.ts、grep.test.ts 覆盖上限终止、信号退出和部分结果。
  • 遍历与协议:hostFsService.test.ts、remote/fs.test.ts 覆盖顺序、ignore、全点号名称、截止时间、截断和单次 RPC。
  • Workspace:fsService.test.ts、kap-server/test/workspaceFs.test.ts 覆盖深度边界、.git、多 root 截止时间、grep 超时与部分结果。
验证结果与未覆盖环境
  • 核心 7 个定向文件 412 项、ACP 文件系统 9 项、acp-server 156 项、kap-server workspaceFs.test.ts 29 项通过;工作区 typecheck、相关 lint、禁注释和 git diff --check 通过。
  • agent-core-v2 全量 7783 项中有 2 项失败:subagent 超时用例在 PR 前的 head 同样失败;watch.test.ts 单独重跑 20 项通过,属于高负载下的 flaky。
  • import-boundary 仅剩 main 已有的 human/agent/origin.ts 违规。
  • 未验证真实 SSH / Docker 高 RTT、Windows 远端或 native SEA 发布产物;executor 仍只接受 POSIX 环境。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue(延续 feat: remote environments for SSH and Docker execution targets (phase 1: creation-time binding) #4062)。
  • I have added tests that prove my feature works.
  • The behavior-change table above is complete, and every removed behavior or flipped default is named in the changeset and either has an escape hatch or was explicitly approved by a maintainer in this PR. 旧开发版 executor 需要同步升级。
  • Ran gen-changesets skill:CLI patch,记录远程性能优化及搜索、补全边界修复。
  • Ran gen-docs skill:无新用户操作或配置,用户指南无需更新;远程协议说明已同步。

Copilot AI balanced review requested due to automatic review settings October 30, 2026 04:30
@changeset-bot

changeset-bot Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d2abf6b

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.

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.

@7Hanrui

7Hanrui commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-02T08:59:46.458826Z d2abf6b Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pkg-pr-new

pkg-pr-new Bot commented Oct 30, 2026 •

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

commit: d2abf6b

@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: 3f497c5099

ℹ️ 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".

for (const file of filePaths) {
if (signal.aborted) {
const outOfTime = signal.aborted || Date.now() >= deadline;
if (outOfTime && (filesScanned > 0 || filePaths.length === 0)) {

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 Handle zero-file inventory timeouts before the scan loop

When ripgrep is unavailable and the batched walk reaches the 30-second deadline before yielding any file (for example, when files exist only beyond the partial inventory), filePaths is empty, so this loop and its only FS_GREP_TIMEOUT check never run. When the array is nonempty, this condition can only be entered after filesScanned > 0, making the nested zero-progress throw unreachable there as well; the Node fallback therefore returns a successful empty/truncated response instead of the timeout error for a zero-progress scan. Check the zero-progress timeout before entering the loop.

Useful? React with 👍 / 👎.

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

Speed up file completion in remote environments without ripgrep.

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 Disclose the new fallback walk limits

The new WorkspaceFsService.walk applies 10,000-directory, 100,000-entry, 8 MiB, and per-directory 50,000-entry limits to local/ACP searches and Node-fallback suggest/grep, while the previous local recursive path had only the depth boundary. Large local workspaces can therefore now omit hits or fail with a too-many-results error, but this release note mentions only faster remote completion and does not name the behavior users lose; update it to disclose the truncation/error behavior (and any retained escape hatch).

AGENTS.md reference: AGENTS.md:L117-L117

Useful? React with 👍 / 👎.

@7Hanrui

7Hanrui commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

@codex review

@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: ff2e2403b4

ℹ️ 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".

const SUGGEST_TIMEOUT_MS = 10_000;
const SUGGEST_WALK_ABORTED = new Error('suggest walk aborted');
const WALK_MAX_DEPTH = 64;
const WALK_DEFAULT_IGNORE = ['.git/'];

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 case-sensitive .git exclusion when ignores are off

On case-sensitive filesystems, requests with follow_gitignore: false now feed this rule to ignore(), whose v5 default is case-insensitive, so a real directory such as .Git/ is pruned before the visitor. The replaced recursive path only skipped name === '.git' when ignores were disabled, so search and the Node grep/suggest fallbacks previously included .Git/; preserve an exact-case metadata check instead of routing the default through the case-folding matcher.

AGENTS.md reference: AGENTS.md:L127-L129

Useful? React with 👍 / 👎.

let inventoryTruncated = false;
for (const root of roots) {
const ignoreRules = query.followGitignore ? await this.walkIgnoreFor(root.dir) : WALK_DEFAULT_IGNORE;
inventoryTruncated = await this.walk(root.dir, ignoreRules, async (relPath, _name, kind) => {

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 Stop visiting candidates after the suggestion deadline

When a batched walk resolves after the 10-second timer has fired—for example, after accumulating many entries before a slow final readdir—this callback still scores every returned entry because the first signal.aborted check is only after this.walk returns. The replaced visitor stopped before scoring each entry, so completion can now process up to the 100,000-entry batch after its deadline; check the absolute deadline during reconstruction/visiting and stop promptly.

AGENTS.md reference: AGENTS.md:L127-L129

Useful? React with 👍 / 👎.

@7Hanrui

7Hanrui commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 61f5df60a7

ℹ️ 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".

@7Hanrui

7Hanrui commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

@codex review

@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: 4023039cc2

ℹ️ 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".

}
this.gitignoreCache.set(rootDir, ig);
return ig;
const rules = ['.git/', ...contents.split(/\r?\n/)];

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 Make .git pruning immune to ignore negations

When follow_gitignore is true and the root .gitignore contains !.git/ (or another later negation matching it), this ordered rule list lets that negation override the synthetic .git/ rule. The walker then inventories .git even though visitDirectory later discards it, so a large object tree can consume the 100,000-entry or 8 MiB budget and omit real workspace hits; the replaced walker performed the exact name === '.git' check before applying the matcher, so keep this as an unconditional exact-name prune instead of an overridable ignore rule.

AGENTS.md reference: AGENTS.md:L127-L129

Useful? React with 👍 / 👎.

}

if (mode === 'files_with_matches') cmd.push('-l');
if (mode === 'files_with_matches') cmd.push('-l', '--sortr=modified');

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 Grep on ripgrep binaries without --sortr

When PATH contains a pre---sortr ripgrep, the existing locator still accepts it (the local path only checks executability, while the remote probe only requires rg --version to succeed), but the default files_with_matches mode now unconditionally passes --sortr=modified; that binary exits with an unknown-option error and Grep returns no matches, although -l worked before. I checked rg 14.1.0 --help, which defines --sortr as descending sorting and describes modified as “Always single-threaded”; capability-probe/version-gate this flag or retain the previous sorting fallback.

AGENTS.md reference: AGENTS.md:L111-L113

Useful? React with 👍 / 👎.

@7Hanrui

7Hanrui commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: 0f3a2c4f1e

ℹ️ 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".

@7Hanrui

7Hanrui commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 8facc09ed3

ℹ️ 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".

@7Sageer 7Sageer changed the title perf: batch remote filesystem walks perf: reduce remote file operation round trips Oct 30, 2026
@7Hanrui

7Hanrui commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

Failed to sample tokens
ℹ️ 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".

@7Hanrui

7Hanrui commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

Failed to sample tokens
ℹ️ 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".

@7Hanrui

7Hanrui commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

@codex review

@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: b799a95a36

ℹ️ 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".

if (signal.aborted || Date.now() >= deadline) break;
}

if ((signal.aborted || Date.now() >= deadline) && filesScanned === 0 && filePaths.length === 0) {

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 Reject an expired inventory before reading its first file

Although the empty-inventory case is now checked, when walk discovers at least one file and then consumes the 30-second deadline (for example in a later slow directory), filePaths.length === 0 is false and the loop guard also permits its first iteration while filesScanned is zero. The Node fallback then starts an unbounded readText after its deadline and can return a normal partial response instead of the previous zero-progress FS_GREP_TIMEOUT; reject any expired inventory with zero scanned files before entering the loop.

AGENTS.md reference: AGENTS.md:L111-L113

Useful? React with 👍 / 👎.

try {
await write();
} catch (error) {
if (!isHostFsNotFound(error) && !isHostFsNotDirectory(error)) throw error;

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 Normalize ACP not-found errors before the retry

When the active backend is AcpHostFileSystem and writeTextFile reports a missing parent as ACP RequestError.resourceNotFound (code === -32002), isHostFsNotFound cannot recognize it because that predicate only accepts HostFsError or string ENOENT; this branch rethrows before ensureParentDirectory. The old execution called stat/mkdir before every write, so ACP Writes to new nested paths now fail instead of creating the parent; map the ACP error or preserve that fallback.

AGENTS.md reference: AGENTS.md:L127-L129

Useful? React with 👍 / 👎.

@7Hanrui

7Hanrui commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

@codex review

@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: 854b50cfdc

ℹ️ 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".

const SUGGEST_TIMEOUT_MS = 10_000;
const SUGGEST_WALK_ABORTED = new Error('suggest walk aborted');
const WALK_MAX_DEPTH = 64;
const WALK_DEFAULT_IGNORE = ['.git/'];

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 Exclude regular .git metadata files from walks

When follow_gitignore is false in a linked worktree or submodule, .git is a regular file, and the directory-only .git/ ignore pattern does not match it. Nonempty workspace search can therefore return that metadata file, and the Node grep fallback can scan its gitdir: contents, whereas the replaced walker skipped every entry whose exact name was .git; preserve an unconditional exact-name prune (or add the file form of the rule).

AGENTS.md reference: AGENTS.md:L127-L129

Useful? React with 👍 / 👎.

@7Hanrui

7Hanrui commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: e565648e7f

ℹ️ 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".

@7Hanrui

7Hanrui commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: ac3633e921

ℹ️ 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".

@7Hanrui

7Hanrui commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: e8a91b101d

ℹ️ 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".

@7Hanrui

7Hanrui commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

@codex review

@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: d2abf6b0ec

ℹ️ 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".

const result = await this.call<FsWalkResult>(FS_WALK_METHOD, {
path,
ignore: options.ignore,
timeoutMs: Math.min(remainingMs, FS_WALK_DEFAULT_TIMEOUT_MS),

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 Leave transfer headroom in the walk RPC budget

When a nonempty remote workspace search runs close to this 55-second walk budget, RemoteExecConnection.call still expires the request after 60 seconds, while the executor constructs and sends the single response (up to 8 MiB) only after traversal finishes. On an SSH link that cannot encode and deliver that frame in the remaining few seconds, the client raises RequestTimeoutError and discards the partial inventory instead of returning truncated: true; the replaced per-directory path did not place the entire traversal and response under one request timer. Reserve post-walk transfer headroom or allow this call a longer timeout.

AGENTS.md reference: AGENTS.md:L129-L129

Useful? React with 👍 / 👎.

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

Fix searches failing on dot-only filenames, completion exceeding its timeout, and false directory warnings.

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 Drop the intra-PR warning fix from the release note

The false-directory-warning clause describes only an intermediate regression in this PR: on the base commit, reaching the 10 MiB capture cap did not terminate ripgrep, so it did not create the signal-exit warning; this PR adds cap-initiated termination and then suppresses that warning. Keep the two net user fixes in this entry, but remove that clause so the release notes do not claim a user-visible fix that never exists in a released tree.

AGENTS.md reference: AGENTS.md:L91-L91

Useful? React with 👍 / 👎.

@7Hanrui

7Hanrui commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

@codex review

@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: d2abf6b0ec

ℹ️ 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".


let traversalWarning: string | undefined;
if (exitCode !== 0 && exitCode !== 1 && !timedOut) {
if (exitCode !== 0 && exitCode !== 1 && !timedOut && !bufferTruncated) {

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 Keep real rg diagnostics when the output cap fires

When stdout crosses the 10 MiB cap after ripgrep has already emitted an unreadable-path diagnostic (for example, a permission error), bufferTruncated bypasses this branch and the matching guard in grepTool.ts:200, after which neither tool incorporates stderr; users see only the cap notice even though the previous code surfaced the warning/error. I checked rg 14.1.0 --help, which says --no-messages suppresses messages for failed opening and reading of files; these invocations do not pass that flag, so legitimate stderr can coexist with matches. Suppress only the cap-induced signal exit and retain nonempty diagnostics.

AGENTS.md reference: AGENTS.md:L111-L113

Useful? React with 👍 / 👎.

timeoutMs: Math.min(remainingMs, FS_WALK_DEFAULT_TIMEOUT_MS),
});
for (const entry of result.entries) {
if (options.deadlineMs !== undefined && Date.now() >= options.deadlineMs) return { truncated: true };

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 remote completion candidates collected before timeout

When rg is unavailable and a remote fs/walk consumes the 10-second suggestion budget, the executor returns the entries collected before its timeout only at or after the caller deadline, so this check exits before invoking the visitor for even the first entry. suggestWithNode therefore returns an empty result instead of the partial candidates retained by the old per-directory visitor (and expected by fsService.test.ts:1608); reserve response/replay headroom or retain a bounded prefix while still honoring the deadline.

AGENTS.md reference: AGENTS.md:L127-L129

Useful? React with 👍 / 👎.

matched += 1;
top.push(this.displayCandidate(root, candidate));
}, { deadlineMs: deadline }) || inventoryTruncated;
if (signal.aborted || Date.now() >= deadline) break;

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 Mark completion truncated when the deadline skips roots

With multiple workspace roots, if the first local walk finishes cleanly just after the deadline but before the abort timer callback runs—for example, its final awaited readdir is a slow empty directory—this branch skips every later root without setting inventoryTruncated. When the match count is below the cap, the response consequently reports truncated: false despite never searching those roots; set the truncation flag before breaking on the absolute deadline.

AGENTS.md reference: AGENTS.md:L131-L133

Useful? React with 👍 / 👎.

@7Sageer
7Sageer merged commit 2d674cf into MoonshotAI:main Nov 2, 2026
18 checks passed
@github-actions github-actions Bot mentioned this pull request Nov 3, 2026
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 5, 2026
Every remote-path file this commit touches is absent from the tree: the
fork's local backend lives at os/backends/host, src/remote carries only
its declaration layer, and the remote filesystem and fs-handler modules
arrive with MoonshotAI#4062. Re-evaluate once that line lands.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 5, 2026
… it blocked

The full remote-environment port landed with 4166ca3, so MoonshotAI#4062 is `ported`
with the evidence that closes it out: 29 port commits, typecheck 23/23, the
fifteen check gates, a 26/26 build whose bundle answers `--version` and an
`exec-server` initialize frame, and every suite green (agent-core-v2 8415,
kap-server 1314, node-sdk 321, klient 118, acp-server 177, apps/kimi-code 5049).

Three rows were parked behind it and now have their prerequisites:

- MoonshotAI#4600 (legacy ACP session file tools) — `IAgentEnvironmentBindingService` and
  `IEnvironmentService` are exported from the engine root, `start.ts` constructs
  `RemoteEnvironmentProviderFactory`, and the provider registration block the
  repair edits exists.
- MoonshotAI#4649 (TUI footer/welcome on the session environment) — the engine half landed
  in 2fa7b6b; the missing piece was the session workdir, which now carries the
  environment cwd.
- MoonshotAI#4543 (remote file round trips) — every remote file it changes exists; the
  batched walk methods it adds are still absent from `methods.ts`.

All three move from `blocked`/`in_progress` to `pending`; none is ported.

Ledger: closed 68 -> 69, remaining 31 -> 30.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 5, 2026
Port of upstream MoonshotAI/kimi-code 2d674cf (MoonshotAI#4543), adapted onto this
fork's host backend and workspace fs.

A remote session paid one round trip per directory and per file the model
touched: `Read` asked for metadata and then for bytes, and every list, search,
grep and completion walked the tree through `readdir` calls.

- `IHostFileSystem` gains `readFileHead(path, maxBytes)` (metadata and the first
  bytes in one answer) and `walk(path, options, visit)` (a streaming visitor
  with an ignore matcher and an optional deadline). `HostFileSystem` implements
  both, `walk` through the new `walkDirectoryTree`, and `RemoteFileSystem` maps
  them onto the new `fs/readFile` head answer and a streamed `fs/walk`.
- `WorkspaceFsService` no longer carries its own recursive walk: the private
  walk delegates to the host filesystem's, keeping the per-root gitignore
  matcher by passing it as a precompiled `HostWalkOptions.matcher`. Errors are
  mapped the same way as before, so an oversized directory still surfaces as
  `fs.too_many_results`.
- `Read` reads the head instead of stat-then-read, `Write` writes optimistically
  and creates the parent only when the first write misses (keeping the fork's
  realpath write guard and file memory), and `runRg` kills ripgrep as soon as
  its output cap is reached.

Local-form notes:
- The fork's backend is `os/backends/host`, not `node-local`, so the two files
  upstream adds there are ported into it.
- `HostWalkOptions.matcher` is a fork addition: this tree caches a compiled
  gitignore per root, and rebuilding rule strings per call would throw that
  cache away.
- `mappingHostFs` (kap's shared remote fs fixture) gained `readFileHead` and
  `walk`; the local copy in the workspace fs test now delegates to
  `walkDirectoryTree` through a separator-normalising readdir, because that
  fixture models a POSIX tree on any host.
- The read-media fixture's `readFileHead` delegates to its own `readBytes` so
  the existing call-count assertions still describe the head read.

Verified: agent-core-v2 typecheck clean; full suite green (pooled failures are
contention and pass in isolation); targeted trees — os backends 380, remote 68
pass / 55 skip, workspace 330, workspaceFs 92, agent tools 82, tool 270,
kap-server 1330 / 14 skip, acp-server 180. check:no-comments,
check:deep-imports and check:no-hardcoded-prose green; oxlint 0 errors on the
touched trees.

Ledger: MoonshotAI#4543 ported.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 5, 2026
The remote filesystem batching landed in 64a73fc. The row records what the
port covers, the two hand-ported paths, the fork-only `HostWalkOptions.matcher`
field and its reason, and the three fixture adaptations.

Ledger: closed 78 -> 79, remaining 21 -> 20.
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.

4 participants