Repository navigation
fix(tui): stop /init from leaving the terminal UI busy - #5628
Merged
Merged
Conversation
Under the v2 engine the SDK reports loop lifecycle events, so finalizeTurn sets the phase back to waiting and leaves the rest to the main agent's turn.ended. /init runs no main turn: a coder subagent writes AGENTS.md and the main agent only gets a reminder. turn.ended never arrives, the spinner never stops and messages typed meanwhile stay queued. /init now settles through finalizeTurnlessRequest, which shares the finalize logic but does not wait for a loop end. finalizeTurn keeps deciding by loopLifecycleEvents as before. Two unit tests under the v2 engine cover the busy state and a message typed while /init runs; both fail without the fix.
🦋 Changeset detectedLatest commit: 4fc847e The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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. |
Grapedge
approved these changes
Nov 27, 2026
commit: |
This was referenced Nov 27, 2026
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
在 TUI 里运行
/init,生成 AGENTS.md 的子 agent 跑完之后,输入框上方的转圈一直不停,Worked for …不出现;用户接着发的消息只会进队列,一直发不出去。默认的 v2 引擎下每次都这样。这个 PR 让/init跑完后 TUI 回到空闲,并按顺序发出排队的消息。新 E2E 的
init自测正例(tests/e2e/self-test/init.spec.ts)和缓存场景tests/e2e/scenarios/cache/init-keeps-the-prefix.spec.ts随 #5578 合入,它们在 main 上的tui、tui-kitty和 Windowstui上一直红在「等回合结束」,就是这个问题。Bug Reproduction Steps
kimi,发一条消息,等回复结束。/init,批准子 agent 写 AGENTS.md。Completed之后,转圈仍在,Worked for …不出现。Root Cause
v2 引擎的 SDK 客户端报告
loopLifecycleEvents: true。这时StreamingUIController.finalizeTurn不自己收尾:它把阶段设回waiting,等主 agent 的turn.ended带着continuation到达,再由finalizeContinuation回到空闲、取出排队的消息。/init不开主回合:引擎起一个 coder 子 agent 写 AGENTS.md,跑完只给主 agent 加一条提醒。所以主 agent 的turn.ended永远不来,TUI 就一直停在waiting。sequenceDiagram participant User participant TUI participant Engine User->>TUI: /init TUI->>TUI: beginSessionRequest (busy) TUI->>Engine: session.init() Engine->>Engine: coder subagent writes AGENTS.md, then a reminder for the main agent Engine-->>TUI: init() resolves, no main turn ran TUI->>TUI: finalizeTurn: lifecycle events on, so phase = waiting until turn.ended Note over TUI,Engine: turn.ended never comes, so the spinner never stops and the queue never drains现有单测「dispatches /init to the active session and clears busy state after completion」没设
loopLifecycleEvents,走的是旧引擎的路径,所以一直是绿的。其他调用beginSessionRequest()的地方都会开一个真正的主回合,提示词被 hook 拦下时也是在已开始的回合里结束、照样有turn.ended,只有/init是这样。这是根本修复:/init按「没有主回合」的请求收尾,不再等一个不会来的事件。Code Changes
StreamingUIController多一个收尾入口finalizeTurnlessRequest,给不开主回合的请求用;/init成功后改用它。finalizeTurn照旧按loopLifecycleEvents决定要不要等turn.ended,两者共用同一段收尾逻辑。awaitLoopEnd为 false 时走的就是旧引擎原来的收尾:有排队的消息就发出下一条,否则回到空闲、重置活动区,并发出终端通知。阅读指南:先看
apps/kimi-code/src/tui/controllers/streaming-ui.ts的finalizeRequest(原finalizeTurn的函数体,只把条件换成参数),再看apps/kimi-code/src/tui/commands/session.ts的一行改动;测试在apps/kimi-code/test/tui/kimi-tui-message-flow.test.ts。Behavior Changes and Affected Users
/init成功之后 TUI 的忙碌状态(v2 引擎)waiting,转圈不停,没有Worked for …Worked for …/init运行期间或之后发的消息(v2 引擎)/init跑完后按顺序发出/init跑完时的终端通知(开了通知时,v2 引擎)loopLifecycleEvents关)下的/initfinalizeTurn的路径(turn.ended、提示词被 hook 拦下)turn.ended的 continuationfinalizeTurn仍按loopLifecycleEvents判断/init失败或被取消finalizeTurn)受影响的只有 TUI 用户(
/init只在 TUI 里有);print 模式、SDK、Desktop、Web、ACP、VS Code 不经过这段代码。测试覆盖:
waiting,后者session.prompt一次都没被调用)。init自测正例和 E6 场景:修复前在 TUI 上超时,修复后通过。验证
基于 main
5f7f90a98(#5578 已合入)。pnpm exec vitest run --reporter=agent apps/kimi-code/test/tui/kimi-tui-message-flow.test.ts567 条通过;两条新用例在修复前都失败。apps/kimi-code/test/tui/controllers和apps/kimi-code/test/tui/commands共 46 个文件、828 条通过。TESTKIT_CLI_BUILD=dist,macOS):--project=tui整套:268 条通过,20 条按设计不在 TUI 上跑,1 条失败,是scenarios/cache/mcp-tool-change-keeps-the-tool-list。它在 main 上本来就红(feat(agent-core-v2): defer MCP tools by default and cap startup wait at 2s #5433 之后),和这个改动无关。self-test/init.spec.ts和scenarios/cache/init-keeps-the-prefix.spec.ts在tui、tui-kitty上 6 条通过;修复前它们在 main 的 CI 上超时。pnpm lint通过;pnpm exec tsc -p apps/kimi-code/tsconfig.json --noEmit通过;node --test 'scripts/checks/*.test.mjs'124 条通过;pnpm run check:duplication 5f7f90a98没有新增重复。Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.