microsoft / microsoft/promptflow

[BUG] Race condition with global state in process pool

Open
#3,553 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug long-term
Dominant language
Python
Stars
11.2k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

Describe the bug
Prompt flow appears to modify the global working directory and workers in the line execution process pool can get spawned with different working directories.

How To Reproduce the bug
I created an example project to reproduce the bug here: https://github.com/bhanson-techempower/promptflow-concurrency-bug

Some runs will succeed and others will randomly fail with:

Flow path .../promptflow-concurrency-bug/sub_flow2/sub_flow3 does not exist.

Due to the worker for that particular node being spawned after the working directory has been changed.

With the example project the bug is reproduced for me almost every time.

In our production application we're seeing it about half the time when running a batch of 20 runs.

Expected behavior
The flow executes successfully every time because prompt flow does not share extra global state between processes.

Running Information:

  • Promptflow Package Version using pf -v:
{
  "promptflow": "1.12.0",
  "promptflow-core": "1.12.0",
  "promptflow-devkit": "1.12.0",
  "promptflow-tracing": "1.12.0"
}

Executable '.../promptflow-concurrency-bug/venv/bin/python'
Python (Darwin) 3.11.3 (main, May 25 2023, 12:42:30) [Clang 11.1.0 ]
  • Operating System: macOS Sonoma 14.5

Additional context

We've worked around the issue by modifying the way we invoke the sub flows:

from pathlib import Path
flow_path = Path(__file__).parent / "sub_flow1"
flow = load_flow(flow_path)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the race with the linked promptflow-concurrency-bug example and inspect the _change_working_dir and getcwd references, including _flow_nodes_scheduler.py. Trace how the process pool workers inherit the working directory during sub-flow execution. Done means repeated concurrent runs succeed without workers seeing different working directories.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.