Skip to content

Fix Studio silently exiting on Windows without error output - #4527

Merged
danielhanchen merged 8 commits into
mainfrom
fix/studio-silent-crash
Mar 22, 2026
Merged

danielhanchen merged 8 commits into
mainfrom
fix/studio-silent-crash

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Mar 22, 2026 •

Copy link
Copy Markdown
Member

Summary

Two issues causing Studio to fail on Windows:

  1. Silent crash on startup -- unsloth studio launches a child process via subprocess.Popen to run the server in the studio venv. If the child crashes during startup (e.g. a missing package like data_designer_unstructured_seed), the parent calls typer.Exit(rc) with no message. The user sees "Launching Unsloth Studio... Please wait..." and then the prompt returns with zero feedback.

  2. Conda Python breaks torch DLL loading -- setup.ps1 and install.ps1 pick up whichever Python appears first on PATH. When Miniconda/Anaconda Python is first, the studio venv is created with conda CPython, which ships modified DLL search paths that prevent torch from loading c10.dll. Standalone CPython (python.org, winget, uv) does not have this issue.

Changes

studio/backend/run.py - Wrap run_server() in try/except with clear error banner. Reconfigure stderr to UTF-8 on Windows.

unsloth_cli/commands/studio.py - Print error when child process exits nonzero on Windows.

studio/backend/routes/data_recipe/seed.py - Make data_designer_unstructured_seed import optional. Server starts normally; HTTP 500 only if endpoints are actually called.

install.ps1 - Find-CompatiblePython skips conda/miniconda/anaconda/miniforge/mambaforge Python paths.

studio/setup.ps1 - Python candidate loop skips conda interpreters with a [SKIP] log. Errors with install instructions if only conda Python is found.

Test plan

  • On Windows with Miniconda on PATH, verify setup skips it and uses standalone CPython
  • Verify unsloth studio starts correctly when all packages are installed
  • Verify clear error message when a required package is missing
  • Verify no regression on Linux/Mac

On Windows, `unsloth studio` launches a child process via
subprocess.Popen to run the server in the studio venv. If the child
crashes (e.g. due to a missing package), the parent just calls
typer.Exit(rc) with no message -- the user sees "Launching Unsloth
Studio... Please wait..." and then the prompt returns with zero
feedback.

Root cause: `data_designer_unstructured_seed` is imported at the top
level in seed.py. If this package is not installed in the studio venv,
the entire import chain (seed.py -> routes/__init__.py -> main.py ->
run_server()) crashes with ModuleNotFoundError. Since run.py has no
try/except around run_server() and studio.py does not report nonzero
exit codes, the failure is completely silent.

Changes:
- run.py: wrap run_server() in try/except, print clear error with
  traceback to stderr. Also reconfigure stderr encoding on Windows so
  tracebacks with non-ASCII paths do not cause secondary failures.
- studio.py: print an error message when the child process exits with
  a nonzero code on Windows, so the user knows something went wrong.
- seed.py: make data_designer_unstructured_seed import optional with
  a try/except fallback. The server starts normally and only returns
  HTTP 500 if the unstructured seed endpoints are actually called.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the user experience on Windows by addressing silent failures when launching Unsloth Studio. It introduces comprehensive error handling and informative messages at various layers, from the CLI to the backend server, ensuring that users are notified and guided when the Studio fails to start, particularly due to missing dependencies. Additionally, it makes a specific dependency optional, allowing the server to function even if that package is not installed, and improves error output reliability on Windows by configuring stderr encoding.

