Skip to content

install.ps1: guard the mirror env restore and run its test in Windows CI - #12849

Merged
danielhanchen merged 1 commit into
mainfrom
guard-mirror-env-restore
Oct 6, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
guard-mirror-env-restore

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

tests/studio/test_unsloth_torch_override.ps1 has been failing since #11786, and nothing caught it because no CI job runs that file.

The test replays the outer finally of install.ps1 on its own, with only the variables that the finally itself touches. #11786 added the mirror env restore to that finally:

foreach ($_mirrorEnvName in @($script:MirrorEnvSaved.Keys)) {
    $_mirrorEnvValue = $script:MirrorEnvSaved[$_mirrorEnvName]

When MirrorEnvSaved is $null, @($null.Keys) is a one-item array holding $null. The loop therefore runs once, and indexing with a null key throws. That aborts the finally before the temp overrides file and UNSLOTH_KEPT_TORCH are cleaned up.

Which side was wrong

  • feat(install): fall back to CERNET and npmmirror when package hosts are blocked or slow #11786 (install.ps1) is correct in production. $script:MirrorEnvSaved = @{} is set before the try, so the null case cannot happen in a real run.
  • The restore loop was still fragile. The WoA resolver restore right above it is guarded with if ($script:WoaResolverEnvSaved), and this one was not. Any future path that reaches the finally without the init, or that resets the table, would silently skip the remaining cleanup.
  • The test was also incomplete. It never set MirrorEnvSaved, and it never checked that the restore actually returns the caller's values.

Changes

  • install.ps1: guard the mirror restore the same way as the WoA restore. Behaviour is unchanged when the table is initialised.
  • tests/studio/test_unsloth_torch_override.ps1: set the nothing-saved state explicitly. Add a case where a variable the fallback added is removed and a variable the caller had is restored, with the overrides file still deleted afterwards.
  • studio-windows-inference-smoke.yml: run the test alongside the other installer .ps1 tests, so a regression here fails CI.

Verification

main install.ps1 this branch
test_unsloth_torch_override.ps1 (pwsh 7, Linux) 5 checks fail All checks passed
at e27337cd89 (before #11786) passes n/a
tests/studio/test_installer_av_shapes.py n/a 246 passed, 1 skipped
scripts/lint_av_shapes.py n/a 0 new errors

@($null.Keys) is a one-item array holding $null, so the restore loop ran
once with a null key and indexing threw, stopping the finally before the
overrides file and UNSLOTH_KEPT_TORCH were cleaned up. Guard it the same way
as the WoA resolver restore just above it. Production initialises
MirrorEnvSaved before the try, so this only hardens the path.

test_unsloth_torch_override.ps1 replays that finally and had been failing
since #11786 added the restore, unnoticed because no CI job ran it. Cover
both the nothing-saved and the saved-variables cases and run the test in
the Windows inference smoke job with the other installer .ps1 tests.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for security reviews. Please try again later.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 6, 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-06T11:31:26.786103Z 180e33f 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: 180e33f0c6

ℹ️ 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".

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