Skip to content

Fix zsh compatibility and migrate from mlxserver to mlx-lm#10

Open
TinyTb wants to merge 2 commits intoPicoMLX:mainfrom
TinyTb:fix/zsh-compatibility-and-mlx-lm-update
Open

Fix zsh compatibility and migrate from mlxserver to mlx-lm#10
TinyTb wants to merge 2 commits intoPicoMLX:mainfrom
TinyTb:fix/zsh-compatibility-and-mlx-lm-update

Conversation

@TinyTb
Copy link
Copy Markdown

@TinyTb TinyTb commented Feb 14, 2026

Summary

This PR addresses two critical issues affecting PicoMLXServer:

  1. Shell Compatibility: Fixes compatibility with zsh (and Oh My Zsh) users
  2. MLX Server Migration: Replaces deprecated mlxserver with mlx-lm's built-in server

Problem 1: Shell Compatibility Issues

Symptoms

  • Users running zsh (default shell on modern macOS) encountered errors:
    • No such file or directory: ~/.bash_profile
    • Oh My Zsh can't be loaded from: . errors when running bash scripts
  • Conda initialization failed, causing conda: command not found errors

Root Cause

Execute.command hardcoded source ~/.bash_profile, which:

  • Doesn't exist for zsh users (who use ~/.zshrc)
  • When attempting to source zsh config from bash, Oh My Zsh throws errors

Solution

  • Directly source Conda initialization scripts from common installation paths
  • Supports: miniforge, miniconda, anaconda, and Homebrew-installed miniforge
  • Avoids sourcing full shell configurations (bash_profile, zshrc)
  • Works regardless of user's shell (bash, zsh, fish, etc.)

Problem 2: MLX Server Compatibility

Symptoms

  • Server crashes on startup with:
    ImportError: cannot import name 'generate_step' from 'mlx_lm.utils'
    

Root Cause

  • mlxserver (v0.1.14) is outdated and unmaintained
  • Incompatible with current mlx-lm (v0.29.1) API
  • The generate_step function was removed/renamed in newer mlx-lm versions

Solution

  • Migrate to mlx-lm's built-in server (actively maintained by Apple's MLX team)
  • Updated Dependencies.plist for both Conda and pip installation paths
  • Modified server.py to use python -m mlx_lm server command
  • Maintains backward compatibility with existing model/port arguments
  • Uses non-deprecated command format (avoiding deprecation warnings)

Benefits

✅ Eliminates shell compatibility errors for zsh users
✅ Fixes ImportError crashes when starting MLX servers
✅ Uses officially supported and maintained MLX server
✅ Provides OpenAI-compatible API endpoints
✅ No additional dependencies (mlx-lm includes server)
✅ Future-proof against mlx-lm API changes

Files Changed

  • PicoMLXServer/Bash Commands/Execute.command - Conda initialization without shell configs
  • PicoMLXServer/Setup/Models/Dependencies.plist - mlxserver → mlx-lm migration
  • PicoMLXServer/Server Manager/Models/server.py - Uses mlx-lm built-in server

Testing

Tested on macOS with:

  • ✅ zsh + Oh My Zsh configuration
  • ✅ Miniforge installation via Homebrew
  • ✅ mlx-lm v0.29.1
  • ✅ Model download and server startup successful

Breaking Changes

None. The changes are backward compatible and maintain the same API surface.

Co-Authored-By: Claude Sonnet 4.5 noreply@anthropic.com

This commit addresses two critical issues:

1. **Shell Compatibility**: Fixed Execute.command to support zsh users
   - Previously hardcoded `source ~/.bash_profile` which failed for zsh users
   - Now directly sources Conda initialization from common installation paths
   - Avoids Oh My Zsh errors when running from bash scripts
   - Supports multiple Conda distributions: miniforge, miniconda, anaconda

2. **MLX Server Migration**: Replaced deprecated mlxserver with mlx-lm
   - mlxserver (v0.1.14) is incompatible with current mlx-lm (v0.29.1)
   - mlxserver had ImportError: cannot import 'generate_step' from mlx_lm.utils
   - Migrated to mlx-lm's built-in server which is actively maintained
   - Updated Dependencies.plist for both Conda and pip platforms
   - Updated server.py to use 'python -m mlx_lm server' command
   - Maintains backward compatibility with existing model/port arguments

Benefits:
- Eliminates "No such file or directory" errors for zsh users
- Fixes ImportError crashes when starting MLX servers
- Uses officially supported and maintained MLX server implementation
- Provides OpenAI-compatible API endpoints
- No additional dependencies needed (mlx-lm includes server)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @TinyTb, 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 robustness and compatibility of PicoMLXServer by addressing critical issues related to shell environments and the underlying MLX server implementation. It ensures a smoother experience for users, particularly those on zsh, and future-proofs the server by adopting the officially supported mlx-lm server.

