Skip to content

feat(emulator): MuMu 新增「启动前强力清理」开关 - #683

Open
qiyinxi wants to merge 5 commits into
AUTO-MAS-Project:devfrom
qiyinxi:feat/mumu-force-kill-before-launch-20260912
Open

qiyinxi wants to merge 5 commits into
AUTO-MAS-Project:devfrom
qiyinxi:feat/mumu-force-kill-before-launch-20260912

Conversation

@qiyinxi

@qiyinxi qiyinxi commented Sep 11, 2026

Copy link
Copy Markdown
Member

Closes #634

  • MuMu 模拟器配置新增「启动前强力清理」开关(默认关闭):启动实例前先对在线 / 启动中的实例逐个 control shutdown 并等其下线,再复用现有的强力清理结束残留进程;残留进程结束不了时直接报错、不再继续启动。关闭了哪些实例、结束了哪些进程都写进日志
  • 开关关闭时启动流程不变;Emulator 2.0 合成的 MuMu 配置不带该开关,行为不变。清理范围与「强力关闭」相同,是整机的 MuMu 进程,并行跑多个实例的用户不要开——界面提示里写明了
  • 前端在「强力关闭」旁增加同款开关与风险提示(中 / 英 / 日);EmulatorConfig_Info.tsyarn openapi 重新生成

本地验证(D:\MAS\code\trees\mumukill.venv\Scripts\python.exe,基线 35424417a):

  • python -m pytest tests/models tests/tools -q:279 passed;python -m pytest tests --collect-only -q 退出码 0
  • 本地边界测试 9 条(按 tests/AGENTS.md 不提交):开关关闭不发 shutdown、只关在线 / 启动中的实例并按 shutdown → 强力清理 → 启动的顺序执行、shutdown 超时转强力清理、残留进程杀不掉时报错且不启动
  • yarn typecheck / yarn lint 通过;yarn test 453 passed,1 条 backendService.test.ts managed 超时是 dev 基线既有失败
  • 真机(本机 MuMu 6):先起 数据加密是出于什么样的考虑? #2 当已有实例,再带开关起 #0——日志依次为「将关闭 MuMu 实例 2」→ 4 秒后「已在运行的 MuMu 实例均已关闭」→ 强力清理 MuMuNxMain.exe 及子进程共 8 个 → #0 20.9 秒上线;多开器被 MuMu 服务重新拉起后按既有逻辑关掉了窗口。浏览器里开关切换后 /api/emulator/get 返回 ForceKillBeforeLaunch: true
  • 未验证:issue 所述「已有非管理员实例导致管理员启动被拒」的原始报错场景本机复现不了,只验证了清理链本身

🤖 Generated with Claude Code

Sourcery 摘要

新增可选的 MuMu 启动前清理模式,在启动新实例前关闭正在运行的实例并清理残留进程。

新功能:

  • 新增可选的 MuMu 设置,在启动新实例前关闭所有正在运行的实例并清理残留进程。
  • 在模拟器界面中向中文、英文和日文用户展示带有风险警告的新设置。

错误修复:

  • 防止已存在的非管理员实例阻止以提升权限启动 MuMu;当残留进程无法终止时,停止启动操作。

改进:

  • 改进 MuMu 清理报告和进程退出验证;当该设置被禁用时,保持现有行为不变。

文档:

  • 在变更日志中记录新的 MuMu 启动前清理选项。
Original summary in English

Sourcery 摘要

新增可选的 MuMu 启动前清理模式,在启动新实例前关闭活动实例并移除残留进程。

新功能:

  • 新增可选的 MuMu 设置,可在启动前关闭正在运行的实例,并强制清理残留进程。

错误修复:

  • 防止现有的非管理员 MuMu 实例阻止以提升权限启动,并在无法终止残留进程时中止启动。

增强功能:

  • 改进 MuMu 清理报告,并确认目标进程已退出;当该设置被禁用时,保留现有的启动行为。

文档:

  • 在变更日志中记录新的 MuMu 启动前强制清理选项。

日常维护:

  • 通过生成的 API 模型和本地化模拟器配置界面提供新的 MuMu 设置,并在中文、英文和日文界面中添加风险警告。
Original summary in English

Sourcery 摘要

新增可选的 MuMu 启动前清理模式:在启动新实例前关闭现有实例并移除残留进程。

新功能:

  • 新增可选的 MuMu 设置,在启动新实例前关闭所有正在运行的实例并清理残留进程。
  • 在中文、英文和日文模拟器配置界面中显示该设置及其风险警告。

