Skip to content

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

Merged
sailist merged 5 commits into
MoonshotAI:mainfrom
sailist:bug-253-09-19-cold-rebuild-turn-id
Sep 19, 2026
Merged

sailist merged 5 commits into
MoonshotAI:mainfrom
sailist:bug-253-09-19-cold-rebuild-turn-id

Conversation

@sailist

@sailist sailist commented Sep 19, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

无对应 issue;内部排查复现(见 Problem)。

Problem

会话 undo 之后,新 turn 的编号会回滚复用旧 turnId——同一 wire 中同一编号对应两条不同消息。冷重建 transcript 基线不看 wire turnId、按消息数从 t0 顺序编号,而 live 投影沿用 wire 编号;当新 turn 的编号撞上冷基线里已有 turn 的 id 时,live 数据在旧位置替换合并,新消息连回复被插到会话很上面的旧 turn 位置,看起来就像消息被吞了。

根因:undo 走 wire.switchBranch 切分支后,human agent 机器的 store 按活跃分支重放,turnIndex 时钟回滚到切割点;engineJournal 在 journal 非空时又丢弃了 initialTurnId 这个「全 wire 最大 id+1」的兜底,于是 undo 后与冷启动后分配的新 turn id 与死分支撞号。已有会话(wire 中已存在复用 id)每次冷启动都会重复触发。

What changed

  • agent-core-v2:engineJournal 对非空 journal 尾部追加内存态种子 turnEnded(initialTurnId - 1)(新增 appendedStoreJournal;种子不落盘,每次引擎构建从 raw wire 重算,存量会话无需迁移);turnIndexSlice.turnEnded 改为 max 守卫,使种子只抬不压。undo 后与冷启动后,新 turn id 恒为全 wire 历史最大 id+1。
  • kap-server:readColdSnapshot 在读取边界过 flattenChain(与引擎 restorableChain 同语义)——死分支的消息/loop 事件与死 compaction 标记不再漏入冷基线,undo/compact 的冷重建归约与 live 语义一致;pre-tree 老 wire 的 unpaired legacy context.undo 仍兼容。
  • 测试(总数净零):undo 对齐测试断言更新为单调编号语义(此前钉住的正是复用 id 的旧行为);readColdSnapshot 缓存一致性测试扩展覆盖「死分支含 compaction 的分支 wire」场景——raw 折叠会让死 compaction 挡住 undo 裁剪、死 turn 复活,归约后只保留活跃分支。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: the issue must have a maintainer's /approve).
  • I have added tests that prove my feature works.
  • 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 Sep 19, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 68765eb

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

@pkg-pr-new

pkg-pr-new Bot commented Sep 19, 2026 •

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

commit: 68765eb

@sailist

sailist commented Sep 19, 2026

Copy link
Copy Markdown
Collaborator Author

@codex

1 similar comment
@liruifengv

Copy link
Copy Markdown
Collaborator

@codex

@sailist
sailist merged commit 9df7a9c into MoonshotAI:main Sep 19, 2026
15 checks passed
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 <[email protected]>

* 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 <[email protected]>
Co-authored-by: liruifengv <[email protected]>
Co-authored-by: Haozhe <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: 7Hanrui <[email protected]>
Co-authored-by: 7Sageer <[email protected]>
Co-authored-by: Zixuan Chen <[email protected]>
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Oct 5, 2026
Step 8 of the incremental sync to 2.1.1: 12 upstream commits over 198
files. The step is dominated by upstream's revert of the flat entity
message protocol (MoonshotAI#3532 reverted by MoonshotAI#3920): the v3 WS surface, the
history API, the projection service and the v3-based kimi-inspect data
model are gone, and kimi-inspect returns to the transcript model.

Upstream's changes in this step, all absorbed:
- revert(kap-server): drop the flat entity message protocol (v3 WS +
  history API) (MoonshotAI#3920) — ~10k lines across kap-server and kimi-inspect
- keep turn ids above the wire-wide max and fold cold transcripts over
  the active branch (MoonshotAI#3922)
- pre-shrink compaction history to the effective model window (MoonshotAI#3911)
- don't record turn.steer when an unconsumed steer seeds the next turn
  (MoonshotAI#3933)
- remove the project-root assertion for cwd from the system prompt
  (MoonshotAI#3929)
- deliver session-level interaction events past agent filters (MoonshotAI#3901)
- parse goods_version from the managed /me profile payload (MoonshotAI#3921)
- ignore Enter during IME composition in the question dialog (MoonshotAI#3915)
- remove the tdd skill (MoonshotAI#3932)
- sync the web dist from code-app (MoonshotAI#3934) and the 2.0.1 changelog
  (MoonshotAI#3912)

Fork behaviour that had to survive:
- the fork's kap-server API surface: the cron and MCP routes
  (routes/cron.ts, routes/mcp.ts, protocol/rest-cron.ts,
  protocol/rest-mcp.ts) and the plugin marketplace home-dir option are
  re-registered on top of upstream's reverted registerApiV1Routes
- the i18n layer: kimi-inspect's localization was re-applied to the
  reverted ChatView, AuditPanel and Inspector
- the fork's goal domain: the transcript boundary now narrows the
  wire's six goal statuses to the model's four through the fork's
  normalize.ts (wired into api.ts and ws.ts), which had been dead code
  since the 0.42.0 merge
- the fork's error-detail exposure and marketplace home dir in start.ts

Verified: typecheck clean across every package and app (kimi-inspect
included, run separately); full suite 17619 passed / 0 failed / 81
skipped / 1 todo, plus kimi-inspect's own 115 tests; lint 0 errors.
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