Repository navigation
Studio: optional launchd agent to keep Studio running on macOS CLI installs - #17879
Conversation
…stalls On macOS, Studio installed with install.sh stops when the terminal closes, so its scheduled tasks stop too. Linux has an opt-in systemd user service (unslothai#9308) and the desktop app has "Run at login"; macOS CLI installs had nothing. UNSLOTH_INSTALL_LAUNCHD=1 now writes and loads ~/Library/LaunchAgents/ai.unsloth.studio.server.plist, mirroring the systemd service: - Binds 127.0.0.1:8888 by default; UNSLOTH_LAUNCHD_HOST/PORT override. - KeepAlive SuccessfulExit=false: restarts after a crash, while `unsloth studio stop` (exit 0) stays stopped. - Skipped when the desktop app's Unsloth.plist agent exists. - Never overwrites a plist it did not write (marker on line 2). - Clear error when there is no GUI session (SSH only). - uninstall.sh boots it out before the kill sweep. - stdout/stderr go to /dev/null: Studio already tees both to logs/server (0600, newest 20 kept), and a launchd log would be an unrotated, world-readable copy holding the startup API key. Closes unslothai#17877 Co-Authored-By: Claude Opus 5.5 <[email protected]>
- uninstall.sh: when `launchctl bootout` fails, fall back to `launchctl remove <label>`. A job left loaded would be respawned by KeepAlive after the kill sweep, mid-uninstall. - install_user_agent.sh: wait up to 130s for the old agent to unload, past the plist's ExitTimeOut (120s), so a Studio finishing a slow shutdown is not reported as a failed install. - install_user_agent.sh: if enable or bootstrap fails, remove the new plist, so a failed install does not start a second server at next login beside the one install.sh falls back to. Co-Authored-By: Claude Opus 5.5 <[email protected]>
[skip ci]
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
…OME owner's account [skip ci]
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: efd426edbe
ℹ️ 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".
| _path="$_exe_dir:$HOME/.local/bin:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" | ||
|
|
||
| # launchd scans the login account's home at login, not a redirected $HOME. | ||
| _account_home="$(dscl . -read "/Users/$(id -un)" NFSHomeDirectory 2>/dev/null | awk '{print $2}' || true)" |
There was a problem hiding this comment.
Preserve spaces when reading the account home directory
When HOME is redirected and the login account's home contains spaces, such as /Volumes/External SSD/alice, the new $2 extraction cannot preserve the complete NFSHomeDirectory. It truncates the path or triggers the fallback to the redirected home, placing the plist outside the account's LaunchAgents directory. A successful initial load therefore does not provide the documented --enable behavior (“so it starts at login”). Preserve the complete attribute value here and in the matching installer/uninstaller lookups.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing: a home with spaces makes dscl print the value on its own line, so the parsed field is not an absolute path and the helper falls back to $HOME, the pre-redirect behaviour (same parsing install.sh already uses for _default_home). It only matters with a redirected HOME and a spaced account home.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Another round soon, please! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Closes #17877
Problem
On macOS, Studio installed with
install.shstops when the terminal closes, so its scheduled tasks stop too. Linux has an opt-in systemd user service (#9308) and the desktop app has "Run at login", but macOS CLI installs had no way to keep Studio running.Change
Opt-in only: without
UNSLOTH_INSTALL_LAUNCHD=1, nothing changes. With it,install.shwrites and loads~/Library/LaunchAgents/ai.unsloth.studio.server.plist, mirroring the systemd service file for file:studio/systemd/install_user_service.shstudio/launchd/install_user_agent.shunsloth-studio.service.inai.unsloth.studio.server.plist.inUNSLOTH_INSTALL_SYSTEMD/_HOST/_PORTUNSLOTH_INSTALL_LAUNCHD/_HOST/_PORTRestart=on-failureKeepAlive→SuccessfulExit = false_remove_systemd_user_service_remove_launchd_user_agentBehaviour:
127.0.0.1:8888by default.UNSLOTH_LAUNCHD_HOST=0.0.0.0opts into LAN.unsloth studio stopsends SIGTERM, Studio exits 0, and launchd leaves it stopped.~/Library/LaunchAgents/Unsloth.plistexists, so two servers don't fight over the port.scripts/uninstall.shboots the agent out before the kill sweep, so launchd can't restart Studio mid-uninstall./usr/bin:/bin:/usr/sbin:/sbin, so the agent sets one that includes the venv,~/.local/binand Homebrew./dev/null. Studio already tees both streams tologs/server/(0600, newest 20 kept). A launchd log file would never rotate, would be world-readable by default, and would contain the startup banner's API key. Startup errors from before that tee starts can be seen by running the command in a terminal; the installer prints that command./bin/bash). XML escaping usessed, because${v//&/&}behaves differently in bash 3.2 and 5.2.Also: packaged via
"launchd/*"inpyproject.toml, added to the cross-platform parity CI path filters and test list, and registered intests/test_installer_interactive_prompts.pyso the helper can never add a prompt.Testing
tests/test_installer_launchd.py: 40 tests using stand-inlaunchctl/uname/id, so they run on the Linux CI runners as well as macOS (they skip on Windows). Installer and related suites locally: 215 passed, 56 skipped (the systemd tests skip on macOS); the launchd tests also pass withshresolved to dash, as on Ubuntu.pre-commit,bash -n/sh -n,plutil -linton a generated plist.UNSLOTH_INSTALL_LAUNCHD=1 UNSLOTH_LAUNCHD_PORT=8899 ./install.sh --local --no-torch:state = running, HTTP 200; ~340 MB RSS, same as a manual runkill -9unsloth studio stoplast exit code = 0, stays stoppedlaunchctl kickstartKnown behaviour, same as systemd: if another Studio already holds the port, the agent's copy exits 1 and launchd retries every 10s until the port frees up.
Failure paths (second commit, from review):
launchctl remove <label>ifbootoutfails, so KeepAlive can't respawn Studio after the kill sweep. Checked against real launchd.ExitTimeOut.enableorbootstrapfails, the helper removes the new plist, so a failed install can't start a second server at next login.Out of scope
Windows Task Scheduler and the scheduled-tasks UI redesign from the ideas list.
🤖 Generated with Claude Code