Repository navigation
fix(kap-server): document missing session actions and add snake_case :undo error fields - #5332
Conversation
Project fork, compact, undo, btw and restore onto their own OpenAPI paths. The projection is now a table keyed by the shared SessionAction union, so a session action without docs fails to compile.
🦋 Changeset detectedLatest commit: 5863543 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 |
Codex Review Summary: ✅ CompletedThis 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. |
commit: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: af39543cbe
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e1f9162465
ℹ️ 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".
main added :predict-prompt and :cancel-prompt-prediction to the session action dispatcher. Project them like every other action, and build operation ids from each hyphen-separated part of the action name so they stay valid identifiers.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2579fd84f8
ℹ️ 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".
The 40911 error from :undo passed the engine's camelCase details through as its data. Return requested_count and undoable_count instead, as public fields are snake_case, and document that data on :undo only; the other session actions keep documenting a null data for 40911. Keep :predict-prompt and :cancel-prompt-prediction out of /openapi.json while prompt prediction stays behind its experimental flag, and drop the hyphen-aware operation id naming that only they needed.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 161af31f26
ℹ️ 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".
…aliases Return requested_count and undoable_count beside the existing requestedCount and undoableCount in the data of the 40911 error from :undo, and mark the camelCase pair deprecated in /openapi.json, so callers that read the old names keep working.
MoonshotAI#5359 and MoonshotAI#5404 need the fork's loop/ACP shapes (LiveTurn state machine, session extensions), MoonshotAI#5434 depends on testkit signal imports, and MoonshotAI#5332 needs a merged SessionAction table. Each is in_progress with the precise remaining work rather than a forced apply.
…ata (MoonshotAI#5332) Project session actions from a SessionAction-keyed docs table: each action gets its request body, success envelope and, for :undo, the 40911 data with requested_count/undoable_count plus the deprecated camelCase fields. The generic {tail} action route is removed from the document. Verified: openapi + apiSurface 18 pass, sessions 135 pass, schema refreshed and the reviewed digest updated; check:no-comments and typecheck clean.
…AI#5332 The docs-table port replaced the fork's strict request schemas with the upstream shapes, so fork, predict-prompt and cancel-prompt-prediction bodies would strip unknown keys instead of rejecting them. Restore .strict() on all three and keep the documentation body schemas strict. Verified: check:strict-request-bodies OK, openapi + apiSurface 18 pass, sessions 135 pass, typecheck clean.
Requirement or Bug
kap.md说每个接口的请求体和响应 schema 以GET /openapi.json为准,但会话的:fork、:compact、:undo、:btw、:restore五个动作不在这份文档里,调用方查不到它们的 schema。这五个接口运行时一直可用,kap.md也把它们列为baseline。同时,
:undo撤销不了时返回的 40911 错误,data里是 camelCase 的requestedCount、undoableCount,不符合 kap-server 公开字段用 snake_case 的约定,而文档一直写这里的data是null。这个 PR 补上五个动作的文档,并在 40911 的data里补上 snake_case 的requested_count、undoable_count;原来的 camelCase 字段继续返回,在文档里标为废弃。在 #5290 的评审中发现,与该 PR 无关,单独修。
Bug Reproduction Steps
schema/openapi.json是服务端/openapi.json的生成快照):jq -r '.paths | keys[] | select(startswith("/api/v1/sessions/{session_id}:"))' packages/kap-server/schema/openapi.json:archive、:cancel、:continue、:delete、:reload、:takeover、:wait七个。:undo要撤销的回合跨过了上下文压缩时返回 40911,响应的data是{ "reason": "compaction_boundary", "requestedCount": …, "undoableCount": … }。Root Cause
文档缺口:会话动作在服务端共用一个分发路由
POST /api/v1/sessions/{tail}。生成 OpenAPI 文档时,patchSessionAction把这个通用路由按动作逐个复制成/api/v1/sessions/{session_id}:<action>(下称"投影"),再删掉通用路由。投影列表是手写的,fork、compact、undo、btw、restore 一直没补,通用路由删掉后它们就不在文档里了。字段命名:引擎内部的撤销详情是 camelCase,kap-server 的
sendMappedError把它原样放进 40911 的data,没有转换成公开协议的 snake_case。两处都是根本修复。
Code Changes
投影改成一张以动作名为键的表。 表的键是分发器的
SessionAction联合,减去显式列出的实验性动作:新增会话动作时,要么在表里写上它的文档,要么加进
ExperimentalSessionAction,否则类型检查不通过。#5180 新加的:predict-prompt、:cancel-prompt-prediction在默认关闭的prompt_prediction实验开关后面,这次不写进文档,与 main 一致。operationId 沿用runSession<Action>Action的规律由动作名生成,已有 7 个不变。40911 的
data在 kap-server 出口补上 snake_case 字段。sendMappedError按引擎给出的详情返回requested_count、undoable_count,同时照常返回原来的requestedCount、undoableCount,后两者在文档里标为 deprecated,做法与旧的cwd字段相同;reason不变;kap-server 自己判定不可撤销的那条路径不带详情,仍返回null。引擎内部的字段名不动。文档只在:undo的投影里声明这个data:分发路由的错误列表由所有会话动作共用,而带数据的 40911 只有:undo会返回,所以其他动作的 40911 仍写data: null。关键决策
/openapi.json就成了对外承诺cwd字段做法一致data在哪声明:undo的投影里阅读指南
packages/kap-server/src/openapi/transforms.ts:文档表、实验性动作的排除,以及:undo的 40911data如何进入文档。packages/kap-server/src/routes/sessionErrors.ts:40911 的data在哪补上 snake_case 字段、保留 camelCase 字段。packages/kap-server/src/protocol/rest-session.ts:SessionAction联合(从routes/sessions.ts移来,openapi/因此不必依赖routes/)、为文档拆出的compactSessionBodySchema(与已有的cancelSessionBodySchema、waitSessionBodySchema同一写法,compactSessionRequestSchema接受的输入不变)和undoUnavailableDataSchema。packages/kap-server/test/openapi.test.ts、packages/kap-server/test/sessions.test.ts:文档断言,以及 fork 和:undo的真实请求。可以略读:
routes/sessions.ts改为从protocol/导入SessionAction;middleware/defineRoute.ts导出已有的buildErrorEnvelopeSchema;schema/*是生成文件;apiSurface.test.ts只更新契约摘要;oxlint-ratchet.json删掉了transforms.ts里已消除的两条存量告警。Behavior Changes and Affected Users
/openapi.json里的会话动作:predict-prompt、:cancel-prompt-prediction的文档:undo返回 40911 时的data{ reason, requestedCount, undoableCount };kap-server 自己判定时为nullrequested_count、undoable_count,原字段照常返回,文档里标为 deprecated;kap-server 自己判定时仍为nullrequestedCount/undoableCount的外部脚本或自建客户端,不受影响。仓库内的 desktop、web、VS Code、klient、node-sdk 都不读这两个字段;TUI 经 SDK 在进程内调用引擎,不经过 RESTcontract.txt与HOST_CONTRACT摘要HOST_API_LEVEL不变HOST_API_LEVEL判断远端是否兼容data,连上一版的远端也不会坏测试覆盖:
test/openapi.test.ts:projects every session action onto its own path钉住 12 条动作路径、operationId 和session_id路径参数,以及通用的{tail}路径已删除;keeps the experimental session actions out of the document钉住两个实验性动作不在文档里;documents the request body each session action accepts钉住哪些动作必须带请求体;documents the data :undo returns when the requested turns cannot be undone钉住:undo的 40911data含 snake_case 字段、camelCase 字段标为 deprecated,:fork的仍为null。test/sessions.test.ts:returns snake_case data beside the deprecated camelCase fields when :undo cannot remove the requested turns用真实请求验证引擎给出详情时同时返回 snake_case 字段和原来的 camelCase 字段、不给时返回null,钉住读旧字段的调用方不受影响;forks a session from a request without a body验证 fork 不带请求体也能成功,对应文档里 fork 的请求体可选。test/apiSurface.test.ts:生成的契约快照与摘要。验证记录
schema/openapi.json:只新增 5 条路径;其余路径(含已有的 7 个会话动作)和非路径部分逐字节相同。contract.txt只有新增行。sendMappedError改回原样透传后运行新的:undo测试:失败,缺少 snake_case 字段;恢复后通过。requestedCount、undoableCount;恢复后通过。data声明对所有动作生效后运行test/openapi.test.ts::fork的断言失败;恢复后通过。pnpm lint与pnpm run check:duplication通过。本机高负载下跑 kap-server 全量测试时,有一批与本改动无关的计时和临时目录类失败,每次失败的文件不同,单独重跑均通过;CI 的全量测试通过。Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.