Repository navigation
fix(loop): cancel prompts while their turn is starting - #5394
Merged
Merged
Conversation
🦋 Changeset detectedLatest commit: c465305 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 |
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. |
commit: |
wbxl2000
approved these changes
Nov 25, 2026
wbxl2000
self-requested a review
November 25, 2026 13:01
7723qqq
pushed a commit
to 7723qqq/kimi-code
that referenced
this pull request
Nov 26, 2026
Port upstream 4d833db onto the fork's LiveTurn actor. Loop.cancel accepts includeStarting; when the prompt still sits in an unannounced starting turn, the actor marks cancelledBeforeStart, aborts that turn and returns the startingTurnId, announceTurn skips it, the journal writes a queued turn.cancel and the prompt projection drops the pending turn. The loop service passes includeStarting from its prompt-cancel path. Verified: core and agent-core-v2 typecheck clean; coreLoopService 20 pass including the new cancel-during-start regression; journal/record/wait 12 pass. The remaining loop.test.ts failures are the pre-existing loopEnd and system-reminder snapshot drift.
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.
6 tasks done
This was referenced Nov 26, 2026
Merged
5 of 6 tasks
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
取消提示可能发生在引擎已经选中它、还在准备首步的时候。这个窗口内,调用方会收到取消成功,模型随后仍收到这条提示。该竞态也让主 CI 的引擎取消测试在核对恢复历史时失败。GitHub Actions 失败作业
Bug Reproduction Steps
在
main上运行pnpm exec vitest run --reporter=agent packages/agent-core-v2/test/agent/loop/loop.test.ts -t 'does not run loop error handlers for aborted turns'。测试中的实时历史包含go,刚恢复的历史为空。门控复现把第一条提示停在提交前回调,排入第二条,再取消第一条。旧代码向模型发送了两次请求,历史从已取消的提示开始。
Root Cause
Loop 在提交前把提示从收件队列移到正在启动的回合。取消路径只尝试从收件队列移除它,随后把提示标记为已取消。回合持有的输入继续执行,模型和回放观察到了与取消结果矛盾的状态。
Code Changes
flowchart LR C[按 ID 取消提示] --> P{提示仍在准备首步} P -->|是| A[中止启动并按 ID 移除提示] A --> Q[按原顺序处理其余排队输入] A --> J[为未宣布的回合写入 queued TurnCancel] P -->|仍在队列| M[按 ID 从队列移除]引擎按提示 ID 取消时启用启动阶段的处理。Loop 在同一 actor 操作中退回尚未提交的输入并移除目标,从而避免目标被再次取走。取消投影清除暂存的提示状态。未宣布的回合使用现有
TurnCancel记录编号,后续恢复可以继续编号,撤销历史也只包含已经形成的提示边界。Behavior Changes and Affected Users
TurnCancel表示取消并保留编号macOS 上的两条回归连续 8 轮通过,共 16 次执行。完整的受影响套件通过 15 个测试文件、303 条用例,覆盖引擎回合、撤销与恢复、KAP 提示及会话场景。Core 和引擎类型检查及
pnpm lint通过。Checklist
main复现红灯。gen-changesets记录 patch 变更。