Repository navigation
Conversation
POST /api/v1/sessions accepts default_workspace: true, exclusive with workspace_id and metadata.cwd. The server resolves <Documents>/KimiCode/Default on every request, creates it on first use, and reuses it afterwards. A path blocked by a file fails with 40409 and a permission error with 40411; the server never relocates silently. Workspace payloads on REST and WebSocket events carry is_default.
… be resolved A failed registry lookup used to fall back to %USERPROFILE%\Documents, which could silently create a second default workspace when Documents is redirected (for example by OneDrive). The lookup now fails with 40409, the failure is not cached so the next request retries, and is_default reports false meanwhile.
Reading User Shell Folders with reg.exe misses the default when the value is absent, cannot expand every variable, and is blocked where registry tools are disabled by policy. Ask Windows for the Documents folder through PowerShell instead, forcing UTF-8 output so non-ASCII paths survive. A reported folder that does not exist is treated as unresolved, so garbled output can never create a workspace in the wrong place.
The Documents lookup spawned the bare name powershell.exe, so Windows resolved it through the current directory and PATH. In an untrusted checkout that lets a repository-provided powershell.exe run before the trust gate. Resolve it under SystemRoot (falling back to windir and then C:\Windows) instead.
…reason
Creating a session in the default workspace used to surface folder problems
as generic codes: 40409 when a file blocked the path or the Windows
Documents folder could not be located, 40411 on permission errors, and a
plain internal error for anything else. Clients could not tell the default
workspace apart from an ordinary missing directory, nor explain what to fix.
DefaultWorkspaceService now throws DefaultWorkspaceUnavailableError
(default_workspace.unavailable) carrying the folder path and one of
blocked_by_file, permission_denied, missing_parent, no_space, read_only,
invalid_path, documents_unavailable or unknown. ensure() also verifies that
a file can be created and removed in the folder, so a read-only folder is
reported before a session is placed there. The server maps the error to
40930 with { path, reason } in data.
|
commit: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 753ba6ef27
ℹ️ 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".
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. |
createExclusive resolves to false when the probe name already exists. The write check ignored that result and went on to remove the path, which is a recursive delete of an entry it did not create. Report the folder as unknown instead and leave the entry alone.
…e-error' into qer/default-workspace-unavailable-error
There was a problem hiding this comment.
🟢 Approval recommended
错误分类、可用性检查与响应契约一致,未发现阻塞问题;未运行项目测试。
0 open findings
What changed in this PR
在 #4224 的默认工作区能力上,统一返回错误码 40930,附带路径和失败原因,便于客户端提供修复提示。当前 diff 同时包含前序 PR 的基础改动。
Changes:
- 新增默认工作区错误分类及创建、删除探测文件的可用性检查。
- 将错误映射为包含
{ path, reason }的服务端响应。 - 补充相关测试并同步中英文 API 文档。
| File | Description |
|---|---|
packages/kap-server/test/workspaces.test.ts |
验证默认工作区标记 |
packages/kap-server/test/sessions.test.ts |
覆盖默认创建、互斥校验及错误响应 |
packages/kap-server/test/sessionEventBroadcaster.test.ts |
更新工作区事件断言 |
packages/kap-server/src/routes/workspaces.ts |
计算响应中的默认标记 |
packages/kap-server/src/routes/sessions.ts |
接入默认工作区及错误映射 |
packages/kap-server/src/routes/defaultWorkspace.ts |
构造专用错误响应 |
packages/kap-server/src/protocol/workspace.ts |
增加 is_default 字段 |
packages/kap-server/src/protocol/session.ts |
接受 default_workspace 参数 |
packages/kap-server/src/protocol/error-codes.ts |
定义错误码 40930 |
packages/kap-server/src/protocol/default-workspace.ts |
定义错误数据结构 |
packages/agent-core-v2/test/app/defaultWorkspace/defaultWorkspace.test.ts |
覆盖路径解析、可用性检查及失败分类 |
packages/agent-core-v2/src/index.ts |
导出默认工作区服务及错误 |
packages/agent-core-v2/src/errors.ts |
注册默认工作区错误域 |
packages/agent-core-v2/src/app/workspace/workspaceProtocol.ts |
扩展工作区协议 |
packages/agent-core-v2/src/app/defaultWorkspace/errors.ts |
定义错误类型及原因说明 |
packages/agent-core-v2/src/app/defaultWorkspace/defaultWorkspaceService.ts |
实现目录准备、探测及错误分类 |
packages/agent-core-v2/src/app/defaultWorkspace/defaultWorkspacePaths.ts |
解析各平台文稿目录 |
packages/agent-core-v2/src/app/defaultWorkspace/defaultWorkspace.ts |
定义服务接口 |
docs/zh/reference/server-api.md |
更新中文接口说明 |
docs/en/reference/server-api.md |
更新英文接口说明 |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e50d0d3386
ℹ️ 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 proc = await this.processes.spawn( | ||
| windowsPowerShellPath(this.bootstrap.getEnv('SystemRoot') ?? this.bootstrap.getEnv('windir')), | ||
| ['-NoProfile', '-NonInteractive', '-Command', WINDOWS_DOCUMENTS_COMMAND], | ||
| { windowsHide: true, timeout: WINDOWS_DOCUMENTS_TIMEOUT_MS }, |
There was a problem hiding this comment.
Enforce the declared PowerShell timeout
When PowerShell hangs on Windows, this call never completes: HostProcessService.buildSpawnOptions() does not forward HostProcessOptions.timeout, and HostProcess.wait() implements no timeout itself. Because toWireWorkspace() now calls isDefault() for every workspace projection, this can indefinitely hang existing GET/POST/PATCH workspace requests as well as default-workspace session creation, rather than failing after 15 seconds. Race the process against a timer and terminate it, or implement the option in the host-process backend.
AGENTS.md reference: AGENTS.md:L102-L104
Useful? React with 👍 / 👎.
| dir = await this.queryWindowsDocumentsDir(); | ||
| if (dir !== undefined && !(await this.isDirectory(dir))) dir = undefined; |
There was a problem hiding this comment.
Preserve the resolved Windows path when validation fails
When Windows successfully resolves MyDocuments but stat is denied by its ACL, or the resolved path is occupied by a file, this assignment discards the known path and reports documents_unavailable with path: null. Clients therefore receive neither the actionable path nor the intended permission_denied/blocked_by_file reason. Preserve the resolved path and map the stat error or non-directory result instead of treating every validation failure as an unresolved Documents folder.
Useful? React with 👍 / 👎.
| const configHome = | ||
| this.bootstrap.getEnv('XDG_CONFIG_HOME') ?? join(this.bootstrap.osHomeDir, '.config'); |
There was a problem hiding this comment.
Validate XDG_CONFIG_HOME before using it
On Linux, XDG_CONFIG_HOME="" is defined but means the default ~/.config, while a relative value is invalid; this nullish fallback accepts both and reads user-dirs.dirs relative to the server working directory instead. The read failure is then swallowed, so a valid ~/.config/user-dirs.dirs redirect is silently ignored and default_workspace: true creates sessions under ~/Documents rather than the user's configured Documents folder. Treat empty or non-absolute values as unset, as required by the XDG Base Directory specification.
AGENTS.md reference: AGENTS.md:L122-L124
Useful? React with 👍 / 👎.
| const match = /^\s*XDG_DOCUMENTS_DIR\s*=\s*"(.*)"\s*$/.exec(line); | ||
| if (match === null) continue; | ||
| const raw = match[1]!; | ||
| const expanded = raw.replace(/^\$HOME(?=\/|$)/, osHomeDir); |
There was a problem hiding this comment.
Decode shell escapes in XDG document paths
The xdg-user-dirs format is shell-formatted, and its writer escapes literal dollar signs, backticks, and backslashes. For example, the valid value XDG_DOCUMENTS_DIR="$HOME/Docs\$2026" represents /home/alice/Docs$2026, but this replacement leaves the escape character in place and creates /home/alice/Docs\$2026/KimiCode/Default instead. Decode the supported shell escapes before validating and returning the path so the configured directory is not silently replaced by a newly created lookalike.
AGENTS.md reference: AGENTS.md:L122-L124
Useful? React with 👍 / 👎.
|
已并入 #4224。 |
Requirement or Bug
默认工作区无法使用时,返回带路径和原因的专用错误码
40930,让客户端能说清楚出了什么问题、该怎么修。依赖 #4224,合入顺序在它之后;从 #4233 拆出,后续依次是 #4244(位置可配置)和 #4245(CLI 与 SDK)。目标分支为 main,#4224 合入前这里的 diff 包含它的提交;本层改动见 753ba6ef2、bc3dd3a4c。
Bug Reproduction Steps
N/A
Root Cause
N/A
Code Changes
原因由 fs 错误码和 errno 映射:已存在 / 不是目录 →
blocked_by_file,权限 →permission_denied,父目录不存在 →missing_parent,ENOSPC/EDQUOT→no_space,EROFS→read_only,ENAMETOOLONG→invalid_path,其余 →unknown。errors.ts新增错误域default_workspace.unavailable,导出DefaultWorkspaceUnavailableError和每种原因的英文说明DEFAULT_WORKSPACE_PROBLEM_MESSAGES;invalid_path的说明写的是「不是绝对路径或过长」,前半句在下一个 PR 引入自定义路径后才会出现。Behavior Changes and Affected Users
POST /sessionsdefault_workspace: true时文件夹无法创建40409,权限40411,其他5000140930,data带path和reason4040940930,reason: documents_unavailable,path: null40930(permission_denied/read_only等),不创建会话受影响模块与测试覆盖:
agent-core-v2/app/defaultWorkspace:defaultWorkspace.test.ts覆盖被文件占用(默认文件夹本身和父文件夹)、权限不足、路径上的悬空符号链接、Windows 找不到文稿目录(含重试)各自报出对应原因;已有文件夹变为不可写时ensure()拒绝交出且不留探测文件;探测文件删不掉时报permission_denied。kap-server:sessions.test.ts的权限错误改为断言40930和{ path, reason },且不注册工作区。docs/{en,zh}/reference/server-api.md:会话创建的错误码列表同步更新。Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.