Skip to content

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

Closed
danielhanchen wants to merge 39 commits into
cluster/home-linkfrom
cluster/tailcat-link
Closed

danielhanchen wants to merge 39 commits into
cluster/home-linkfrom
cluster/tailcat-link

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

Stacked on #14274 (home cluster pairing), which is stacked on #13726 and #10323. Part of #4858.

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.
  • 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, 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. 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

…s tunnel closes, refuse workers without approval words, and list relayed workers as serving when relays are allowed
…test pins tailcat off, a longer pairing wait under load
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 14, 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-14T18:34:24.523612Z 941db93 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 danielhanchen self-assigned this Nov 14, 2026

@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: 23f93557ee

ℹ️ 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 on lines +127 to +129
const { code: fresh, ...state } = await startPairing();
setCode(fresh);
setPairing(state);

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 Cancel pairing windows returned after the dialog closes

If the dialog closes while startPairing() is pending—for example, while the backend downloads the helper on first use—the effect cleanup sees no pairing and cannot cancel it. These unconditional state updates then retain the newly opened window and start polling it even though the dialog is closed. The backend pairing listener and tunnel remain open until expiry instead of being cancelled when the user dismisses the dialog. Track the request's lifetime and cancel any pairing returned after its dialog has closed, rather than applying that late result.

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 951a3e1. Each start now takes a generation number, and closing the dialog (or starting again) bumps it. A start that comes back late cancels the window it opened and leaves the dialog state alone, so no listener or poll outlives a closed dialog. The frontend typecheck (tsc) passes.

@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. More of your lovely PRs please.

Reviewed commit: 951a3e1df2

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

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

danielhanchen added a commit to NilayYadav/unsloth that referenced this pull request Nov 14, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: ad481b5dc2

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

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. You're on a roll.

Reviewed commit: 941db93b6c

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

Superseded by #18279, which has the same changes rebuilt on a stack that no longer needs the DGX Spark PRs: #18276 (ships ggml-rpc-server), then #18277 (N-node serving), #18278 (home pairing) and #18279 (pairing across networks).

#10280 and #10323 stay open as optional Spark extras stacked on top. Closing this one so review continues on #18279; the discussion here stays for reference.

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