Skip to content

fix: 修复关闭被控端关闭时,关闭自身无法生效#164

Closed
overflow65537 wants to merge 2 commits intoMistEO:mainfrom
overflow65537:fix/CloseSelf
Closed

fix: 修复关闭被控端关闭时,关闭自身无法生效#164
overflow65537 wants to merge 2 commits intoMistEO:mainfrom
overflow65537:fix/CloseSelf

Conversation

@overflow65537
Copy link
Copy Markdown
Contributor

@overflow65537 overflow65537 commented Apr 9, 2026

close MaaEnd/MaaEnd#1882

Summary by Sourcery

为自闭合的“结束进程(kill process)”任务模式提供支持,并将其集成到实例/任务执行流程中,使应用能在相关任务队列完成后自动退出。

New Features:

  • 为 MXU 的 kill-process 特殊任务引入自闭合模式,可触发前端应用退出。
  • 允许实例和工具栏任务执行在当前任务队列稳定(settle)后,根据自闭合任务模式调度应用退出。
  • 支持在自闭合任务是队列中唯一或最后一个相关任务时,直接从前端退出应用。

Bug Fixes:

  • 确保任务队列的收尾与取消操作能正确清除所有“队列结束后退出”的待处理状态,以避免意外退出。

Enhancements:

  • 按实例跟踪“在任务队列稳定后退出应用”的标志,并在取消或启动失败时将其清除。
  • 扩展任务选择逻辑,使自闭合任务在无连接时也可运行,并从正常的 Maa 任务提交中排除,但仍能影响关闭行为。
  • 允许向正在运行的队列中添加自闭合任务,以在现有队列完成后安排应用退出。
Original summary in English

Summary by Sourcery

Add support for a self-closing "kill process" task mode and integrate it into instance/task execution flows so the app can exit automatically after relevant task queues finish.

New Features:

  • Introduce a self-closing mode for the MXU kill-process special task that can trigger the frontend application to exit.
  • Allow instance and toolbar task execution to schedule application exit after the current task queue settles based on the self-closing task mode.
  • Support directly exiting the application from the frontend when the self-closing task is the only or final relevant task in the queue.

Bug Fixes:

  • Ensure task-queue finalization and cancellation correctly clear any pending exit-after-queue state to avoid unintended exits.

Enhancements:

  • Track per-instance flags to exit the app after task queues settle and clear them on cancellation or startup failures.
  • Extend task selection logic so self-closing tasks can run without a connection and are excluded from normal Maa task submission while still affecting shutdown behavior.
  • Enable adding a self-closing task to a running queue to schedule app exit once the existing queue completes.

Summary by Sourcery

为 MXU kill-process 任务增加自终止变体的支持,并将其接入任务队列的生命周期,以便在相关任务队列完成后应用可以自动退出。

New Features:

  • 引入“特殊任务模式”,将 MXU kill-process 任务视为一种自终止动作,使其可以在没有控制器连接的情况下运行。
  • 允许用户在队列运行期间追加一个自终止任务,使应用在当前队列完成后自动退出。

Enhancements:

  • 调整任务执行流程(实例卡片、工具栏和监视器),以识别并区分退出前任务和自终止任务,并在这些任务完成后调度应用退出。
  • 增加一个共享的 UI 任务服务,用于调度、清除和消费按实例维度的 “exit-after-queue” 标志,并在可用时通过 Tauri 执行直接应用退出。
  • 确保在任务启动失败或监视器取消时清除退出调度,以避免意外关闭应用程序。
Original summary in English

Summary by Sourcery

Add support for a self-termination variant of the MXU kill-process task and wire it into the task queue lifecycle so the app can exit automatically after relevant task queues finish.

New Features:

  • Introduce a special-task mode to treat the MXU kill-process task as a self-termination action that can run without a controller connection.
  • Allow users to append a self-termination task while a queue is running so the app exits after the current queue completes.

Enhancements:

  • Route task execution flows (instance cards, toolbar, and monitor) to recognize and separate pre-exit tasks from the self-termination task, scheduling an app exit once those tasks complete.
  • Add a shared UI task service to schedule, clear, and consume per-instance exit-after-queue flags and to perform a direct app exit via Tauri when available.
  • Ensure exit scheduling is cleared on task start failures or monitor cancellation to avoid unintended application shutdowns.

@overflow65537 overflow65537 marked this pull request as ready for review April 9, 2026 05:15
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - 我在这里给出了一些整体上的反馈:

  • 用于检测 MXU_KILLPROC 自身模式、拆分 tasksBeforeSelfManaged,以及决定是立即退出还是在队列被复制之后再退出的逻辑,在 DashboardView.InstanceCardToolbar 之间存在轻微差异;建议抽取一个共享的辅助方法来封装这部分决策逻辑,以保持行为的一致性,并让未来的演进更容易。
  • finalizeTaskRun 中,exitAppDirectly 会在清理实例状态并消费已计划的退出标记之后被 await;如果退出失败,应用会保持打开状态,且没有重试或用户反馈——建议显式处理返回 false/错误的情况(例如记录一个用户可见的消息,或者重新安排退出),这样自我关闭失败会更容易被发现并加以恢复。
