Skip to content

fix: delay等逻辑移出action#1190

Merged
MistEO merged 6 commits intomainfrom
fix/action_delay
Mar 6, 2026
Merged

fix: delay等逻辑移出action#1190
MistEO merged 6 commits intomainfrom
fix/action_delay

Conversation

@MistEO
Copy link
Member

@MistEO MistEO commented Mar 6, 2026

Summary by Sourcery

将延迟和等待冻结(wait-freeze)的处理从动作执行器中移至任务运行器,在动作执行周围集中统一时间控制。

Bug Fixes:

  • 确保前置、重复和后置动作的延迟以及冻结等待都在任务层面执行,同时遵守提前停止(early-stop)条件。

Enhancements:

  • 简化 Actuator,使其专注于执行单个动作并记录其结果,将重复与计时相关的逻辑委托给 TaskBase 处理。
Original summary in English

Summary by Sourcery

Move delay and wait-freeze handling from the action executor into the task runner, centralizing timing control around action execution.

Bug Fixes:

  • Ensure pre-, repeat-, and post-action delays and freeze waits are executed at the task level while respecting early-stop conditions.

Enhancements:

  • Simplify the Actuator to focus solely on executing a single action and recording its result, delegating repetition and timing concerns to TaskBase.

Copilot AI review requested due to automatic review settings March 6, 2026 18:37
Copy link
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 - 我发现了 1 个问题,并给出了一些整体层面的反馈:

  • 现在 pre/post 的 wait_freezes 和 delay 调用是在 MaaMsg_Node_Action_Starting/Succeeded|Failed 通知之前/之后执行,而不是像之前那样在 Actuator::run 内部;如果外部使用方依赖于之前的事件触发时机,请考虑这些等待逻辑是否应该仍然围绕实际动作执行本身,而不是围绕通知调用。
  • Actuator::run 在 execute_action 周围不再进行 need_to_stop 检查,而 TaskBase::run_action 则在每次调用 Actuator::run 时增加了这些检查;如果 Actuator::run 在其他地方也被使用,请确认这些调用方仍然能获得预期的“提前停止”行为,或者在 Actuator 内重新引入这些检查。
  • repeat 处理逻辑(pre/repeat/post 的 wait_freezes 和 delays)现在被拆分到了 TaskBase 和 Actuator 两层;为了让职责更清晰,可以考虑把所有与时间/等待相关的逻辑集中到同一层(例如 TaskBase),并让 Actuator::run 只负责一次纯粹的单次执行,而不再关心计时和等待。
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The pre/post wait_freezes and delay calls are now executed before/after the MaaMsg_Node_Action_Starting/Succeeded|Failed notifications instead of being inside Actuator::run; if external consumers rely on the previous event timing, consider whether these waits should remain around the actual action execution instead of around the notifications.
- Actuator::run has lost the need_to_stop checks around execute_action, while TaskBase::run_action adds them around each Actuator::run; if Actuator::run is used anywhere else, ensure that those callers still get the intended early-stop behavior or reintroduce the checks inside Actuator.
- The repeat handling logic (pre/repeat/post wait_freezes and delays) is now split between TaskBase and Actuator; to keep responsibilities clearer, consider centralizing all timing/wait logic in one layer (e.g., TaskBase) and making Actuator::run a pure single-execution helper with no timing concerns.

## Individual Comments

