NVIDIA-NeMo / NVIDIA-NeMo/Guardrails

test: scope asyncio cleanup in test_parallel_rail_outcome_bypass.py instead of awaiting all event-loop tasks

Open
#2,171 0 comments 0 reactions 1 assignee View on GitHub

@Pouyanpi is already working on this.

Since Jul 15, 2026.

Dominant language
Python
Stars
7.2k
Forks
842
Avg merge
3d 1h
Merged PRs (30d)
25

Description

Before submitting: This issue documents a pre-existing concern identified during review of PR #2151, not introduced by that PR.

Did you check docs and existing issues?
  • I have read all the NeMo-Guardrails docs
  • I have updated the package to the latest version before submitting this issue
  • I have used the develop branch
  • I have searched the existing issues of NeMo-Guardrails
Python version (python --version)

N/A (test-infra issue, not version-specific)

Operating system/version

N/A (CI/test-infra issue)

NeMo-Guardrails version

develop branch (as of PR #2151)

Describe the bug

tests/test_parallel_rail_outcome_bypass.py uses asyncio.all_tasks() - {asyncio.current_task()} during test cleanup (lines ~125 and ~147) to await pending tasks after streaming a response via TestChat. This is a broad, unscoped cleanup pattern: asyncio.all_tasks() returns all tasks scheduled on the current event loop, not just the ones created by the TestChat/streaming run. In a shared test-runner event loop (e.g., under pytest-asyncio), this can inadvertently include unrelated pytest/plugin/background tasks, which may hang or behave unpredictably during CI runs.

This pattern was flagged by CodeRabbit during review of PR #2151 (https://github.com/NVIDIA-NeMo/Guardrails/pull/2151#discussion_r3585336550) as pre-existing and not introduced by that PR, per the author's (@Pouyanpi) own confirmation in the review thread. This issue tracks it for future investigation, since it did not block that PR.

Steps To Reproduce
  1. Open tests/test_parallel_rail_outcome_bypass.py.
  2. Note the cleanup lines using asyncio.gather(*asyncio.all_tasks() - {asyncio.current_task()}) (around lines 125 and 147).
  3. Consider running this test suite in a CI environment with other concurrently scheduled tasks on the same event loop (e.g., other async tests/plugins), and evaluate whether this could hang or interfere with unrelated tasks.
Expected Behavior

Test cleanup should only await tasks that are owned by/created during the specific TestChat streaming run being tested (e.g., via a scoped shutdown path on TestChat, or by explicitly tracking task references created within the test), rather than sweeping up all tasks on the event loop.

Actual Behavior

The cleanup code awaits every task currently scheduled on the event loop except the current one, which could include unrelated tasks and risks hanging or masking failures in CI.

Affected files
  • tests/test_parallel_rail_outcome_bypass.py (lines ~125, ~147)
References

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.