Skip to content

Studio: let the owner share a connection with every account - #14365

Merged
danielhanchen merged 19 commits into
mainfrom
studio-shared-connections
Oct 21, 2026
Merged

danielhanchen merged 19 commits into
mainfrom
studio-shared-connections

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

Fixes #14196

What this does

On an install with more than one account, every person had to add the same external connection (for example a household Gufo, Ollama or llama.cpp server, or a hosted API key) again in their own account, and the owner's per-account Model access list did not apply to connection models at all.

The installation owner can now turn on Share with all accounts when adding or editing a connection in Settings > Connections:

  • Other accounts see the connection in their Connections list and model picker with a "Shared by owner" tag, and can chat, transcribe, speak and generate images through it.
  • The saved API key stays on the server and is never returned to another account. A connection whose base URL carries a credential (userinfo or a query string) cannot be shared; the owner is asked to move it into the API key field.
  • Other accounts cannot edit, delete or re-key a shared connection (403). Only the owner can share, and a subscription sign-in connection (an OpenAI account login rather than an API key) cannot be shared.
  • Only the models the owner enabled on the connection are shared (the provider's defaults when none were picked); a request naming any other model is refused (403).
  • The owner's Model access list for an account now also limits the models of a shared connection, by model id (unsloth/*, unsloth/Qwen3-8B-GGUF, gpt-4o, a :tag suffix is ignored). Disallowed models are hidden from the list and refused (403) on chat, speech, transcription, image and research requests. A shared connection with no allowed model is hidden for that account.
  • Turning sharing off, or deleting the connection, removes it from every other account immediately.
  • From another account, Check connection on a shared row only lists models (no model is invoked) and returns a fixed message on failure, so upstream error text that can quote the saved URL is never shown. OpenAI container management (list, create, delete) is refused on a shared row, since containers belong to the owner's whole OpenAI project; hosted code execution falls back to container_auto.
  • Requests from other accounts on a shared row take the owner's provider lock, so an edit by the owner cannot pair a new key with the old URL mid-request.

Each account's own connections are unchanged: they still come first, keep their own keys, and are not limited by Model access.

A shared connection to a local or LAN address uses the existing owner switch in Settings for managed accounts (Local and network connections), the same rule as an account's own connections. That switch stays the single place where the owner decides whether other accounts can reach this machine's network.

Compatibility

  • Single-account installs: the toggle is not shown and requests are byte-identical (no shared field is sent). The backend only reads the owner's store from a managed-account context, so the owner's request path is unchanged.
  • Storage: one shared INTEGER NOT NULL DEFAULT 0 column, added idempotently like the existing migrations. Every existing connection stays private. An older build reading the same database ignores the column, so a downgrade keeps working and nothing is shared.

Tests

  • studio/backend/tests/test_account_shared_connections.py: sharing, owner-key resolution server-side only, read-only for other accounts, owner-only sharing, no sharing of a subscription sign-in, unshare revokes, own connections first, Model access filtering and refusal, hidden when nothing is allowed, refusing to share a credential-bearing URL, a real loopback upstream receiving the owner's bearer through a shared connection, a connection check that makes no model request and quotes no URL, OpenAI containers refused, readers sharing the owner's lock, the private address switch still applying, and an upgrade from a pre-sharing table.
  • studio/frontend/tests/connections-shared-by-owner.test.ts: toggle shown only to the owner with another account, no shared field for single-account saves, no edit/delete on a row shared by the owner, sync never writes back to it.

Screenshots

Before (merge base) and after (this PR), two fresh Studio installs. The owner saves a custom connection "Household Gufo" with sharing on, then a managed account "alice" opens Settings > Connections.

Owner editing the connection: the new "Share with all accounts" switch.

Owner connection form, before and after

Alice's Connections page: before, she has no connections and the add form opens; after, the owner's connection is listed with a "Shared by owner" tag and only the Check button (no edit or delete).

Managed account Connections list, before and after

@danielhanchen danielhanchen self-assigned this Oct 20, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 20, 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 ⚠️ Failed 2026-10-21T11:26:11.929707Z
We couldn’t complete this review. Comment @codex review to try again.
16acf8c New commits
🔒 Security Review ✅ Completed 2026-10-20T15:11:52.930642Z 7051940 Manual request

Security findings

Advisory findings (2)

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

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@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: 70519403af

ℹ️ 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 +833 to +835
model_id = (model_id or "").strip().lower()
candidates = {model_id, model_id.split(":", 1)[0]}
return any(fnmatchcase(candidate, pattern) for candidate in candidates for pattern in allowlist)

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 Strip only the final model tag separator

For model IDs containing another colon before the tag, such as a registry-qualified host:5000/org/model:latest, splitting at the first colon produces host instead of the untagged host:5000/org/model. An allowlist containing the actual untagged model consequently hides and rejects it even though tag suffixes are meant to be ignored. Use the final colon when deriving the tagless candidate.

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.

Model access entries can never contain a colon: normalize_model_allowlist cuts each entry at its first colon, so an untagged candidate like host:5000/org/model could not match any entry whichever colon is split.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 20, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 20, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 20, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 20, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 20, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 20, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 20, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 20, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 20, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 20, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 20, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 20, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 20, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 20, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 20, 2026
@unslothai unslothai deleted a comment from danielhanchen Oct 20, 2026
@unslothai unslothai deleted a comment from danielhanchen Oct 20, 2026
@NilayYadav

Copy link
Copy Markdown
Collaborator

@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: 3128bb0056

ℹ️ 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 +25966 to +25968
async with provider_config_guard(
provider_id, shared_by_owner = bool(config.get("shared_by_owner"))
):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Recheck routing after resolving the shared credential

With multiple backend processes, this per-event-loop lock cannot coordinate an owner update in another process: STT can read the old URL in current, the owner can atomically replace the URL and key, and the subsequent credential lookup then returns the new key, which is sent to the old endpoint because this path has no final row check. Fresh evidence beyond the earlier in-process concern is that the TTS and image paths explicitly perform a post-key reread for cross-process edits, while STT, chat, /models, /model-capabilities, and /test do not; these paths need the same final routing comparison (or a single consistent database snapshot).

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Not changed here: the STT block (read under the guard, then resolve the key, no final row check) is identical on main for an account's own connections, and this PR only adds the shared flag to the guard call. The URL in a shared row is set by the owner alone, so a managed account cannot steer the key anywhere. A cross-process final recheck for STT, chat and the listing routes is worth a separate change.

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: a5f48f0a28

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

@NilayYadav

NilayYadav commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

Review + reproduction evidence

Pinned review: f2e347318e. Three findings, fixed on the branch in 36c8dae, 3128bb0 and a5f48f0; two smaller ones are suggested inline.

I reproduced the shared connection flow on the merge base 811c08e and on the PR (Linux, Chromium, 1400x900): the owner adds a custom OpenAI-compatible connection with one of three upstream models enabled, a second account "alice" signs in, opens Settings > Connections and chats with that model.

  • Before (run): there is no share switch. alice's Connections page opens an empty "New connection" form, the model picker has no Connected tab, and a chat naming the owner's provider id returns 404 Provider config not found. With the fix reverted and the tests kept, the 4 frontend tests (only the owner sees the share toggle... and three more) and every test in test_account_shared_connections.py fail.
  • PR head (run): alice sees "Household Gufo, 1 model, Shared by owner" with only Check, and the reply is "Hello from the household server, model household-small." The upstream received the owner's key from the server. alice's rename, base URL change, delete and key migrate all return 403, and a chat with a model the owner did not enable returns 403. Changing the Model access list or unsharing hides the row at once, and a base URL with ?key= cannot be shared (400).

Owner connection form: no share switch on main, "Share with all accounts" on the PR

alice opens Connections: empty add form on main, the shared "Household Gufo" row on the PR

alice chats through the shared connection on the PR

  • Fixed on the branch: 36c8dae limits a shared row's available_models, /providers/models and /providers/model-capabilities to the models the owner enabled. Before it, alice was shown all three upstream models, not just the one the owner shared. 3128bb0 stops provider_config_guard from reading the provider store on the event loop for every request from another account. a5f48f0 rechecks the model against the row re-read under the lock, so a request that waited behind the owner's edit sees the new model list. Each has a regression test that fails before the fix and passes after.
  • The share flags add 180 B raw / 20 B transfer to the eager startup JS (6,862,624 -> 6,862,804 B raw against main 723a43b, Node 22), which put the bundle budget check over by that much; f2e3473 merges main and raises the budget by that growth plus the usual margin. The share switch itself loads with the lazy Connections tab.
  • The scoped backend and frontend tests pass on Ubuntu, Windows and macOS 15 (26 passed, node 4/4), and the Studio launch smoke passes.

Conclusion: real gap from #14196, now working end to end. The owner's key never leaves the server, and other accounts cannot change a shared row or reach models the owner did not enable. Two small follow-ups are inline.

@NilayYadav NilayYadav left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you for the PR! The goal of this PR is to let the installation owner set up an external connection once and share it with every managed account, with the owner's Model access list applying to connection models. As a summary, this PR adds a shared flag on saved connections, lets managed accounts read shared rows and resolve the owner's key server-side only, refuses edits and unenabled models from other accounts, and adds a "Share with all accounts" switch and a "Shared by owner" tag in Settings > Connections.

Reviewers Severity Finding
1/4 Medium The OpenAI code execution section still mounts on a connection shared by the owner, so its container list and poll hit the new 403
1/4 Low Capabilities fetched through a shared row are filtered to the shared models but cached for the whole provider type

See inline comments for details and suggested fixes.

status_code = 400,
detail = "OpenAI container management requires a saved OpenAI provider.",
)
if config.get("shared_by_owner"):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[1/4 reviewers] This 403 is right, but the chat settings sheet still mounts OpenAICodeExecSection for a shared OpenAI row: showOpenAICodeExecSection in chat-settings-sheet.tsx only checks the provider type, model and base URL, and hasCredential is true because has_api_key is true for the shared row. The section lists containers on mount, on its poll and on every tab focus, so a managed account on a shared OpenAI connection with a code-exec model gets a "Failed to list containers" toast each time. Hiding the section for sharedByOwner rows matches this guard (chat-settings-sheet.tsx is outside the diff, so the change is below):

   const showOpenAICodeExecSection =
     activeExternalProvider != null &&
