Skip to content

Studio cluster: pair and serve across networks with one code - #18279

Open
danielhanchen wants to merge 11 commits into
cluster/pairingfrom
cluster/tailcat
Open

danielhanchen wants to merge 11 commits into
cluster/pairingfrom
cluster/tailcat

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Stacked on #18278 (home cluster pairing), which is stacked on #18277 and #18276. Part of #4858. This replaces #17763, rebuilt on the Spark-free stack with the same content.

What this does

Pairing a machine now takes one code and one command on each side, and it also works when the two machines are on different networks or behind NAT. There is no port forwarding, no account and no admin rights involved.

master$ unsloth cluster pair
On the other machine run `unsloth worker --join` and paste this code when asked:
    unsloth-pair-2.<code>
mac-2 wants to join (hazel rabbit teapot). Allow? [Y/n]

worker$ unsloth worker --join
Check that the master shows these words, then allow it there: hazel rabbit teapot

Studio gets the same flow under Settings > Machines:

  • an "Add a machine" dialog showing the code and the command to run on the other machine;
  • the approval step with the three words;
  • a list of paired machines with their status and a Remove button.

How it works

  • Transport: connections across networks use tailcat, a BSD-3 userspace WireGuard tunnel with NAT traversal. It runs inside a small helper, unsloth-link, built from studio/cluster_link/tailcat_helper with tailcat pinned to e00cdde6.
    • Python drives the helper over stdin/stdout.
    • Tunnel addresses and keys never appear in argv, the environment or logs.
  • Security model: the existing mutual TLS (cluster CA, pinned certificates, cluster remove) runs inside the tunnel, so it is still what decides who may connect. The tunnel only provides reachability.
    • Each worker serves only its agent port, plus the native TLS RPC port when the bundle has it.
    • The worker's tunnel allows only its paired master's key.
  • Local network first: the master dials the worker's LAN address first and uses the tunnel only when that fails.
  • Relayed connections: if the tunnel only reaches the worker through a DERP relay, the worker is left out of splits ("reachable only through a relay, too slow to serve models"). The public relays are rate limited and unfit for uploading model weights. UNSLOTH_CLUSTER_ALLOW_RELAY=1 overrides this, for example with your own relay set via UNSLOTH_CLUSTER_DERP_MAP.
  • Pairing code v2: it adds the master's one-time tunnel address to the existing fields. The worker tries the LAN addresses first, then the tunnel.
    • The worker's persistent tunnel address and key, and the master's client key, are bound into the pairing transcript, so they cannot be swapped.
    • Both sides show three words derived from that transcript, and the master must approve them. This stops someone who gets hold of a code from enrolling their own machine.
    • --yes skips approval for scripted setups. Existing unattended cluster pair scripts need it now.
    • An unanswered prompt, or Ctrl-C at it, ends the command with the timeout or cancellation message instead of waiting for input.
  • Installing the helper: the helper is downloaded the first time a machine pairs, from the CLI or from Studio. Installs that never pair pull nothing. UNSLOTH_CLUSTER_TAILNET=0 keeps pairing local-only and offline.
    • The download is checked against the sha256 and size in studio/unsloth_link_pins.json before anything is extracted or run.
    • .github/workflows/unsloth-link.yml builds byte-reproducible archives for Linux, macOS and Windows (amd64 and arm64) and fails unless they match the pins. It then smoke-tests each platform natively and publishes on the unsloth-link-v1 tag.
    • UNSLOTH_CLUSTER_TAILNET=0 turns the whole thing off.

Tests

  • Cluster tests: the cluster test files, the installer tests and the Spark serving tests pass locally: 1002 passed, 7 skipped.
  • End to end with real helpers (tests/studio/test_cluster_link_tailnet_e2e.py, run when UNSLOTH_LINK_BIN is set):
    • Two workers pair through the real CLI while the master's LAN address is unreachable, so pairing has to go through the tunnel.
    • The words match on both sides, and no loopback or unreachable address is recorded.
    • A real GGUF layer split through the tunnels gives text identical to direct RPC.
    • cluster remove drops the worker.
  • Relay-only case: a forced relay-only path is reported and left out of splits unless overridden.
  • Installer tests: digest and size mismatches, archive path traversal and symlinks, concurrent installs, a failed smoke leaving nothing behind, and the offline and unsupported-platform messages.

