Repository navigation
test(e2e): keep the TUI busy until queued messages reach the transcript - #5431
Conversation
When a turn ends with messages queued, the TUI takes the next message off the queue, switches to idle and sends it on the next timer tick. A render can land in between and draw a frame with no activity indicator and an empty queue. The TUI driver read that frame as the end of the turn, so waitIdle() sometimes returned before the queued message was sent. The driver now remembers the messages queue() puts in the queue and counts the product as busy until each one shows up as a user message in the transcript. Failure descriptions list the queued messages that never showed up.
|
Codex Review Summary: ❌ FailedThis 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: |
Port the testkit half of MoonshotAI#5380: UNIT_TEST_SWITCHES names the defaults that exist only to speed unit tests, TEST_ENV_DEFAULTS spreads them, and the fixtures test pins that setting each name to undefined restores product defaults while telemetry isolation stays on. Ledger: MoonshotAI#5373, MoonshotAI#5389, MoonshotAI#5431 and MoonshotAI#5423 are not-applicable because the tests/e2e Playwright suite and its workflow do not exist here. MoonshotAI#5380 is partial (testkit half landed), and MoonshotAI#5385 is partial: its ACP fake-model migration remains for the testkit wave while the legacy-e2e freeze does not apply.
Requirement or Bug
新 E2E 的 TUI 驱动在回合结束、还有排队消息时,偶尔会提前判定产品已空闲:
waitIdle()在排队消息还没发出去时就返回了。用到排队的场景和自测因此偶发变红。main 上已出现过一次:#5206 合入后那次运行里,TUI 的queue positive自测红了,模型只收到 1 个请求。这个 PR 之后,TUI 上waitIdle()会等到每条排队消息都真正发出、跑完才返回。Bug Reproduction Steps
在 main 上加压跑四条用到排队的用例:
本机 macOS 上 120 次里有 5 次失败:
queue positive2 次:waitIdle返回时,model.requests('main')只有 1 个请求。expectReply negative: does not take the reply to an earlier queued message3 次:waitIdle停在两条排队消息之间,把第一条排队消息的回复当成了最后一条回复。Root Cause
产品没有 bug,问题出在驱动把一帧过渡画面当成了空闲。
回合结束且队列里还有消息时,TUI 会做三件事(
apps/kimi-code/src/tui/controllers/streaming-ui.ts的finalizeTurn和dispatchQueuedAfterContinuation):setTimeout(0)推迟发送;如果第 1 步之前已经有一个排好的渲染定时器,它会在第 2 步之前触发,画出这样一帧:没有活动指示,排队区是空的,状态栏是上一回合的
Worked for …,排队的那条消息也还没出现在转录里。下一次渲染要等 pi-tui 的 16ms 节流,所以这帧至少停留约 15ms,机器负载高时更久。sequenceDiagram participant CLI as TUI (product) participant Screen as Terminal screen participant Driver as TUI driver CLI->>CLI: finalizeTurn: shift queued message, phase = idle CLI->>Screen: pending render draws a frame with no activity indicator and an empty queue Driver->>Screen: read twice, 20ms apart: identical idle frame Driver-->>Driver: waitIdle() returns CLI->>CLI: setTimeout(0): send the queued message CLI->>Screen: user message + activity indicator驱动的
turnOver()认为回合结束的条件是:编辑器可见、没有活动指示、排队区为空、有完成标记,并且settle()连续两次(间隔 20ms)读到同样的画面。上面那帧停留超过一个轮询间隔,就会被当成空闲。这一帧和真正空闲的画面在屏幕上没有区别,所以只能从「用户自己排过哪些消息」这条线索区分。这个 PR 是根本修复,没有加等待或重试。
Code Changes
只改 TUI 驱动(
tests/e2e/surfaces/tui.ts)和 E2E 指南,不碰产品代码。驱动依据的是用户自己能看到的证据:自己排进去的消息离开了排队区,但还没出现在对话里,说明还在发送中。产品以后如果悄悄丢了排队消息,
waitIdle()会超时,报错里会写明是哪条消息没出现,不会把这种情况当成空闲。tests/e2e/AGENTS.md里waitIdle()那一条补充了 TUI 上的这个空档,以及对应的破坏性检查。Behavior Changes and Affected Users
产品行为不变。下表是驱动行为的变化,受影响的只有写 TUI 场景的人和 CI。
waitIdle()和所有以「产品空闲」为前提的判断(send、compact、newSession、expectAbsent、场景收尾),出队后、新回合开始前的那一帧queue、steer、stop、expectTool({ status: 'running' })queue()照旧报错waitIdle()等它发出waitIdle(),预期这条消息会被发出waitIdle()超时,报错列出这些消息Desktop、Web、ACP 的驱动没有改动。Desktop 和 Web 出队、标记正在发送、加乐观的用户消息是在同一个同步块里完成的(
packages/app-client/src/client/usePromptPipeline.ts的flushQueueHead),按代码看没有这个空档。ACP 上没有排队动作。验证覆盖:所有用到
queue()的 TUI 自测和场景(queue、steer、waitIdle、expectReply的相关用例,以及turn/queued-messages-run-in-order),分别在tui和tui-kitty两个跑法下验证。没有新增用例:这些现有用例在修复前就会失败,平时是偶发,把空档放大后每次都会失败(见下面的破坏性检查),它们就是这次修复的回归测试。未验证:Windows(驱动在 Windows 上走同一条代码路径,可以手动触发 Windows 作业来看)。本机验证记录(macOS)
setTimeout(0)改成 300ms(两处),跑 7 条用到排队的用例,每条 2 遍waitIdle提前返回导致的断言失败;新驱动 14/14 绿。产品改动已还原,不在本 PR 里tui+tui-kitty全套pnpm exec tsc -p tests/e2e/tsconfig.json --noEmitpnpm lintnode --test 'scripts/checks/*.test.mjs'pnpm run check:duplication <base>Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.