Skip to content

fix: preserve input order in WorkerPool.map() by replacing as_complet…#2

Merged
jmestwa-coder merged 1 commit into
jmestwa-coder:mainfrom
rashmikandadka:fix/workerpool-map-ordering
May 23, 2026
Merged

fix: preserve input order in WorkerPool.map() by replacing as_complet…#2
jmestwa-coder merged 1 commit into
jmestwa-coder:mainfrom
rashmikandadka:fix/workerpool-map-ordering

Conversation

@rashmikandadka
Copy link
Copy Markdown
Contributor

Fixes #1

Problem

as_completed() returns futures in completion order, not submission order.
This caused WorkerPool.map() to return results misaligned with input items.

Fix

Replaced as_completed() loop with ThreadPoolExecutor.map() which preserves
input order by design.

Test

Updated test_worker_pool_maps_items to assert strict ordering (removed the
sorted() workaround that was masking the bug).

@jmestwa-coder
Copy link
Copy Markdown
Owner

One small suggestion before merge: could you also add a timing-based regression test similar to the reproduction scenario from the issue? That would help permanently validate ordering preservation under varying task completion times.

Other than that, the change looks good.

@rashmikandadka
Copy link
Copy Markdown
Contributor Author

Hi, I have added the timing-based regression test as suggested.
The new test test_worker_pool_preserves_order_with_varying_times
simulates varying task completion times and verifies that the output
order matches the input order. Please review!

@jmestwa-coder
Copy link
Copy Markdown
Owner

@rashmikandadka

Squash these into a single commit with a clean Conventional Commits message, then force-push to the same branch.

@rashmikandadka rashmikandadka force-pushed the fix/workerpool-map-ordering branch from bc7f8c5 to 1ca206e Compare May 23, 2026 15:22
@rashmikandadka
Copy link
Copy Markdown
Contributor Author

Hi, I have squashed the commits into a single clean commit
and force-pushed to the branch. Please review!

@jmestwa-coder
Copy link
Copy Markdown
Owner

LGTM, thank you! Merging.

@jmestwa-coder jmestwa-coder merged commit 46990ce into jmestwa-coder:main May 23, 2026
3 checks passed
@jmestwa-coder
Copy link
Copy Markdown
Owner

Thank you for your contribution.

The submitted fix has been reviewed and merged successfully. You have successfully completed this evaluation task and have been shortlisted for the next round of the selection process.

Please send the following details to hr@digiscrypt.com for verification purposes:

  • Pull Request link
  • Merged commit link

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.

WorkerPool.map() returns results in non-deterministic order due to use of as_completed()

2 participants