Highlights

  • Improved Error Reporting on Windows: The Studio server (run.py) now includes robust try/except blocks around its startup, providing clear error messages and full tracebacks to stderr if it fails to launch. This addresses the issue of silent exits.
  • Optional data_designer_unstructured_seed Dependency: The data_designer_unstructured_seed package import in seed.py is now optional. If the package is not installed, the server will still start, and attempts to use its functionality will result in a clear HTTP 500 error, rather than a silent crash.
  • Enhanced CLI Feedback for Child Process Exits: The unsloth studio command now checks the exit code of the child process on Windows. If the child process exits with a non-zero code, the CLI will display an informative error message to the user, guiding them to re-run setup if necessary.
  • Windows stderr Encoding Configuration: To prevent UnicodeEncodeError when tracebacks contain non-ASCII paths on Windows, sys.stderr is now reconfigured to use UTF-8 encoding in run.py.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request effectively addresses the issue of unsloth studio silently exiting on Windows during startup failures. The changes are well-structured: the root cause, an unconditional import, is fixed by making the dependency optional; the backend script is enhanced to catch and report startup errors with a detailed traceback; and the command-line interface is updated to notify the user of non-zero exit codes. I have one minor suggestion to improve debuggability by logging an exception that is currently being silenced, in accordance with the repository's general guidelines.

Comment thread studio/backend/run.py
Comment on lines +265 to +266
except Exception:
pass

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Silently ignoring exceptions here can hide issues with terminal configuration on Windows, which could lead to Unicode-related errors later. It's better to log this failure, even if it's just a warning, to aid in debugging. This aligns with the general rule to avoid silent except Exception: pass blocks.

Suggested change
except Exception:
pass
except Exception as e:
print(f"Warning: Failed to reconfigure stderr for UTF-8: {e}", file=sys.stderr)
References
  1. Avoid using broad, silent exception handlers like except Exception: pass. Instead, log the exception, even if at a debug level, to aid in future debugging.

Conda-bundled CPython ships modified DLL search paths that prevent
torch from loading c10.dll on Windows. The Studio server fails
silently at startup because the venv was created with conda's Python.

Standalone CPython (python.org, winget, uv) does not have this issue.

Both install.ps1 and setup.ps1 now skip any Python binary whose path
contains conda, miniconda, anaconda, miniforge, or mambaforge when
selecting the interpreter for the studio venv. If only conda Python
is available, the scripts print an error with instructions to install
standalone CPython.
@danielhanchen

Copy link
Copy Markdown
Member Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request effectively addresses two critical issues on Windows: a silent crash on startup and incompatibilities with conda's Python distribution. The changes introduce robust error handling in the server startup process and refine the Python environment detection in the installation scripts to avoid problematic conda interpreters. My review includes a couple of suggestions for improvement: one to enhance logging by avoiding a silent exception, and another to improve the consistency of optional dependency handling. Overall, these are solid improvements for the stability and user experience of Unsloth Studio on Windows.

Comment on lines +19 to +28
try:
from data_designer_unstructured_seed.chunking import (
build_unstructured_preview_rows,
normalize_unstructured_text,
resolve_chunking,
)
except ImportError:
build_unstructured_preview_rows = None
normalize_unstructured_text = None
resolve_chunking = None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

To handle the optional data_designer_unstructured_seed dependency consistently, consider also handling the import for build_multi_file_preview_rows here. It's currently imported locally in _read_preview_rows_from_multi_files and will raise a raw ImportError if the package is missing. This would make the error handling more consistent and user-friendly. You would then need to add a runtime check in _read_preview_rows_from_multi_files similar to the other functions.

Suggested change
try:
from data_designer_unstructured_seed.chunking import (
build_unstructured_preview_rows,
normalize_unstructured_text,
resolve_chunking,
)
except ImportError:
build_unstructured_preview_rows = None
normalize_unstructured_text = None
resolve_chunking = None
try:
from data_designer_unstructured_seed.chunking import (
build_unstructured_preview_rows,
normalize_unstructured_text,
resolve_chunking,
build_multi_file_preview_rows,
)
except ImportError:
build_unstructured_preview_rows = None
normalize_unstructured_text = None
resolve_chunking = None
build_multi_file_preview_rows = None

Comment thread studio/backend/run.py
Comment on lines +265 to +266
except Exception:
pass

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

This broad, silent exception handler violates one of the general rules for this repository, which advises against except Exception: pass. It's better to log the exception, even if it's not considered a critical failure, to aid in future debugging if stderr.reconfigure fails unexpectedly.

