Repository navigation
feat(kap-server): push approvals and questions as interaction frames - #4428
Conversation
Replace event.approval.* / event.question.* with a single volatile interaction event carrying the draft Interaction shape. Every subscriber of a session receives it, including interactions raised by sub-agents whose transcripts are subscribed. After each subscribe ack the server sends the session's pending interactions to that connection, so clients rebuild their list on (re)subscribe instead of relying on journal replay. Map engine-cancelled questions to cancelled instead of answered.
🦋 Changeset detectedLatest commit: 5646dc8 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 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. |
commit: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c6b115b7dd
ℹ️ 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 i updated, continue review |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f190193700
ℹ️ 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".
…oute
Send `interaction` as a flat, unsequenced frame `{ type, session_id, agent_id,
event_created_at, interaction_id, kind, status, ... }` outside the event
envelope, add approval `expires_at`, and register the frame in the WS schema
and AsyncAPI document.
Replace `POST /sessions/{sid}/approvals/{id}`, `POST /sessions/{sid}/questions/{id}`
and `:dismiss` with `POST /sessions/{sid}/interactions/{id}`, whose body is
discriminated by `kind` and whose result is `{ outcome, ended_at }`; dismissing a
question now succeeds with code 0. Error codes become 40404 (interaction not
found), 40902 (interaction ended) and 40001 (kind mismatch).
|
@codex review |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! 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". |
Pending interactions now reach clients only through the interaction frames
sent after each subscribe ack, so drop GET /sessions/{sid}/approvals and
GET /sessions/{sid}/questions with their schemas, docs and harness helpers.
The wire helpers still used by the WS broadcaster and the snapshot route move
to protocol/interaction-wire.ts.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5807d9178d
ℹ️ 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 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f987052901
ℹ️ 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 |
|
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". |
Ports upstream MoonshotAI#4428. Approvals and questions now reach clients as one flat, unsequenced WebSocket `interaction` frame instead of the `event.approval.*` / `event.question.*` envelopes, and one route answers either kind: - `POST /api/v1/sessions/{id}/interactions/{interaction_id}` takes a body discriminated by `kind` and returns `{ outcome, ended_at }`; dismissing a question now succeeds with code 0 instead of a 40909. - `GET .../approvals`, `POST .../approvals/{id}`, `GET .../questions`, `POST .../questions/{tail}` and `.../{id}:dismiss` are removed. Pending interactions are replayed to a subscriber right after each accepted subscribe ack, so a client no longer lists them over REST. - Error codes: 40404 becomes `INTERACTION_NOT_FOUND`, 40902 becomes `INTERACTION_ENDED`, 40505/40909 (`QUESTION_NOT_FOUND`, `QUESTION_DISMISSED`) are dropped. - The frame carries approval `expires_at`, the tool-call id, and — on `status: "ended"` — the decision or the question answers, so the transcript and the clients close a card from one event. Cancelled questions no longer read as answered in history: the shared interaction-state mapping treats the engine's cancellation shape (`{cancelled: true, reason}`) as cancelled before it looks at the question/approval split, and only that exact shape counts — a bare `{cancelled: true}` still reads as answered. Local shape notes: - The fork's `defineRoute` rejects a request body schema that is not strict, so both union members are `.strict()`; upstream relied on the outer schema only. `check:strict-request-bodies` reads the declaration, so the members are inlined into `interactionRespondRequestSchema` rather than exported separately. - `mapInteractionEndState` lives in `packages/transcript`'s contract layer here (one shared copy for cold and hot projection), not in kap-server's `coreEventMap`, so the cancellation-shape fix landed there; the projector now derives its state from `interactionOutcome`. - The apiSurface snapshot was still a Vitest-format file holding a stale duplicate of the same snapshot; regenerating with bun keeps one canonical entry, so the diff drops the dead copy as well. - The klient e2e harness loses its reverse-RPC approval/question helpers (`reverse-rpc.ts` deleted) and gains `respondInteraction`. Gates: kap-server 1403 pass / 9 skip, transcript 164 pass, klient 34 pass / 12 skip, kimi-inspect and apps/kimi-code `tsc` clean, `check:no-comments`, `check:no-hardcoded-prose`, `check:locale-keys`, `check:deep-imports`, `check:strict-request-bodies`, `check:service-naming` green. Pre-existing review findings left alone: `orphan-exports` on the in-progress TUI code-highlight file, `silent-catch` in `workspaceService.ts`, `text-as-protocol` in `search/indexCore.ts`, and the stale `agent-core-v2` state manifest.
…tions Ports the remaining upstream MoonshotAI#4428 assertions. A subscriber now gets the pending interactions of each accepted session immediately after the ack, so the connection test drives subscribe and subscribe_v2 through a broadcaster that replays one frame and asserts the ack/frame ordering. The projector tests pin the shape rule behind the history fix: the engine's cancellation (`{cancelled: true, reason: 'turn_ended'}`) resolves a question as cancelled, while an answer whose question happens to be named "cancelled" still resolves as answered. Gates: wsConnectionV1 39 pass, services/transcript 135 pass.
The respond route's own test is the probe; --verify runs it green. The row records the one unported piece: upstream's change to test/transcriptContract.e2e.test.ts, which bunfig excludes from the default run.
Requirement or Bug
用单个平铺的
interaction帧推送审批与提问(含 subagent 与侧聊发起的),替换旧的event.approval.*/event.question.*;答复统一到POST /sessions/{sid}/interactions/{id},删除待处理审批 / 提问的 GET 列表接口;顺带修复被取消的提问在历史里显示为已回答。Bug Reproduction Steps
AskUserQuestion)。Root Cause
引擎取消交互时的响应是
{ cancelled: true, reason }。kap-server 的mapInteractionEndState和 transcript 的foldFacts只区分「有响应 → answered / 无响应 → dismissed」,把取消响应也当成了回答。现在先识别cancelled: true并映射为cancelled,属于根本修复。Code Changes
WS 帧:不进事件信封,没有
seq/offset/timestamp,不进 journal、不回放;已注册进 WS schema 与 AsyncAPI(protocol/interaction.ts)。投递与恢复:每次订阅确认后,服务端立即把该会话当前待处理的交互发给这条连接,客户端据此重建列表。
sequenceDiagram participant Client participant WS as wsConnectionV1 participant B as SessionEventBroadcaster Client->>WS: client_hello / subscribe / subscribe_v2 WS->>B: attach + replay WS-->>Client: ack WS->>B: sendPendingInteractions(accepted) B-->>Client: interaction (pending) × N Note over B,Client: live B-->>Client: interaction (pending / ended)答复接口:
interaction不带 camelCaseagentId,因此不受agent_filter和 transcript 抑制影响,session 的每个订阅者都能收到 subagent 的交互。草案中的turn_id、agent_name暂不提供:引擎 turn id 到 transcript turn id 的映射只在 transcript projector 内,agent 名称与AgentState.name重复。Behavior Changes and Affected Users
event.approval.*、event.question.*,持久、带seq、可回放interaction帧,无seq,不回放/approvals/{id}、/questions/{id}、/questions/{id}:dismiss/interactions/{id},旧路由 404answeredcancelledGET /approvals、GET /questionsinteraction帧获得/snapshot的pending_approvals/pending_questions暂保留受影响的消费者与兼容:
apps/kimi-code/dist-web):本 PR 不同步 dist。合入后、下一次 dist 同步前,打包的旧 web 页面仍能从 transcript 看到主 agent 和已打开面板的 agent 的审批与提问,但批准、回答、忽略的请求会 404;需要在 code-app 那边合入后尽快按常规流程提 dist PR。测试覆盖:
sessionEventBroadcaster.test.ts:帧按interactionEventMessageSchema校验;提问 pending → answered 且不进回放;dismissed / cancelled 提问无 response;审批 approved 与 cancelled、expires_at;agent_filter: ['main']加 transcript grade 下 subagent 交互照常投递;sendPendingInteractions只发给请求方、立即发送、结束后不再补发。wsConnectionV1.test.ts:subscribe/subscribe_v2的 ack 之后紧跟interaction帧。approvals.test.ts、questions.test.ts:新路由的批准 / 回答 / 忽略,kind 不符与 answers、dismissed 同时有或都没有返回 40001,未知 id 返回 40404,重复答复返回 40902,未知会话返回 40401;待处理状态直接查引擎。transcriptContract.e2e.test.ts、klient legacy 测试、kimi-inspect 测试随路由迁移。services/transcript.test.ts、transcript/test/layers.test.ts:被取消的提问折叠为cancelled。apiSurface快照更新。Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.