Skip to content

[Bugfix] Fix spawn_new_process_for_each_test silently swallowing test failures#41423

Merged
ProExpertProg merged 11 commits intovllm-project:mainfrom
dzhengAP:bugfix/fix-spawn-decorator-exitcode
May 6, 2026
Merged

[Bugfix] Fix spawn_new_process_for_each_test silently swallowing test failures#41423
ProExpertProg merged 11 commits intovllm-project:mainfrom
dzhengAP:bugfix/fix-spawn-decorator-exitcode

Conversation

@dzhengAP
Copy link
Copy Markdown
Contributor

Problem

spawn_new_process_for_each_test was broken — it always passed regardless
of what the test function did, causing silent test coverage failures.

The previous implementation ran python -m <module_name> in the child
process, which re-executed the module's __main__ block instead of
actually calling the test function. check_returncode() always saw
exit 0, so any exception raised inside the test was silently swallowed.

Repro from the issue:

@create_new_process_for_each_test("spawn")
def test_failing():
    raise ValueError  # always passed before this fix

Fix

Serialize the test function and its arguments with cloudpickle and
pass them to a minimal child script via stdin. The child writes its
full traceback to a temp file on failure; the parent reads it and
raises RuntimeError with the traceback included, making CI failures
actionable.

This matches the robustness of fork_new_process_for_each_test which
already handled exception propagation correctly.

Verification

Tested locally with the exact repro from #41415:

Testing failure propagation...
FIXED: failure correctly propagated
Test subprocess 'test_failing' failed (exit code 1):
Traceback (most recent call last):
  File "<string>", line 4, in <module>
    f(*args, **kwargs)
  File "/tmp/test_fix3.py", line 45, in test_failing
    raise ValueError('should propagate')
ValueError: should propagate

Testing success case...
FIXED: success case passes cleanly
  • Failing tests now correctly raise RuntimeError with the full traceback from the child process
  • Passing tests continue to work normally

Fixes #41415

Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@github-actions
Copy link
Copy Markdown

👋 Hi! Thank you for contributing to the vLLM project.

💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels.

PRs do not trigger a full CI run by default. Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging.

To run CI, PR reviewers can either: Add ready label to the PR or enable auto-merge.

If you have any questions, please reach out to us on Slack at https://slack.vllm.ai.

Agent Guidelines

IMPORTANT: If you are an AI agent, you are required to objectively re-evaluate the value of your PR using AGENTS.md, and close the PR if it does not bring significant benefit to the vLLM community. Failure to do so may result in an immediate ban.

🚀

@mergify mergify Bot added the bug Something isn't working label Apr 30, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates tests/utils.py to reimplement spawn_new_process_for_each_test using subprocess and cloudpickle, ensuring that test failures are correctly propagated to the parent process. However, the current implementation contains a critical syntax error because the old function body was left dangling at the module level after the header was removed, which will cause an IndentationError. Additionally, the new logic for handling exceptions in the child process needs to account for pytest.skip to prevent skipped tests from being incorrectly flagged as failures.

Comment thread tests/utils.py
Comment thread tests/utils.py
@dzhengAP dzhengAP force-pushed the bugfix/fix-spawn-decorator-exitcode branch 2 times, most recently from fa2ec87 to 072afe3 Compare April 30, 2026 23:32
@ProExpertProg
Copy link
Copy Markdown
Collaborator

Please combine the two approaches, and add tests that check that this works, 1 passing test and 1 failing test (with pytest.mark.xfail) to make sure the failures are caught

@dzhengAP dzhengAP force-pushed the bugfix/fix-spawn-decorator-exitcode branch from 072afe3 to afc7b14 Compare May 1, 2026 00:12
@dzhengAP
Copy link
Copy Markdown
Contributor Author

dzhengAP commented May 1, 2026

@ProExpertProg

Done! My implementation already addressed the root cause — switching from python -m (which only imports the module and never calls f) to python -c with an inline runner that explicitly calls f(*args, **kwargs). This incorporates the same fix as @sriharshamudumba's approach, plus adds proper error propagation via a traceback file and Skipped exception handling.
Added three tests as requested:

test_spawn_decorator_passing — verifies a passing function completes normally
test_spawn_decorator_failure_is_caught (xfail, strict=True) — verifies failures are never silently swallowed
test_spawn_decorator_parametrized — verifies args/kwargs are forwarded correctly to the subprocess

