Skip to content

Conversation

@hiroshihorie
Copy link
Member

Problem

The testSerialRunnerCancel() test was failing with the counter ending up negative (-1, -8, etc.) instead of the expected 0, indicating a race condition.

Root Cause

The condition !Task.isCancelled was causing cancelled tasks to skip waiting for the previous task to complete. This broke the serial execution guarantee, allowing multiple blocks to run concurrently and causing unsynchronized access to the shared counter.

Fix

Removed the !Task.isCancelled condition to ensure all tasks wait for the previous task, even when cancelled. This maintains the serial ordering guarantee that the actor is designed to provide.

@hiroshihorie hiroshihorie requested a review from pblazej October 3, 2025 09:47
@pblazej
Copy link
Contributor

pblazej commented Oct 3, 2025

Nice, will take a deeper look early next week 💯

// Wait for the previous task to complete, but cancel it if needed
if let previousTask, !Task.isCancelled {
// Always wait for the previous task to maintain serial ordering
if let previousTask {
Copy link
Contributor

@pblazej pblazej Oct 3, 2025

Choose a reason for hiding this comment

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

I'm just wondering what would happen if we move this wait before Task (essentially "blocking" run)?

Copy link
Contributor

Choose a reason for hiding this comment

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

NVM, it just breaks the assumptions made in the 3rd test case 👍

@pblazej pblazej changed the base branch from blaze/tests-ci to main October 6, 2025 07:21
@pblazej pblazej force-pushed the hiroshi/fix-serialrunner branch from 5bf69be to fd4b1f2 Compare October 6, 2025 07:23
@github-actions
Copy link

github-actions bot commented Oct 6, 2025

⚠️ This PR does not contain any files in the .changes directory.

Copy link
Contributor

@pblazej pblazej left a comment

Choose a reason for hiding this comment

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

I rebased it onto main as my test branch needs more work 👍

@hiroshihorie hiroshihorie merged commit 3323ba3 into main Oct 6, 2025
36 of 42 checks passed
@hiroshihorie hiroshihorie deleted the hiroshi/fix-serialrunner branch October 6, 2025 07:59
@pblazej pblazej mentioned this pull request Nov 25, 2025
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