Suggested change
except Exception:
pass
except Exception as e:
print(f"Warning: Could not reconfigure stderr to UTF-8: {e}", file=sys.stderr)
References
  1. Avoid using broad, silent exception handlers like except Exception: pass. Instead, log the exception, even if at a debug level, to aid in future debugging.

Addresses review findings [10/10] and [8/10]:

1. seed.py: _read_preview_rows_from_multi_files() had a hard import
   of build_multi_file_preview_rows inside the function body, bypassing
   the optional-plugin guard. Moved it into the top-level try/except
   block and added a None guard matching the other functions.

2. setup.ps1: Python discovery now probes py.exe (Python Launcher)
   first, uses Get-Command -All to look past conda entries that shadow
   standalone CPython further down PATH, skips WindowsApps stubs, and
   resolves the actual executable path so venv creation does not
   re-resolve back to a conda interpreter.
@danielhanchen

Copy link
Copy Markdown
Member Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request effectively addresses silent exits on Windows by introducing robust error handling in both parent and child processes, and by making the installation scripts resilient to issues with Conda environments. The changes are well-implemented and significantly improve the user experience on Windows. I have one suggestion to enhance the new exception handling logic in studio/backend/run.py to avoid silently ignoring an error, aligning with the repository's general coding practices.

Comment thread studio/backend/run.py
Comment on lines +265 to +266
except Exception:
pass

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

This broad, silent exception handler should be avoided. While failing to reconfigure stderr is not critical, logging the exception can help with debugging obscure encoding issues on Windows. Consider printing the exception to stderr.

Suggested change
except Exception:
pass
except Exception as e:
sys.stderr.write(f"Warning: Could not reconfigure stderr to UTF-8: {e}\n")
References
  1. Avoid using broad, silent exception handlers like except Exception: pass. Instead, log the exception, even if at a debug level, to aid in future debugging.

A venv created from conda Python (e.g. C:\Users\danie\.venv) has a
path that does not contain "conda", but sys.base_prefix still points
to the conda install (e.g. C:\Users\danie\miniconda3). The previous
path-only check missed this case entirely.

Both install.ps1 and setup.ps1 now use a Test-IsConda helper that
checks both the executable path AND sys.base_prefix against the
conda/miniconda/anaconda/miniforge/mambaforge pattern. This catches:
- Direct conda Python executables
- Venvs created from conda Python (base_prefix reveals the origin)
… path

Find-CompatiblePython returned a bare version string (e.g. "3.13")
which was passed to `uv venv --python 3.13`. uv performs its own
interpreter discovery and can resolve that version string back to a
conda Python, defeating the entire conda-skip logic.

Now Find-CompatiblePython returns a hashtable with both .Version (for
display) and .Path (the resolved absolute executable path). The venv
is created with `uv venv --python <absolute-path>`, ensuring uv uses
the exact interpreter we validated.
@danielhanchen

Copy link
Copy Markdown
Member Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request effectively addresses two critical issues for Windows users of Unsloth Studio: silent crashes on startup and incompatibilities with Conda's Python distribution. The changes are well-implemented, with robust error handling added to the CLI and backend server, and more resilient Python detection in the PowerShell setup scripts. The optional import for data_designer_unstructured_seed is also a good improvement for modularity. My review includes one suggestion in studio/backend/run.py to improve logging in an exception handler, aligning it with the repository's general guidelines.

Comment thread studio/backend/run.py
Comment on lines +265 to +266
except Exception:
pass

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

This silent except Exception: pass goes against the repository's general rule to avoid broad, silent exception handlers. While failing to reconfigure stderr might not be critical, logging the exception would aid in debugging potential environment-specific issues on Windows. It's better to have a record of why the reconfiguration failed.

Suggested change
except Exception:
pass
except Exception as e:
print(f"Warning: Could not reconfigure stderr to UTF-8: {e}", file=sys.stderr)
References
  1. Avoid using broad, silent exception handlers like except Exception: pass. Instead, log the exception, even if at a debug level, to aid in future debugging.

