Skip to content

fix(agent-core-v2): route foreground shell events by origin - #4954

Merged
sailist merged 3 commits into
bug-370-11-15-release-fixesfrom
bug-373-11-15-foreground-bang-double-render
Nov 15, 2026
Merged

sailist merged 3 commits into
bug-370-11-15-release-fixesfrom
bug-373-11-15-foreground-bang-double-render

Conversation

@sailist

@sailist sailist commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

Requirement or Bug

普通前台执行 ! 命令时,TUI 可能重复显示命令,并在命令结束后继续显示月亮加载图标。这是 #4630 引入普通前台执行新链路后的回归;本 PR 以 #4948 的分支为 base,让前台 shell 输出只渲染一次并正确结束加载状态。

Bug Reproduction Steps

  1. 在 TUI 中输入并执行 ! printf 'SHELL_ONCE_MARK\n'。
  2. 观察命令与输出:旧实现会再次显示 $ printf 'SHELL_ONCE_MARK\n',并残留月相加载图标。
  3. 再询问模型刚才的输出,确认 shell 输入与输出仍应进入后续请求上下文。

Root Cause

ShellCommand 改用通用 ToolExecutor 后,一次执行同时产生普通 tool.call.started / tool.updated / tool.result 和专用 shell.* 事件。TUI 把两组事件都当成独立渲染来源:普通事件创建 Bash 卡片,专用事件更新 ShellRunComponent。普通 tool.result 还将 livePane 留在 waiting,而 shell 完成路径只清理 streamingPhase,因此月亮不消失。

本 PR 是根本修复:在执行上下文和事件中显式标记来源,客户端按来源选择渲染路径,而不是隐藏执行事件或仅重置最终 UI 状态。

Code Changes

核心思路是新增 ToolExecutionOrigin = 'loop' | 'shellCommand',让同一套工具事件携带明确的触发方。Loop 继续按普通工具卡片渲染,ShellCommand 则由专用 shell UI 渲染。

flowchart LR
  Loop[LoopActor · origin: loop] --> Executor[ToolExecutor]
  Shell[ShellCommand · origin: shellCommand] --> Executor
  Executor --> Events[tool.call / tool.updated / tool.result + origin]
  Events --> Clients[Core / klient / SDK clients]
  Clients --> TUI[TUI event router]
  TUI -->|loop| ToolCard[普通工具卡片]
  TUI -->|shellCommand| ShellRun[专用 ShellRunComponent]
Loading
  • LoopActor 与 ShellCommand 分别显式写入 'loop' 和 'shellCommand';实际 Legacy Tool 上下文也携带来源。
  • 三类普通工具事件逐项透传 origin,klient 的 zod schema 同步并在旧 host 未提供来源时归一化为 'loop',ACP replay 显式标记 'loop'。
  • TUI 在普通工具事件进入卡片注册、setTurnId 和 livePane 逻辑前识别 'shellCommand',仅由专用 shell.* 事件驱动前台 shell UI。
  • 保留 handler 回收、调度释放、Task 通知、telemetry 和前后台转换路径,不以 turnId=-1 作为事件开关。
  • 现有 Core、TUI、klient、KAP、ACP 与 VSCode 测试构造点同步补齐来源;流式 tool.call.delta 不增加该字段。

建议先读 packages/agent-core-v2/src/tool/toolContract.ts 和 toolExecutorEvents.ts 理解来源契约,再读 toolExecutorService.ts 的事件投影,最后读 apps/kimi-code/src/tui/controllers/session-event-handler.ts 的客户端分派。其余文件主要是两个生产入口、传输 schema 和对应测试适配。

Screenshots / Recordings

以下文本来自同一 aimock shell-command play 的真实运行。重点看旧实现重复的第二行 $ printf ... 和月相图标,在本 PR 中均已消失。

Before(已安装 canary) After(本 PR)
 $ printf 'SHELL_ONCE_MARK\n'
SHELL_ONCE_MARK

$ printf 'SHELL_ONCE_MARK\n'

🌓 · Tip: /goal for multi-step work with a clear finish line
 $ printf 'SHELL_ONCE_MARK\n'
SHELL_ONCE_MARK

本 PR 的 play 还验证了后续唯一一次模型请求只包含一组 <bash-input>、<bash-stdout> 和用户追问,所有自动检查通过。

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
普通前台 ! 渲染与加载终态 可能重复显示命令,普通 tool.result 让月亮残留 只由专用 shell UI 渲染一次并正常结束加载 TUI 前台 shell 用户;重复渲染和残留属于回归,没有合法依赖 无需退路,恢复既有预期行为
普通工具事件的来源信息 tool.call.started、tool.updated、tool.result 没有执行来源 Core 新事件显式携带 origin: 'loop' | 'shellCommand';klient 对旧 host 缺失的 origin 归一化为 'loop',既有字段和值不变 Core、klient、node-sdk、KAP、ACP、VSCode 等事件消费者;旧客户端可忽略附加字段 无需行为开关,属于附加信息
Loop 工具的渲染与执行 普通工具卡片和执行生命周期 'loop' 事件继续走原路径,卡片、Task、detach、telemetry 不变 Loop 工具调用及普通模型 Turn 不涉及

受影响模块与覆盖:

  • Core 执行与事件投影:shellCommand 和 toolExecutor 用例覆盖两个来源,既有 Loop 用例保持普通事件行为。
  • TUI:现有 bash echo 用例模拟完整双事件流,断言单份 $、单份输出、streamingPhase/livePane 都为 idle 且月亮为空;真实 TUI play 覆盖同一用户场景。
  • klient / KAP / ACP / VSCode:schema、事件构造、replay 与 facade 用例同步覆盖,负例仍保留缺少既有必填字段的事件。
验证详情
  • Core、TUI、klient、VSCode typecheck 通过。
  • Core/TUI 聚焦测试 561/561;klient memory + IPC 62/62。
  • 扩展回归其余 452 项通过;来源快照修正后失败文件复验 165/165。
  • klient facade(含旧 host 来源归一化)+ VSCode event-adapter 63/63;VSCode session-runtime + workspace-paths 51/51。
  • 生产 scoped lint 0 errors / 33 warnings;测试 scoped lint 0 errors / 92 warnings;本轮新增 VSCode 补充文件 0 warnings / 0 errors。
  • 根 corepack pnpm run build 通过,构建生成的 .d.ts 已清理。
  • 只读交付审计及复核无剩余阻断;无敏感信息、临时 play、构建产物或代理署名。
  • 未验证:m0-dev 与 coding-win 的远程 broader regressions。m0-dev 主机密钥变化未获确认,coding-win 连接被关闭;未绕过 SSH 严格校验,也未将上述结果外推为全仓测试通过。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: issue must have a maintainer's /approve).
  • I have added tests that prove my feature works.
  • The behavior-change table above is complete, and every removed behavior or flipped default is named in the changeset and either has an escape hatch or was explicitly approved by a maintainer in this PR.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot

changeset-bot Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 6ae5ad9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-15T06:17:03.921076Z 6ae5ad9 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pkg-pr-new

pkg-pr-new Bot commented Nov 15, 2026 •

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

commit: 6ae5ad9

@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: ee55c0e310

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

