Skip to content

MAINT: Enable Ruff ASYNC240/ASYNC250 and move blocking path calls off the event loop - #4467

Open
MUKUNDU SAI VARUN (HARUTO-09) wants to merge 1 commit into
microsoft:mainfrom
HARUTO-09:maint/enable-ruff-async-checks
Open

MUKUNDU SAI VARUN (HARUTO-09) wants to merge 1 commit into
microsoft:mainfrom
HARUTO-09:maint/enable-ruff-async-checks

Conversation

@HARUTO-09

Copy link
Copy Markdown

Description

Completes the ASYNC stage of #3721: blocking pathlib.Path calls no longer run on the event loop inside async library code, and Ruff now enforces that.

  • Moved the 9 blocking path calls in pyrit/ (exists, is_file, stat, mkdir, unlink) onto a worker thread with asyncio.to_thread, the same pattern the codebase already uses elsewhere. Files: download_hf_model.py, serializers.py, chat_message_normalizer.py, audio_transcript_scorer.py and video_scorer.py.
  • Fixed the same pattern in build_scripts/export_adversarial_benchmark_result.py.
  • Selected ASYNC240 and ASYNC250 in pyproject.toml. ASYNC250 has no current hits and guards against blocking input() calls.
  • Added ASYNC240 per-file ignores for tests/**, frontend/e2e/** (the e2e fixture backends) and doc/**, as proposed in Enable low-noise correctness Ruff checks instead of large stylistic rule families #3721. Blocking path calls in test setup and doc examples don't affect library users, and fixing them would touch ~190 test lines.

… the event loop

Async functions in pyrit/ called blocking pathlib.Path methods (exists,
is_file, stat, mkdir, unlink) directly on the event loop. Run them through
asyncio.to_thread, matching how the rest of the codebase already does it,
and fix the same pattern in the adversarial benchmark export script.

Select ASYNC240 and ASYNC250 (ASYNC250 has no current hits) so new blocking
calls are caught. Test code (tests/ and the frontend e2e fixture backends)
and doc examples ignore ASYNC240, since blocking path calls there do not
affect library users.

Part of microsoft#3721.
Copilot AI balanced review requested due to automatic review settings November 20, 2026 08:23

Copilot AI left a comment

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.

🟢 Approval recommended

No active review issues remain for the changes that offload blocking filesystem operations and add async lint checks.

No open issues 🎉

What changed in this PR

Completes the ASYNC stage of #3721 by moving blocking filesystem calls off the event loop and adding Ruff checks to prevent similar calls in async library code.

Changes:

  • Uses asyncio.to_thread for path checks, directory creation, file metadata reads, and temporary-file cleanup.
  • Enables Ruff ASYNC240 and ASYNC250 to flag blocking path methods and input() calls.
  • Exempts documentation, tests, and frontend end-to-end fixtures from ASYNC240.
File Description
pyrit/​score/​video_scorer.py Offloads video existence checks and extracted-audio cleanup.
pyrit/​score/​audio_transcript_scorer.py Offloads audio existence checks, file metadata reads, and WAV cleanup.
pyrit/​message_normalizer/​chat_message_normalizer.py Offloads the audio-file check before encoding.
pyrit/​memory/​storage/​serializers.py Offloads temporary audio-file cleanup.
pyrit/​common/​download_hf_model.py Offloads model cache directory creation.
pyproject.toml Enables async blocking-call checks with scoped path-call exemptions.
build_scripts/​export_adversarial_benchmark_result.py Offloads export directory creation.

Review effort: Balanced

@HARUTO-09

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants