Skip to content

[Fix] multimodal: Fail bad client media with a client error - #48778

Merged
hnyls2002 merged 6 commits into
mainfrom
lsyin/media-input-errors
Nov 11, 2026
Merged

hnyls2002 merged 6 commits into
mainfrom
lsyin/media-input-errors

Conversation

@hnyls2002

@hnyls2002 hnyls2002 commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Port of #48414

Takes the media-input hardening from the Kimi-K3.1 Day-0 branch and finishes it for every loader: bad client media fails the request as a client error (400), and server-side invariant failures are no longer reported as one. The HEIF opener and the new image extensions from the same branch are in #49673.

Summary

On main, these reach the server as a 500 or hang a worker:

  • A local path that is a FIFO hangs the reading worker; /dev/zero grows memory without bound (8.5 GB in 4 s for an image); a directory or missing path is a 500.
  • A raw base64 JPEG (it starts with /9j/) is opened as a file path and fails with a 500.
  • On the Kimi _load_single_item path, snapshot_media and decode_media_snapshot, an unreachable URL, a timeout or a decompression bomb is a 500, because those paths skip the client-error mapping the base processor does.

With this PR:

  • One local-file reader (read_local_media_file / check_local_media_file in multimodal/media_io.py) for images, video and audio, and for the loaders that read paths themselves (Inkling, MiMo, MoSS-VL). It opens with O_NONBLOCK (a FIFO fails at once), accepts only regular files, caps the size at --media-url-max-file-size-mb, and turns a missing, directory, looping or socket path into a ValueError (400). Permission errors stay 500s.
  • Two server args, next to --allowed-media-domains and --media-url-max-file-size-mb and applied the same way (also to spawned CPU workers):
    • --media-url-timeout: one download timeout for every media loader. Default: unset, so each loader keeps its timeout (REQUEST_TIMEOUT if set, else its own default).
    • --allow-local-media-files (default on; --no-allow-local-media-files to reject local paths and file:// URLs). Rejection happens before any file probe, so the error does not reveal whether a file exists.
  • A value that is neither valid base64 nor an existing file says both, instead of Non-base64 digit found.
  • snapshot_media, decode_media_snapshot and the Kimi _load_single_item map client media failures to ValueError.
  • Artifact-cache and Kimi-K3 processor invariant checks raise RuntimeError (500) instead of ValueError.

Changes to existing code

Without the new args:

  • Local image, video and audio files over --media-url-max-file-size-mb (64 MiB by default) are rejected; before, local files had no cap.
  • REQUEST_TIMEOUT now also applies to the Inkling (30 s) and MiMo image (3 s) downloads, and is parsed as a float.
  • A plain video path containing #, ? or %xx loads the file it names (main checked one path and opened another).
  • Spawned CPU workers (cuda_vmm) now get the server's media policy; before they fell back to the defaults.
  • The cases in the Summary return 400 instead of 500 or hanging.

Verification

  • Probes against main and this branch for each loader: FIFO, /dev/zero, directory, missing path, symlink loop, over-cap file, raw /9j/ base64, decompression bomb on the artifact path, unreachable URL on the Kimi path, and every loader with --no-allow-local-media-files.
  • cd test && python -m pytest -q registered/unit/multimodal/test_media_input_errors.py registered/unit/models/test_kimi_k25.py registered/unit/test_server_args_migration.py: 79 passed. Every file under registered/unit/multimodal/, registered/unit/server_args/ and registered/unit/models/test_kimi_k25.py fails no test that passes on main (local macOS, CPU).

CI States

Latest PR Test (Base): 🚫 Run #42931812221
Latest PR Test (Extra): ❌ Run #42931812182
Latest PR Test (AMD ROCm 10): 🚫 Run #42931812284

Tip

Base CI only covers the core cases, and its workload may not exercise your change. Use /rerun-test to run the tests your change touches, or copy this prompt for an agent:

Find the registered tests this PR affects and run them with /rerun-test, following https://github.com/sgl-project/sglang/blob/main/.agents/skills/rerun-test/SKILL.md

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

@mintlify

mintlify Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
sglang-doc 🟢 Ready View Preview Nov 11, 2026, 12:18 AM

💡 Tip: Enable Automations to automatically generate PRs for you.

# Conflicts:
#	python/sglang/srt/arg_groups/field_order.py
@hnyls2002

Copy link
Copy Markdown
Collaborator Author

/rerun-test test_media_input_errors.py test_media_url_security.py test_base_processor_bad_input.py test_media_artifact_processor.py test_inkling_media_errors.py test_audio_container_decode.py test_preprocess_cache.py registered/unit/models/test_kimi_k25.py test_server_args_migration.py registered/unit/server_args/test_server_args.py

@hnyls2002

Copy link
Copy Markdown
Collaborator Author

/rerun-test test_feature_identity.py

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

🚀 ubuntu-latest (9 tests): ✅ View workflow run

cd test/ && python3 registered/unit/multimodal/test_media_input_errors.py  # base-a
cd test/ && python3 registered/unit/multimodal/test_media_url_security.py  # base-a
cd test/ && python3 registered/unit/multimodal/test_base_processor_bad_input.py  # base-a
cd test/ && python3 registered/unit/multimodal/test_media_artifact_processor.py  # base-a
cd test/ && python3 registered/unit/multimodal/test_inkling_media_errors.py  # base-a
cd test/ && python3 registered/unit/multimodal/test_audio_container_decode.py  # base-a
cd test/ && python3 registered/unit/models/test_kimi_k25.py  # base-a
cd test/ && python3 registered/unit/test_server_args_migration.py  # base-a
cd test/ && python3 registered/unit/server_args/test_server_args.py  # base-a

🚀 1-gpu-5090 (1 test): ✅ View workflow run

cd test/ && python3 registered/unit/multimodal/test_preprocess_cache.py  # base-b

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

🚀 ubuntu-latest (1 test): ✅ View workflow run

cd test/ && python3 registered/unit/multimodal/test_feature_identity.py  # base-a

@hnyls2002 hnyls2002 added the run-ci CI: run the baseline test suite on this PR label Nov 11, 2026
@hnyls2002

Copy link
Copy Markdown
Collaborator Author

/rerun-test registered/unit/multimodal/rust/shared/test_fetch.py

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

🚀 ubuntu-latest (1 test): ✅ View workflow run

cd test/ && python3 registered/unit/multimodal/rust/shared/test_fetch.py  # base-a

@hnyls2002
hnyls2002 merged commit ddd9cc9 into main Nov 11, 2026
93 of 127 checks passed
@hnyls2002
hnyls2002 deleted the lsyin/media-input-errors branch November 11, 2026 00:33
hnyls2002 added a commit that referenced this pull request Nov 11, 2026
yhyang201 added a commit that referenced this pull request Nov 13, 2026
Carry media_url_timeout and allow_local_media_files (#48778) through MultimodalProcessorConfig.
yhyang201 added a commit to knlb-tml/sglang that referenced this pull request Dec 1, 2026
…lvers

sgl-project#48778 dropped the is_file check in _read_media_bytes, so registered-scheme URLs with an image extension skipped the resolver registry.
sgl-project#51926 added the Inkling-2 processor, whose _resolve_image did not consult the registry.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation npu run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant