Skip to content

fix(studio): report why a model's security checks blocked it - #16292

Merged
danielhanchen merged 4 commits into
unslothai:mainfrom
Lyxot:fix/studio-unscannable-model-message
Nov 1, 2026
Merged

danielhanchen merged 4 commits into
unslothai:mainfrom
Lyxot:fix/studio-unscannable-model-message

Conversation

@Lyxot

@Lyxot Lyxot commented Oct 31, 2026 •

Copy link
Copy Markdown
Collaborator

Bug

With ModelScope as the model source, a repo with no .py files and no auto_map could show "Custom code blocked ... declares custom Python code ... A security scan flagged CRITICAL issues". No scan had run and nothing was flagged. A direct load would have reported "flagged as None".

Root cause

Two separate problems:

  • The dialog treated every non-approvable result as a CRITICAL finding, including checks that could not run, where max_severity is None. The gates fail closed correctly, but nothing carried the reason for the block.
  • _config_has_auto_map returns "unknown" when any optional config cannot be read, and the gate then reported has_remote_code=True. On a source 404 this happens even for a cached repo whose config has no auto_map, because the one optional config missing from the cache cannot be confirmed absent.

What changed

  • Both gates now record a block_cause: unsafe_files, critical_findings, unscanned_weights, managed_refused, not_on_source or unscannable. The scan route reports the strongest one, so a finding always outranks a check that could not run, along with the active source and the missing repo.
  • The dialog picks its copy from the cause and names the source and the next step. Unscanned pickle weights no longer claim Hugging Face flagged them, and a managed-account refusal no longer claims a CRITICAL finding. New strings are in all locales.
  • The inference, training and export workers only say "flagged as" when a scan produced a severity.
  • A repo the source does not have now reports has_remote_code=False. It stays blocked and non-approvable, and the route still forces the dialog.

Behavior change to review closely: cached snapshots on ModelScope

This is the one place a load blocked today can now pass. When ModelScope answers that it has no such repo and the cache holds a main snapshot, both gates evaluate that snapshot instead of blocking.

Measured with huggingface_hub 1.32: on a repo 404, hf_hub_download and snapshot_download return the refs/main cached files, so a load by repo id reads that snapshot. Judging it inspects what would actually run: code in it still goes through the full scan (a CRITICAL there still hard-blocks), and pickle weights still block as unscanned_weights. Hugging Face is excluded because its 404 can mean private to this caller.

Validation

Against the real ModelScope adapter:

Repo Result
Absent from ModelScope, cached, no code, safetensors allowed, no auto_map, cached weights inert
Absent from ModelScope, not cached blocked, not_on_source, has_remote_code=False
Present on ModelScope unchanged, allowed

The new dialog was checked in a running Unsloth Studio with an absent repo: it shows the source and the switch instruction, with no CRITICAL claim and no enable button. An actual load of the cached repo was not run because it is 187 GB; only its gate decisions were checked.

pytest studio/backend/tests/test_consent_gate.py studio/backend/tests/test_file_security.py studio/backend/tests/test_export_ssm_kernels.py
node --experimental-strip-types --test tests/remote-code-block-copy.test.ts
npm run i18n:check:strict

Mutation checks: 25 of 25 backend and 8 of 8 frontend mutants were caught by the test that owns each guarantee. Four tests in test_export_ssm_kernels.py fail on macOS, and the same four fail on unmodified main. The dialog's rendering has no automated test: its test covers the copy selection and that the dialog is wired to it.

Before / after

Studio set to ModelScope, loading from the chat model picker a cached repo that exists on no hub (config.json plus pytorch_model.bin, no auto_map, no .py). Merge base d6ab4f64a on the left, head 77f0afdb2 on the right, each a separate install with its own isolated cache.

Block dialog before and after

Before, the dialog claims the repo declares custom code and a scan flagged CRITICAL issues (the backend reported has_remote_code: true and "Remote code is present (auto_map)"). After, it names the unscanned pickle file and the way forward (has_remote_code: false, block_cause: unscanned_weights). The load stays blocked on both sides.

A check that could not run reached the consent dialog as a CRITICAL finding, and a repo missing from the active source as one with custom code. Both gates now record a block cause, which the dialog and load errors report with the source and next step. On ModelScope, a missing repo with a cached main snapshot is judged by that snapshot, which is what the hub falls back to loading.
[skip ci]
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 1, 2026
@danielhanchen

Copy link
Copy Markdown
Member

Review record for #16292, carried over from the mirror it was reviewed on: danielhanchen/unsloth-staging-review#649.

Findings are quoted as posted and attributed to the account that posted them. The reactions shown are the triage recorded on the mirror; none were re-applied here. Commits are named as the mirror's, with this PR's equivalent where one was found.

Round 1: reviewed mirror 952d2285bc (this PR's 77f0afdb2)

chatgpt-codex-connector[bot] (on the mirror)

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 952d2285bc

No triage reaction was recorded on the mirror

Verdict

The round converged at mirror 952d2285bc (this PR's 77f0afdb2).

This is the review as it stood at that commit. Anything pushed to this PR afterwards was not part of it.

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.

2 participants