Skip to content

Unbreak main: catch the install.ps1 handoff harness up with the block it drives - #10538

Merged
danielhanchen merged 3 commits into
mainfrom
ci-handoff-tests
Sep 9, 2026
Merged

danielhanchen merged 3 commits into
mainfrom
ci-handoff-tests

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

tests/test_windows_amd_gpu_scan_fallback.py fails four cases on main, so every open PR inherits them.

What is actually wrong

The harness lifts install.ps1's save / set / try / finally block around the setup call and runs it with that call replaced by a probe. The block has grown dependencies since the harness was written:

None of them were bound in the stub script. Under $ErrorActionPreference = 'Stop' the block threw, the harness's own catch { } swallowed it, and every assertion read "never ran". That looks like a handoff defect and is not one: the shipped code is fine.

The fourth failure is test_installer_restores_the_private_handoff_after_setup, which asserted that the save appears after the --with-llama-cpp-dir bail in file order. That bail now sits inside the try whose finally restores, which is a stronger guarantee than the ordering the test used as a proxy for it.

What this changes

  • Bind the installer inputs and stub the functions the block calls.
  • Assert the replacement actually matched, so a future rename fails with that sentence rather than an empty probe.
  • Report the swallowed exception and fail on it, unless the case under test asked the block to throw.
  • Read the report as the last JSON line on stdout, so a stub's own return value cannot be mistaken for it.
  • Replace the ordering assertion with the invariant it stood for: save, then the bail, then the restore.

It is still a real test

Dropping the inherited-handoff clear from install.ps1 fails stale_only; restoring it passes. All 82 tests in the file pass.

…y why when it cannot

main fails four cases in tests/test_windows_amd_gpu_scan_fallback.py.

The lifecycle harness lifts install.ps1's save / set / try / finally block and runs
it with the setup call replaced by a probe. That block has since grown a dependency
on the installer's own inputs and helpers (Get-ExpectedTorchFlavorTag and the torch
pin check from #10524, Write-ApplicationControlBlocked from #8066), and it reads
$script:ManagedUnslothCliExit on the line right after the call it replaces, then
returns early when that exit code is null. None of those were bound, so under
ErrorActionPreference Stop the block threw, the harness's own catch swallowed it,
and every assertion read "never ran" -- which looks like a handoff defect and is not
one.

Bound them, and made the harness loud rather than silent: the replacement is
asserted to have matched, the swallowed error is reported back and fails the test
with its message, and the report is read as the last JSON line so a stub's own
output cannot be mistaken for it.

The fourth failure was an ordering assertion, that the save appears after the
--with-llama-cpp-dir bail in file order. That bail now sits inside the try whose
finally restores, which is a stronger arrangement than the ordering stood for, so
the check is now the arrangement itself: save, then the bail, then the restore.

Still a real test: dropping the inherited-handoff clear from install.ps1 fails
stale_only, and restoring it passes. 82 tests in the file.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 8, 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-09-08T20:15:21.761378Z 14b16c4 New commits
ℹ️ 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.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 8, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…d throw

Two review points, both about this harness accepting less than it claims.

The setup_throws cases skipped the error assertion entirely, so any exception
passed: a helper failing before the setup call would leave the shipped finally to
restore the environment, and every assertion would hold without the failure path
ever running. They now require the injected "setup exploded" and fail on anything
else. Checked by calling an undefined function before the setup call: all four
cases fail, and pass again once it is removed.

The restore invariant was three string offsets, which establish order and not
structure. The block now runs inside a function, so its own return leaves the
block rather than the script, and a new case takes the --with-llama-cpp-dir bail
with a directory that does not exist and reads the environment afterwards. It
asserts on the two variables the block sets at the top of its try, above the bail,
since those are what say the finally ran rather than that nothing happened.
Checked by moving the assignments and the bail out of the try, which the textual
ordering still accepts and this rejects.

83 tests in the file.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: dc996ee67a

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

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 8, 2026
Collapse the multi-line explanations added with the bail test down to one or
two lines each, and drop the parts the code already says. No behaviour change:
comments and whitespace only.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 8, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 8, 2026
@danielhanchen
danielhanchen merged commit 4d96157 into main Sep 9, 2026
15 of 16 checks passed
@danielhanchen
danielhanchen deleted the ci-handoff-tests branch September 9, 2026 01:09
danielhanchen added a commit that referenced this pull request Sep 9, 2026
#10538 caught the handoff harness up with the block and added a runtime bail test.
That test asserts two variables, STUDIO_PACKAGE_NAME and SKIP_STUDIO_BASE, and
the setup-call cases assert none: they check the ROCm handoff and the public
override only. The block saves and restores fifteen. Twelve had no restore
assertion anywhere, and each is a variable that leaks into the caller's shell,
which `irm ... | iex` makes the user's own terminal.

The other half was missing too. Nothing seeded those variables in the child env,
so only the arm of the finally that REMOVES a variable ever ran. The arm that puts
a caller's prior value back was unexercised for all fifteen.

Three changes.

The block is sliced from the first save rather than from the ROCm one. Five pairs
are saved above that point, and the harness was supplying their $previous* and
$hadPrevious* itself, so their restores were measured against harness constants
and a save-side bug could not show at all. Now all fifteen are shipped code on
both halves.

Presence of the caller variables is a parameter, crossed with the existing
setup_ok / setup_throws split and applied to the bail. The absent arm asserts
Test-Path Env:NAME is false, not an empty or null value: PowerShell 7.5+ keeps a
variable present when it is assigned "", so a restore writing "" instead of
removing would satisfy a value comparison while leaving the caller holding a
variable it never had.

Sentinels are distinct per variable, so a finally that restored every variable
from the wrong save is caught rather than passing.

The table is checked against the source, so a sixteenth save becomes a named
failure instead of a silent gap. UV_CACHE_DIR, TMP and TEMP stay out of scope and
the test says why: they are saved and restored hundreds of lines outside this
block, so reaching them means slicing most of install.ps1.

Kept as they are: the save < bail < restore offset assertion from #10538, which is
a cheap companion to the runtime tests rather than a substitute, and its own
docstring already says ordering cannot prove the finally runs. The two variables
its bail test named individually are now two of the fifteen, checked in both
directions instead of only for removal.