Not proven yet

  • The workflow has not run on GitHub yet, so the pins come from local builds that were checked to be reproducible.

  • Speed across the internet is not measured yet. On a real gigabit LAN of 5 CPU machines, RPC through tailcat was compared with the same mutual-TLS RPC over the LAN, both with copies between workers going through the master:

    Machines LAN Through tailcat Change
    2 199.0 tok/s 194.7 tok/s -2%
    3 243.9 tok/s 241.5 tok/s -1%
    4 264.8 tok/s 219.3 tok/s -17%
    5 268.5 tok/s 146.7 tok/s -45%

    Every tunnel reached a direct path at about 865 Mbit/s. At 4 and 5 machines, all worker-to-worker copies cross the master's tunnel endpoint. That is why the LAN stays first, and tailcat is only used for workers the LAN cannot reach.

  • The macOS and Windows helper binaries are cross-compiled but unsigned, and have not run on those platforms outside CI.

  • cluster remove on the master drops the worker at once: the master's TLS check refuses it and its tunnel is closed. The worker's own tunnel keeps admitting the master's key until cluster leave is run on the worker.

Screenshots

These come from two separate install.sh --local --no-torch installs: BEFORE is this PR's base (#18278), AFTER is this branch. The worker is a real unsloth worker --join run from a second cluster state directory on the same host. The code is blanked out.

Settings gains Machines, in the Connections group after Remote & LAN (19 tabs before, 20 after). Before, /api/cluster/machines answered 404.

Settings tabs before and after

Nothing paired yet:

Machines, empty

Add a machine shows the command to run on the other machine and the one-time code:

Add a machine

Approval: the worker ran unsloth worker --join and its terminal showed the same three words.

Approval words

After Allow:

Paired

The paired worker is Ready:

Machines list

Remove asks first:

Remove confirmation

…n Settings

Pairing codes (v2) carry the master's one-time tailcat address, so a worker the
master cannot reach on the LAN pairs and serves through a userspace WireGuard
tunnel (tailscale/tailcat, run by the small unsloth-link helper) with the same
mutual TLS inside. Both sides show three words derived from the pairing
transcript and the master approves them; --yes skips that for scripts. The
local network stays first; a worker reachable only through a relay is left out
of splits unless UNSLOTH_CLUSTER_ALLOW_RELAY=1.

The helper is built reproducibly for six targets by unsloth-link.yml, pinned
by archive and binary sha256, and downloaded on the first pairing only.
Settings > Machines adds a machine, shows the approval words, lists paired
machines and removes them.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T15:10:05.838076Z eaae94e 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

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 4bee7fdc80

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

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 5a3eaa7f96

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

The rail now renders only tabs listed in SETTINGS_NAV_GROUPS, so Machines was
defined, routable and searchable but never shown (the browser gate saw 19 of
20 tabs). It sits after Remote access in Connections, and a guard test fails
for any Settings tab that no group lists.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 97b558ceaa

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

Comment thread unsloth_cli/commands/cluster.py Outdated
port = port or PAIR_PORT_DEFAULT,
ttl = seconds,
addrs = addr or None,
approve = None if yes else (lambda name, words: asyncio.to_thread(ask, name, words)),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Make the CLI approval prompt cancellable

When the owner leaves the approval prompt unanswered until APPROVAL_TIMEOUT_S expires, or presses Ctrl-C while it is displayed, cancelling the asyncio.to_thread await does not stop the thread blocked inside typer.confirm. The enclosing asyncio.run(run()) then waits for its default executor to shut down, so the command remains stuck until someone supplies input instead of reporting the timeout or cancellation. Use a cancellable input mechanism, or otherwise ensure the blocked prompt cannot hold up executor shutdown.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in a661cec. The prompt now runs on a daemon thread and hands its answer back as a future on the running loop (prompt_in_background), not through asyncio.to_thread. When the approval times out or Ctrl-C is pressed, asyncio.run has no executor thread to join, so the command reports the timeout or the cancellation and exits. With the old asyncio.to_thread version, the same unanswered prompt keeps the process alive until a 10 s kill. tests/test_cluster_cli_approval_prompt.py runs it in a subprocess.

The merge of the TLS-port fix skips that direct dial for workers reached through tailcat (70183bd). There the forward is the reachability check. test_native_tls_through_tailcat_dials_the_forwarded_native_port now fails if it dials.

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 18, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 18, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 18, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 18, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 18, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 18, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 18, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 70183bd4d8

ℹ️ 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 added >3000# affects UI# codex-converged# new-feature# security# Moves a security boundary: sandbox, allowlist, permission or network guard labels Nov 19, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: eaae94e928

ℹ️ 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 self-assigned this Nov 22, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

affects UI# codex-converged# new-feature# security# Moves a security boundary: sandbox, allowlist, permission or network guard >3000#

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant