Repository navigation
feat(desktop): continue running sessions after an update restart - #5221
Conversation
The update restart confirmation lists the sessions whose turns are still running and offers a default-checked option to continue them after the restart. The chosen session ids are recorded in ui-state before quitting and consumed once when the next process freshly starts the embedded server, guarded by an app version change and a ten-minute window, then continued one at a time through the sessions continue endpoint. The browser overlay confirm surface now carries the checkbox of app confirms, so the option behaves the same whether the in-app dialog, the browser overlay or the native dialog shows the prompt.
🦋 Changeset detectedLatest commit: 0df3825 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. |
commit: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ad00580de4
ℹ️ 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".
| export function takePendingSessionContinue(file: string = defaultStateFile()): PendingSessionContinue | undefined { | ||
| const value: unknown = loadUiState(file).pendingSessionContinue; | ||
| if (value === undefined) return undefined; | ||
| writeUiState({ pendingSessionContinue: undefined }, file); |
There was a problem hiding this comment.
Propagate failure to clear the continuation marker
When ui-state.json becomes unwritable after the marker was armed—for example because of a full disk or changed permissions—writeUiState silently swallows the failed clear, but this function still returns the marker and resumes the sessions. The marker therefore remains on disk, so another launch within the 10-minute TTL can resume those sessions again without confirmation, even if the user closed the app to stop them. Clear through the throwing writer and do not consume the marker unless that write succeeds.
AGENTS.md reference: AGENTS.md:L211-L213
Useful? React with 👍 / 👎.
The check icon was only rendered while checked, so toggling moved the box baseline and changed the height of the line the checkbox sits on. Dialogs that lay the checkbox out inline in their body grew or shrank by a few pixels on every toggle. Render the icon always and hide it while unchecked. Quick clicks on the label also selected its text; the control is now unselectable.
Add the update-restart i18n keys the renderer already referenced, carry the confirm checkbox through the browser overlay and ConfirmDialogHost, apply the Checkbox layout fix, and port the remaining tests and the changeset for MoonshotAI#5221.
Screenshots / Recordings
有 4 个会话正在运行时的更新重启确认框(应用内弹窗):列出前 3 个会话、其余计数,下方是默认勾选的继续选项。改动前这里只有一句通用提示,没有会话列表和勾选框。
远程控制同时在运行时,两项提醒在同一个确认框里:会话列表之后另起一段说明远程控制会被中断,勾选项照常显示。改动前更新重启借用的是退出确认框,这种情况只有一句合并提示「还有会话在进行,退出会中断它们;远程控制正在运行,退出客户端会停止远程控制」。
Requirement or Bug
桌面端在有会话正在运行时点「重启并更新」,确认框只笼统提示会话会被中断;重启后这些会话停在中断处,用户得逐个点开手动继续。
本 PR 让更新重启的确认框列出正在运行的会话,并提供一个默认勾选的「重启后继续这些会话」选项。重启完成后,桌面端调用 #5048 引入的
:continue接口自动继续这些会话。Bug Reproduction Steps
N/A
Root Cause
N/A
Code Changes
核心思路:更新重启前,主进程在原有的忙碌探测之外,并行拉一份正在运行的会话列表;标题交给确认框展示,会话 ID 留在主进程。用户确认重启且保留勾选时,updater 在
quitAndInstall之前把这些 ID 连同当前版本号和时间写进 ui-state(下称 marker)。新进程第一次全新启动内嵌 server 时取出并清除 marker;只有版本确实变了、且距写入不超过 10 分钟,才逐个调用POST /api/v1/sessions/{id}:continue。继续失败只记日志,不打扰用户。activity === 'turn'的会话。只有后台任务在跑的会话仍计入忙碌提示,但不列出、不继续pendingSessionContinue){ sessionIds, armedAt, fromVersion },只被消费一次,消费即清除flowchart LR subgraph old["旧进程"] U["更新已下载,用户点重启并更新"] --> Q["退出确认:忙碌探测 + 正在运行的会话列表"] Q -->|标题| D["确认框:应用内 / 浏览器浮层 / 原生弹窗"] D -->|"重启 + 勾选"| P["写 marker:会话 ID、版本、时间"] P --> I["quitAndInstall"] end subgraph new["新进程"] S["首次全新启动内嵌 server"] --> T["取出并清除 marker"] T -->|"版本已变化且 10 分钟内"| C["逐个 POST :continue"] T -->|"版本未变或已过期"| X["丢弃,记日志和遥测"] end I -.->|重启| S要继续的 ID 和确认框里的标题来自同一份列表,所以只会继续用户看到并同意的会话。marker 只在新进程全新启动内嵌 server 时消费,「继续」因此绑定在真正装上新版本的那次启动上;复用已运行的 server、连接失败后重试都不会重复继续。
关键决策
KIMI_SERVER_URL)不消费page_size=1探测,列表只负责展示confirmWithCheckbox在三种确认界面上语义一致,以后的调用方不会在浮层上静默拿到默认值更新安装流程:确认结果从布尔值变成「是否重启 + 要继续的会话」,写 marker 失败不阻止安装。
重启后的消费点:只挂在全新启动内嵌 server 的分支上。
connectOnce if no embedded server is running start embedded server log "connected" + continueSessionsAfterRestart(origin, secret) # fire-and-forget; takes and clears the marker else log "reusing embedded server" restoreRemoteControlOnStartup(...)确认框:共享的
useConfirmDialog新增带勾选框的确认;应用内和浏览器浮层两个界面都渲染勾选框并回传状态。浮层上只有勾选框、没有输入框的对话框,此前确认时不会回传勾选状态,现在和带输入框的对话框一样走表单提交。阅读指南
apps/desktop/src/main/server/session-continue.ts:正在运行的会话列表怎么拉、marker 怎么写,以及重启后的消费和护栏。apps/desktop/src/main/app/quit-confirm.ts:更新重启确认如何组合探测和列表、生成文案,以及应用内和原生两条路径如何把勾选结果映射成会话 ID。apps/desktop/src/main/release/updater.ts和apps/desktop/src/main/server/connect.ts:写 marker 与消费 marker 的位置。apps/desktop/src/renderer/composables/useQuitConfirm.ts、packages/app-client/src/composables/useConfirmDialog.ts:渲染端带勾选框的确认框。BrowserOverlayConfirmHost.vue、BrowserOverlayMenu.vue、apps/desktop/src/main/browser/browser-overlay.ts:浮层确认框的勾选框往返。可以略读:preload / register 的参数透传和校验、
ui-state.ts的 marker 读写、ConfirmDialog.vue的勾选框渲染、i18n 词条、遥测事件定义和测试。Behavior Changes and Affected Users
app-ui的Checkbox,所有用到它的地方)pendingSessionContinueupdate_session_continuearmed/not_updated/expired/attempted受影响模块与测试覆盖:
tests/main/server/session-continue.test.ts覆盖分页、标题截断、写入和清除、写入失败不报 armed、版本与时效护栏、串行继续和单个失败。tests/main/app/ui-state.test.ts覆盖 marker 往返、畸形数据、损坏文件下写入和写入失败上抛。tests/main/app/quit-confirm.test.ts覆盖列表与截断、混有后台任务时只列运行中的会话、列表失败退回通用文案、全部查询失败直接重启、普通退出只发原来的两个请求且没有勾选框,以及应用内和原生两条路径的勾选结果。updater.test.ts、canary-updater.test.ts、preview-release.test.ts、lifecycle.test.ts覆盖确认 → 写 marker → 安装的顺序,写 marker 失败仍安装、取消不写;connect.test.ts、connect-failure-screen.test.ts覆盖只在全新启动时消费一次,复用 server 和启动失败时不消费。useQuitConfirm.test.ts、tests/web/confirm-dialog.test.ts、packages/app-components/test/dialog.test.ts覆盖默认勾选、取消勾选、取消重启从不继续;preload.test.ts、register.test.ts覆盖参数清洗,以及只有严格为true时才转发「继续」。browser-overlay.test.ts、browser-page-dialog-agent.test.ts覆盖只有勾选框的对话框在主进程、浮层页面、确认框宿主三处的往返,以及普通对话框仍拒绝表单提交。验证结论:上面的单测全部通过;另外用本地真实 server 跑过一遍端到端脚本(真实的确认逻辑和 server 接口,原生弹窗用桩代替),覆盖列出并继续(旧 server 分别以 SIGKILL 和 SIGTERM 退出)、混有后台任务时只继续运行中的会话、版本未变时不继续、重试时取消勾选会清掉上一次的选择,5/5 通过。没有验证真实打包后的自动更新安装(需要签名包和更新源),也没有看 Windows / Linux 原生弹窗的外观。
已知限制:
本地检查
pnpm --filter kimi-code-app run typecheck(tsc + vue-tsc)pnpm lint(check-comments、oxlint、guards、ratchet 等)pnpm run check:duplication origin/mainbrowser-aot.test.ts)全部通过Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.