Skip to content

feat(desktop): continue running sessions after an update restart - #5221

Merged
wbxl2000 merged 2 commits into
mainfrom
feat/desktop-update-continue-sessions
Nov 23, 2026
Merged

wbxl2000 merged 2 commits into
mainfrom
feat/desktop-update-continue-sessions

Conversation

@wbxl2000

@wbxl2000 wbxl2000 commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Screenshots / Recordings

有 4 个会话正在运行时的更新重启确认框(应用内弹窗):列出前 3 个会话、其余计数,下方是默认勾选的继续选项。改动前这里只有一句通用提示,没有会话列表和勾选框。

English 中文
Update restart confirmation listing running sessions 更新重启确认框列出正在运行的会话

远程控制同时在运行时,两项提醒在同一个确认框里:会话列表之后另起一段说明远程控制会被中断,勾选项照常显示。改动前更新重启借用的是退出确认框,这种情况只有一句合并提示「还有会话在进行,退出会中断它们;远程控制正在运行,退出客户端会停止远程控制」。

English 中文
Update restart confirmation listing running sessions with the Remote Control notice 更新重启确认框列出会话并提示远程控制

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。继续失败只记日志,不打扰用户。

概念 回答什么问题 本 PR 之后
正在运行的会话 哪些会话会被重启打断、又能被继续 忙碌列表里 activity === 'turn' 的会话。只有后台任务在跑的会话仍计入忙碌提示,但不列出、不继续
marker(ui-state 的 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
Loading

要继续的 ID 和确认框里的标题来自同一份列表,所以只会继续用户看到并同意的会话。marker 只在新进程全新启动内嵌 server 时消费,「继续」因此绑定在真正装上新版本的那次启动上;复用已运行的 server、连接失败后重试都不会重复继续。

关键决策

决策 选择 没选 理由
继续哪些会话 确认框展示时那份列表的 ID,随用户的回答交给 updater 写 marker 前再拉一次列表 只继续用户看到并同意的;确认之后才开始的会话不会被顺带继续
重启后的护栏 版本号必须变化,且 10 分钟内有效 无条件继续 更新没真正装上(比如安装失败后普通重启),或很久之后才启动时,不该突然继续旧任务
消费时机 本进程首次全新启动内嵌 server 时 每次连上 server 时 复用 server 或重试连接不会重复继续;外部 server 模式(KIMI_SERVER_URL)不消费
继续方式 串行调用,失败只记日志 并发调用;重启后弹提示 重启后不弹提示是产品决定;串行避免同时拉起多个 turn
goal 会话 只继续当前 turn,goal 保持暂停 同时恢复 goal 产品决定
忙碌判定 保留原来的 page_size=1 探测,列表只负责展示 用列表结果判定是否忙碌 列表失败或超时(整体 1.5 s)时仍能提示会话在运行,只是不列标题、不显示勾选框
浏览器浮层上的确认框 浮层确认框补上勾选框并回传勾选状态 浮层激活时改走原生弹窗 confirmWithCheckbox 在三种确认界面上语义一致,以后的调用方不会在浮层上静默拿到默认值

更新安装流程:确认结果从布尔值变成「是否重启 + 要继续的会话」,写 marker 失败不阻止安装。

 on(user clicks Restart & Update)
-  blocked = shouldBlockQuit()            # failure → not blocked
-  if blocked: return
+  decision = confirmRestart()            # { proceed, continueSessionIds }; failure → proceed, continue nothing
+  if not decision.proceed: return
+  try prepareSessionContinue(decision.continueSessionIds)   # write the marker, or clear it when empty
+  catch: warn "sessions will not continue after the update restart"
   markQuitting()
   quitAndInstall()

重启后的消费点:只挂在全新启动内嵌 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 新增带勾选框的确认;应用内和浏览器浮层两个界面都渲染勾选框并回传状态。浮层上只有勾选框、没有输入框的对话框,此前确认时不会回传勾选状态,现在和带输入框的对话框一样走表单提交。

 useConfirmDialog()
   confirm(options)
+  confirmWithCheckbox(options & { checkbox })   # → { confirmed, checked }
+  setCheckboxChecked(checked)
 <ConfirmDialogHost>                 # in-app surface
   <ConfirmDialog>
+    <Checkbox v-if="checkbox" />
 <BrowserOverlayConfirmHost>         # browser overlay surface
-  show({ title, message, ... })
+  show({ title, message, ..., checkbox })
+  onConfirm(value, checked) → setCheckboxChecked(checked)
 BrowserOverlayMenu.activate(confirm | cancel)
-  if dialog has input: submitForm({ value, checked })
+  if dialog has input or checkbox: submitForm({ value, checked })
 main submitBrowserOverlayForm
-  refuse dialogs without input
+  refuse dialogs without input and checkbox

阅读指南

  1. apps/desktop/src/main/server/session-continue.ts:正在运行的会话列表怎么拉、marker 怎么写,以及重启后的消费和护栏。
  2. apps/desktop/src/main/app/quit-confirm.ts:更新重启确认如何组合探测和列表、生成文案,以及应用内和原生两条路径如何把勾选结果映射成会话 ID。
  3. apps/desktop/src/main/release/updater.ts 和 apps/desktop/src/main/server/connect.ts:写 marker 与消费 marker 的位置。
  4. apps/desktop/src/renderer/composables/useQuitConfirm.ts、packages/app-client/src/composables/useConfirmDialog.ts:渲染端带勾选框的确认框。
  5. 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

行为 之前 之后 谁依赖旧行为 退路
有会话正在运行时的更新重启确认文案 通用提示「会话仍在运行,重启会中断」 列出前 3 个会话标题,其余显示「以及其他 N 个会话」;标题取会话标题,没有则取最后一条提问 所有自动更新的 desktop 用户(macOS / Windows / Linux,正式版与 Canary) 列表拉取失败或超时时退回原通用文案
更新重启确认框的勾选框 无 「重启后继续这些会话」,默认勾选;只在列出了会话时出现 同上 取消勾选即与之前一致
远程控制在运行时的更新重启提示 借用退出确认框;有会话在跑时和会话提示合成一句「……远程控制正在运行,退出客户端会停止远程控制」 同一个确认框里,在会话列表(或通用提示)之后另起一段「远程控制正在运行,重启会中断远程控制」;只有远程控制在运行时只显示这一句,不出现勾选框 开着远程控制、自动更新的 desktop 用户 无
重启后的会话 停在中断处 勾选时,新版本首次启动内嵌 server 后逐个继续当前 turn;goal 保持暂停 习惯重启后先检查再手动继续的用户 取消勾选
只有后台任务在跑的会话 计入忙碌提示 仍计入忙碌提示,但不列出、不继续 无 无
更新重启确认的查询请求 1 个忙碌探测请求 探测加并行的列表请求(每页 100 条、最多 10 页,共用 1.5 s 超时) 无 无
普通退出(Cmd+Q、关窗口)的确认 — 不变:同样的请求、文案和返回语义,没有勾选框 — —
浏览器浮层上只有勾选框的对话框 确认时不回传勾选状态 走表单提交,回传勾选状态;不带输入框和勾选框的对话框仍拒绝表单提交 无现有调用方(此前唯一带勾选框的浮层对话框是批注框,它本身有输入框) 无
共享勾选框(app-ui 的 Checkbox,所有用到它的地方) 对勾只在勾选时渲染,确认框这类把勾选框放在正文行内的地方,每次切换弹窗高度变化约 2.5 px;快速点击会选中标签文字 对勾始终渲染、未勾选时隐藏,切换不再改变高度;整个控件不可选中文字 无 无
ui-state 新字段 pendingSessionContinue — 更新重启时写入,下次全新启动内嵌 server 时清除 降级到旧版本:旧版本忽略该字段 —
新遥测事件 update_session_continue — outcome 取值:armed / not_updated / expired / attempted — —

受影响模块与测试覆盖:

  • 会话列表、marker 和重启后继续:tests/main/server/session-continue.test.ts 覆盖分页、标题截断、写入和清除、写入失败不报 armed、版本与时效护栏、串行继续和单个失败。tests/main/app/ui-state.test.ts 覆盖 marker 往返、畸形数据、损坏文件下写入和写入失败上抛。
  • 更新重启确认:tests/main/app/quit-confirm.test.ts 覆盖列表与截断、混有后台任务时只列运行中的会话、列表失败退回通用文案、全部查询失败直接重启、普通退出只发原来的两个请求且没有勾选框,以及应用内和原生两条路径的勾选结果。
  • updater 与接线: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 和启动失败时不消费。
  • 渲染端与 IPC: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 覆盖只有勾选框的对话框在主进程、浮层页面、确认框宿主三处的往返,以及普通对话框仍拒绝表单提交。
  • 共享勾选框:jsdom 不做布局,没有加单测。在 dev 渲染页的真实样式下打开更新重启确认框实测,修复前勾选 / 未勾选时弹窗高 255.6 / 258.1 px,修复后都是 255.6 px;用系统 Chrome 真实双击标签,修复后没有选中文字,恢复旧样式的对照组会选中。

验证结论:上面的单测全部通过;另外用本地真实 server 跑过一遍端到端脚本(真实的确认逻辑和 server 接口,原生弹窗用桩代替),覆盖列出并继续(旧 server 分别以 SIGKILL 和 SIGTERM 退出)、混有后台任务时只继续运行中的会话、版本未变时不继续、重试时取消勾选会清掉上一次的选择,5/5 通过。没有验证真实打包后的自动更新安装(需要签名包和更新源),也没有看 Windows / Linux 原生弹窗的外观。

已知限制:

  • macOS 上更新包还没交给系统安装器时,点「重启并更新」后应用会多停留几秒;这期间用户手动停掉的列表内会话,重启后仍会被继续。
  • 确认框显示在浏览器浮层时,如果浏览器面板在确认前被关掉,确认框会回到应用内弹窗,浮层上刚改过的勾选状态恢复成改之前的值(界面上可见,不会静默生效)。
本地检查
  • pnpm --filter kimi-code-app run typecheck(tsc + vue-tsc)
  • pnpm lint(check-comments、oxlint、guards、ratchet 等)
  • pnpm run check:duplication origin/main
  • 受影响的 23 个测试文件(含 browser-aot.test.ts)全部通过
  • 去掉浮层改动后,新增的 3 个浮层测试全部失败,恢复后通过

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: issue must have a maintainer's /approve).
  • I have added tests that prove my feature works.
  • The behavior-change table above is complete, and every removed behavior or flipped default is named in the changeset and either has an escape hatch or was explicitly approved by a maintainer in this PR.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

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-bot

changeset-bot Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0df3825

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
kimi-code-app Patch

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T11:08:46.555369Z ad00580 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pkg-pr-new

pkg-pr-new Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@0df3825
npx https://pkg.pr.new/@moonshot-ai/kimi-code@0df3825

commit: 0df3825

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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.
@wbxl2000
wbxl2000 merged commit ec6f58c into main Nov 23, 2026
32 of 33 checks passed
@wbxl2000
wbxl2000 deleted the feat/desktop-update-continue-sessions branch November 23, 2026 06:47
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 24, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants