Skip to content

fix(sdk): make map/parallel child exec order invariant#108

Merged
1 commit merged intomainfrom
quinsclr/fix-concurrency-on-map-and-parallel
Oct 29, 2025
Merged

fix(sdk): make map/parallel child exec order invariant#108
1 commit merged intomainfrom
quinsclr/fix-concurrency-on-map-and-parallel

Conversation

@ghost
Copy link
Copy Markdown

@ghost ghost commented Oct 29, 2025

Context:

  • Currently the operation_id for children in map and parallel
    is contingent on execution order due to internal method that
    always increments a counter for safety.
  • In map and parallel, depending on when the executor decides
    to run a particular branch, we may observe different ordering.

Changes:

  • we skip using executor context's run_in_child_context to run a
    concurrent branch, and instead call child_handler directly.
  • we generate the appropriate operation_id before we call child_handler
    and use executable.index to make it deterministic.

Issue #, if available:

fixes: #107

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@ghost ghost changed the title fix: make map/parallel child exec order invariant fix(sdk): make map/parallel child exec order invariant Oct 29, 2025
@ghost ghost force-pushed the quinsclr/fix-concurrency-on-map-and-parallel branch from fae2007 to 93d6f68 Compare October 29, 2025 10:56
Context:
- Currently the operation_id for children in map and parallel
is contingent on execution order due to internal method that
always increments a counter for safety.
- In map and parallel, depending on when the executor decides
to run a particular branch, we may observe different ordering.

Changes:
- we skip using executor context's run_in_child_context to run a
concurrent branch, and instead call child_handler directly.
- we generate the appropriate operation_id before we call child_handler
  and use executable.index to make it deterministic.
@ghost ghost force-pushed the quinsclr/fix-concurrency-on-map-and-parallel branch from 93d6f68 to 3889a42 Compare October 29, 2025 10:59
@ghost ghost marked this pull request as ready for review October 29, 2025 11:01
@ghost ghost merged commit f01f6eb into main Oct 29, 2025
8 checks passed
@ghost ghost deleted the quinsclr/fix-concurrency-on-map-and-parallel branch October 29, 2025 15:50
info=self._log_info,
)

def _create_step_id_for_logical_step(self, step: int) -> str:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

step maybe better described as counter

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

_create_step_id_with_preset_counter


def _create_step_id_for_logical_step(self, step: int) -> str:
"""
Generate a step_id based on the given logical step.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

on the given counter.

"logical step" doesn't really have a well defined meaning.

we generate an operation_id for the child, and then call `child_handler`
directly. This avoids the hidden mutation of the context's internal counter.
we can do this because we explicitly control the generation of step_id and do it
using executable.index.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

phrasing.

"This avoids the hidden mutation of the context's internal counter.
we can do this because we explicitly control the generation of step_id and do it
using executable.index."

This pull request was closed.
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.

Race Condition in Parallel and Map wrt operation_identifiers

3 participants