给 AI Agent 的提示
Please address the comments from this code review:

## Overall Comments
- 用于检测 `MXU_KILLPROC` 自身模式、拆分 `tasksBeforeSelfManaged`,以及决定是立即退出还是在队列被复制之后再退出的逻辑,在 `DashboardView.InstanceCard``Toolbar` 之间存在轻微差异;建议抽取一个共享的辅助方法来封装这部分决策逻辑,以保持行为的一致性,并让未来的演进更容易。
-`finalizeTaskRun` 中,`exitAppDirectly` 会在清理实例状态并消费已计划的退出标记之后被 `await`;如果退出失败,应用会保持打开状态,且没有重试或用户反馈——建议显式处理返回 `false`/错误的情况(例如记录一个用户可见的消息,或者重新安排退出),这样自我关闭失败会更容易被发现并加以恢复。

Sourcery 对开源项目是免费的——如果你觉得我们的评审有帮助,欢迎分享给更多人 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的评审。
Original comment in English

Hey - I've left some high level feedback:

  • The logic for detecting MXU_KILLPROC self mode, splitting tasksBeforeSelfManaged, and deciding whether to exit immediately vs. after the queue is duplicated (and slightly diverges) between DashboardView.InstanceCard and Toolbar; consider extracting a shared helper that encapsulates this decision-making to keep behavior consistent and easier to evolve.
  • In finalizeTaskRun, exitAppDirectly is awaited after clearing instance state and consuming the scheduled exit flag; if the exit fails, the app will stay open with no retry or user feedback—consider handling the false/error case explicitly (e.g., logging a user-visible message or re-scheduling) so failures to self-close are more observable and recoverable.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The logic for detecting `MXU_KILLPROC` self mode, splitting `tasksBeforeSelfManaged`, and deciding whether to exit immediately vs. after the queue is duplicated (and slightly diverges) between `DashboardView.InstanceCard` and `Toolbar`; consider extracting a shared helper that encapsulates this decision-making to keep behavior consistent and easier to evolve.
- In `finalizeTaskRun`, `exitAppDirectly` is awaited after clearing instance state and consuming the scheduled exit flag; if the exit fails, the app will stay open with no retry or user feedback—consider handling the `false`/error case explicitly (e.g., logging a user-visible message or re-scheduling) so failures to self-close are more observable and recoverable.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@overflow65537 overflow65537 changed the title feat: 添加关闭自身模式任务支持,优化任务队列结束后的退出逻辑 fix: 修复关闭被控端关闭时,关闭自身无法生效 Apr 9, 2026
overflow65537 and others added 2 commits April 17, 2026 21:03
- Move task-splitting logic into uiTaskService.ts as a shared helper

- Log warning when tasks after kill-self are silently dropped

- Fix exitAppDirectly to return false in non-Tauri environment

- Fix operator precedence readability in DashboardView

- Add trailing newline to uiTaskService.ts

Made-with: Cursor
@MistEO
Copy link
Copy Markdown
Owner

MistEO commented Apr 17, 2026

感谢提交!我已帮你 rebase 到最新的 main 并解决了冲突,同时做了一些小的优化:

  • 把 DashboardView 和 Toolbar 中重复的任务拆分逻辑(找到 kill-self → 分割前置任务/退出调度)抽取到 uiTaskService.tssplitSelfClosingTasks()
  • 修复 exitAppDirectly 在非 Tauri 环境下的返回值语义
  • kill_self 任务之后的任务被静默丢弃时增加了日志警告
  • 移除了未使用的 isAbortError/isTimeoutError

关于合并的考虑:

方案本身能修复 #1882 的问题,但实现方式和项目整体架构的方向有一定距离:

  1. 与 MaaFramework 执行模型耦合过深:当前方案在前端任务提交层面做了拆分(找到 kill-self 任务 → 截断队列 → 调度退出),这要求 MXU 前端对特定任务的语义做硬编码判断。理想情况下,这类"不依赖控制器"的任务应该在更底层(MaaFramework 或 Tauri backend)有对应的执行通道,而非在 UI 层 patch。

  2. task monitor 的状态追踪回退:main 分支已经把任务状态追踪迁移到 Rust 后端(通过 MaaFramework tasker sink 回调),而本 PR 恢复了前端 monitorTaskQueue 的完整轮询逻辑以实现退出调度。这引入了前后端状态管理的冗余。

  3. 扩展性受限:如果后续有更多"不依赖控制器"的特殊任务需要类似处理,当前的硬编码判断方式会导致前端逻辑不断膨胀。

综合考虑,这个 PR 可能暂时不会合入,后续如果需要这个功能,我会在架构层面整体设计一个更通用的方案(比如特殊任务的 execution_mode 标记 + Tauri 层的统一调度)。

再次感谢你的贡献,分析和思路都是对的!

MistEO

This comment was marked as off-topic.

@MistEO
Copy link
Copy Markdown
Owner

MistEO commented Apr 20, 2026

🤖 关了

@MistEO MistEO closed this Apr 20, 2026
@overflow65537 overflow65537 deleted the fix/CloseSelf branch April 20, 2026 17:52
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