+    !activeExternalProvider.sharedByOwner &&
     providerSupportsBuiltinCodeExecution(

shared_models = _shared_target_models(payload)
capabilities = await _list_model_capabilities(payload, via_api_key)
if shared_models is not None:
capabilities = [entry for entry in capabilities if entry.get("id", "") in shared_models]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[1/4 reviewers] This list is now limited to the models the owner enabled, which is what a shared row should expose, but the frontend stores capability results per provider type with a 24 hour TTL. If the shared row is fetched first, an account's own connection of the same type (or a second shared one) then misses metadata such as output limits and mandatory reasoning for every model outside that set until the TTL runs out. Either skip the TTL shortcut and merge instead of replace for shared rows in sync-external-providers.ts / model-catalog.ts, or keep the shared fetch out of the provider-wide cache:

-    if (fetchedAt != null && Date.now() - fetchedAt < MODEL_CATALOG_TTL_MS) continue;
+    if (!provider.sharedByOwner && fetchedAt != null &&
+        Date.now() - fetchedAt < MODEL_CATALOG_TTL_MS) continue;

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: db20204ae0

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

Frontend build + bundle sanity fails on the startup bundle budget, just barely:

over the startup budget: raw 6698.9 KB > 6698.9 KB

That run merged into b098d77e81, which already carries the current budget (#14407), and main was within it there, so the extra bytes come from this PR's frontend changes. They are small, so either move the new code behind a lazy import, or raise BUDGET in studio/frontend/scripts/check-bundle-budget.ts in this PR, set to the merged build's measurement plus the same 160 B raw / 189 B transfer margin, with a comment entry like the others.

danielhanchen added a commit that referenced this pull request Oct 21, 2026
…mpile packing test off leaked env (#14425)

## Problem

Two tests on main fail in CI for reasons in the tests, not the product.
They are red on unrelated PRs, for example #14409 and #14365.

**1. `tests/python/test_v100_fullft_precision.py` (10 tests, `Repo tests
(CPU, studio)`)**

```
tests/python/test_v100_fullft_precision.py:80: in _decide
    exec(CODE, {"torch": torch, "os": os}, {"args": args, "model": model})
E   NameError: name 'args' is not defined
```

The test runs the `mixed_precision` template from `unsloth/models/rl.py`
with separate globals and locals dicts. #14394 added
`_unsloth_precision_requested = tuple(getattr(args, k, False) for k in
(...))` to that template. In the generated trainer this runs inside a
function, where the generator sees `args`, so the product is fine. A
generator inside `exec` with a separate locals dict cannot see those
locals, so the test raises `NameError`.

**2.
`tests/test_legacy_block_compile_install.py::test_packed_calls_keep_the_unsloth_layer_forward`
(`Repo tests (CPU, rest)`)**

```
tests/test_legacy_block_compile_install.py:105: in test_packed_calls_keep_the_unsloth_layer_forward
E   assert []
```

The test (from #14398) expects an unpacked call to go through the
compiled block. `_block_compile._wrap` keeps every call on the stock
forward when `UNSLOTH_COMPILE_DISABLE` is `1`, `UNSLOTH_BLOCK_COMPILE`
is `0`, or `UNSLOTH_FORCE_FLOAT32` is `1`. Eight test modules run
`os.environ.setdefault("UNSLOTH_COMPILE_DISABLE", "1")` at import time,
so the result depends on which modules a worker collected. The test
passes alone and fails with any of those variables set.

## Fix

Test only:

- `test_v100_fullft_precision.py`: `exec` the template in one namespace,
as in the trainer's function scope. Results are still read from `args`
and the environment.
- `test_legacy_block_compile_install.py`: the packing test clears the
three variables with `monkeypatch.delenv` before wrapping.

## Verification

- `test_v100_fullft_precision.py`: on main 10 failed (the `NameError`
above); with this change 10 passed.
- `test_legacy_block_compile_install.py` on main:
- with any one of `UNSLOTH_COMPILE_DISABLE=1`, `UNSLOTH_BLOCK_COMPILE=0`
or `UNSLOTH_FORCE_FLOAT32=1` set: 1 failed (the packing test), 5 passed;
- with this change: 6 passed in each of those three cases and with none
set.
@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: f2e347318e

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

# Conflicts:
#	studio/frontend/scripts/check-bundle-budget.ts
@unslothai unslothai deleted a comment from NilayYadav Oct 21, 2026
# Conflicts:
#	studio/frontend/scripts/check-bundle-budget.ts
# Conflicts:
#	studio/frontend/scripts/check-bundle-budget.ts
@danielhanchen
danielhanchen merged commit 0a930d4 into main Oct 21, 2026
@danielhanchen
danielhanchen deleted the studio-shared-connections branch October 21, 2026 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Add ability to share external connections

2 participants