Skip to content

fix: serialise _change_working_dir to stop cwd races (#3553) - #4229

Open
lsmlhi_25 (FOWEPJF255) wants to merge 2 commits into
microsoft:mainfrom
FOWEPJF255:fix/3553-working-dir-race
Open

lsmlhi_25 (FOWEPJF255) wants to merge 2 commits into
microsoft:mainfrom
FOWEPJF255:fix/3553-working-dir-race

Conversation

@FOWEPJF255

@FOWEPJF255 lsmlhi_25 (FOWEPJF255) commented Sep 30, 2026 •

Copy link
Copy Markdown

Summary

  • Serialise _change_working_dir, including creation of relative working directories, with a module-level threading.Lock so concurrent threads in the line-execution process pool cannot observe each other's intermediate os.chdir state.
  • Add regression tests for basic restore, exception restore, mkdir, and thread-safety (fixes [BUG] Race condition with global state in process pool #3553).

Context

Reclaims the approach from stale closed PR #4205. Issue has 0 open competing PRs.

Test plan

  • Targeted context-utils tests: 5 passed on Python 3.12.10.
  • Black formatting, Python compilation, and git diff --check passed for the changed files.

Disclosure: drafted with AI assistance; personally reviewed against #3553 repro and prior #4205.

os.chdir is process-global; concurrent threads sharing the line-execution
pool could spawn workers with the wrong working directory (microsoft#3553).
Hold a module lock around getcwd/chdir/restore and add regression tests.
@github-actions

Copy link
Copy Markdown

Hi, thank you for your interest in helping to improve the prompt flow experience and for your contribution. We've noticed that there hasn't been recent engagement on this pull request. If this is still an active work stream, please let us know by pushing some changes or leaving a comment.

@github-actions github-actions Bot added the no-recent-activity There has been no recent activity on this issue/pull request label Oct 14, 2026
@FOWEPJF255

Copy link
Copy Markdown
Author

Yes, this PR is still active. I pushed a follow-up fix that moves relative directory creation under _working_dir_lock, so os.makedirs cannot resolve a path against another thread's temporary working directory. I also added a regression test that checks directory creation happens while the lock is held.

Validation: the targeted context-utils test file passes 5/5 on Python 3.12.10; Black formatting, Python compilation, and git diff --check pass. The latest PR checks report triage, CLA, and Snyk passing; no test workflow is currently reported.

Commit: 27dae5c

@FOWEPJF255

Copy link
Copy Markdown
Author

The latest parallel unit and end-to-end workflow runs both ended with action_required before executing any jobs (zero jobs and no logs): unit run and e2e run. So these runs have not tested this PR yet. Separately, the workflow files on main declare report jobs with needs: test, while the corresponding jobs are named parallel-unit-test and parallel-e2e-test; that appears to be a pre-existing workflow configuration issue. The focused local tests and checks for this change pass.

@github-actions github-actions Bot removed the no-recent-activity There has been no recent activity on this issue/pull request label Oct 16, 2026

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Race condition with global state in process pool

2 participants