Make job completion order deterministic, improve tests - #42
Merged
Merged
Conversation
When multiple jobs complete in the same "tick" of the parallel execution loop, the `done_futures` set can result in different colcon return codes depending on which one happens to get processed first. A more desirable behavior is to prefer the return code of the job which was started first. While it is currently unlikely to see multiple jobs finish in the same tick due to strict concurrency pre-limiting, this becomes much more common under dynamic scheduling and resource-guarded execution. This change also includes an additional test for the parallel executor, and switches all of the job identifiers to use consistent identifiers, where they were previously using different values in the overall job dictionary from the identifier used on the job objects themselves. Assisted-by: Gemini 3.5 Flash <gemini@google.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #42 +/- ##
==========================================
+ Coverage 96.73% 97.38% +0.65%
==========================================
Files 4 4
Lines 153 153
Branches 41 41
==========================================
+ Hits 148 149 +1
Misses 1 1
+ Partials 4 3 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
|
I'll review this so add me as reviewer @knmcguire |
knmcguire
suggested changes
Sep 7, 2026
knmcguire
left a comment
Contributor
There was a problem hiding this comment.
Should we also have a test on the first addition you made?
Claude Opus 5.1 generated this:
class ImmediateJob(Job):
def __init__(self, identifier, rc):
super().__init__(
identifier=identifier, dependencies=set(), task=None,
task_context=None)
self.rc = rc
async def __call__(self, *args, **kwargs):
return self.rc
def test_simultaneous_completion_prefers_first_started():
extension = ParallelExecutorExtension()
args = SimpleNamespace(parallel_workers=2)
# repeat: set iteration order varies run to run, so a single
# pass would only catch the bug ~50% of the time
for _ in range(50):
jobs = OrderedDict()
jobs['early'] = ImmediateJob('early', 3)
jobs['late'] = ImmediateJob('late', 7)
rc = extension.execute(args, jobs, on_error=OnError.continue_)
assert rc == 3, f'expected first-started rc 3, got {rc}'
I've tested it out on the current master and the patch, and indeed it passes on your fix.
FYI, I had to use Claude Opus 5.1 to check out a couple of assumptions for the review as here but I tested off of the changes myself.
Assisted-by: Claude Opus 5.1 <noreply@anthropic.com>
Member
Author
Sure! Added verbatim in 7b5e008. |
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.
When multiple jobs complete in the same "tick" of the parallel execution loop, the
done_futuresset can result in different colcon return codes depending on which one happens to get processed first. A more desirable behavior is to prefer the return code of the job which was started first.While it is currently unlikely to see multiple jobs finish in the same tick due to strict concurrency pre-limiting, this becomes much more common under dynamic scheduling and resource-guarded execution.
This change also includes an additional test for the parallel executor, and switches all of the job identifiers to use consistent identifiers, where they were previously using different values in the overall job dictionary from the identifier used on the job objects themselves.
Assisted-by: Gemini 3.5 Flash