问题修复:

  • 防止残留的 MuMu 实例或进程阻止提权启动;当清理操作无法终止目标进程时,中止启动。

改进:

  • 在禁用新设置时保留现有的启动行为,同时改进清理报告和进程退出验证。

文档:

  • 在更新日志中记录新的 MuMu 启动前强制清理选项。

杂项:

  • 为新设置重新生成模拟器配置 API 模型。
Original summary in English

Sourcery 总结

新增可选的 MuMu 启动前强制清理工作流,以便可靠地启动提升权限的实例,同时避免遗留冲突进程。

新功能:

  • 新增可选的 MuMu 启动模式,在启动新实例前关闭所有活动实例,并强制清理遗留进程。
  • 在模拟器 UI 中为中文、英文和日文用户显示新的 MuMu 设置及风险警告。

错误修复:

  • 防止遗留的或非管理员权限运行的 MuMu 实例阻止提升权限的启动;当所需进程无法终止时中止启动。

改进:

  • 在禁用该选项时保留现有的启动行为,同时改进清理报告和进程退出验证。

文档:

  • 在变更日志中记录新的 MuMu 启动前强制清理选项。

杂项:

  • 针对新设置重新生成模拟器配置 API 模型。
Original summary in English

Sourcery 摘要

为 MuMu 增加启动前强力清理选项,以解决已有实例或残留进程阻碍新实例启动的问题。

新增功能:

  • 为 MuMu 模拟器新增可选的“启动前强力清理”配置,在启动前关闭运行中的实例并清理残留进程。
  • 在中文、英文和日文模拟器配置界面中提供该开关及风险提示。

错误修复:

  • 当残留 MuMu 进程无法终止时阻止新实例继续启动,避免启动状态不可靠。

增强功能:

  • 在启用清理模式时增加实例关闭顺序、进程退出确认和清理结果日志,同时保持关闭开关时的原有启动行为。

文档:

  • 在变更日志中记录 MuMu 启动前强力清理选项。

日常维护:

  • 更新模拟器配置的前后端 API 模型以支持新设置。
Original summary in English

Summary by Sourcery

为 MuMu 增加启动前强力清理选项,以解决已有实例或残留进程阻碍新实例启动的问题。

New Features:

  • 为 MuMu 模拟器新增可选的“启动前强力清理”配置,在启动前关闭运行中的实例并清理残留进程。
  • 在中文、英文和日文模拟器配置界面中提供该开关及风险提示。

Bug Fixes:

  • 当残留 MuMu 进程无法终止时阻止新实例继续启动,避免启动状态不可靠。

Enhancements:

  • 在启用清理模式时增加实例关闭顺序、进程退出确认和清理结果日志,同时保持关闭开关时的原有启动行为。

Documentation:

  • 在变更日志中记录 MuMu 启动前强力清理选项。

Chores:

  • 更新模拟器配置的前后端 API 模型以支持新设置。

已有非管理员权限的 MuMu 实例在跑时,新实例无法以管理员身份启动。
开关打开后,启动前先逐个 shutdown 在线 / 启动中的实例并等其下线,
再复用现有的固定进程白名单强力清理残留进程;残留进程结束不了时
直接报错,不再继续启动。默认关闭,关闭时启动流程不变。

Closes AUTO-MAS-Project#634

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

@sourcery-ai sourcery-ai 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.

Sorry @qiyinxi, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 11 hours and 56 minutes by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Sep 11, 2026

Copy link
Copy Markdown

审查者指南

本 PR 为 MuMu 增加默认关闭的“启动前强力清理”能力:启动前先关闭整机范围内的在线实例,再清理残留进程并确认其退出;清理失败会中止启动。前端提供中英日开关和风险提示,同时保持开关关闭时的原有行为。

MuMu 启动前强力清理时序图

sequenceDiagram
    participant User
    participant Emulator as MuMuEmulator
    participant CLI as MuMuCLI
    participant Processes as MuMuProcesses

    User->>Emulator: open(idx)
    alt ForceKillBeforeLaunch enabled
        Emulator->>CLI: get_device_info(all)
        CLI-->>Emulator: running instances
        loop each online or starting instance
            Emulator->>CLI: control -v index shutdown
        end
        Emulator->>CLI: get_device_info(all)
        CLI-->>Emulator: all instances offline
        Emulator->>Processes: _force_kill_mumu_processes()
        Processes-->>Emulator: targeted processes
        Emulator->>Processes: _wait_processes_exit()
        alt residual process remains
            Emulator-->>User: RuntimeError
        else cleanup succeeds
            Emulator->>Emulator: launch instance
            Emulator-->>User: DeviceInfo
        end
    else ForceKillBeforeLaunch disabled
        Emulator->>Emulator: launch instance
        Emulator-->>User: DeviceInfo
    end