All tests pass locally:
collected 3 items
tests/test_spawn_decorator.py::test_spawn_decorator_passing PASSED [ 33%]
tests/test_spawn_decorator.py::test_spawn_decorator_failure_is_caught XFAIL [ 66%]
tests/test_spawn_decorator.py::test_spawn_decorator_parametrized PASSED [100%]
========================= 2 passed, 1 xfailed in 0.20s =========================

Comment thread tests/test_spawn_decorator.py Outdated
Comment thread tests/test_spawn_decorator.py Outdated
@tjtanaa tjtanaa added rocm Related to AMD ROCm ready ONLY add when PR is ready to merge/full CI is needed labels May 1, 2026
@github-project-automation github-project-automation Bot moved this to Todo in AMD May 1, 2026
@tjtanaa tjtanaa removed the ready ONLY add when PR is ready to merge/full CI is needed label May 1, 2026
@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented May 1, 2026

Hi @dzhengAP, the pre-commit checks have failed. Please run:

uv pip install pre-commit>=4.5.1
pre-commit install
pre-commit run --all-files

Then, commit the changes and push to your branch.

For future commits, pre-commit will run automatically on changed files before each commit.

Tip

Is mypy failing?
mypy is run differently in CI. If the failure is related to this check, please use the following command to run it locally:
# For mypy (substitute "3.10" with the failing version if needed)
pre-commit run --hook-stage manual mypy-3.10

@dzhengAP dzhengAP force-pushed the bugfix/fix-spawn-decorator-exitcode branch from 4596c4c to 2971da8 Compare May 1, 2026 01:48
@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented May 1, 2026

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @dzhengAP.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

…ures

The previous implementation ran 'python -m <module_name>' in the child
process, which re-executed the module's __main__ block instead of
actually calling the test function. As a result, check_returncode()
always saw exit 0 and any exception in the test was silently swallowed.

Fix: serialize the test function with cloudpickle and pass it to a
minimal child script via stdin, matching the robustness of
fork_new_process_for_each_test. The child writes its traceback to a
temp file on failure; the parent reads it and raises RuntimeError with
the full traceback included.

Fixes vllm-project#41415

Signed-off-by: dqzhengAP <dqzheng1996@gmail.com>
Catch Skipped before BaseException so that pytest.skip() inside a
decorated test exits with code 0 instead of 1, matching the behavior
of fork_new_process_for_each_test.

Addresses review comment from gemini-code-assist.

Signed-off-by: dqzhengAP <dqzheng1996@gmail.com>
The previous replacement removed the def header but left the old
function body at module level (lines 1284-1331), which would cause
an IndentationError on import. Remove the leftover block.

Addresses critical review comment from gemini-code-assist.

Signed-off-by: dqzhengAP <dqzheng1996@gmail.com>
@dzhengAP dzhengAP force-pushed the bugfix/fix-spawn-decorator-exitcode branch from d13033e to e80a2a1 Compare May 1, 2026 01:53
@dzhengAP
Copy link
Copy Markdown
Contributor Author

dzhengAP commented May 1, 2026

Updated the test file to address both review comments: importing the actual spawn_new_process_for_each_test from tests.utils and decorating at module level. Also fixed a line-length lint error in tests/utils.py. @ProExpertProg @tjtanaa please let me know if anything else is needed!

@ProExpertProg ProExpertProg added the ready ONLY add when PR is ready to merge/full CI is needed label May 1, 2026
@ProExpertProg
Copy link
Copy Markdown
Collaborator

@claude review once

Copy link
Copy Markdown
Collaborator

@ProExpertProg ProExpertProg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also test the skipping logic please. And what happens if the decorator is above the parametrize marks?

Comment thread tests/utils_/test_spawn_decorator.py
Comment thread tests/utils_/test_spawn_decorator.py
@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented May 2, 2026

Hi @dzhengAP, the pre-commit checks have failed. Please run:

uv pip install pre-commit>=4.5.1
pre-commit install
pre-commit run --all-files

Then, commit the changes and push to your branch.

For future commits, pre-commit will run automatically on changed files before each commit.

Tip

Is mypy failing?
mypy is run differently in CI. If the failure is related to this check, please use the following command to run it locally:
# For mypy (substitute "3.10" with the failing version if needed)
pre-commit run --hook-stage manual mypy-3.10

