Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix xdist collisions for captured_info artifacts and preserve CI debug logs#45645

Open
stationeros wants to merge 14 commits into
huggingface:mainfrom
stationeros:main
Open

Fix xdist collisions for captured_info artifacts and preserve CI debug logs#45645
stationeros wants to merge 14 commits into
huggingface:mainfrom
stationeros:main

Conversation

@stationeros

Copy link
Copy Markdown

What does this PR do?

Fixes #45561.

This PR fixes a race in the test failure reporting flow when the suite is run with pytest-xdist.

Right now every worker writes debug output to the same captured_info.txt file. In parallel runs that means workers can overwrite each other’s output, and in some cases one worker can remove the file another worker was still relying on. The end result is flaky or incomplete failure logs, which makes CI failures much harder to debug.

The fix keeps the current behavior for non-xdist runs, but switches to worker-specific files when PYTEST_XDIST_WORKER is set. So instead of multiple workers all writing to the same file, each one writes its own captured_info_<worker>.txt.

Along with that, this PR also updates the surrounding plumbing so the debug info still shows up where people expect it:

  • CI log collection now prints all matching captured_info*.txt files instead of assuming there is only one.
  • notification artifact handling aggregates worker-specific captured info files back into the existing reporting flow.
  • stale captured_info*.txt files are cleaned up before a new collection starts so repeated runs do not pick up leftovers from earlier failures.

I also added tests covering:

  • worker-specific path selection under xdist
  • legacy single-file behavior outside xdist
  • cleanup of stale captured info files
  • aggregation of worker-specific artifacts in notification handling

Code Agent Policy

  • I confirm that this is not a pure code agent PR.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

This touches test infrastructure / CI behavior, so @ydshieh seems like the most relevant reviewer.

@Qodo-Free-For-OSS

Copy link
Copy Markdown

Hi, In xdist mode, only the current worker’s captured_info file is removed at startup, so if the output directory is reused, old captured_info_.txt files from prior runs can persist and be merged/printed as if they belong to the current run.

Severity: remediation recommended | Category: correctness

How to fix: Clear outputs at run start

Agent prompt to fix - you can give this to your LLM of choice:

Issue description

With xdist enabled, only the current worker’s captured_info_<worker>.txt is removed, so other worker files from prior runs can remain in the output directory and later be merged/printed.

Issue Context

  • patch_testing_methods_to_collect_info() currently unlinks only _get_patched_testing_methods_output_path().
  • retrieve_artifact() merges all captured_info*.txt files.
  • If the reports directory is reused (common in local tooling), stale worker files can be misattributed to the current run.

Fix Focus Areas

  • src/transformers/testing_utils.py[3778-3786]
  • src/transformers/testing_utils.py[3540-3548]
  • utils/notification_service.py[933-964]

Recommended fixes (pick one)

  1. Ensure the output directory is unique per run (preferred): have the runner/tooling set _PATCHED_TESTING_METHODS_OUTPUT_DIR to a run-unique directory (timestamp/UUID) before launching pytest/xdist.
  2. Clear captured_info*.txt once before xdist workers start (e.g., in the CI workflow step before invoking pytest), avoiding cross-worker deletion races.
  3. If clearing inside pytest, do it only in the xdist controller process (not workers) using an xdist hook/plugin mechanism, so it happens before workers write.

Qodo code review - free for open-source.

@stationeros

Copy link
Copy Markdown
Author

@ydshieh Can you help review this ?

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.

[Bug] pytest-xdist workers race on captured_info.txt in patched testing utils

3 participants