Repository navigation
fix(app): gate completion notifications on turn continuation - #5383
Conversation
🦋 Changeset detectedLatest commit: 706bae9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 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: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 706bae90dc
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const hasPendingApproval = (rawState.approvalsBySession[sid] ?? []).length > 0; | ||
| const hasPendingQuestion = (rawState.questionsBySession[sid] ?? []).length > 0; | ||
| if (!goalActive && shouldNotifyCompletion(status, hasPendingApproval, hasPendingQuestion)) { | ||
| if (!goalActive && shouldNotifyCompletion(status, hasPendingApproval, hasPendingQuestion, opts.continuation)) { |
There was a problem hiding this comment.
Account for client-side queued prompts before notifying
When a Web or Desktop user queues a message through the composer while a turn is running, sendPrompt stores it only in queuedBySession and does not submit it to KAP until the current turn becomes idle (usePromptPipeline.ts:479-501,588-590). The server therefore reports continuation: 'none' for that current turn, and this condition still sends the intermediate completion notification before the client flushes the queued message, followed by another notification after the next turn—the primary reproduction described by this change. Include the client-side queued/in-flight state in the suppression decision, or submit the queued prompt early enough for the server continuation to reflect it.
AGENTS.md reference: AGENTS.md:L192-L194
Useful? React with 👍 / 👎.
| ratingTurnId: turn.turn_id, | ||
| predictionSourceId: turn.turn_id, | ||
| predictionTurnId: turn.ordinal, | ||
| continuation: turn.continuation, |
There was a problem hiding this comment.
Settle the final continuation from the initial page
When a newly activated conversation finishes a fast automatic continuation before its initial turns page arrives, onMainPage settles the first turn because its opener matches the optimistic prompt, but it marks the following hook/notification continuation as settled without calling settleMainTurnEnd because that turn has no optimistic opener (onMainPage lines 1889-1899). Passing 'turn' here suppresses the only notification that is evaluated, while the final turn is never evaluated, so a hidden Web/Desktop window receives no completion notification at all. The initial-page fallback needs to settle the terminal continuation in the same chain, not only the user-owned first turn.
AGENTS.md reference: AGENTS.md:L192-L194
Useful? React with 👍 / 👎.
* refactor(core): replace turn.ended loopEnd with continuation * fix(app): gate completion notifications on turn continuation
* refactor(core): replace turn.ended loopEnd with continuation * fix(app): gate completion notifications on turn continuation
Stacked on #5381
Requirement or Bug
将 #5376(
b17c3ad+9c3e168)移植到release/2026-11-25(叠在 #5381 之上),随 11-25 发版一起发布。Web 与 Desktop 用户开启系统完成通知并切到后台时,连续回合(排队消息、steer、hook 通知)的第一个回合结束就会弹出「回合完成」通知,等后续回合结束时再弹一次。本 PR 基于 #5359/#5381 的
turn.ended.continuation三态契约,让 KAP 透传该字段:Web 与 Desktop 仅在continuation === 'turn'(后面紧接连续回合)时压住不发;'background'(前台回合已结束、后台任务仍在运行)与'none'(队列与后台任务全部结束)均正常发送完成通知。Bug Reproduction Steps
kimi web)或 Desktop 开启系统通知,切到其他窗口使页面不可见;Root Cause
根本修复(由服务端在
turn.ended发射点给出权威后续去向,客户端不再自行猜测):continuation:ConversationFeed将实时事件与历史 wire 记录统一折叠为ConversationTurnHeader,供 WebSocketturn.ended/turns与 REST/turns共用,但applyTurnEnded未读取continuation,协议 schema 与app-core类型也没有该字段。turn.ended都当作完成:settleMainTurnEnd在每个主 agent 回合结束时调用shouldNotifyCompletion,只要completed、无活跃 goal、无待处理审批/提问就通知。agent的idle帧和session的activity: 'idle'在连续回合间隙会出现瞬时空闲,客户端无法从这两个状态帧区分「中间回合结束」与「前台回合队列已排空」。maybeNotifyCompletion使用promptId ?? Date.now()作为 tag,连续回合的promptId不同(或退化为时间戳),每个中间回合都会生成独立通知。Code Changes
核心思路
KAP 在折叠
turn.ended时把continuation写入ConversationTurnHeader,让实时 WebSocket 帧、REST 分页与重启回放都能读到同一个字段;客户端settleMainTurnEnd将turn.continuation传给shouldNotifyCompletion,仅当'turn'时拦截完成通知,'background'、'none'(或旧服务端未提供该字段)均允许弹完成通知,其余每回合副作用保持原样。flowchart LR A[core / v2<br/>turn.ended.continuation] -->|serialize| B[KAP conversationFold<br/>applyTurnEnded] B --> C[ConversationTurnHeader<br/>continuation?] C -->|WS turn.ended / turns| D[app-client<br/>settleMainTurnEnd] C -->|REST /turns 首屏与重连兜底| D D --> E{shouldNotifyCompletion} E -->|background / none<br/>或旧服务端 undefined| F[无 goal / 无待处理交互时<br/>发完成通知] E -->|turn| G[不通知,保留其他回合结束副作用]因为 WS 实时帧与 REST 分页共用
ConversationTurnHeader和同一个settleMainTurnEnd入口,所以在协议头部统一透传,而不是只在 WS 帧上补字段,否则首屏/重连竞态下走分页结算时会丢失该字段并误触发通知。移植到 release 分支的适配
default_swarm_mode(改变了配置接口 schema 与HOST_CONTRACT摘要)。本 PR 在保留default_swarm_mode的基础上运行pnpm qa:refresh schema,contract.txt相对 refactor(core): replace turn.ended loopEnd with continuation #5381 仅新增 3 处可选continuation(REST/turns、WSturn、WSturns),HOST_CONTRACT摘要更新为1b9cf493...,HOST_API_LEVEL保持1。main上 CItest (1)失败是因为新增响应字段后未刷新 L0 录制快照。本 PR 已运行pnpm qa:refresh replay(经维护者确认),tests/scenarios/recordings/first-turn/trace.json的 diff 仅在 4 处新增"continuation": "none"(primary / late 两路流各自的回合结束 WSturn帧与最终 RESTturns[0]),其余帧、时序与字段均无变化。关键决策
turn.ended(含onMainPage竞态兜底),新增continuation === 'turn'过滤;'background'与'none'均通知agent的idle帧或sessionWorkChanged(activity: 'idle');或仅在'none'通知idle帧在连续回合间隙会瞬时空闲,无法表达「还有排队/通知回合」;主回复结束但后台任务仍在运行('background')时也需要即时提醒用户前台回复已完成/turns同步新增字段ConversationTurnHeader.continuationonMainPage会走同一settleMainTurnEnd补结算,需要同一份continuationcontinuationundefined时回退原有判定,HOST_API_LEVEL保持1HOST_API_LEVELturnForNumber重开时清空continuationcontinuation)都不应残留'turn'执行阅读指南
packages/kap-server/src/protocol/conversation.ts与services/conversation/conversationFold.ts:conversationContinuationSchema、协议头部字段及applyTurnEnded/turnForNumber折叠逻辑。packages/app-core/src/conversation/types.ts:客户端ConversationContinuation类型镜像。packages/app-client/src/composables/useNotification.ts与client/useKimiWebClient.ts:continuation的判定与参数透传。schema/、apiSurface.test.ts)、L0 首轮录制(recordings/first-turn/trace.json)、docs/kap.md、changeset 与三层测试,可略读。Behavior Changes and Affected Users
ConversationTurnHeader(WSturn/turns与 RESTGET /api/v1/sessions/{session_id}/agents/{agent_id}/turns)continuationcontinuation?: 'turn' | 'background' | 'none';运行中、loop 关闭及旧记录省略tests/scenarios/recordings/first-turn/trace.json)continuation"continuation": "none"tests/scenarios/replay.test.ts与packages/app-core/test/replayturn.ended只要completed且无 goal / 待处理交互即通知continuation === 'turn'(后续紧接排队/steer/hook 回合)时不通知;'background'(后台任务仍在运行)与'none'时均正常通知'turn'回合通知)continuation)undefined回退)受影响模块与测试覆盖:
packages/kap-server:services/conversation.test.ts覆盖折叠三态与旧记录缺失、实时turn.ended帧、REST 分页与回放透传;apiSurface.test.ts校验 OpenAPI / AsyncAPI 契约快照与HOST_CONTRACT摘要。packages/app-client:notification-logic.test.ts覆盖shouldNotifyCompletion对'none'/'background'/'turn'/undefined及取消、待处理交互的判定矩阵;conversation-events.test.ts覆盖真实客户端事件流中'turn'不通知、'background'与'none'正常通知、旧帧回退通知及'none'+ interrupted 不通知。tests/scenarios:replay.test.ts(L0)与packages/app-core/test/replay校验录制与离线回放一致;conversation.test.ts在真实 KAP 单回合('none')、排队连续回合('turn' → 'none')、后台子代理('background' → 'none')场景中同时断言 WebSocket 实时帧与 REST 结果。Verification
pnpm lint(独立 git worktree,0 警告 0 错误)与check:duplication(基线 refactor(core): replace turn.ended loopEnd with continuation #5381 提交):通过,无新增重复片段。kap-server/test/services/conversation.test.ts、kap-server/test/apiSurface.test.ts、app-client/test/notification-logic.test.ts、app-client/test/conversation-events.test.ts、tests/scenarios/replay.test.ts、tests/scenarios/conversation.test.ts、packages/app-core/test/replay共 136 通过、1 失败。唯一失败为tests/scenarios/conversation.test.ts的waits for approval in manual mode...(item.ended计数为 2),已在未移植本 PR 与 refactor(core): replace turn.ended loopEnd with continuation #5381 的 release 基线(feat(prediction): refine next-prompt interactions #5379 提交)上复现同样失败,属基线既有问题,与本改动无关(Linux CI 上该用例通过)。kap-server与kimi-code-app(含 renderervue-tsc)TypeScript 类型检查通过。Checklist
gen-changesetsskill(沿用 fix(app): gate completion notifications on turn continuation #5376 已评审的 changeset:kap-serverminor、CLI / Desktop patch).gen-docsskill, or this PR needs no doc update(packages/kap-server/docs/kap.md与schema/已同步更新).