Repository navigation
refactor(core): replace turn.ended loopEnd with continuation - #5359
Merged
Merged
Conversation
Codex Review Summary: ✅ CompletedThis 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. |
🦋 Changeset detectedLatest commit: 38c10d1 The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 packages
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 |
commit: |
6 tasks done
liruifengv
approved these changes
Nov 25, 2026
This was referenced Nov 25, 2026
7723qqq
pushed a commit
to 7723qqq/kimi-code
that referenced
this pull request
Nov 25, 2026
MoonshotAI#5359 and MoonshotAI#5404 need the fork's loop/ACP shapes (LiveTurn state machine, session extensions), MoonshotAI#5434 depends on testkit signal imports, and MoonshotAI#5332 needs a merged SessionAction table. Each is in_progress with the precise remaining work rather than a forced apply.
7723qqq
pushed a commit
to 7723qqq/kimi-code
that referenced
this pull request
Nov 26, 2026
Mark MoonshotAI#5394 ported with its cancel-during-start regression; record MoonshotAI#5359 and MoonshotAI#5351 as blocked on the TUI continuation capability and the tool activation model, and keep MoonshotAI#5432 partial until those rows close.
7723qqq
pushed a commit
to 7723qqq/kimi-code
that referenced
this pull request
Nov 26, 2026
The core loop now reports TurnContinuation on turn.ended: 'turn' when a queued trigger or pending task completion runs next, 'background' when only background tasks remain, and 'none' when the loop is settled. The agent turn contract, journal, projection, klient schema and wire manifest carry the field. The TUI finalizeTurn consumes it: 'turn' keeps the session running and leaves queued dispatch to the next turn, 'background' notifies that background tasks are still running, and 'none' idles as before. The old loop-ended changeset is replaced by the continuation changeset. Verified: loop record/journal/wait/coreLoopService 32 pass; TUI message-flow 489 pass; klient contract 13 pass; node-sdk event types 10 pass; core, agent-core-v2, klient, node-sdk and apps/kimi-code typecheck clean.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requirement or Bug
#5337 已将独立的
loop.drained/loop.idle事件收敛为turn.ended上的loopEnd?: { outcome: 'drained' | 'idle' },但该字段尚未随正式版本发布。loopEnd容易让使用方误以为存在成对的loopStart生命周期事件,嵌套的.outcome也与 coreturn.ended自带的outcome: TurnOutcome重名,且「后面紧接下一回合」只能通过字段缺失来隐式推断。本 PR 在发版前将其替换为扁平三态字段continuation?: 'turn' | 'background' | 'none',让客户端直接读取回合结束后的后续去向。Bug Reproduction Steps
N/A
Root Cause
N/A
Code Changes
核心思路
由 core loop 在发射
turn.ended时同步计算本回合结束后的后续去向,以扁平可选字段continuation承载,经 agent-core-v2 原样透传到 wire、node-sdk 与 klient。TUI 与 vis 改为消费三态枚举,不再依赖「字段存在与否」区分是否还有连续回合。'turn''background''none'undefined!open()),或旧版本写入的会话记录因为后续去向的判定输入在
turn.ended发射点同步可读,所以在 core 单点计算并随事件透传,客户端不需要再维护 generation 配对或猜测队列状态。关键决策
continuation?: 'turn' | 'background' | 'none'loopEnd?: { outcome }outcome: TurnOutcome撞词,也少一层嵌套'turn'shouldQueueTaskNotification,被抑制则不标'turn'completionPending一律标'turn''turn'会让客户端永远等不到终态turn-ended-loop-end.md阅读指南
packages/core/src/loop/contract/emitted.ts与packages/core/src/loop/loop-actor.ts:TurnContinuation类型与三态判定逻辑(resolveContinuation、hasFollowUpTurn、closeUnfinished)。packages/agent-core-v2/src/agent/loop/turnOps.ts、turnProjection.ts、journal.ts:事件 schema、序列化与透传。apps/kimi-code/src/tui/controllers/session-event-handler.ts与streaming-ui.ts:TUI 在'background' | 'none'时执行终态处理(含压缩恢复与 feat(prediction): refine next-prompt interactions #5180 的下一问预测触发),'turn'保持等待。Behavior Changes and Affected Users
turn.ended事件载荷loopEnd?: { outcome: 'drained' | 'idle' }continuation?: 'turn' | 'background' | 'none'main(#5337 之后)对接loopEnd的客户端或脚本loopEnd)turn.endedloopEndcontinuation: 'turn'turn.ended字段的消费者(TUI、vis、klient)loopEnd'background'或'none'agent.events的 klient 消费者drained提示后台任务仍在运行,idle提示完成;派发队列时不通知'background'/'none'触发,'turn'不触发turn.ended标签loop idle/loop drainedcontinuation none/continuation background/continuation turn受影响模块与测试覆盖:
packages/core、packages/agent-core-v2:wait.test.ts、record.test.ts、journal.test.ts、loop.test.ts、task-tools.test.ts覆盖单回合'none'、连续/notify/取消后续'turn' → 'none'、后台任务'background' → 'none'、崩溃恢复结算;toolAdapter.test.ts新增取消时仍有待交接完成消息(抑制/不抑制通知)的参数化用例。apps/kimi-code(TUI):kimi-tui-message-flow.test.ts显式验证'turn'不派发客户端队列也不通知,'background'/'none'正常去重、派发与区分文案,压缩挂起恢复及会话切换不回归。packages/klient、packages/node-sdk、apps/vis/web:契约类型断言、facade 事件校验与渲染器类型检查。验证记录
core、agent-core-v2、klient、node-sdk、apps/kimi-code、apps/vis/web、apps/vis/server共 7 个包tsc --noEmit全部通过。packages/core36/36 文件通过;packages/agent-core-v2373 通过 + 1 跳过、0 失败。main(含 feat(prediction): refine next-prompt interactions #5180)后:TUI 类型检查通过,kimi-tui-message-flow.test.ts+prompt-prediction.test.ts546/546 通过,toolAdapter.test.ts本地与远程均 8/8 通过。pnpm lint与check:duplication全部通过。Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.