Loading

MuMu 启动前清理失败处理流程图

flowchart TD
    A["MuMu open(idx)"] --> B{"ForceKillBeforeLaunch enabled?"}
    B -- No --> E["Existing launch flow"]
    B -- Yes --> C["List online or starting instances"]
    C --> D["control shutdown each instance"]
    D --> F{"All instances offline?"}
    F -- No --> G["Wait timeout, then force cleanup"]
    F -- Yes --> H["Force-kill MuMu processes"]
    G --> H
    H --> I["Wait for targeted processes to exit"]
    I --> J{"Any process still alive?"}
    J -- Yes --> K["Raise RuntimeError; do not launch"]
    J -- No --> L["Launch requested instance"]
Loading

文件级变更

变更 详情 文件
新增 MuMu 启动前强力清理流程,并在清理失败时阻止启动。
  • 新增默认关闭的配置项及 OpenAPI/前端模型映射。
  • 启动前枚举在线或启动中的实例,逐个执行 control shutdown 并等待下线。
  • 复用 MuMu 进程白名单清理残留进程,等待进程实际退出;仍存活时抛出错误。
  • 保留关闭开关时的原有启动流程,并记录实例关闭、进程清理及失败信息。
app/models/config.py
app/models/schema.py
app/utils/emulator/mumu.py
frontend/src/api/models/EmulatorConfig_Info.ts
在 MuMu 配置界面增加启动前清理开关及多语言风险提示。
  • 在强力关闭设置旁新增开关,仅对 MuMu 显示。
  • 支持中/英/日文案,明确会关闭全部实例、可能丢失未保存数据及不适用于多开场景。
  • 接入配置读取与保存,默认关闭以保持既有行为。
frontend/src/views/Emulator.vue
frontend/src/i18n/locales/zh-CN.ts
frontend/src/i18n/locales/en-US.ts
frontend/src/i18n/locales/ja-JP.ts
更新版本与变更记录,说明新功能及其适用风险。
  • 在 CHANGELOG 中记录 MuMu 启动前强力清理功能。
  • 更新版本元数据。
CHANGELOG.md
res/version.json

可能关联的 issue


提示与命令

与 Sourcery 交互

  • 触发新的审查: 在 pull request 中评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审查评论。
  • 根据审查评论生成 GitHub issue: 回复审查评论,请 Sourcery 根据该评论创建 issue。你也可以使用 @sourcery-ai issue 回复审查评论,以便根据该评论创建 issue。
  • 生成 pull request 标题: 在 pull request 标题的任意位置写入 @sourcery-ai,即可随时生成标题。你也可以在 pull request 中评论 @sourcery-ai title,以便随时生成或重新生成标题。
  • 生成 pull request 摘要: 在 pull request 正文中任意位置写入 @sourcery-ai summary,即可在指定位置随时生成 PR 摘要。你也可以在 pull request 中评论 @sourcery-ai summary,以便随时生成或重新生成摘要。
  • 生成审查者指南: 在 pull request 中评论 @sourcery-ai guide,即可随时生成或重新生成审查者指南。
  • 解决所有 Sourcery 评论: 在 pull request 中评论 @sourcery-ai resolve,即可解决所有 Sourcery 评论。如果你已经处理完所有评论且不想再看到它们,这一功能会非常有用。
  • 忽略所有 Sourcery 审查: 在 pull request 中评论 @sourcery-ai dismiss,即可忽略所有现有的 Sourcery 审查。如果你想从头开始新的审查,这一功能尤其有用——别忘了评论 @sourcery-ai review 来触发新的审查!

自定义使用体验

访问你的控制面板

  • 启用或禁用审查功能,例如 Sourcery 生成的 pull request 摘要、审查者指南等。
  • 更改审查语言。
  • 添加、删除或编辑自定义审查指令。
  • 调整其他审查设置。

获取帮助

Original review guide in English

Reviewer's Guide

