Skip to content

Desktop: allow a custom backend port with UNSLOTH_DESKTOP_PORT - #16523

Merged
danielhanchen merged 3 commits into
mainfrom
fix/desktop-port-env-16100
Nov 3, 2026
Merged

danielhanchen merged 3 commits into
mainfrom
fix/desktop-port-env-16100

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Unsloth Desktop always requests port 8888 when it starts its local backend. This prevents users from keeping that port available for development projects while Desktop runs in the background.

Add UNSLOTH_DESKTOP_PORT to choose the native Desktop backend's starting port. Set it in the environment that launches Desktop, then fully quit and reopen the app. For example, UNSLOTH_DESKTOP_PORT=9000 requests port 9000. Unset or empty keeps today's behavior, and an occupied port keeps the existing fallback to the next 20 ports.

The override is resolved in the shared native launch path, so initial startup and backend restarts after updates use the same port. Discovery includes the custom fallback range and retains the existing range; recovery of an owned backend uses its recorded request. Invalid values, browser-restricted ranges, and starting ports without room for all 20 fallbacks fail before launch state changes. Supported starting ports are 1024 through 65515, with browser-restricted ports excluded from the whole range. There are no new settings, prompts, dependencies, or persistent state, and browser Studio and notebook launch paths are unchanged.

Validation:

  • Six native Rust unit tests pass, including every accepted fallback range across the full 16-bit port space.
  • Thirteen portable native launch/discovery regression checks pass on the branch.
  • The same tests on the merge base have ten behavioral failures and three passing default-path checks. No tests fail because of a missing new API.
  • Repository formatting and pre-push checks pass.
  • The final thirteen scoped checks pass without skips on Linux, Windows, and macOS.
  • Real Linux socket checks preserve an existing listener and bind a free fallback port on both base and head.
  • Isolated before/after Studio installs show matching Connections controls and text. The final auth, settings, and crawl regression run reports functional NO_REGRESSION. One API-monitor row retains a classifier difference with zero changed screenshot pixels and becomes DOM-only on confirmation. One Hub difference was not reproduced on retry.
  • The final-head staged comparisons report functional NO_REGRESSION on Linux, macOS, and Windows. Both native Linux Desktop builds launched and recorded seven successful startup/navigation steps. Some early captures still show loading screens, so they do not prove loaded content. Settings then failed identically on both arms because the harness attempted a non-interactable click; update-banner and IPC steps were skipped. These are existing harness limits, not a full Desktop journey pass. Remaining visual differences include loading animations, randomized greetings, and seeded Data Recipes state. Regular upstream checks finished with 49 passing and four failing. Failed logs concern offline model metadata, installer package-pair resolution, and source checks naming files outside this diff; the native builds and scoped port tests passed.

Fixes #16100

UI parity at the default configuration, merge base 3647f334b versus head aeedd565f: both sides retain Enable connections, Add connection, and the same empty connection list. This image checks the existing UI flow; compiled native launch tests establish the Desktop port override.

