Skip to content

fix(multimodal): release resources after failed transfer preparation - #15500

Merged
krishung5 merged 6 commits into
ai-dynamo:mainfrom
bojiang-li:bojiang-li/cleanup-unpublished-mm-transfers-20261001
Nov 3, 2026
Merged

krishung5 merged 6 commits into
ai-dynamo:mainfrom
bojiang-li:bojiang-li/cleanup-unpublished-mm-transfers-20261001

Conversation

@bojiang-li

@bojiang-li bojiang-li commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #16056.

Keep ownership of multimodal transfer resources until preparation returns successfully. A sender can create the first shared memory segment or NIXL registration, then fail on the next item and return no cleanup handles. That leaves the first resource without an owner.

The sender now releases resources if serialization, allocation, registration, metadata construction, or cancellation prevents preparation from returning. Each item encoder also cleans its own resource if it fails before handing back a cleanup handle. Cleanup keeps the original preparation error.

For unpublished NIXL registrations, release directly because no receiver has their metadata yet. Successful transfers still hand cleanup to the caller and keep their existing completion wait. This does not change cleanup after a transfer has been published.

Merged current main and kept its typed msgpack serializer, buffer framing, and decoder restrictions. The new tests use real vLLM multimodal items.

Validation

All 41 tests in the transfer module pass on Linux ARM64 with vLLM 0.27.1. That includes real POSIX shared memory round trips, buffer framing, restricted decoding, NIXL ordering, and all ten preparation ownership cases. On unchanged current main, those ten cases produce eight failures and two successful controls. The file checks pass.

The test runner loads the actual transfer module and vLLM serializer while skipping unrelated native package bootstraps. Shared memory round trips use the real OS implementation. Ownership failure cases control the shared memory or NIXL operation boundary. Native NIXL registration, RDMA, GPU serving, and performance were not tested.

AI assistance was used for the code, tests, and review.

@bojiang-li
bojiang-li requested review from a team as code owners October 1, 2026 15:56
@copy-pr-bot

copy-pr-bot Bot commented Oct 1, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@bojiang-li
bojiang-li temporarily deployed to external_collaborator October 1, 2026 15:56 — with GitHub Actions Inactive
@bojiang-li
bojiang-li temporarily deployed to external_collaborator October 1, 2026 15:56 — with GitHub Actions Inactive
@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

👋 Hi bojiang-li! Thank you for contributing to ai-dynamo/dynamo.

Just a reminder: The NVIDIA Test Github Validation CI runs an essential subset of the testing framework to quickly catch errors.Your PR reviewers may elect to test the changes comprehensively before approving your changes.

🚀

@github-actions github-actions Bot added external-contribution Pull request is from an external contributor fix multimodal labels Oct 1, 2026
@coderabbitai

coderabbitai Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: ai-dynamo/dynamo/.coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: b201c831-8340-4567-91cf-b3d5b5d91550


📥 Commits

Reviewing files that changed from the base of the PR and between 3af83c2 and 3b65ba3.


📒 Files selected for processing (2)
  • components/src/dynamo/common/multimodal/mm_kwargs_transfer.py
  • components/src/dynamo/common/tests/multimodal/test_mm_kwargs_transfer.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 8 remain after this review.



Walkthrough

Preparation failures now clean up acquired SHM segments and NIXL operations before re-raising the original exception. Successful preparation leaves resources for caller cleanup.

Changes

Preparation cleanup

Layer / File(s) Summary
Shared and NIXL cleanup
components/src/dynamo/common/multimodal/mm_kwargs_transfer.py, components/src/dynamo/common/tests/multimodal/test_mm_kwargs_transfer.py
The shared preparation path invokes an abort hook when preparation fails. The NIXL sender releases registered operations without waiting for reads. Tests cover preparation failures, cancellation, and caller cleanup after success.
SHM segment cleanup
components/src/dynamo/common/multimodal/mm_kwargs_transfer.py, components/src/dynamo/common/tests/multimodal/test_mm_kwargs_transfer.py
The SHM sender cleans up a segment if writing or later preparation steps fail. Tests cover failure cleanup and caller cleanup after success.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 3b65b

This change releases multimodal transfer resources when preparation fails and leaves the success path unchanged. No actionable merge-blocking risk was identified.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 24.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 25 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title clearly and concisely describes the main change: releasing resources after failed multimodal transfer preparation.
Description check Passed The description explains the problem, implementation, validation, scope, and related issue. It uses Summary and Validation headings instead of the template headings and does not include a separate rev…


  • Fix all pre-merge checks with AI
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Comment @coderabbitai help to get the list of available commands.

@bojiang-li
bojiang-li temporarily deployed to external_collaborator October 10, 2026 01:19 — with GitHub Actions Inactive
@krishung5

Copy link
Copy Markdown
Contributor

/ok to test 4926fac

@devin-ai-integration

devin-ai-integration Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

✅ Dynamo PR CI passed — run 41546985792 (attempt 1) on d7ef5ad52c