dzhengAP added 3 commits May 1, 2026 19:22
Signed-off-by: dqzhengAP <dqzheng1996@gmail.com>
Signed-off-by: dqzhengAP <dqzheng1996@gmail.com>
In test_capture_replay_bypass_logic, step 4 was passing desc_2 =
BatchDescriptor(num_tokens=2, num_reqs=None) to _run_and_monitor_call,
but the captured graph was stored under the key returned by
dispatcher.dispatch() which has num_reqs=2. The dict lookup missed,
causing the wrapper to re-capture instead of replay.

Fix: pass key (from dispatcher.dispatch) instead of desc_2.

Signed-off-by: dqzhengAP <dqzheng1996@gmail.com>
@dzhengAP
Copy link
Copy Markdown
Contributor Author

dzhengAP commented May 3, 2026

@ProExpertProg Hi Luka, fixed and all CI tests passed.

Copy link
Copy Markdown
Collaborator

@ProExpertProg ProExpertProg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@njhill @Isotr0py could you guys take a look at the logits processor test?

@ProExpertProg
Copy link
Copy Markdown
Collaborator

@dzhengAP You need to manually add tests/test_spawn_decorator.py to a test. I think the easiest way is to add it to tests/utils_ folder

Signed-off-by: dqzhengAP <dqzheng1996@gmail.com>
@dzhengAP
Copy link
Copy Markdown
Contributor Author

dzhengAP commented May 4, 2026

@njhill @Isotr0py could you guys take a look at the logits processor test?

Background is the logits processor test was broken for the same reason as the cudagraph test: @create_new_process_for_each_test uses spawn + cloudpickle to run the test in a subprocess, and anything unpicklable in the function's arguments causes a PicklingError. The client fixture was an AsyncOpenAI object containing a threading.RLock — not picklable across process boundaries.

The fixed logic there is test_custom_logitsprocs has been refactored to create the async client inside the test body (srv.get_async_client()) rather than receiving it as a fixture kwarg, making it compatible with @create_new_process_for_each_test("spawn"). test_invalid_custom_logitsproc_arg does not use the decorator so the fixture-based client is fine there.

@njhill @Isotr0py @ProExpertProg all CI tests passed.

@ProExpertProg ProExpertProg merged commit ee38750 into vllm-project:main May 6, 2026
17 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in AMD May 6, 2026
@github-project-automation github-project-automation Bot moved this from Ready to Done in NVIDIA May 6, 2026
amd-mghanimi pushed a commit to amd-mghanimi/vllm that referenced this pull request May 6, 2026
… failures (vllm-project#41423)

Signed-off-by: dqzhengAP <dqzheng1996@gmail.com>
Signed-off-by: Mehdi Ghanimifard <mehdi.ghanimifard@amd.com>
Comment thread tests/utils.py
@dzhengAP
Copy link
Copy Markdown
Contributor Author

dzhengAP commented May 7, 2026

Follow-up fix and relevant discussion for XPU/ROCm compatibility submitted in #41895 — restores mp.set_start_method("spawn").The failure-propagation fix remains intact.

Please do not merge that autog-enerated revert#41887. I've submitted a targeted fix in #41895 that restores mp.set_start_method("spawn") for XPU/ROCm compatibility without reverting the entire #41423 fix.

The 3 CI failures in build #64792 are pre-existing bugs that were silently swallowed by the old decorator — not regressions. Reverting #41423 would bring back the silent failure swallowing behavior, which is worse.

Additionally, the reimplementation in this revert PR is non-functional — it doesn't pass args/kwargs to the subprocess, so tests would appear to pass without actually running.

Please close this revert and let #41895 land instead. Happy to follow up with fixes for the 3 exposed pre-existing failures separately.

cc @jikunshang @ProExpertProg

ikaadil pushed a commit to ikaadil/vllm that referenced this pull request May 7, 2026
… failures (vllm-project#41423)

Signed-off-by: dqzhengAP <dqzheng1996@gmail.com>
Signed-off-by: Ifta Khairul Alam Adil <ikaadil007@gmail.com>
libinta pushed a commit to libinta/vllm that referenced this pull request May 8, 2026
… failures (vllm-project#41423)

Signed-off-by: dqzhengAP <dqzheng1996@gmail.com>
Signed-off-by: Libin Tang <libin.tang@intel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working nvidia ready ONLY add when PR is ready to merge/full CI is needed rocm Related to AMD ROCm v1

Projects

Status: Done
Status: Done

Development

Successfully merging this pull request may close these issues.

[bug] spawn_new_process_for_each_test decorator broken

4 participants