Skip to content

Python: Clarify async concurrency guarantees in WorkflowExecutor #3524

Description

Summary

The WorkflowExecutor stores execution contexts in a dictionary. Note: Python dicts ARE thread-safe for individual operations (due to the GIL). The real question is whether there are async race conditions - multiple coroutines interleaving at await points that could cause logical issues.

Files

File Line
_workflow_executor.py 383

Context

# TODO check thread safety (clean up throughout ...) or declare not thread safe
self._execution_contexts[execution_id] = execution_context

Clarification needed:

  1. Can two async coroutines access the same execution_id concurrently?
  2. Are there compound "check-then-act" patterns that could race between await points?
  3. If two writes to the same key occur, is "last write wins" acceptable?

The _execution_contexts dict is accessed when:

  • Starting sub-workflow executions
  • Handling response messages
  • Cleaning up completed executions
  • Checkpoint save/restore operations

Action Items

  • Audit access patterns for async race conditions (not thread safety - dicts are already thread-safe)
  • Determine if concurrent access to the same execution_id is possible
  • If races exist, decide: add asyncio.Lock, or document that it is safe by design
  • Update the TODO comment in code (says "thread safety" but really means async concurrency)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

orchestrationUsage: [Issues, PRs], Target: multi-agent orchestration (high-level patterns)pythonUsage: [Issues, PRs], Target: PythonworkflowsUsage: [Issues, PRs], Target: Workflows

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions