Skip to content

Refresh a rewritten shortcut's icon where the shell cannot define the type - #11116

Merged
danielhanchen merged 99 commits into
mainfrom
av-fp-icon-refresh
Sep 28, 2026
Merged

danielhanchen merged 99 commits into
mainfrom
av-fp-icon-refresh

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Stacked on #11115. Review the top commit only; the base will disappear from this diff once #11115 merges.

What this changes

After writing the Unsloth Studio shortcuts, the installer tells Explorer about them with SHChangeNotify. The per-item notification is the one that matters: the global SHCNE_ASSOCCHANGED broadcast misses a same-name .lnk that was rewritten in place, and rewriting one in place is what every update does.

That call needs a type defined at runtime. Constrained Language Mode and WDAC Dynamic Code Security both refuse it, and on those hosts the whole block threw straight into its own catch: the shortcut worked, but its icon stayed stale until something else invalidated Explorer's cache.

The catch now sends the same two notifications, with the same constants in the same order, through a child interpreter using ctypes.

Why it is additive only

Cosmetic in both directions: the best case is a correct icon, the worst case is the stale icon that host already had.

A gap the test found

The function's own comment promised every path returns rather than throws, and a throw from the runner escaped it. That was covered by the caller's catch, so it would never have failed an install, but the function was not what it said it was. It now holds on its own, and removing the guard makes the check fail.

Testing

New tests/studio/test_early_python_icon_refresh.ps1, 12 checks, wired into cross-platform-parity-ci.yml on both the pwsh 7 and the Windows PowerShell 5.1 legs.

The notifications themselves are Windows only, so the rung is driven through a stubbed runner: every shortcut written is named to the child rather than just the last, a silent or unexpected answer is not treated as success, a throwing child does not escape, an empty list is handled, and the rung declines off Windows without spawning anything. The embedded probe is extracted from the AST, compiled as Python, and checked for both notification calls and for the declared SHChangeNotify signature, since an undeclared ctypes argument defaults to a C int and would truncate a pointer on 64 bit.

tests/studio/test_ci_shell_suite_coverage.py, tests/studio/test_installer_av_shapes.py and both installer test suites: 394 passed, 18 skipped.

No effect on installation, update, login or the shortcuts themselves

The shortcuts are written by exactly the code that wrote them before, to the same paths, with the same targets and icons. Only the notification that follows changes, and only on hosts where it previously did not happen at all.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 16, 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 ⚠️ Failed 2026-09-28T04:40:14.794739Z 7da0d11 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.

danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 16, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 16, 2026
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 16, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

Adversarial verification pass, and three real defects it found

I ran this stack through an independent adversarial audit whose brief was to falsify the claim that these are pure hardening changes, plus AST routing checks and a measured idempotency run. Three findings were genuine and are fixed here.

1. The Constrained Language Mode fallback did not work

Fixing the launcher was necessary and not sufficient, and my own check gave a false pass by exercising the launcher in isolation.

Driven end to end in a runspace created with InitialSessionState.LanguageMode = ConstrainedLanguage, the rung was still dead: Get-StudioEarlyPython threw on [System.IO.Path]::GetDirectoryName before the launcher was ever reached. CLM throws rather than returning null, so the ladder did not degrade to the rung below, it failed outright. Measured, per call:

Call Under CLM
[string]::IsNullOrWhiteSpace allowed
[System.IO.Path]::GetDirectoryName blocked
[System.IO.Path]::IsPathRooted blocked
[int]::TryParse blocked
Split-Path -Parent, -IsAbsolute allowed

Discovery now uses Split-Path -Parent, the resolver uses Split-Path -IsAbsolute, and the process image table parses its pid with a regex and a cast. The check now runs every function between the entry point and the answer. Restoring either blocked call makes it fail.

2. A broken extraction reported itself as a skip, and CI recorded a pass

