Repository navigation
Conversation
- expose turn.ended continuation on KAP conversation turn headers over WebSocket and REST - notify completion in web and desktop only when continuation is none, falling back for older servers without the field - cover fold, live frames, client notification gating, and KAP scenarios
🦋 Changeset detectedLatest commit: 9c3e168 The changes in this PR will be included in the next version bump. This PR includes changesets to release 7 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: b17c3ad598
ℹ️ 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.
Gate notifications on the client-side prompt queue
When a web or desktop user queues another prompt while the current turn is running, that prompt remains in promptStore().queuedBySession and is not yet known to the server, so the ending turn legitimately arrives with continuation: "none". This condition consequently sends a completion notification before the idle agent frame lets resumeQueueIfIdle submit the queued prompt, despite work still being pending; include the existing local-work/queue state in this notification gate.
AGENTS.md reference: AGENTS.md:L112-L115
Useful? React with 👍 / 👎.
- suppress completion notifications only when continuation is 'turn' - notify on 'background' and 'none', keeping the legacy undefined fallback - update notification tests and changeset to match
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9c3e168476
ℹ️ 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".
| hasPendingQuestion: boolean, | ||
| continuation?: ConversationContinuation, | ||
| ): boolean { | ||
| if (continuation === 'turn') return false; |
There was a problem hiding this comment.
Suppress completion for background continuations
When a detached Bash or sub-agent task remains active, the server ends the foreground turn with continuation: 'background' and later runs a notification turn ending with 'none'. Because this condition rejects only 'turn', Web/Desktop display the generic completion notification for both turns, preserving the premature and duplicate notification this change is intended to remove. Allow notifications only for 'none', while retaining the undefined fallback for legacy servers.
AGENTS.md reference: AGENTS.md:L112-L117
Useful? React with 👍 / 👎.
Stacked on #5359
Requirement or Bug
Web 与 Desktop 用户开启系统完成通知并切到后台时,连续回合(排队消息、steer、hook 通知)的第一个回合结束就会弹出「回合完成」通知,等后续回合结束时再弹一次。本 PR 基于 #5359 的
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 帧上补字段,否则首屏/重连竞态下走分页结算时会丢失该字段并误触发通知。关键决策
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)、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 关闭及旧记录省略turn.ended只要completed且无 goal / 待处理交互即通知continuation === 'turn'(后续紧接排队/steer/hook 回合)时不通知;'background'(后台任务仍在运行)与'none'时均正常通知'turn'回合通知)continuation)undefined回退)受影响模块与测试覆盖:
packages/kap-server: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:conversation.test.ts在真实 KAP 单回合('none')、排队连续回合('turn' → 'none')、后台子代理('background' → 'none')场景中同时断言 WebSocket 实时帧与 REST 结果。验证记录
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全部通过(新增与调整断言在修复前均失败)。packages/app-client/test全量:126 个文件 2409/2409 通过。tsc -p packages/kap-server/tsconfig.json --noEmit与pnpm --filter kimi-code-app run typecheck(含 renderervue-tsc,m0 Linux)通过。tests/scenarios/conversation.test.ts+packages/kap-server/test/services+packages/app-client/test+packages/app-core/test共 3874 通过、1 失败。唯一失败为conversation.test.ts的waits for approval in manual mode...(item.ended计数为 2),在父分支 refactor(core): replace turn.ended loopEnd with continuation #5359(38c10d16)干净基线上可复现同样失败,与本 PR 无关。pnpm lint与check:duplication通过。Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.