Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Added
^^^^^

* Added :func:`~isaaclab.utils.assets.unmirror_file_path`, which maps a locally cached asset copy
written by :func:`~isaaclab.utils.assets.retrieve_file_path` back to the URL it was downloaded
from. Exports of a stage that references cached copies can use it to name the source assets
instead of machine-specific cache paths.
32 changes: 32 additions & 0 deletions source/isaaclab/isaaclab/utils/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ def _resolve_asset_root() -> str:

_GIT_SSH_RE = re.compile(r"^[^@/:]+@[^:]+:.+")

_MIRROR_URL_SCHEMES = frozenset({"http", "https", "omniverse"})

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

should these schemes be hard coded. I think I may have seen other schemes as well like s3://

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

should these schemes be hard coded

This sounds like a question, but I am not sure. Are you suggesting that we shouldn't hard code those and rely on other functionality? Have you had something specific in mind?

"""URL schemes whose assets are cached locally, and which therefore start a cache layout."""

_MIRROR_NETLOC_PORT_RE = re.compile(r"^(.+)_(\d+)$")


def retrieve_git_asset_path(
git_path: str, local_path: str, cache_dir: str | None = None, force_update: bool = False
Expand Down Expand Up @@ -305,6 +310,33 @@ def _mirror_path(url: str, download_dir: str) -> str:
return os.path.join(download_dir, parsed.scheme, netloc, *parsed.path.lstrip("/").split("/"))

@mataylor-nvidia mataylor-nvidia Aug 13, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

additional problem I found with _mirror_path from 6751 is that it treats a Windows drive letter as a URL scheme. this should also be resolved

@mataylor-nvidia mataylor-nvidia Aug 13, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

tests should be added for Windows paths like this


def unmirror_file_path(path: str) -> str:
"""Reverses :func:`retrieve_file_path` caching, mapping a cached copy back to its source URL.

A remote asset is cached under ``<download_dir>/<scheme>/<host>/<path>``, and stages reference
that cached copy rather than the URL it came from. Exports of such a stage therefore carry
absolute paths that only resolve on the machine holding the cache. This recovers the URL so an
export can name the source asset instead.

Args:
path: Local filesystem path, typically an asset path read from a USD layer.

Returns:
The URL the path was cached from, or ``""`` when it does not lie inside a cache layout.
"""
parts = path.replace(os.sep, "/").split("/")
# the last two components are the host and at least one path component, so a scheme found
# there cannot be the start of a cache layout
for index, part in enumerate(parts[:-2]):

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.

🟡 Warning · Design Architecture — Cache detection not anchored to download directory

The scan accepts any path component named http/https/omniverse (case-insensitively) without verifying the path lies under a cache download directory, unlike _mirror_path which is parameterized by download_dir and writes a lowercase scheme. A locally authored path such as ~/Documents/Omniverse/Assets/foo.usd is rewritten to omniverse://Assets/foo.usd, so _restore_remote_asset_paths corrupts it in the exported stage despite both docstrings promising local paths are untouched. Anchor the match to a known cache root and match the scheme exactly.

if part.lower() not in _MIRROR_URL_SCHEMES:
continue
netloc, *remainder = parts[index + 1 :]
# ``_mirror_path`` writes a port separator as '_', which is not valid in a host name
netloc = _MIRROR_NETLOC_PORT_RE.sub(r"\1:\2", netloc)
return f"{part.lower()}://{netloc}/{'/'.join(remainder)}"
Comment on lines +330 to +336

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.

P1 Cache paths are overmatched

When a locally authored asset path contains a directory named http, https, or omniverse, unmirror_file_path treats that component as the start of a cache layout, causing the exported stage to replace the local dependency with an unrelated remote URL that fails to resolve or loads the wrong resource.

Knowledge Base Used: Terrains and Shared Utilities

return ""


def _remote_fingerprint(url: str) -> dict | None:
"""Provider metadata identifying the revision of ``url`` the server currently holds.

Expand Down
22 changes: 22 additions & 0 deletions source/isaaclab/test/utils/test_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,28 @@ def test_using_local_copies_is_announced_once_per_cache_directory(asset_cache, m
assert {_REMOTE_URL, other_url} == {record.args[0] for record in per_asset}


@pytest.mark.parametrize(
"url",
[
"https://example.com/Assets/Isaac/6.0/Isaac/Props/Blocks/DexCube/Materials/dex_cube_mod.png",
"http://example.com/Assets/example.usd",
"omniverse://nucleus.example-lab.com:3009/Assets/example.usd",
],
)
def test_unmirror_file_path_recovers_the_url_a_copy_was_cached_from(tmp_path, url):
"""Test a cached copy names the asset it came from, so exports do not carry local paths."""
assert assets_utils.unmirror_file_path(assets_utils._mirror_path(url, str(tmp_path))) == url


@pytest.mark.parametrize(
"path",
["/home/user/assets/example.usd", "Materials/dex_cube_mod.png", "OmniPBR.mdl", ""],
)
def test_unmirror_file_path_leaves_paths_outside_the_cache_unclaimed(path):
"""Test a locally authored asset path is not mistaken for a cached remote copy."""
assert assets_utils.unmirror_file_path(path) == ""


def test_newton_asset_dir_uses_environment_override(tmp_path, monkeypatch):
"""Test that the Newton asset directory is defined from the environment."""
repo_dir = tmp_path / "newton-assets"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Rendering test stage dumps rewrite cached asset paths back to their source URLs, so a stage saved
through ``ISAAC_LAB_SAVE_STAGES`` no longer carries texture paths that only resolve on the machine
that ran the test.
15 changes: 15 additions & 0 deletions source/isaaclab_tasks/test/rendering_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,20 @@ def _sanitize_golden_stage_text(text: str) -> str:
return text.rstrip("\n") + "\n"


def _restore_remote_asset_paths(layer) -> None:
"""Point cached asset paths in ``layer`` back at the URLs they were downloaded from.

Remote USD assets are referenced through a local cache copy, so flattening resolves the
textures and materials they carry into absolute cache paths that exist only on the machine
that ran the test. Locally authored paths are left untouched.
"""
from pxr import UsdUtils # noqa: PLC0415

from isaaclab.utils.assets import unmirror_file_path # noqa: PLC0415

UsdUtils.ModifyAssetPaths(layer, lambda asset_path: unmirror_file_path(asset_path) or asset_path)


def maybe_save_stage(
test_name: str,
physics_backend: str,
Expand Down Expand Up @@ -551,6 +565,7 @@ def maybe_save_stage(
flat_layer = opened_stage.Flatten()
if flat_layer is None:
pytest.fail(f"Could not flatten the saved stage at {stage_path}.")
_restore_remote_asset_paths(flat_layer)

if out_dir:
os.makedirs(out_dir, exist_ok=True)
Expand Down
Loading