Gate checks: ✅ backend-status-check · ✅ deploy-status-check · ✅ dynamo-status-check

Posted automatically by Devin for run 41546985792. Updated on every full-CI run of this PR.

Merge upstream/main at f24c59b, including the aisimulate dependency update in b208989. The PR remains scoped to transfer preparation cleanup.

Assisted-by: Codex
Signed-off-by: bojiang-li <[email protected]>
@bojiang-li
bojiang-li temporarily deployed to external_collaborator October 17, 2026 07:16 — with GitHub Actions Inactive
@bojiang-li

Copy link
Copy Markdown
Contributor Author

Thanks for enabling CI. The planner image in run 38982928369 failed during cargo metadata because aisimulate-core =0.13.0-dev.202610060000000067 was unavailable.

I merged main at f24c59b, including the dependency update from #16077. The new head is d2268ca. The PR still changes only the two transfer cleanup files relative to main. All 41 transfer tests pass on DGX Spark, including real shared memory round trips and all ten preparation ownership cases. Full touched-file pre-commit also passes. Native NIXL and GPU serving were not tested.

@krishung5 could you authorize full CI for the new head when convenient? Thank you.

@krishung5
krishung5 temporarily deployed to external_collaborator October 21, 2026 23:16 — with GitHub Actions Inactive
@krishung5

Copy link
Copy Markdown
Contributor

/ok to test ba3087f

@bojiang-li
bojiang-li temporarily deployed to external_collaborator October 31, 2026 19:14 — with GitHub Actions Inactive
@krishung5
krishung5 temporarily deployed to external_collaborator November 2, 2026 23:38 — with GitHub Actions Inactive
@krishung5

Copy link
Copy Markdown
Contributor

/ok to test d7ef5ad

@krishung5 krishung5 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.

Lgtm

@krishung5
krishung5 merged commit 319ad3b into ai-dynamo:main Nov 3, 2026
113 checks passed
@dmitry-tokarev-nv

Copy link
Copy Markdown
Contributor

@bojiang-li @krishung5, a note from a review of this PR after the merge.

[P3] No test makes sure that a failed SHM release keeps the original preparation error. components/src/dynamo/common/multimodal/mm_kwargs_transfer.py:749. The NIXL path has such a test. A deliberate break that adds raise after the warning in SHM cleanup() passes all 10 new tests. Please add the test below in a follow-up PR.

Measured in the CI test image of d7ef5ad, in a container with no network.
Code under test 10 new tests Test below, 2 cases
Merged code, 319ad3b906 10 pass 2 pass
SHM cleanup() with raise after the warning 10 pass 2 fail: assert OSError(5, 'release failed') is OSError(28, 'controlled preparation failure')
Parent ff072fcc32, without the fix 8 fail, 2 pass 2 fail

The same break in NIXL _release_all() fails test_nixl_failure_releases_without_waiting_for_unpublished_reads[batch_metadata].

The test to add, 31 lines. It applies to `main` at 319ad3b, and `ruff check` passes.
--- a/components/src/dynamo/common/tests/multimodal/test_mm_kwargs_transfer.py
+++ b/components/src/dynamo/common/tests/multimodal/test_mm_kwargs_transfer.py
@@ -173,6 +173,37 @@
         handles[0].unlink.assert_called_once_with()
 
     @pytest.mark.asyncio
+    @pytest.mark.parametrize("failure_site", ["item_metadata", "batch_metadata"])
+    async def test_shm_release_failure_keeps_preparation_error(
+        self, monkeypatch, failure_site
+    ):
+        handles, _ = self._shm_boundary(monkeypatch)
+        sender = MmKwargsShmSender()
+        failure = OSError(errno.ENOSPC, "controlled preparation failure")
+
+        def fail(*args, **kwargs):
+            # A failed unlink must not replace the preparation error or stop
+            # the release of later segments.
+            handles[0].unlink.side_effect = OSError(errno.EIO, "release failed")
+            raise failure
+
+        if failure_site == "item_metadata":
+            monkeypatch.setattr(mm_kwargs_transfer, "MmKwargsShmItem", fail)
+        else:
+            monkeypatch.setattr(sender, "_assemble_extra_args", fail)
+
+        with pytest.raises(OSError) as caught:
+            await sender.prepare(
+                [_make_feature(data=_make_kwargs_item(i)) for i in range(2)]
+            )
+
+        assert caught.value is failure
+        assert len(handles) == (2 if failure_site == "batch_metadata" else 1)
+        for handle in handles:
+            handle.close.assert_called_once_with()
+            handle.unlink.assert_called_once_with()
+
+    @pytest.mark.asyncio
     @pytest.mark.parametrize(
         "failure_site", ["registration", "item_metadata", "batch_metadata"]
     )

This branch was previously deployed

1 inactive deployment
external_collaborator — d7ef5ad5 Deployed Nov 2, 2026 by krishung5 via ok-to-test #43707
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external-contribution Pull request is from an external contributor fix multimodal size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Multimodal preparation failures leak unpublished transfer resources

3 participants