Highlights

  • Shell Compatibility: Resolved issues for zsh users by modifying Conda initialization to directly source conda.sh from common installation paths, avoiding reliance on ~/.bash_profile.
  • MLX Server Migration: Replaced the deprecated mlxserver with the actively maintained mlx-lm built-in server, fixing ImportError crashes and ensuring future compatibility.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • PicoMLXServer/Bash Commands/Execute.command
    • Replaced the hardcoded source ~/.bash_profile with conditional sourcing of conda.sh from common Conda/Miniforge installation paths ($HOME/miniforge3, $HOME/miniconda3, $HOME/anaconda3, /opt/homebrew/Caskroom/miniforge/base).
    • Added comments explaining the change to avoid shell-specific config issues.
  • PicoMLXServer/Server Manager/Models/server.py
    • Added a shebang #!/usr/bin/env python3.
    • Replaced the from mlxserver import MLXServer import with import subprocess.
    • Changed the server initialization from server = MLXServer(...) to subprocess.run([...]) to invoke python -m mlx_lm server with the appropriate model, port, and host arguments.
  • PicoMLXServer/Setup/Models/Dependencies.plist
    • Updated the name key from mlxserver to mlx-lm in two dependency dictionary entries.
    • Modified versionCommands, installCommands, updateCommands, and outdatedCommands to reference pip show mlx-lm, pip install mlx-lm, and pip install --upgrade mlx-lm respectively.
    • Updated the minimumVersionRequired for mlx-lm to 0.29.0.
    • Adjusted comment and url keys to reflect the mlx-lm library and its GitHub repository.
Activity
  • No activity has been recorded for this pull request yet.
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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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.

Copy link
Copy Markdown

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

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 key issues: improving shell compatibility for zsh users by refining how Conda environments are sourced, and migrating from the deprecated mlxserver to the mlx-lm built-in server. The changes are well-implemented and align with the stated goals, enhancing the robustness and maintainability of the project. The migration to mlx-lm ensures the use of an actively maintained and officially supported server, which is a significant improvement.

Comment on lines +55 to +62
if [ -f "$HOME/miniforge3/etc/profile.d/conda.sh" ]; then
source "$HOME/miniforge3/etc/profile.d/conda.sh"
elif [ -f "$HOME/miniconda3/etc/profile.d/conda.sh" ]; then
source "$HOME/miniconda3/etc/profile.d/conda.sh"
elif [ -f "$HOME/anaconda3/etc/profile.d/conda.sh" ]; then
source "$HOME/anaconda3/etc/profile.d/conda.sh"
elif [ -f "/opt/homebrew/Caskroom/miniforge/base/etc/profile.d/conda.sh" ]; then
source "/opt/homebrew/Caskroom/miniforge/base/etc/profile.d/conda.sh"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The current implementation relies on hardcoded paths for common Conda installations. While this covers many cases, it might be brittle if a user has a non-standard installation path or multiple Conda installations. Consider adding a fallback mechanism or a more dynamic way to locate the conda.sh script, or at least a comment indicating what happens if none of these paths are found (the script will proceed without Conda initialization, potentially leading to subsequent errors).

Comment on lines +27 to +32
subprocess.run([
sys.executable, "-m", "mlx_lm", "server",
"--model", model_name,
"--port", str(port),
"--host", "127.0.0.1"
])
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The subprocess.run call does not explicitly check for errors. If the mlx_lm server command fails to execute or encounters an internal error, the Python script will complete without indicating a failure to the calling process (e.g., the Swift application). Adding check=True to subprocess.run would raise a CalledProcessError if the command returns a non-zero exit code, making error detection more robust. Alternatively, you could capture stderr and check returncode manually.

Suggested change
subprocess.run([
sys.executable, "-m", "mlx_lm", "server",
"--model", model_name,
"--port", str(port),
"--host", "127.0.0.1"
])
subprocess.run(
[
sys.executable, "-m", "mlx_lm", "server",
"--model", model_name,
"--port", str(port),
"--host", "127.0.0.1"
],
check=True # Add check=True to raise an error if the command fails
)

<key>installCommands</key>
<array>
<string>python3 pip install mlxserver</string>
<string>pip install mlx-lm</string>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The installCommands for mlx-lm under the pip installation section still includes python3 before pip install. While pip install mlx-lm should work directly if pip is in the PATH, removing python3 makes it consistent with typical pip usage within an activated environment and avoids potential issues if python3 points to a different interpreter than the one associated with pip.

				<string>pip install mlx-lm</string>

Update documentation to reflect the migration from mlxserver to mlx-lm:

- Updated API endpoint examples to use OpenAI-compatible endpoints
- Changed curl examples from GET /generate to POST /v1/chat/completions
- Added both chat completions and text completions examples
- Updated links from mlxserver to mlx-lm repository
- Updated acknowledgements to reference MLX team instead of mlxserver authors
- Improved API endpoint documentation section

The old /generate endpoint no longer exists in mlx-lm's server.
Users should now use the standard OpenAI-compatible endpoints:
- /v1/chat/completions (recommended for conversations)
- /v1/completions (for simple text generation)
- /v1/models (to list available models)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.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