fix(cli): restart safely for automatic updates - #7250
Closed
yiliang114 wants to merge 3 commits into
Closed
Conversation
Contributor
Code Coverage Summary
CLI Package - Full Text ReportCore Package - Full Text ReportFor detailed HTML reports, please see the 'coverage-reports-22.x-ubuntu-latest' artifact from the main CI run. |
This was referenced Jul 19, 2026
Collaborator
Author
|
Superseded by #7322. The replacement keeps the current session running, stages the npm update into an immutable version directory after first render, and activates it on the next ordinary invocation without automatic restart or session-resume machinery. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does
Automatic updates now restart Qwen Code at a safe idle boundary, install the update after the running process has exited, and resume the durable session in the updated CLI. The handoff waits for active turns, queued input, drafts, background work, team or arena sessions, and other in-flight submissions. Unsupported launch modes continue to show manual update instructions.
The relaunch boundary also validates session identifiers, preserves sandbox handoff state, removes conflicting resume and fork options, prevents stale transcripts from being resumed when chat recording is disabled, and falls back safely when a stable launcher or temporary state directory is unavailable.
Why it's needed
Deferring every automatic update until the user exits makes updates feel unreliable and can reopen a session the user intentionally closed. Updating the global installation while the old process is still running is also unsafe because the old process may import chunks that the install just replaced. A supervised restart preserves the immediate update experience without mutating the installation underneath a live process.
Reviewer Test Plan
How to verify
Start an interactive globally installed CLI with automatic updates enabled and an available update. Confirm that an idle session exits, installs the update, starts the updated CLI, and resumes the same recorded conversation without replaying the initial prompt. Confirm that an active turn, draft, queued message, background task, team, or arena session delays the restart until it is safe. Confirm that worktree launches, non-resumable recorded sessions, custom sandbox images, and launchers without a stable shim keep the manual update guidance. Confirm that invalid handoff state cannot add CLI flags and that sandboxed sessions preserve the host handoff.
Evidence (Before & After)
Before: automatic updates were announced as installing only after the user exited the session.
After: supported installations restart and resume immediately at a safe idle boundary; unsupported cases retain manual guidance.
Local verification: 183 focused update/relaunch tests passed, 119 AppContainer tests passed, changed-file lint passed, and the full build and typecheck passed.
Tested on
Environment (optional)
macOS local workspace; wrapper and sandbox boundaries additionally covered by subprocess tests.
Risk & Scope
Linked Issues
N/A
中文说明
本 PR 做了什么
自动更新现在会等待安全的空闲边界,退出正在运行的 Qwen Code,在旧进程结束后安装更新,并由新版本 CLI 恢复持久化会话。交接会等待当前模型轮次、排队输入、未发送草稿、后台工作、Team/Arena 会话以及其他进行中的提交。无法安全重启的启动方式继续显示手动更新提示。
重启边界同时会校验会话 ID、保留 sandbox 的宿主交接状态、移除冲突的 resume/fork 参数、避免在关闭聊天记录时恢复陈旧 transcript,并在缺少稳定 launcher 或临时状态目录不可用时安全回退。
为什么需要
把所有自动更新推迟到用户主动退出,会让更新体验显得不可靠,也可能重新打开用户本来已经结束的会话。另一方面,在旧进程仍运行时原地更新全局安装并不安全,因为旧进程可能继续加载刚被安装过程替换掉的 chunk。由稳定父进程监督重启,可以保留即时更新体验,同时避免修改运行中进程依赖的安装内容。
Reviewer 测试计划
如何验证
使用已全局安装、启用自动更新且存在可用更新的交互式 CLI。确认空闲会话会退出、安装更新、启动新版本并恢复同一个已记录会话,且不会重放初始 prompt。确认活动轮次、草稿、排队消息、后台任务、Team 或 Arena 会话会延迟重启,直到进入安全状态。确认 worktree 启动、无法恢复的已记录会话、自定义 sandbox 镜像以及没有稳定 shim 的 launcher 会保留手动更新提示。确认无效交接状态不能注入 CLI 参数,且 sandbox 会话能保留宿主交接状态。
前后证据
之前:自动更新提示为仅在用户退出会话后安装。
之后:受支持的安装会在安全空闲边界立即重启并恢复会话;不受支持的情况保留手动提示。
本地验证:183 个更新/重启聚焦测试通过,119 个 AppContainer 测试通过,改动文件 lint 通过,完整 build 与 typecheck 通过。
测试平台
环境(可选)
macOS 本地工作区;wrapper 与 sandbox 边界另有子进程测试覆盖。
风险与范围
关联 Issue
无