Skip to content

fix(agent-core-v2): preserve origins when pairing legacy turn inputs - #5626

Merged
sailist merged 3 commits into
MoonshotAI:mainfrom
pvzheroes125:fix/steer-input-origin-matching-20261127
Nov 27, 2026
Merged

sailist merged 3 commits into
MoonshotAI:mainfrom
pvzheroes125:fix/steer-input-origin-matching-20261127

Conversation

@pvzheroes125

@pvzheroes125 pvzheroes125 commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Requirement or Bug

旧会话在撤回后包含用户追加输入和系统提醒时,恢复或按轮次创建分支可能把后续输入分配到错误的回合,下游回放也可能重复显示消息。本 PR 补齐 #5599 的来源配对边界,保留正确的用户输入归属。

Bug Reproduction Steps

  1. 完成 A、B 两轮,撤回 B。
  2. 在保留的会话中记录系统日期提醒,再提交 C,并在运行中追加 C1、C2。
  3. 使用缺少输入关联 ID 的旧记录恢复会话,创建包含 C2 的分支,再序列化并冷恢复。
  4. 检查用户输入及回合归属:应保留 A、C、C1、C2,C1/C2 分别属于回合 3/4,B 不应恢复。

Root Cause

全用户消息配对路径会纳入系统注入消息。缺少关联 ID 时,它原先允许内容和顺序回退跨越来源类别,因此较早的系统提醒可以先占用后面的用户追加输入,继续使后续配对错位。

修复位于共享配对函数,覆盖旧输入规范化、回放和运行中分支调用方。

Code Changes

明确的输入/消息 ID 仍先按原规则比较。只有缺少关联 ID、需要使用内容或顺序回退时,才要求来源类别兼容;缺少来源的旧记录按 user 兼容处理。旧 skill_activation/plugin_command 来源缺少 trigger、shell_command 来源缺少 phase 时,也保留与 user 正文的兼容配对和回放轮次归属。

生产变更共 15 行,复用已有 origin 字段,不增加状态、配置、协议或依赖。

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
缺关联 ID 的内容/顺序配对 全用户路径可以跨来源类别匹配 仅匹配兼容来源,避免系统注入占用用户输入 CLI、Desktop、VS Code、SDK 及 KAP 恢复或创建旧会话分支的调用方 无需迁移,已有记录不改写
明确关联 ID 的配对 直接比较关联 ID 保持原比较顺序和结果,包括跨来源的精确关联 保留明确消息 ID 的记录与转换后的消息 原行为保留
后台通知和缺来源旧记录 通知参与全用户配对,旧来源可以缺失 同来源 task/system_trigger 通知仍可配对,缺来源仍兼容 user 后台通知与旧版本会话 原行为保留
来源字段不完整的旧记录 skill_activation/plugin_command 缺 trigger、shell_command 缺 phase 时仍保留回放轮次归属 继续按 user 兼容配对,合法 injection 仍与用户输入隔离 SDK 恢复含不完整来源字段的旧会话 原行为保留,已有记录不改写

两个现有测试文件增加回归,覆盖系统提醒、撤回、多次追加输入、分支序列化冷恢复、合法通知、缺来源记录和跨来源强 ID。既有 SDK 四参数回归先红后绿,4/4 通过;最终基底上的来源和 fork 定向回归 29/29 通过,Core/SDK 类型检查、完整 lint 与提交后干净工作树重复检查通过。原测试期望保持不变。未验证 Windows 实机行为;本修复不涉及平台路径或原生后端。

验证命令
pnpm exec vitest run --reporter=agent --retry=0 packages/node-sdk/test/sdk-rpc-client-v2.test.ts -t 'preserves replay when a turn prompt has an invalid origin'
pnpm exec vitest run --reporter=agent --retry=0 packages/agent-core-v2/test/agent/replayBuilder/fold.test.ts packages/agent-core-v2/test/project/sessionLifecycle/forkTurnSlice.test.ts
pnpm exec tsc -p packages/agent-core-v2/tsconfig.json --noEmit
pnpm exec tsc -p packages/node-sdk/tsconfig.json --noEmit
pnpm lint
pnpm run check:duplication 2c5ce9af4534e34101a5fc0b269f8e7375bce253
git diff --check

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.
  • Ran gen-docs skill; no documentation update is needed because commands, configuration and supported usage are unchanged.

@changeset-bot

changeset-bot Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1082f19

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

This PR includes changesets to release 4 packages
Name Type
@moonshot-ai/kimi-code Patch
kimi-code-app Patch
kimi-code Patch
@moonshot-ai/agent-core-v2 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 27, 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-27T09:54:12.595311Z 8bcbcf0 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 27, 2026 •

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

commit: 8bcbcf0

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

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

@pvzheroes125
pvzheroes125 force-pushed the fix/steer-input-origin-matching-20261127 branch from a42a133 to 1082f19 Compare November 27, 2026 06:49
@pvzheroes125

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 8bcbcf0fee

ℹ️ 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 18fdf03 into MoonshotAI:main Nov 27, 2026
22 checks passed
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Dec 2, 2026
`bun scripts/upstream-ledger.mjs --refresh` at upstream/main 4eb2919
added 126 rows, so every open upstream commit and every PR it references
now has a ledger row: 0/596, down from 125 at 8bf8ba3 and 126 at the
fetched tip. The refresh only reads `upstream/main ^ main`, so the three
release-2.6.2 commits named by the mission (MoonshotAI#4875/MoonshotAI#4905/MoonshotAI#4922) gained
rows with the refresh's row shape.

Settled with live probes in this tree:

- ported: MoonshotAI#5533 (docs 2.8.1 changelog), MoonshotAI#4875 (registry search_url and
  feedback_url plus the feedback service), MoonshotAI#4905 (Kimi upload status
  validation in packages/core), MoonshotAI#4922 (swarm task events in
  sessionTaskFeed), MoonshotAI#5438 (unload only declared dynamic tools), MoonshotAI#5592
  (dynamic tool replacement order), MoonshotAI#5595 (append-log known length),
  MoonshotAI#5573 (skill roots for every work dir), MoonshotAI#5576 (date reminder cwd
  comparison), MoonshotAI#5618 (session titles for skill openers), MoonshotAI#5638 (frozen
  loop tool baseline), MoonshotAI#5626 (legacy turn-input origins)
- partial: MoonshotAI#5505 (processLiveness source and consumers present; the
  upstream unit test file was never carried), MoonshotAI#5571 (program-resume and
  OSC 7577 present; the upstream test helper was never carried), MoonshotAI#5532
  (gitService half present; fsService still leaks the environment lease
  at fsService.ts:1133 and :1267), MoonshotAI#5557 (app-client icon registry kept;
  the move to app-ui was never carried)
- not-applicable: MoonshotAI#4655 (upstream reverted auto review in MoonshotAI#5649), MoonshotAI#5333
  (PLAYBOOK:111 deliberate flat experimental flags)

M39's "likely present" list was checked, not trusted: MoonshotAI#5438 is present
(upstream test passes), MoonshotAI#5487 is not (nativeStartSettleMs/leg.nativeSettled
absent), MoonshotAI#5635 is not (ToolsSettled absent), MoonshotAI#5429 needs a visual probe.
The remaining 194 pending rows stay open with their reasons; no feature
was ported and no upstream-drift allowlist entry was added.

Verification: verify -> 332 closed rows, 332 carry every file of their
PR; 317 probes pass, 2 foreign-runner skips, 0 fail; a second verify is
byte-identical (ledger sha256 cbf53638...). Probe tests 29 pass; bun run
lint and node scripts/checks/ratchet.mjs green.
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.

2 participants