Repository navigation
fix(kap-server): restore legacy ACP session file tools - #4600
Conversation
🦋 Changeset detectedLatest commit: 338fc5d 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. Try requesting a review at a lower effort level.
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 |
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. |
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
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". |
commit: |
|
@codex review |
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
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". |
…pe gap MoonshotAI#4526 is already in the tree: the loadable-tools announcement refreshes on every turn and only awaits the MCP initial load when the turn is new. MoonshotAI#4600 does not port as written. This fork binds a session to `{ workspaceId, runtimeId }` rather than upstream's `{ environmentId, cwd }`, and `IEnvironmentService` is not exported from the agent-core-v2 root, so the legacy `acp:<id>` rebind needs a field mapping plus a public export. Recorded rather than forced, so the next attempt starts from the shape difference instead of rediscovering it. Ledger: closed 34 -> 35, remaining 64.
The repair reads IAgentEnvironmentBindingService, which MoonshotAI#4062 introduces and re-exports; this tree still runs the old runtimeBinding layer, so the environmentBinding files present here have no importers and nothing reaches them from the engine root. A trial port was written and reverted.
… 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.
Port of upstream MoonshotAI/kimi-code 1401bdd (MoonshotAI#4600). A desktop session written by the pre-environment client carries `acp:<session>` as its environment id. Nothing registers that environment in this server, so after an upgrade its main agent still resolved the tool filesystem through it and local file tools failed on paths that exist — `Read` on a file in the session cwd included. `startServer` now subscribes to `ISessionManager.onDidCreateSession` and, when the main agent's binding names `acp:<session>` and no such environment is registered, rebinds it to `local` at the binding cwd (falling back to the session cwd). A binding whose environment is registered is left alone, and the subscription is disposed on close with the rest of the server teardown. Verified: kap-server 1316 pass / 14 skip; both new cases fail with the migration short-circuited and pass with it restored. check:no-comments, check:deep-imports and check:boundaries green. Ledger: MoonshotAI#4600 ported; closed 69 -> 70, remaining 30 -> 29.
Requirement or Bug
用户先通过 ACP 客户端(如 Zed)创建并使用会话,随后在 Desktop 中打开同一会话时,Read / Write / Bash 会因
environment acp:session_... does not exist无法运行;直接由 Desktop 新建的会话则正常。本 PR 让这些来自 ACP 的会话在 Desktop 所用的 kap-server 恢复后重新获得本地文件与命令执行能力,并将迁移结果持久化,后续重启不再重复失败。Bug Reproduction Steps
acp:<sessionId>,并通过environment.set_binding持久化到 wire。environment acp:session_... does not exist。回归测试向真实 kap-server 会话写入同样的
environment.set_binding,再完整重启服务并用IReadTool复现恢复与读取链路;未额外驱动真实 ACP 客户端或 Desktop UI。Root Cause
ACP 会话创建时,session metadata 使用
local,main agent 随后在 ACP 会话激活时绑定acp:<sessionId>。Desktop 通过 kap-server 恢复该会话时可以创建本地 workdir,但 wire replay 会把 main agent 恢复到旧的 ACP ID;当前进程的环境注册表中没有这个 ID,因此所有依赖环境租约的工具都会失败。这是针对 ACP 会话数据的跨客户端兼容迁移:恢复完成后,仅当绑定恰好是当前会话的
acp:<sessionId>且注册表已没有该环境时,保留原 cwd 并改绑local,再把新绑定写回 wire。通用 environment 解析仍对失效的远程环境显式报错,ACP 服务自身的恢复路径不变。Code Changes
核心改动位于 kap-server 的 session-created 生命周期,确保任何 REST / WebSocket 恢复入口都先修正绑定,再向调用方返回会话。
这里同时检查注册表:如果同名 ACP 环境仍然可用,恢复后继续使用它。其他 environment ID、远程环境和新会话均不进入迁移分支。
阅读顺序:
packages/kap-server/src/start.ts:查看生命周期接入、迁移条件以及订阅释放。packages/kap-server/test/sessions.test.ts:查看旧绑定复现、真实 Read、二次重启持久化,以及同名 ACP 环境仍可解析时的 guard。.changeset/fix-legacy-acp-sessions.md:用户可见修复说明。Behavior Changes and Affected Users
acp:<sessionId>环境已缺失local并持久化,工具继续执行受影响模块与覆盖:
验证记录
pnpm exec vitest run --maxWorkers=4:72 个测试文件通过,1441 passed / 1 skipped。默认并发运行曾两次命中searchRoute.test.ts的既有间歇失败,该文件单独复跑通过,最终全量复跑通过。pnpm typecheck:通过。pnpm build:通过。pnpm lint:0 errors。git diff --check:通过。ReadTool.resolveExecution稳定抛出environment acp:session_... does not exist;修复后同一场景通过,并能跨第二次重启保留local绑定。Checklist
gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.