Skip to content

fix(kap-server): deliver session-level interaction events past agent filters - #3901

Merged
sailist merged 1 commit into
mainfrom
fix/subagent-approval-visibility
Sep 19, 2026
Merged

sailist merged 1 commit into
mainfrom
fix/subagent-approval-visibility

Conversation

@liruifengv

@liruifengv liruifengv commented Sep 18, 2026 •

Copy link
Copy Markdown
Collaborator

根因

desktop(以及任何按 agent 过滤订阅的 WebSocket 客户端)的会话侧栏显示「待授权」,但消息流里永远出现不了可操作的授权卡片,刷新也不消失。断链分两层:

  1. 后台子 agent(Agent 工具 / AgentSwarm 派发的 agent-N)发起审批或提问时,event.approval.* / event.question.* 事件在 payload 顶层携带子 agent 的 agentId,v1 广播器的 matchesAgentFilter 按每个连接的 agent_filter(desktop 订阅的是 ['main'])把它们过滤掉——实时广播和 journal replay 两条路径共用同一个过滤器,客户端因此永远收不到交互明细。
  2. 而会话级 pendingInteraction: 'approval' 是按 session 聚合所有 agent 算出来的,经 session.work_changed(agentId 硬编码 main)正常下发——所以徽标能亮,卡片永远没有。
  3. 服务端内存里的 interaction 记录因子 agent 的 turn 被审批 await 阻塞而常驻(turn_ended / agent_closed / purge 三条清理路径都不触发,要等默认 2 小时子 agent 超时),所以刷新后徽标反复亮起。
  4. wire 协议里 approval / question 没有 agent 归属字段,客户端即使拿到请求也分不清来自主 agent 还是子 agent。

解决方案

  • 交互事件(event.approval.* / event.question.*)在 matchesAgentFilter 中直接放行。审批 / 提问是会话级人机操作(REST resolve 路径本来就不按 agent 过滤),事件量极小,不破坏 main-agent-only 订阅的节流意图;实时广播与 replay 共用同一过滤器,一处修改两条路径同时修复。
  • toWireApproval 增加 agent_id(无 agent tag 时兜底 main);toWireQuestion 增加可选 agent_id。REST 列表 / 快照 / WS 事件都携带该字段,客户端可据此把待处理交互归属到发起它的子 agent。
  • server-api 参考文档(en / zh)同步新字段。

影响范围

  • 只影响 v1 WS 广播器的事件过滤行为,以及 approval / question 的 wire 字段(新增字段,不改变既有字段语义)。TUI 不走该通道,不受影响;不带过滤订阅的客户端(web)行为不变,只是响应里多了 agent_id 字段。
  • 配套客户端修复在 MoonshotAI/kimi-code-app#734。
  • 测试:子 agent 的 approval / question 事件在 agent_filter=['main'] 下的实时送达与 replay 送达、agent_id 落值(子 agent tag 与 main 兜底);另经真实会话端到端验证:后台子 agent 的 Bash 审批送达到带过滤的 WS 订阅,处理后 resolved 事件正常送达。

Copilot AI balanced review requested due to automatic review settings September 18, 2026 10:16
@changeset-bot

changeset-bot Bot commented Sep 18, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 5bafe66

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Sep 18, 2026

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

commit: 5bafe66

@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: 5bafe66707

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

Comment thread packages/kap-server/src/transport/ws/v1/sessionEventBroadcaster.ts

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.

🟡 Changes recommended

The user-visible fix requires a patch changeset targeting @moonshot-ai/kimi-code.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Fixes delivery and attribution of subagent approval and question interactions for filtered WebSocket clients.

Changes:

  • Bypasses agent filters for session-level interaction events.
  • Adds agent_id to approval and question payloads.
  • Adds tests and bilingual API documentation.
File summaries
File Description
packages/kap-server/src/transport/ws/v1/sessionEventBroadcaster.ts Bypasses filters and attributes interaction events.
packages/kap-server/src/routes/approvals.ts Adds approval agent attribution.
packages/kap-server/src/routes/questions.ts Attributes listed questions.
packages/kap-server/src/routes/snapshot.ts Attributes snapshot questions.
packages/kap-server/src/protocol/approval.ts Adds required agent_id.
packages/kap-server/src/protocol/question.ts Adds optional agent_id.
packages/kap-server/src/protocol/question-wire.ts Serializes question agent IDs.
packages/kap-server/test/approvals.test.ts Tests attribution and fallback.
packages/kap-server/test/sessionEventBroadcaster.test.ts Tests filtered delivery and replay.
docs/en/reference/server-api.md Documents the field in English.
docs/zh/reference/server-api.md Documents the field in Chinese.
Review details
  • Files reviewed: 11/11 changed files
  • Comments generated: 1
  • Review effort level: Balanced

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