tests/studio/test_early_python_path_resolver.ps1 stopped extracting the helpers its own bodies call when the launcher was split in two. Get-StudioEarlyPython then failed, the probe found no interpreter, the suite took its no-Python-on-this-host branch, and exited 0 having tested nothing.

All three early-Python suites now tell those two states apart: if the probe finds nothing while a python is on PATH, that is a broken extraction in the test file and it exits 1. Removing the helper names again reproduces the original break and now exits 1 instead of 0.

3. The icon rung's "never throws" promise was false

Invoke-StudioPythonShellIconRefresh called discovery outside its own try, on exactly the hosts where discovery throws. The caller's catch happened to cover it; the promise is now true on its own.

Idempotency, measured

The cmdlet launcher is the only new code that writes anything: three temporary files per call. Pointed at a private empty directory so a concurrent process cannot move the measurement, then run through ten successful calls, five non-zero exits, two timeout kills and a missing interpreter: nothing left behind. Removing the finally block makes the check fail.

Nothing else in this stack writes to disk or the registry at all, confirmed by scanning every new function body for write operations.

Exactness

The ctypes rung and the native rung must return the same string for the same process, or Test-StudioProtectedPathMatch compares a path from one against a path recorded by the other. They agree by construction only if the call is identical, so the three things that decide it are now read out of both and compared: the access right, the flags argument (0 is the Win32 path form; 1 would give \Device\HarddiskVolume...) and the buffer size. Three mutations, each caught by its own check.

Routing

AST checks confirm each new function has exactly one definition and its call sites are guarded as intended:

Get-StudioPythonProcessImageTable      1 def, 1 call, guarded by -not $script:StudioPythonProcessImageProbed
Invoke-StudioEarlyPythonScriptViaCmdlets 1 def, 1 call, only from the catch of the primary launcher
Invoke-StudioPythonShellIconRefresh    1 def, 1 call, inside a catch, under $createdShortcutCount -gt 0

Every call is inside a function invoked later, so PowerShell's lack of hoisting does not bite here.

Cross-platform

Staging CI on six OSes: Linux x64, Linux ARM64, Windows x64, Apple Silicon macOS, Intel macOS all green. Windows ARM64 failed on pyarrow having no win_arm64 wheel on PyPI, which is a dependency-availability problem in my staging harness rather than anything in this PR; that leg now points at the Windows-ARM64 wheelhouse release and is re-running.

What I will not claim

This is not zero-effect on every host. On a locked-down host the installer now sees a running Unsloth it previously missed, and refuses to install over it rather than proceeding. That is the intended behaviour and the reason the rung exists, but it is a behaviour change, not an invisible one.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 16, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex security review

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 16, 2026
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 16, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 9371c69e0b

ℹ️ 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 added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 16, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

Confirmed the type-defining rung in install.ps1 is still tried first and the child interpreter is only reached from its catch, with the same two SHChangeNotify constants in the same order. Will get this reviewed after the base lands.

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

Confirmed the type-defining rung in install.ps1 is still tried first and the child interpreter is only reached from its catch, with the same two SHChangeNotify constants in the same order. Will get this reviewed after the base lands.

@danielhanchen
danielhanchen force-pushed the av-fp-icon-refresh branch 2 times, most recently from 79726aa to 1a4a5cf Compare September 17, 2026 00:08
chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 17, 2026
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 17, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 1653d4a8f3

ℹ️ 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 added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 17, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: a6869a9b64

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

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 3f6b02e18a

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

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: f59bb73a31

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

Base automatically changed from av-fp-ctypes-helper to main September 28, 2026 04:39
# Conflicts:
#	.github/workflows/cross-platform-parity-ci.yml
#	install.ps1
#	tests/studio/test_early_python_path_resolver.ps1
#	tests/studio/test_early_python_process_image.ps1
@danielhanchen
danielhanchen merged commit ecc691b into main Sep 28, 2026
4 of 5 checks passed
@danielhanchen
danielhanchen deleted the av-fp-icon-refresh branch September 28, 2026 04:40
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants