Skip to content

fix(maafw): 只关自己开起来的模拟器 - #632

Closed
qiyinxi wants to merge 2 commits into
AUTO-MAS-Project:devfrom
qiyinxi:fix/maafw-emulator-close-20260909
Closed

fix(maafw): 只关自己开起来的模拟器#632
qiyinxi wants to merge 2 commits into
AUTO-MAS-Project:devfrom
qiyinxi:fix/maafw-emulator-close-20260909

Conversation

@qiyinxi

@qiyinxi qiyinxi commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

MFW 内置运行无条件把 opened_emulator 置为 True,收尾时连用户自己开着的模拟器一起关掉。

改成先查状态:getStatus() == ONLINE 说明本来就在跑,只连接、不接管生命周期;查询失败按「不是我开的」处理,宁可少关一次。

app/task/MaaFW/tools/embedded/runner_task.py,+16/-3。

本地:pytest tests -q 710 passed / 3 skipped,--collect-only 退出码 0。

🤖 Generated with Claude Code

Sourcery 摘要

在继续管理由 AUTO-MAS 启动的实例的同时,保留用户启动的模拟器的生命周期。

错误修复:

  • 防止 MFW 关闭任务开始前已运行的模拟器实例。
  • 保守处理模拟器状态检查失败的情况,避免误关闭现有实例。
Original summary in English

Summary by Sourcery

Preserve the lifecycle of user-started emulators while continuing to manage instances launched by AUTO-MAS.

Bug Fixes:

  • Prevent MFW from closing emulator instances that were already running before the task started.
  • Treat emulator status-check failures conservatively so existing instances are not mistakenly shut down.

qiyinxi and others added 2 commits September 9, 2026 01:03
`opened_emulator` 原来在调 `open()` 前无条件置真,收尾的 `_close_emulator()` 只看这个
标记——于是用户自己开着的模拟器,跑完一轮任务就被 MAS 关掉了。模拟器开关在 Windows
上还要过 UAC,被误关一次的代价不只是「再开一次」。

改成先查一次 `getStatus()`:已经 ONLINE 就只连接、不接管生命周期;查状态本身失败时按
「不是我开的」处理——宁可少关一次,也不误关别人的。日志也跟着分开,本来就开着时不再
误报「正在启动模拟器」。

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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 3 days and 12 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Sep 8, 2026

Copy link
Copy Markdown
审查者指南(小型 PR 中折叠显示)

审查者指南

MFW 启动模拟器前先查询其在线状态:已运行的实例仅连接、不接管生命周期;只有确认原先未运行时才标记为 AUTO-MAS 启动并在任务结束时关闭,查询失败则采取保守策略避免误关用户实例。

MFW 模拟器所有权与清理流程图

sequenceDiagram
    participant RunnerTask
    participant EmulatorManager
    participant Emulator

    RunnerTask->>EmulatorManager: getStatus(emulator_index)
    alt status is DeviceStatus.ONLINE
        EmulatorManager-->>RunnerTask: DeviceStatus.ONLINE
        RunnerTask->>RunnerTask: opened_emulator = False
        RunnerTask->>EmulatorManager: open(emulator_index)
        EmulatorManager->>Emulator: connect
    else status is not ONLINE or query fails
        EmulatorManager-->>RunnerTask: unavailable or other status
        RunnerTask->>RunnerTask: opened_emulator = True
        RunnerTask->>EmulatorManager: open(emulator_index)
        EmulatorManager->>Emulator: start and connect
    end
    RunnerTask-->>Emulator: close only when opened_emulator is True
Loading

文件级变更

变更 详情 文件
改为根据模拟器当前状态决定是否接管其生命周期,避免关闭用户预先启动的实例。
  • 调用 getStatus() 检查目标模拟器是否在线
  • 在线时仅连接并记录日志,不将实例标记为本次启动
  • 状态查询失败按非本次启动处理,降低误关闭风险
  • 仅在确认原先未运行时设置 opened_emulator 并允许收尾关闭
app/task/MaaFW/tools/embedded/runner_task.py
补充本次模拟器生命周期修复的变更记录。
  • 在修复章节说明仅关闭 AUTO-MAS 自己启动的实例
CHANGELOG.md
更新项目版本信息。
  • 调整版本元数据以反映本次修复
res/version.json

提示与命令

与 Sourcery 交互

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

自定义你的体验

访问你的控制面板即可:

  • 启用或禁用审查功能,例如 Sourcery 生成的拉取请求摘要、审查者指南等。
  • 更改审查语言。
  • 添加、移除或编辑自定义审查说明。
  • 调整其他审查设置。

获取帮助

Original review guide in English
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

MFW 启动模拟器前先查询其在线状态:已运行的实例仅连接、不接管生命周期;只有确认原先未运行时才标记为 AUTO-MAS 启动并在任务结束时关闭,查询失败则采取保守策略避免误关用户实例。

Sequence diagram for MFW emulator ownership and cleanup

sequenceDiagram
    participant RunnerTask
    participant EmulatorManager
    participant Emulator

    RunnerTask->>EmulatorManager: getStatus(emulator_index)
    alt status is DeviceStatus.ONLINE
        EmulatorManager-->>RunnerTask: DeviceStatus.ONLINE
        RunnerTask->>RunnerTask: opened_emulator = False
        RunnerTask->>EmulatorManager: open(emulator_index)
        EmulatorManager->>Emulator: connect
    else status is not ONLINE or query fails
        EmulatorManager-->>RunnerTask: unavailable or other status
        RunnerTask->>RunnerTask: opened_emulator = True
        RunnerTask->>EmulatorManager: open(emulator_index)
        EmulatorManager->>Emulator: start and connect
    end
    RunnerTask-->>Emulator: close only when opened_emulator is True
Loading

File-Level Changes

Change Details Files
改为根据模拟器当前状态决定是否接管其生命周期,避免关闭用户预先启动的实例。
  • 调用 getStatus() 检查目标模拟器是否在线
  • 在线时仅连接并记录日志,不将实例标记为本次启动
  • 状态查询失败按非本次启动处理,降低误关闭风险
  • 仅在确认原先未运行时设置 opened_emulator 并允许收尾关闭
app/task/MaaFW/tools/embedded/runner_task.py
补充本次模拟器生命周期修复的变更记录。
  • 在修复章节说明仅关闭 AUTO-MAS 自己启动的实例
CHANGELOG.md
更新项目版本信息。
  • 调整版本元数据以反映本次修复
res/version.json

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

@qiyinxi

qiyinxi commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

误提,撤回。

@qiyinxi qiyinxi closed this Sep 9, 2026
@qiyinxi
qiyinxi deleted the fix/maafw-emulator-close-20260909 branch September 9, 2026 07:58
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.

1 participant