Before and after Connections settings

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 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-11-03T13:13:59.683240Z aeedd56 Manual request
ℹ️ 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 pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 3, 2026
danielhanchen added a commit that referenced this pull request Nov 3, 2026
…as benign timing (#16526)

## Summary

`workflow-trigger lint` is red on main since #16422 (`1a951a93d6`). Its
"Workflow guard suites" step fails on unrelated PRs. In the last hour
that was the staging runs for #16423, #16182 and #16523:

```
tests/studio/test_backend_ci_parallel_isolation.py::test_every_tight_elapsed_bound_is_isolated
AssertionError: these backend tests compare clock-derived values and still run under -n 4 ...:
{'test_hf_download_fallback_and_kill.py': ['...:32 one duration against another'],
 'test_hf_download_reclaim_race.py': ['...:113 one duration against another'],
 'test_hf_download_ref_concurrency.py': ['...:72 one duration against another']}
```

All three sites are the same poll loop, which waits for a child process
to touch a `ready` file:

```python
deadline = time.monotonic() + 20   # 10 in test_hf_download_ref_concurrency.py
while not (tmp_path / "ready").exists():
    assert child.poll() is None, child.communicate()
    assert time.monotonic() < deadline, "worker did not reach the transfer barrier"
    time.sleep(0.01)
```

Being descheduled under `-n 4` only delays a poll; it cannot make the
condition false. The guard casts a deliberately wide net, and its
message names this exact case: a poll deadline goes in `BENIGN_TIMING`
as `(file, enclosing function)` with a reason. The tests and #16422's
download logic are fine; those entries were just never added.

## Change

`tests/studio/test_backend_ci_parallel_isolation.py`: three
`BENIGN_TIMING` entries under one reason comment. Each names the
function that holds the loop:
- `_wait_for_transfer`
- `test_gguf_reclaim_preserves_publication_and_active_peer`
- `test_peer_completion_survives_an_older_process`

I checked each of those functions: its only uses of `time.` are this
deadline, the comparison and the `sleep`, so the entries hide no other
timing check.

## Testing

- `tests/studio/test_backend_ci_parallel_isolation.py`:
- main: `test_every_tight_elapsed_bound_is_isolated` fails with the
error above;
  - this branch: 43 passed.
- No product or workflow file changes.
shimmyshimmer pushed a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Nov 3, 2026
shimmyshimmer pushed a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Nov 3, 2026
danielhanchen added a commit that referenced this pull request Nov 3, 2026
…16530)

## Summary

Since #16422 (`1a951a93d6`), `(Python 3.13, rest)` fails on unrelated
PRs. On staging CI it hit #16423, #16182 and #16523 in the last hour,
and it reproduces on current main:

```
studio/backend/tests/test_scoped_download_worker.py::test_offline_scoped_download_fails_when_the_files_are_not_on_disk
studio/backend/tests/test_scoped_download_worker.py::test_offline_scoped_download_passes_when_every_file_is_present
studio/backend/tests/test_scoped_download_worker.py::test_a_dangling_symlink_does_not_count_as_present
hub/workers/hf_download.py:476: in _pinned_snapshot_download
E   OSError: Cannot resolve an immutable revision for black-forest-labs/FLUX.1-dev; retry when metadata is available
```

#16422 made every download pin an immutable commit. When metadata is
unreachable, `_pinned_snapshot_download` takes the commit from the Hub
cache's `refs/main` and refuses when there is none, rather than letting
`snapshot_download` hand back whatever folder is there. That is the
point of #16422, and I left it alone.

These tests' `offline` fixture predates it. It returns a bare tmp
`snapshot` dir and never puts a `refs/main` in the Hub cache, so every
case now stops at "no revision to pin" before reaching what it checks:
an incomplete copy, a complete copy, a dangling blob symlink. A real
offline user with a previously downloaded model has `refs/main` and its
`snapshots/<commit>`, so nothing changes for them.

## Change

`studio/backend/tests/test_scoped_download_worker.py` only:
- The fixture points `huggingface_hub.constants.HF_HUB_CACHE` at a tmp
dir. It writes `refs/main` and returns `snapshots/<commit>` there, the
layout an earlier download leaves behind.
- The three existing tests and their assertions are unchanged.
- New `test_offline_with_no_cached_revision_refuses_before_downloading`:
with no metadata and no `refs/main`, the worker raises the "immutable
revision" `OSError` and never calls `snapshot_download`. This pins
#16422's refusal, so the fixture change cannot hide a regression there.

## Testing

- `tests/test_scoped_download_worker.py`:
  - main: 3 failed, 1 passed (the error above);
  - this branch: 5 passed.
- Sabotage: with the offline missing-file refusal in
`_download_scoped_snapshot` disabled, the incomplete-copy and
dangling-symlink tests fail, so they still guard what they were written
for.
- `tests/test_hf_download*.py` plus this file: 102 passed.
danielhanchen added a commit that referenced this pull request Nov 3, 2026
## Summary

