Repository navigation
Fix cancelling or killing a task while it is interrupted - #153
Open
HappySamuel wants to merge 1 commit into
Open
HappySamuel wants to merge 1 commit into
HappySamuel wants to merge 1 commit into
Conversation
When a task is interrupted, Task::Active keeps the active phase's Resume in _resume_phase. If the task is then cancelled or killed, the active phase finishes, but _begin_next_stage() returned at the interruption check before reaching the code that clears _resume_phase. As a result: * the cancellation sequence (or _finish_task() for a kill) never ran, so the task stayed stuck until it was resumed, and * resuming the task called the finished phase's Resume, restarting the phase that had just been cancelled. Clear _resume_phase before the interruption check, so resuming a task whose interrupted phase has finished moves on to the cancellation sequence or finishes the task. In the Resume callback, also skip the phase's own Resume when that phase was cancelled or killed. Dropping a stale Resume still triggers it (Resume fires on destruction), so events must ignore a resume that arrives after they have finished. The mock activity used by the tests now does that, matching the fleet adapter events once open-rmf/rmf_ros2 guards them the same way. Adds tests for cancelling and for killing an interrupted task. Signed-off-by: HappySamuel <18137963+HappySamuel@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug fix
Fixed bug
Fixes #150: cancelling or killing a task while it is interrupted leaves the task stuck, and resuming it afterwards restarts the phase that was cancelled.
Must be merged together with open-rmf/rmf_ros2#576 (see "Why two PRs" below).
Fix applied
In
Task::Active(rmf_task_sequence), an interrupted task keeps the active phase'sResumein_resume_phase. When the task is then cancelled or killed, the phase finishes, but_begin_next_stage()returns at the interruption check before reaching the code that clears_resume_phase. So:_finish_task()for a kill) never runs, andResume, restarting the cancelled phase.Changes:
_begin_next_stage()clears_resume_phasebefore the interruption check. Resuming a task whose interrupted phase already finished then moves on to the cancellation sequence or finishes the task. This is what the existing comment ("the phase that we tried to interrupt finished instead of being interrupted") intends.Resumecallback created ininterrupt()skips the phase's ownResumewhen that phase was cancelled or killed.One thing reviewers should know: a dropped
Resumestill fires, becauseResumetriggers on destruction. So events have to ignore a resume that arrives after they finished. The fleet adapter's events did not, so a cancelledGoToPlacewould plan its route again. open-rmf/rmf_ros2#576 adds that guard. The mock activity in this repo's tests now behaves the same way.Tests
Two new cases in
test_Sequence.cpp: cancelling an interrupted task, and killing an interrupted task.Full
test_rmf_task_sequence: all tests pass (319 assertions).ament_uncrustifywithrmf_code_style.cfgis clean.Why two PRs
The bug has one half in each repo, and each half alone is worse than today. Measured in rmf_demos (office, jazzy branch) with
mainof rmf_task and rmf_ros2 built from source on Ubuntu 24.04 / Jazzy. Task A goes topatrol_A2; it is interrupted once the robot moves, then cancelled; task B is sent to the same robot:maincanceled, the robot stays on A, B never starts. A manual resume makes the robot drive to A's destination and A endscompleted.completed, B still needs a manual resumecanceled, the robot stops, but B never starts, even after a resumecanceled, the robot does not continue to A's destination, B starts immediately and completes, both for a direct robot task and for a dispatched taskGenAI Use
We follow OSRA's policy on GenAI tools
Generated-by: Claude Code (Claude Opus 5.5) was used to analyse the bug, write the change and tests, run the rmf_demos trials and draft this description. I reviewed the changes and results.
🤖 Generated with Claude Code