@danielhanchen
danielhanchen merged commit 797ddd2 into main Mar 22, 2026
4 checks passed
@danielhanchen
danielhanchen deleted the fix/studio-silent-crash branch March 22, 2026 15:23
shibizhao pushed a commit to shibizhao/unsloth-npu that referenced this pull request Apr 7, 2026
…i#4527)

* Fix Studio silently exiting on Windows without error output

On Windows, `unsloth studio` launches a child process via
subprocess.Popen to run the server in the studio venv. If the child
crashes (e.g. due to a missing package), the parent just calls
typer.Exit(rc) with no message -- the user sees "Launching Unsloth
Studio... Please wait..." and then the prompt returns with zero
feedback.

Root cause: `data_designer_unstructured_seed` is imported at the top
level in seed.py. If this package is not installed in the studio venv,
the entire import chain (seed.py -> routes/__init__.py -> main.py ->
run_server()) crashes with ModuleNotFoundError. Since run.py has no
try/except around run_server() and studio.py does not report nonzero
exit codes, the failure is completely silent.

Changes:
- run.py: wrap run_server() in try/except, print clear error with
  traceback to stderr. Also reconfigure stderr encoding on Windows so
  tracebacks with non-ASCII paths do not cause secondary failures.
- studio.py: print an error message when the child process exits with
  a nonzero code on Windows, so the user knows something went wrong.
- seed.py: make data_designer_unstructured_seed import optional with
  a try/except fallback. The server starts normally and only returns
  HTTP 500 if the unstructured seed endpoints are actually called.

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

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

* Skip Anaconda/Miniconda Python when creating Studio venv on Windows

Conda-bundled CPython ships modified DLL search paths that prevent
torch from loading c10.dll on Windows. The Studio server fails
silently at startup because the venv was created with conda's Python.

Standalone CPython (python.org, winget, uv) does not have this issue.

Both install.ps1 and setup.ps1 now skip any Python binary whose path
contains conda, miniconda, anaconda, miniforge, or mambaforge when
selecting the interpreter for the studio venv. If only conda Python
is available, the scripts print an error with instructions to install
standalone CPython.

* Fix multi-file preview crash and improve setup.ps1 Python discovery

Addresses review findings [10/10] and [8/10]:

1. seed.py: _read_preview_rows_from_multi_files() had a hard import
   of build_multi_file_preview_rows inside the function body, bypassing
   the optional-plugin guard. Moved it into the top-level try/except
   block and added a None guard matching the other functions.

2. setup.ps1: Python discovery now probes py.exe (Python Launcher)
   first, uses Get-Command -All to look past conda entries that shadow
   standalone CPython further down PATH, skips WindowsApps stubs, and
   resolves the actual executable path so venv creation does not
   re-resolve back to a conda interpreter.

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

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

* Check sys.base_prefix to catch venvs created from conda Python

A venv created from conda Python (e.g. C:\Users\danie\.venv) has a
path that does not contain "conda", but sys.base_prefix still points
to the conda install (e.g. C:\Users\danie\miniconda3). The previous
path-only check missed this case entirely.

Both install.ps1 and setup.ps1 now use a Test-IsConda helper that
checks both the executable path AND sys.base_prefix against the
conda/miniconda/anaconda/miniforge/mambaforge pattern. This catches:
- Direct conda Python executables
- Venvs created from conda Python (base_prefix reveals the origin)

* Fix install.ps1 passing version string to uv venv instead of resolved path

Find-CompatiblePython returned a bare version string (e.g. "3.13")
which was passed to `uv venv --python 3.13`. uv performs its own
interpreter discovery and can resolve that version string back to a
conda Python, defeating the entire conda-skip logic.

Now Find-CompatiblePython returns a hashtable with both .Version (for
display) and .Path (the resolved absolute executable path). The venv
is created with `uv venv --python <absolute-path>`, ensuring uv uses
the exact interpreter we validated.

* Quote resolved Python path in uv venv call for paths with spaces

---------

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