`Repo tests (CPU, rest-2)` is red on main since #16415 (`bf38ae0ac6`).
On staging CI it hit #16423, #16182 and #16523 in the last hour:

```
tests/test_source_read_encoding.py::test_checked_in_file_reads_name_an_encoding
AssertionError: 1 file reads in the test trees touch a checked-in file with the platform default encoding,
so they break on Windows as soon as that file gains a non-ASCII byte. Pass encoding = "utf-8":
['tests/test_multi_lora_cold_compile_cpu.py:33: read_text()']
```

#16415's new test parses a checked-in source file with
`path.read_text()`. On Windows that decodes with the ANSI codepage, so
it breaks as soon as the source file gains a non-ASCII byte. The guard
is right.

## Change

`tests/test_multi_lora_cold_compile_cpu.py`: `read_text()` becomes
`read_text(encoding = "utf-8")`. Nothing else changes.

## Testing

- `tests/test_source_read_encoding.py` and
`tests/test_multi_lora_cold_compile_cpu.py`:
  - main: the encoding guard fails as above;
  - this branch: 20 passed.
danielhanchen added a commit that referenced this pull request Nov 3, 2026
…o pair (#16532)

## Summary

Since #16157 (`95aae40bb4`), three installer tests fail on main. On
staging CI, `Repo tests (CPU, studio-install)` failed on #16423, #16182
and #16523 in the last hour:

```
tests/studio/install/test_ca_trust_floor.py::test_the_full_pass_raises_the_floor_in_both_modes[no-torch-update]
tests/python/test_no_torch_filtering.py::TestInstallPythonStackSubprocessMock::test_update_path_intel_macos_still_skips_overrides
tests/python/test_no_torch_filtering.py::TestInstallPythonStackSubprocessMock::test_update_path_intel_macos_still_skips_triton
studio/install_python_stack.py:10044: in _desktop_unsloth_spec
E   RuntimeError: Could not resolve a compatible unsloth / unsloth-zoo pair for no-torch mode
```

#16157 makes every no-torch install pin a compatible Unsloth / Zoo pair,
read from wheel metadata by `_no_torch_pair`, and refuse when none
resolves. That is deliberate, and its own tests cover it with real
offline wheels. The refusal can only trigger when the feed cannot serve
Unsloth's metadata, and then the no-deps install would fail anyway, so I
left the product as it is.

All three failing tests run `install_python_stack()` through
`TestInstallPythonStackSubprocessMock._capture_install`, which mocks
every `subprocess.run` to return 0 and write nothing. The pair probe
then finds no installed metadata and returns `None`, so every no-torch
update path through this harness now stops before reaching what the test
checks: the CA trust floor, and the Intel macOS override and triton
skips.

## Change

`tests/python/test_no_torch_filtering.py`: `_capture_install` also
patches `ips._no_torch_pair` to return a resolved pair, modelling a feed
that serves one, as a real index does. No assertion changes. The pair
logic itself stays covered by
`tests/python/test_desktop_unsloth_spec_no_deps_pair.py`, which runs the
real probe against real wheels.

## Testing

- `tests/python/test_no_torch_filtering.py`,
`tests/studio/install/test_ca_trust_floor.py`,
`tests/python/test_install_python_stack.py` and
`tests/python/test_desktop_unsloth_spec_no_deps_pair.py`:
  - main: 3 failed, with the error above;
  - this branch: 423 passed, 3 skipped.
@danielhanchen danielhanchen added edge case# new-feature# security# Moves a security boundary: sandbox, allowlist, permission or network guard labels Nov 3, 2026
@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. What shall we delve into next?

Reviewed commit: aeedd565fb

ℹ️ 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
danielhanchen merged commit a68651e into main Nov 3, 2026
@danielhanchen
danielhanchen deleted the fix/desktop-port-env-16100 branch November 3, 2026 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

edge case# new-feature# security# Moves a security boundary: sandbox, allowlist, permission or network guard

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Unsloth Desktop - Add configuration for HTTP Port

1 participant