Skip to content

Studio: install the dataset image URL guard when datasets loads, not at startup - #14888

Merged
danielhanchen merged 3 commits into
mainfrom
studio-lazy-image-decode-guard
Oct 23, 2026
Merged

danielhanchen merged 3 commits into
mainfrom
studio-lazy-image-decode-guard

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

#14701 routes dataset image URLs through the SSRF-guarded fetch by patching datasets.Image.decode_example. It applies that patch with a module-level install_guarded_image_decode() call in utils/datasets/remote_images.py, which runs from datasets import config. That module is on the startup import path:

routes/__init__.py -> routes/datasets.py -> hub/services/datasets/formatting.py
-> hub/utils/dataset_format.py -> utils/datasets/__init__.py -> format_conversion.py -> remote_images.py

So every Unsloth Studio and Desktop start loads datasets, pandas and pyarrow (and torch in CI). On main this fails test_startup_defers_torch.py (4 tests), and the Startup profile job fails its budget: 8.123 s median to a healthy port against 8.0 s.

Change

The guard itself is unchanged. Only when it is installed changes:

  • If datasets.features.image is already imported, it is patched immediately, as before.
  • Otherwise a meta-path finder wraps that module's loader and patches it as soon as it finishes loading, before any caller can decode a row. This is the same pattern utils/security/hub_data_files.py uses.

install_guarded_image_decode() keeps its name and idempotence. It now takes the module as an optional argument, so it can patch from inside the loader. The finder is inserted once.

Testing

  • New test_guard_applies_when_datasets_loads_after_this_module runs in a subprocess. It imports remote_images first and asserts datasets was not loaded, then imports datasets.features.image and asserts decode_example is guarded.
    • On main's code: this test and the 4 startup tests fail (5 failed).
    • With this change: all pass.
  • Dataset, VLM, image, format and startup test files in studio/backend/tests: 2598 passed, 34 skipped.
  • import main wall time, 5 runs each on the same machine: main 9.07 (cold), 6.36, 6.07, 6.26, 6.34 s; this branch 6.12, 6.12, 5.72, 5.70, 5.54 s.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-23T03:28:44.419486Z a1dc499 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: a1dc499bf9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit aab980f into main Oct 23, 2026
2 of 36 checks passed
@danielhanchen
danielhanchen deleted the studio-lazy-image-decode-guard branch October 23, 2026 04:15
danielhanchen added a commit that referenced this pull request Oct 23, 2026
…sion harness (#14903)

## Summary

`TestFormatConversionNoTorchVenv` (4 tests, Python 3.12 and 3.13) fails
on main, so Backend CI is red on every PR:

```
File "<string>", line 10, in <module>
ImportError: attempted relative import with no known parent package
```

The harness execs `format_conversion.py` as a standalone script and
rewrites its relative imports (`.cells`, `.iterable`,
`.format_detection`) to top-level ones. #14701 added `from
.remote_images import fetch_untrusted_image_bytes, is_network_share` on
line 10, which the harness does not rewrite.

## Change

Rewrite `from .remote_images import` the same way as `.cells` in the
four exec snippets. `remote_images.py` imports only the standard library
at module level, so it loads in the no-torch venv. Test-only change.

## Testing

- `tests/python/test_studio_import_no_torch.py` on main: 4 failed. With
this change: 29 passed.
- With #14888's `remote_images.py` (guard installed on datasets import)
in place: 29 passed.
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.

1 participant