### Comment 1
<location path="source/MaaFramework/Task/TaskBase.cpp" line_range="142-144" />
<code_context>
-    sleep(pipeline_data.pre_delay);
-
-    auto& rt_cache = tasker_->runtime_cache();
-    ActionResult result;
-
-    for (uint i = 0; i < pipeline_data.repeat; ++i) {
</code_context>
<issue_to_address>
**issue:** Potential use of uninitialized `result` when `data.repeat == 0`.

If `data.repeat` can be 0, the loop won't run and `result` will be used uninitialized when building `cb_detail["action_details"]` and as the function return value, leading to undefined behavior. Please either initialize `result` to a default `ActionResult` or handle the `data.repeat == 0` case explicitly (for example, by returning a default `ActionResult` early).
</issue_to_address>

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

Hey - I've found 1 issue, and left some high level feedback:

  • The pre/post wait_freezes and delay calls are now executed before/after the MaaMsg_Node_Action_Starting/Succeeded|Failed notifications instead of being inside Actuator::run; if external consumers rely on the previous event timing, consider whether these waits should remain around the actual action execution instead of around the notifications.
  • Actuator::run has lost the need_to_stop checks around execute_action, while TaskBase::run_action adds them around each Actuator::run; if Actuator::run is used anywhere else, ensure that those callers still get the intended early-stop behavior or reintroduce the checks inside Actuator.
  • The repeat handling logic (pre/repeat/post wait_freezes and delays) is now split between TaskBase and Actuator; to keep responsibilities clearer, consider centralizing all timing/wait logic in one layer (e.g., TaskBase) and making Actuator::run a pure single-execution helper with no timing concerns.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The pre/post wait_freezes and delay calls are now executed before/after the MaaMsg_Node_Action_Starting/Succeeded|Failed notifications instead of being inside Actuator::run; if external consumers rely on the previous event timing, consider whether these waits should remain around the actual action execution instead of around the notifications.
- Actuator::run has lost the need_to_stop checks around execute_action, while TaskBase::run_action adds them around each Actuator::run; if Actuator::run is used anywhere else, ensure that those callers still get the intended early-stop behavior or reintroduce the checks inside Actuator.
- The repeat handling logic (pre/repeat/post wait_freezes and delays) is now split between TaskBase and Actuator; to keep responsibilities clearer, consider centralizing all timing/wait logic in one layer (e.g., TaskBase) and making Actuator::run a pure single-execution helper with no timing concerns.

## Individual Comments

### Comment 1
<location path="source/MaaFramework/Task/TaskBase.cpp" line_range="142-144" />
<code_context>
-    sleep(pipeline_data.pre_delay);
-
-    auto& rt_cache = tasker_->runtime_cache();
-    ActionResult result;
-
-    for (uint i = 0; i < pipeline_data.repeat; ++i) {
</code_context>
<issue_to_address>
**issue:** Potential use of uninitialized `result` when `data.repeat == 0`.

If `data.repeat` can be 0, the loop won't run and `result` will be used uninitialized when building `cb_detail["action_details"]` and as the function return value, leading to undefined behavior. Please either initialize `result` to a default `ActionResult` or handle the `data.repeat == 0` case explicitly (for example, by returning a default `ActionResult` early).
</issue_to_address>

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.

Copy link

@isHarryh isHarryh left a comment

Choose a reason for hiding this comment

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

这集神了!

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

将节点 action 的 delay / wait_freezes / repeat 编排逻辑从 Actuator::run() 移到 TaskBase::run_action(),使 Actuator 更接近“单次执行 action”的职责边界。

Changes:

  • TaskBase::run_action() 中新增 pre/repeat/postwait_freezessleep_for,并在此处实现 repeat 循环
  • Actuator::run() 简化为单次 execute_action() + 写入 runtime_cache

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
source/MaaFramework/Task/TaskBase.cpp 将 action 的 wait/delay/repeat 逻辑上移到 TaskBase 层进行编排
source/MaaFramework/Task/Component/Actuator.cpp 将 Actuator::run 简化为只负责执行一次 action 并缓存结果

@MistEO MistEO force-pushed the fix/action_delay branch from 60fc2fe to 34d33d0 Compare March 6, 2026 19:10
@MistEO MistEO merged commit a2576ee into main Mar 6, 2026
14 checks passed
@MistEO MistEO deleted the fix/action_delay branch March 6, 2026 19:30
MistEO added a commit that referenced this pull request Mar 6, 2026
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.

3 participants