Skip to content

fix: 修复任务停止后的队列收尾与跨客户端重启 - #444

Open
MistEO wants to merge 1 commit into
mainfrom
codex/fix-stop-restart-task-lifecycle
Open

MistEO wants to merge 1 commit into
mainfrom
codex/fix-stop-restart-task-lifecycle

Conversation

@MistEO

@MistEO MistEO commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Agent 调用 PostStop 时,MaaFramework 可能拒绝新任务并返回 ID 0;MXU 原先仍把它登记为 pending。控制器断开时,停止标记也可能无法入队,留下 Running 状态和本轮 Agent 子进程。单任务和批量入口现在只登记有效任务 ID,并回收被原生 Stop 丢弃的队列。

每轮增加独立的 idle 检查,处理最后一次普通回调之后发生 Stop、没有后续回调的情况。Start 准入和 Agent 注册后的提交阶段检查旧队列,等待本轮清理再开放下一轮。观察器按实例和轮次隔离,迟到的停止标记不能影响新队列;普通 Stop 仍复用健康 controller。

Web 客户端等待停止时每 800 ms 重发 Stop,可能取消另一客户端刚开始的新队列。现在每次停止操作只发一次请求,成功读到 idle 后才清理前端状态,状态查询失败继续等待。

基于 main c321532,与 #434 head 21494a8 对照。独立复审发现并修复了最后一次回调后的漏收尾窗口,以及新实现中的 Start 取锁、同 ID 实例重建和连续状态查询竞态;最终复审无阻塞问题。

验证:

  • 官方 MaaFramework v5.16.0 的 Windows x64 回归通过。涵盖整批拒绝、正常追加、Agent Stop、旧标记、重复 Stop 后立即 Start、断连导致停止标记失败、最后普通回调之后 Stop、已有 completion 的追加尾项、Start 先于空闲检测和实例销毁重建。用独立 Windows 进程句柄检查子进程退出。
  • pnpm test:123 passed、1 skipped,包含 4 个 Web Stop 回归。前端 build、格式和 Rust 格式检查通过。
  • Rust 库测试:95 passed、1 ignored。本机基线测试 EXE 同样存在 0xc0000139 加载问题,为临时 EXE 副本嵌入 Common Controls v6 manifest 后执行,未修改应用清单。
  • 与独立的 pretask、截图补丁组合后,前端 123 项、浏览器 26 项、build 和 cargo check --all-targets --locked 通过。

可复跑原生测试和依赖说明位于 tests/windows/task-stop-lifecycle。fixture 直接调用真实 Tasker API;异步追加窗口使用真实 submission permit 和原生 post 模拟 Agent 注册结束后的状态。完整 Agent IPC、真实游戏、设备与打包桌面 UI 未验证。

Sourcery 总结

强化原生客户端和 Web 客户端中任务停止与重启的生命周期管理,确保被拒绝或已放弃的队列能够安全清理,同时不影响后续运行。

Bug 修复:

  • 防止停止过程中被拒绝的任务被记录为有效待处理任务,并确保已放弃的队列能够完成处理并清理。
  • 处理原生回调缺失或延迟到达时的停止完成逻辑,包括最后一个普通回调完成后的清理以及控制器断开连接的情况。
  • 按实例和运行代次隔离停止处理,避免过期的停止事件影响替换后的队列。
  • 使 Web 停止请求仅发送一次,并在确认进入空闲状态后再清除状态或允许重启。

功能增强:

  • 协调任务启动准入与已放弃队列的清理,并在必要时安全地重建任务器实例。

文档:

  • 添加说明,介绍如何针对 MaaFramework 复现 Windows 原生任务停止/重启回归问题。

测试:

  • 添加 Web 和 Windows 回归测试,覆盖提交被拒绝、停止/重启竞态、回调缺失、停止事件延迟到达、已放弃队列清理以及同 ID 实例替换等情况。
Original summary in English

Summary by Sourcery

Harden task stopping and restart lifecycle across native and web clients so rejected or abandoned queues are cleaned up safely without affecting subsequent runs.

Bug Fixes:

  • Prevent tasks rejected during stopping from being recorded as valid pending work and ensure abandoned queues are finalized and cleaned up.
  • Handle stop completion when native callbacks are missing or arrive late, including cleanup after the final ordinary callback and controller disconnects.
  • Isolate stop handling by instance and run generation so stale stop events cannot affect replacement queues.
  • Make web stop requests single-shot and wait for confirmed idle before clearing state or allowing a restart.

Enhancements:

  • Coordinate task start admission with abandoned-queue cleanup and safely rebuild tasker instances when necessary.

Documentation:

  • Add instructions for reproducing native Windows task stop/restart regressions against MaaFramework.

Tests:

  • Add Web and Windows regression coverage for rejected submissions, stop/restart races, missing callbacks, late stop events, abandoned queue cleanup, and same-ID instance replacement.

AI 使用信息:

  • Agent:Codex
  • 模型:gpt-6-astra(实现与内部复审),gpt-6.1-sol(额外交叉审查)
  • 思考强度:ultra(实现与内部复审),max(额外交叉审查)

@MistEO
MistEO marked this pull request as ready for review November 11, 2026 08:43
Copilot AI balanced review requested due to automatic review settings November 11, 2026 08:43
@sourcery-ai

sourcery-ai Bot commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

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

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 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-11T08:45:28.820348Z 3410694 Draft marked ready
ℹ️ 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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

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