本 PR 为 MuMu 增加默认关闭的“启动前强力清理”能力:启动前先关闭整机范围内的在线实例,再清理残留进程并确认其退出;清理失败会中止启动。前端提供中英日开关和风险提示,同时保持开关关闭时的原有行为。

Sequence diagram for MuMu force cleanup before launch

sequenceDiagram
    participant User
    participant Emulator as MuMuEmulator
    participant CLI as MuMuCLI
    participant Processes as MuMuProcesses

    User->>Emulator: open(idx)
    alt ForceKillBeforeLaunch enabled
        Emulator->>CLI: get_device_info(all)
        CLI-->>Emulator: running instances
        loop each online or starting instance
            Emulator->>CLI: control -v index shutdown
        end
        Emulator->>CLI: get_device_info(all)
        CLI-->>Emulator: all instances offline
        Emulator->>Processes: _force_kill_mumu_processes()
        Processes-->>Emulator: targeted processes
        Emulator->>Processes: _wait_processes_exit()
        alt residual process remains
            Emulator-->>User: RuntimeError
        else cleanup succeeds
            Emulator->>Emulator: launch instance
            Emulator-->>User: DeviceInfo
        end
    else ForceKillBeforeLaunch disabled
        Emulator->>Emulator: launch instance
        Emulator-->>User: DeviceInfo
    end
Loading

Flow diagram for MuMu pre-launch cleanup failure handling

flowchart TD
    A["MuMu open(idx)"] --> B{"ForceKillBeforeLaunch enabled?"}
    B -- No --> E["Existing launch flow"]
    B -- Yes --> C["List online or starting instances"]
    C --> D["control shutdown each instance"]
    D --> F{"All instances offline?"}
    F -- No --> G["Wait timeout, then force cleanup"]
    F -- Yes --> H["Force-kill MuMu processes"]
    G --> H
    H --> I["Wait for targeted processes to exit"]
    I --> J{"Any process still alive?"}
    J -- Yes --> K["Raise RuntimeError; do not launch"]
    J -- No --> L["Launch requested instance"]
Loading

File-Level Changes

Change Details Files
新增 MuMu 启动前强力清理流程,并在清理失败时阻止启动。
  • 新增默认关闭的配置项及 OpenAPI/前端模型映射。
  • 启动前枚举在线或启动中的实例,逐个执行 control shutdown 并等待下线。
  • 复用 MuMu 进程白名单清理残留进程,等待进程实际退出;仍存活时抛出错误。
  • 保留关闭开关时的原有启动流程,并记录实例关闭、进程清理及失败信息。
app/models/config.py
app/models/schema.py
app/utils/emulator/mumu.py
frontend/src/api/models/EmulatorConfig_Info.ts
在 MuMu 配置界面增加启动前清理开关及多语言风险提示。
  • 在强力关闭设置旁新增开关,仅对 MuMu 显示。
  • 支持中/英/日文案,明确会关闭全部实例、可能丢失未保存数据及不适用于多开场景。
  • 接入配置读取与保存,默认关闭以保持既有行为。
frontend/src/views/Emulator.vue
frontend/src/i18n/locales/zh-CN.ts
frontend/src/i18n/locales/en-US.ts
frontend/src/i18n/locales/ja-JP.ts
更新版本与变更记录,说明新功能及其适用风险。
  • 在 CHANGELOG 中记录 MuMu 启动前强力清理功能。
  • 更新版本元数据。
CHANGELOG.md
res/version.json

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@Craun718

Copy link
Copy Markdown
Member

@qiyinxi 版本再更新一下

解决 CHANGELOG.md / res/version.json 冲突:以 dev 当前内容为准,
把本 PR 的一条 changelog 记录重新放进顶部未发布版本段的「新增」下,
再运行 python scripts/changelog.py sync 重新生成 res/version.json。

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
dev 已把顶部未发布段改为 v5.5.0-beta.6。自动合并把本 PR 的 changelog 记录留在了
已发布的 beta.4 段里,手动移回 beta.6 未发布段的「新增」下,并重新 sync。

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@qiyinxi

qiyinxi commented Sep 13, 2026

Copy link
Copy Markdown
Member Author

@Craun718 看了一下,现在能直接合,不用动:b65639f9 已经合进 dev 当前头(1c62358c),记录在 v5.5.0-beta.6 - 未发布 的「新增」下只有一条,changelog.py check 与 CI 两项检查都过,四处版本号与 dev 一致。
未验证:前端(本地没装依赖)。

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