if (filter === undefined) return true;
if (isGlobalEvent(envelope.type)) return true;
if (isAgentLifecycleEvent(envelope.type)) return true;
if (isInteractionEvent(envelope.type)) return true;
@liruifengv

Copy link
Copy Markdown
Collaborator Author

@codex

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 5bafe66707

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

@sailist
sailist merged commit 2cedfaf into main Sep 19, 2026
18 checks passed
@sailist
sailist deleted the fix/subagent-approval-visibility branch September 19, 2026 04:05
Leeeon233 added a commit to LodyAI/acp-extension-kimi that referenced this pull request Sep 24, 2026
* feat(kimi-code): carry turn trace id and copilot stats in rating surveys (MoonshotAI#3907)

* feat: expose resolved base_url on models.dev catalog provider items (MoonshotAI#3909)

* fix(agent-core-v2): restore thinking for the openrouter reasoning dialect (MoonshotAI#3910)

Keep string reasoning fields when a reasoning_details array is present, stamp each think part by source, and replay those fields on the next request.

* ci: release packages (MoonshotAI#3862)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* docs(changelog): sync 2.0.1 from apps/kimi-code/CHANGELOG.md (MoonshotAI#3912)

* fix(agent-core-v2): pre-shrink compaction history to the effective model window (MoonshotAI#3911)

* fix(vscode): ignore Enter during IME composition in question dialog (MoonshotAI#3915)

* fix(kap-server): deliver session-level interaction events past agent filters (MoonshotAI#3901)

* revert(kap-server): drop the flat entity message protocol (v3 WS + history API) (MoonshotAI#3532) (MoonshotAI#3920)

This reverts 64505e3.

The v1 WS + legacy REST + transcript surfaces are alive on main and remain
the single protocol surface; kimi-inspect returns to the transcript-based
data model (keeping MoonshotAI#3747's removal of the prompt input, which adapted to
the agent-core-v2 prompt-queue fold).

* feat(oauth): parse goods_version from the managed /me profile payload (MoonshotAI#3921)

* fix: keep turn ids above the wire-wide max and fold cold transcripts over the active branch (MoonshotAI#3922)

* fix(agent-core-v2): floor the human turn clock at the wire-wide max on engine journal reset

* fix(kap-server): fold the cold transcript snapshot over the restorable branch chain

* fix(agent-core-v2): advance the human turn clock when a turn starts

* fix(kap-server): split reused wire turn ids in the live transcript projector

* fix(kap-server): adopt the completed cold tip for mid-turn attach events

Continuation deltas after a lazy transcript attach belong on the last
cold turn, not a newly split export id.

* fix(agent-core-v2): remove the project-root assertion for cwd from the system prompt (MoonshotAI#3929)

Co-authored-by: 7Sageer <7sageer@djwcb.cn>

* chore: remove the tdd skill (MoonshotAI#3932)

* fix(agent-core-v2): don't record turn.steer when an unconsumed steer seeds the next turn (MoonshotAI#3933)

* chore: sync web dist from code-app (MoonshotAI#3934)

* chore: sync web dist from code-app

code-app: 44d7281c7a63ee3c7a907f9406e490efdbec7411

* chore: collapse web dist sync changesets into one summary entry

* ci: release packages (MoonshotAI#3913)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* feat: generate native Kimi ACP session titles (#15)

---------

Co-authored-by: Grapedge <shiwang.lj@alibaba-inc.com>
Co-authored-by: liruifengv <liruifeng1024@gmail.com>
Co-authored-by: Haozhe <yanghaozhe@moonshot.ai>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: 7Hanrui <qihanrui@moonshot.ai>
Co-authored-by: 7Sageer <7sageer@djwcb.cn>
Co-authored-by: Zixuan Chen <remch183@outlook.com>
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.

3 participants