export const toolCallStartedEventSchema = z.object({
type: z.literal('tool.call.started'),
time: z.number().optional(),
origin: z.enum(['loop', 'shellCommand']),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Accept tool events from pre-origin IPC hosts

When a new klient connects to a host from the previous release, its tool.call.started, tool.updated, and tool.result payloads have no origin. Because validation defaults to enabled and these three schemas now require the field, EventHub rejects and drops every such event; unless the caller registered onError, tool lifecycle data silently disappears. Keep origin optional or normalize missing values as legacy events at the wire boundary so version-skewed IPC clients continue receiving tool events. The same issue occurs at lines 96 and 109.

AGENTS.md reference: AGENTS.md:L110-L112

Useful? React with 👍 / 👎.

@sailist

sailist commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator Author

@codex

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 6ae5ad9514

ℹ️ 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 8453eb9 into bug-370-11-15-release-fixes Nov 15, 2026
15 checks passed
@sailist
sailist deleted the bug-373-11-15-foreground-bang-double-render branch November 15, 2026 06:24
sailist added a commit that referenced this pull request Nov 16, 2026
…4994)

* fix(agent-core-v2): route foreground shell events by origin

* test(agent-core-v2): expect tool event origins in snapshots

* fix(klient): accept tool events from pre-origin hosts
wbxl2000 pushed a commit that referenced this pull request Nov 17, 2026
* fix: resume sessions with removed default models (#4982)

* fix(node-sdk): resume sessions with missing default model

* fix(cli): check auth for the resumed session model

* chore: add changeset for unavailable model recovery

* fix(agent-core-v2): stop rebuilding mismatched session indexes (#4980)

* fix(agent-core-v2): reject repeated model responses (#4977)

* fix(agent-core-v2): reject repeated model responses

* chore: add changeset for repeated model responses

---------

Co-authored-by: 7Sageer <[email protected]>

* fix(agent-core-v2): inline deferred tools without dynamic loading (#4971)

* fix(agent-core-v2): record restored task notifications without model requests (#4949) (#4989)

* fix(agent-core-v2): record restored task notifications without model requests

- queue restored task notifications as prompt-only turns after loop initialization
- preserve interrupted and queued turns during resume and fork
- complete reconciliation before initialization and reset return to keep Wire reads ordered
- run loop and container cleanup when reconciliation fails
- surface restored notification persistence failures

* chore: add changeset for restored task notifications

* fix(agent-core-v2): restore overflow recovery after LLM retries (#4950) (#4990)

* fix(agent-core-v2): restore step state after LLM retries

* test(agent-core-v2): scope retry event to overflow regression

* fix(config): allow sessions with invalid user config (#4951) (#4991)

* fix(agent-core-v2): tolerate config read failures for permission rules

* chore: add changeset for permission config recovery

* docs: document permission config recovery

* docs: qualify permission config recovery scope

* fix(config): surface read error diagnostics

* fix(config): allow sessions with invalid user config

* fix(config): preserve valid values and replay diagnostics

* fix(config): remove startup diagnostic replay

* fix(agent-core-v2): ignore non-user prompts during Tower wake (#4952) (#4992)

* fix(agent-core-v2): ignore non-user prompts during Tower wake

* chore: add Tower notification fix changeset

* fix(agent-core-v2): preserve slash prompts during Tower wake

* fix(agent-core-v2): route foreground shell events by origin (#4954) (#4994)

* fix(agent-core-v2): route foreground shell events by origin

* test(agent-core-v2): expect tool event origins in snapshots

* fix(klient): accept tool events from pre-origin hosts

* fix(agent-core-v2): run external Stop hooks after turn completion (#4956) (#4995)

* fix(agent-core-v2): run external Stop hooks after turn completion

* chore: add changeset for external Stop hooks

* docs: clarify post-turn Stop hook timing

* fix(agent-core-v2): wait for subagent quiescence (#4953) (#4993)

* fix(agent-core-v2): reject incomplete model streams (#5006)

* fix(agent-core-v2): preserve choice-level OpenAI token usage (#5017)

* fix(capability): confirm stopping WebBridge before Windows updates (#4999)

* fix(capability): confirm stopping WebBridge before Windows updates

* fix(capability): harden WebBridge update recovery

* fix(capability): restore WebBridge after startup failure

* fix(capability): wait for WebBridge process exit

* fix(capability): handle WebBridge confirmation edge cases

---------

Co-authored-by: kimi-agent-bot <[email protected]>
Co-authored-by: kimi-agent-bot <[email protected]>

* chore: sync release 2.6.3 back to main

* chore: finish release 2.6.3 backsync

* chore: sync node-sdk lockfile importer

* fix(sdk): preserve main core type dependencies

* fix: complete release 2.6.3 backsync

---------

Co-authored-by: Haozhe <[email protected]>
Co-authored-by: 7Sageer <[email protected]>
Co-authored-by: kimi-agent-bot <[email protected]>
Co-authored-by: kimi-agent-bot <[email protected]>
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.

1 participant