Mutation-checked against this base. Writing "" instead of removing
UNSLOTH_SETUP_PYTHON fails nine absent cases and no present case. Dropping the
UNSLOTH_NO_TORCH restore fails both arms. Restoring UNSLOTH_NO_TORCH from the
STUDIO_PACKAGE_NAME save fails nine present cases, the cross-wiring only distinct
sentinels can see. Breaking the UNSLOTH_TAURI_MODE save fails nine present cases
here and is invisible on main, where all 83 pass with it broken.
danielhanchen added a commit that referenced this pull request Sep 10, 2026
…es (#10566)

* Cover the restore of every variable the handoff block saves

#10538 caught the handoff harness up with the block and added a runtime bail test.
That test asserts two variables, STUDIO_PACKAGE_NAME and SKIP_STUDIO_BASE, and
the setup-call cases assert none: they check the ROCm handoff and the public
override only. The block saves and restores fifteen. Twelve had no restore
assertion anywhere, and each is a variable that leaks into the caller's shell,
which `irm ... | iex` makes the user's own terminal.

The other half was missing too. Nothing seeded those variables in the child env,
so only the arm of the finally that REMOVES a variable ever ran. The arm that puts
a caller's prior value back was unexercised for all fifteen.

Three changes.

The block is sliced from the first save rather than from the ROCm one. Five pairs
are saved above that point, and the harness was supplying their $previous* and
$hadPrevious* itself, so their restores were measured against harness constants
and a save-side bug could not show at all. Now all fifteen are shipped code on
both halves.

Presence of the caller variables is a parameter, crossed with the existing
setup_ok / setup_throws split and applied to the bail. The absent arm asserts
Test-Path Env:NAME is false, not an empty or null value: PowerShell 7.5+ keeps a
variable present when it is assigned "", so a restore writing "" instead of
removing would satisfy a value comparison while leaving the caller holding a
variable it never had.

Sentinels are distinct per variable, so a finally that restored every variable
from the wrong save is caught rather than passing.

The table is checked against the source, so a sixteenth save becomes a named
failure instead of a silent gap. UV_CACHE_DIR, TMP and TEMP stay out of scope and
the test says why: they are saved and restored hundreds of lines outside this
block, so reaching them means slicing most of install.ps1.

Kept as they are: the save < bail < restore offset assertion from #10538, which is
a cheap companion to the runtime tests rather than a substitute, and its own
docstring already says ordering cannot prove the finally runs. The two variables
its bail test named individually are now two of the fifteen, checked in both
directions instead of only for removal.

Mutation-checked against this base. Writing "" instead of removing
UNSLOTH_SETUP_PYTHON fails nine absent cases and no present case. Dropping the
UNSLOTH_NO_TORCH restore fails both arms. Restoring UNSLOTH_NO_TORCH from the
STUDIO_PACKAGE_NAME save fails nine present cases, the cross-wiring only distinct
sentinels can see. Breaking the UNSLOTH_TAURI_MODE save fails nine present cases
here and is invisible on main, where all 83 pass with it broken.

* Vary caller-variable presence per variable, and take the llama.cpp success path

Two gaps in the coverage this branch added.

Presence was one flag for all fifteen variables, so the suite only ever ran
all-present or all-absent. Distinct sentinels catch a restore reading the wrong
variable's VALUE, but not one reading the wrong variable's $hadPrevious FLAG:
with every flag the same, that bug picks the right branch by luck. Presence is now
a pattern, and two complementary mixed ones run alongside all and none, so no
variable is always on the same side as any other. Not exhaustive on purpose, 2**15
would be a worse test rather than a better one.

Mutation-checked. Pointing the UNSLOTH_NO_TORCH restore at
$hadPreviousStudioPackageName while leaving its value correct fails ten mixed
cases and passes every all-present and all-absent case, which is the shape of bug
the mixed patterns exist for. It also passes the complementary mixed pattern,
where the wrong flag is true and the value restored is $null, and assigning $null
to an env var removes it, so the accident lands on the right answer.

--with-llama-cpp-dir was only ever given a path that does not exist. The success
path resolves it into UNSLOTH_LOCAL_LLAMA_CPP_DIR, and that is the only assignment
to that variable in the block, so nothing reached it: the bail returns above it and
every other case passes $null. Its restore was being satisfied by never being
dirtied. A new case passes a directory that is there, asserts the block runs on to
the setup call rather than bailing, and asserts the restore.

Mutation-checked too. Deleting the UNSLOTH_LOCAL_LLAMA_CPP_DIR restore leaves all
thirty-two setup-call cases and all four bail cases green and fails only the four
new ones.

* Separate every pair of restoration flags, and close the anchor hole

Three follow-ups.

The presence patterns were even/odd complements, which do not do the job they
claim. Two variables of the same parity are present together in one pattern and
absent together in the other, so a restore consulting the wrong variable's
$hadPrevious flag still picks the right branch for them in every case. Cross-wiring
between indices 0 and 2 was invisible.

Replaced with a binary encoding: pattern k keeps the names whose index has bit k
set. Any two distinct indices differ in some bit, so every PAIR is split by at
least one mask, which is the condition under which a wrong flag produces a wrong
branch. Fifteen names need four masks. Six patterns in total, and the exhaustive
claim is over pairs, which is the failure mode, rather than over subsets. A new
test asserts the separation property directly, so adding a sixteenth name reports
the shortfall rather than quietly thinning the coverage.

Demonstrated rather than argued. Cross-wiring UNSLOTH_TAURI_MODE (index 2) to
SKIP_STUDIO_BASE (index 0), same parity, value left correct: the old scheme passes
all 32 cases, the masks fail 8, all of them mask1, which is the mask that separates
those two indices.

The coverage guard had a hole of its own. It read the save side of a slice that
starts at whichever save is first today, so a save PREPENDED above the anchor fell
outside the slice and was invisible to the very guard meant to catch that drift.
The guard now also reads the restore side, which cannot escape because the finally
is inside the slice by construction: a prepended save appears as a variable the
block restores but never seems to save. Anchoring on the enclosing function was the
alternative, and it is no more stable than the current anchor while being harder to
read, so the check was made anchor-independent instead of the anchor made clever.

The llama.cpp success case asserted only that the block ran past the bail, not that
the child received anything. It now asserts the resolved path the child would
inherit, read at the setup call rather than after the finally.

* Cover every ORDERED pair of restoration flags, not just every pair

Separating each pair of caller variables was not enough. Substituting a
flag in the finally is a directed edit: `if ($hadPreviousSkipStudioBase)`
becoming `if ($hadPreviousTauriMode)` still assigns
$previousSkipStudioBase, so it is only observable when SKIP_STUDIO_BASE
is present and UNSLOTH_TAURI_MODE is absent. In the other direction the
then-arm assigns the saved $null, which removes the variable exactly as
the correct code does, and nothing changes.

The binary masks could not supply that direction for every pair. A mask
gives "A present, B absent" only when index(A) is not a submask of
index(B), and index 0 is a submask of everything: SKIP_STUDIO_BASE was
absent from every mask and present only in "all", where every other name
is present too. Mutation testing the 182 directed substitutions between
the fourteen masked variables killed 139 and left 43 alive, thirteen of
them in SKIP_STUDIO_BASE's own restore, and the file passed 136 tests
against an install.ps1 whose SKIP_STUDIO_BASE restore read the tauri
flag.

Add the complement of each mask, which reverses the ordering of every
pair the mask splits, and assert the directional property instead of the
symmetric one. All 182 substitutions are now detected, as are the 28
that involve the ROCm handoff, for 210 of 210 over all fifteen flags.
The properties that already held are unchanged: 91 of 91 unordered pairs
still separated, all 15 save deletions and all 15 restore deletions
still rejected, and all 15 restores that write "" instead of removing
still rejected on PowerShell 7.6.0.

* Run the repo formatter over the new assertion

* Dirty the two optional handoffs, and pin every save above the try

Two holes left in the handoff lifecycle coverage, both found by mutating
install.ps1 and watching the suite stay green.

UNSLOTH_STUDIO_HOME and STUDIO_LOCAL_REPO are the only two saved variables
the try does not always assign: the first is set only under redirect mode
'env', the second only under --local, and every other mode removes them
instead. The harness hard-coded redirect mode 'none' and no local install,
so for those two the try left the variable ABSENT and the finally's
Remove-Item arm had nothing to undo. Deleting that arm outright was
invisible, while the same deletion on any of the other thirteen is caught
at once. A new case drives the modes that really do set them, on both the
success and the failure path, and asserts the child saw each value so the
case cannot quietly stop dirtying them and go green again on an
undirtied restore.

Second, the save-order check compared SETS, so moving a save from above
the try down next to its assignment still matched. Nothing at runtime
catches that either: the injected failure is the setup call and the bail
is the missing directory, both below where such a save would land. The
case that bites is a throw above it, leaving $hadPrevious unbound and the
finally removing a value the caller owned. The order check now covers all
fifteen saves and their flags rather than the ROCm handoff alone.

Mutation over the block, 257 mutants, survivors 0. Before: deleting the
else-arm Remove-Item survived for exactly those two variables (13/15
killed), and moving a save inside the try survived for 14 of 15.

* Tighten the comments on the handoff coverage tests

* Parametrise the child-arch test over the caller patterns

Adding caller_env to _run_handoff_lifecycle gave it a default of "all", and
test_only_this_runs_arch_is_handed_to_the_child took that default silently. Before
this branch the helper had no such parameter, so that test ran with no caller
variables set at all. The default quietly replaced the empty-caller case, and the
empty-caller case is the one with teeth.

Shown with a mutant that makes the stale-handoff clear depend on an unrelated
variable's $hadPreviousTauriMode flag:

  base                      1 failed
  this branch before        3 passed     the defect goes through
  this branch after         5 failed

Under caller_env="all" the Tauri variable is present, so the wrong flag reads true
and the clear happens anyway. Only a pattern that leaves it absent exposes it.

Unmutated: 224 passed, up from 197.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: danielhanchen <[email protected]>
Co-authored-by: oobabooga <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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