Skip to content

fix(studio): verify TLS against the OS trust store at runtime (corporate TLS-inspection proxies) - #8108

Merged
danielhanchen merged 19 commits into
unslothai:mainfrom
Cesarsk:fix/studio-runtime-native-tls
Aug 9, 2026
Merged

danielhanchen merged 19 commits into
unslothai:mainfrom
Cesarsk:fix/studio-runtime-native-tls

Conversation

@Cesarsk

@Cesarsk Cesarsk commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Follow-up to #6671. That PR fixed install-time TLS behind corporate TLS-inspecting proxies (Cisco Umbrella, Zscaler, Netskope) by switching uv to native TLS. The runtime has the same defect: Python verifies against certifi's bundled Mozilla roots and ignores the OS trust store where the proxy CA lives, so every huggingface.co call from the Studio backend fails:

SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED]
certificate verify failed: unable to get local issuer certificate'))

Model downloads, repo metadata and LoRA base resolution are all broken. A terminal user can export SSL_CERT_FILE, but launching Studio from the macOS .app or a desktop shortcut never reads shell profiles, so GUI launches have no workaround at all. Install succeeds (thanks to #6671), then the installed app cannot download anything.

Fix

Verify TLS against the OS trust store with truststore, the same mechanism pip has enabled by default since 24.2 and the runtime counterpart of UV_NATIVE_TLS.

truststore.inject_into_ssl() is process-wide but does not survive a spawn, so utils/native_tls.py is called once at each interpreter that touches the network:

  • Importable children call activate_native_tls() at module level: main.py plus the HF download, STT download, inference, export, training and data-recipe workers, and the diffusion training child (inside its own spawn target, after the lease-secret scrub).
  • Children that cannot import backend modules carry the gate as source: the python -c AutoConfig and vision probes, and prebuilt_core.py, which ships standalone for the llama.cpp / whisper.cpp installers. Rather than three hand-written copies drifting apart, native_tls.inline_gate_source() renders the gate from the same constants native_tls_enabled() reads; the probes concatenate it, and the one true paste in prebuilt_core.py is asserted against it by AST in tests/test_native_tls_entrypoints.py.
  • uv child installers do their own TLS through rustls, which ignores in-process injection, so the helper points them at the OS store too. UV_SYSTEM_CERTS (uv >= 0.11) and UV_NATIVE_TLS (older) are mirrored from one resolved value rather than defaulted independently, because uv treats either as an opt-in: an opt-out in one spelling has to carry to the other. utils/mlx_repair.py passes both through its env allowlist.

truststore is vendored at studio/backend/vendor/, not depended on. Nothing in Unsloth required it before, directly or transitively, so declaring it would have added a package to every Studio install to fix a proxy most users do not have. It is MIT, six pure-Python files, no dependencies of its own, and pip vendors it for the same reason.

The repo's usual mechanism for pinned third-party source, utils/third_party_source.py, is not an option here: it downloads over urllib at first use, so behind the very proxy this PR fixes, fetching truststore would itself fail with CERTIFICATE_VERIFY_FAILED. The copy has to exist before the network does.

Consumers append the vendor directory to sys.path and import the top-level name, so a truststore the user installed themselves still wins. The directory is deliberately not a package: a dotted studio.backend.vendor.truststore import would load the same files under a second module name, and each copy would wrap ssl again. The copy is static: nothing refreshes it, and tests/test_vendored_truststore.py pins it to the published 0.10.4 wheel hashes so a formatter or a stray edit fails rather than silently changing how certificates are verified. A version bump means replacing the tree and updating the manifest in the same commit. That check matters because vendored code is invisible to the dependency scanners.

Behaviour

Default on for macOS (Security framework) and Windows (CertStore), which answers the Windows-uniformity question raised in #6671. Linux stays opt-in via UNSLOTH_STUDIO_NATIVE_TLS=1, since distro OpenSSL and cert layouts vary. 0 opts out anywhere.

Two things worth stating plainly:

  • SSL_CERT_FILE and REQUESTS_CA_BUNDLE keep working, but they become additive rather than exclusive: truststore keeps the OS anchors alongside the supplied bundle (macOS via SecTrustSetAnchorCertificatesOnly(trust, False), Windows by trying the system engine first). If a bundle was being used to narrow trust, UNSLOTH_STUDIO_NATIVE_TLS=0 is the way back. This matches pip's behaviour under the same injection.
  • The injection is client side. A context built after activation verifies a peer chain on every handshake and so cannot serve TLS. Studio serves plain HTTP on loopback, and a test keeps it that way; a future in-process HTTPS listener would need truststore.SSLContext for outbound connections instead of the process-wide injection.

If truststore is missing or injection fails, the helper logs one warning line and falls back to certifi, which is the pre-existing and strictly less permissive behaviour. Python 3.9 is unaffected either way: truststore refuses to import below 3.10 by design, vendored or not.

Verification

  • 38 unit tests across tests/test_native_tls.py, tests/test_native_tls_entrypoints.py and tests/test_vendored_truststore.py, no network: platform defaults, env tri-state, uv mirroring, idempotency, fail-open recovery, a check that every spawned entry point still activates before its first Hub call so a future worker cannot quietly skip it, and a digest of the vendored tree that fails if a formatter or an edit moves it off upstream 0.10.4.
  • Live on an Umbrella-intercepted macOS machine, launched from the .app with no shell environment: startup model-list refresh, HF metadata and LoRA base checks all succeed where they previously logged SSLError retry walls. A spawned worker verifies the same way.
  • Negative control: UNSLOTH_STUDIO_NATIVE_TLS=0 reproduces the original CERTIFICATE_VERIFY_FAILED, confirming the injection is what does the work.
  • With truststore deliberately not installed, in a clean venv and again against an installed wheel: the backend helper, the rendered python -c probe child and prebuilt_core.py all resolve the vendored copy and inject; with a real truststore installed, all three resolve site-packages instead, which is what append-rather-than-prepend buys. Wheel and sdist both ship the six modules, py.typed and the MIT LICENSE, and the wheel METADATA no longer declares truststore.
  • End-to-end against a real TLS server with a private CA (rather than the stubbed unit tests), across requests, httpx sync and async, urllib3 and huggingface_hub, over the [Windows, Linux, WSL, macOS] x [NVIDIA, AMD, CPU] gate matrix, plus a before and after benchmark: no steady-state regression (pooled request latency unchanged), around 16 ms per new TLS connection on Linux from truststore's per-handshake set_default_verify_paths(), and around 27 ms and 4.5 MB per spawned worker for the extra imports.

Workaround (until merged)

SSL_CERT_FILE=<bundle-with-corp-CA> REQUESTS_CA_BUNDLE=<bundle-with-corp-CA> unsloth studio

Terminal launches only, which is exactly what the .app cannot do.

On macOS/Windows behind a TLS-inspecting proxy (Cisco Umbrella, Zscaler,
...), every huggingface.co request from the Studio backend fails with
CERTIFICATE_VERIFY_FAILED: Python verifies against certifi's bundled
Mozilla roots and ignores the OS trust store where the proxy CA lives. A
terminal user can export SSL_CERT_FILE, but macOS .app / desktop-shortcut
launches never read shell profiles, so GUI-launched Studio has no
workaround.

Inject truststore into ssl at each network-touching entry point (server,
HF download worker, STT download worker, training worker) — injection is
per-process and does not survive spawns. Default-on for macOS/Windows,
opt-in on Linux, opt-out anywhere via UNSLOTH_STUDIO_NATIVE_TLS=0,
mirroring UV_NATIVE_TLS in install.sh (#6671), whose runtime counterpart
this is.

Co-Authored-By: Claude Fable 5 <[email protected]>
@Cesarsk
Cesarsk requested a review from danielhanchen as a code owner August 7, 2026 12:19
chatgpt-codex-connector[bot]

This comment was marked as resolved.

Review follow-ups: the inference worker resolves remote LoRA bases and the
export worker pushes/loads from the Hub, both in fresh spawned interpreters
that missed the injection; and pyproject's studio extra must mirror
requirements/studio.txt (test_studio_extra_matches_requirements), so
truststore is added there too for `pip install "unsloth[studio]"`.

Co-Authored-By: Claude Fable 5 <[email protected]>
chatgpt-codex-connector[bot]

This comment was marked as resolved.

Second review round: the data-recipe jobs worker and the transformers
-c config probe are further fresh interpreters with Hub/provider
traffic, so activate in the worker and inline the gated injection in
the probe script (it cannot import backend modules). uv/pip child
installers do their own TLS (rustls ignores in-process injection), so
activation now exports UV_SYSTEM_CERTS/UV_NATIVE_TLS, mirroring
install.sh. truststore requires Python >=3.10 while the project floor
is 3.9, so the dependency gets a python_version marker on both sides
of the requirements mirror; activate_native_tls() already falls back
to certifi where the import is unavailable.

Co-Authored-By: Claude Fable 5 <[email protected]>
@Cesarsk

Cesarsk commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

Note on the failing checks — both groups reproduce on main and are unrelated to this PR:

  • pip scan-packages (×3): the scanner flags huggingface-hub 0.36.2's retry loop (_http.py, while True:) as "C2 polling/beaconing"; it's above baseline and fails main's own Security-audit runs today identically.
  • test_research_runs_hardening.py (×4 jobs): _run_stream returns a 4-tuple since Clamp Deep Research max_tokens to loaded context window #7985 (merged today) while the hardening tests still expect 3 — a clean checkout of current main fails the same 4 tests locally; the push's own CI run was concurrency-cancelled before reporting.

@oobabooga

Copy link
Copy Markdown
Member

I addressed the remaining spawned-worker gap in a05c8c5. Diffusion LoRA training uses its own spawn target, so it now activates native TLS before importing diffusers and calling from_pretrained. Added regression coverage for the activation order.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen and others added 2 commits August 8, 2026 03:38
- native_tls: mirror one resolved value across UV_SYSTEM_CERTS/UV_NATIVE_TLS.
  uv takes either variable as an opt-in, so UV_SYSTEM_CERTS=0 alone was
  re-enabled by the legacy name defaulting to 1. Matches install.sh.
- native_tls: warn instead of debug when injection fails, and document that
  explicit CA bundles become additive rather than exclusive under truststore.
- model_config: activate in the _VISION_CHECK_SCRIPT child, which calls
  AutoConfig.from_pretrained and fails quiet, so VLM detection silently
  degraded behind a proxy.
- prebuilt_core: activate at import so the llama.cpp / whisper.cpp installers
  and the resolve-prebuilt probe verify their urllib downloads the same way.
- mlx_repair: forward the UV cert variables through the allowlisted child env,
  the one uv installer that did not inherit them.
- diffusion_training_service: activate inside run_without_native_path_secret
  so truststore imports after the lease secret is scrubbed, and scrub the
  parent env before the child starts, like the other orchestrators.
- tests: pin the uv mirror both ways, stop leaking the UV vars into the pytest
  process, assert the diffusion ordering, and add static coverage that every
  spawned entry point still activates.

@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: 63cdb4a211

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

# Fresh interpreter: main.py's truststore injection does not survive the spawn.
from utils.native_tls import activate_native_tls

activate_native_tls()

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 Scrub lease secret before activating download TLS

When this worker is spawned from download_lifecycle.spawn_worker, its environment is built with get_hf_cache_paths().child_env() (a copy of os.environ) and is not passed through child_env_without_native_path_secret; the same pattern is used by the dictation download worker. In desktop sessions that have UNSLOTH_STUDIO_NATIVE_PATH_LEASE_SECRET, this new module-level activation imports and runs third-party truststore while the signing secret is still present in the child environment. Scrub the env before Popen, or wrap these subprocess entrypoints like the mp workers before activating TLS.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The env does carry the secret, but no boundary is crossed here. The lease is a signed grant the frontend forwards and the backend verifies before a native read (verify_native_path_lease, consumed only by routes/rag.py, routes/inference.py and hub/services/datasets/local.py); it exists to stop the webview forging a path. A backend-spawned child already runs as the same user with the same filesystem access, so the key grants it nothing open() does not. The inheritance is also pre-existing and unchanged by this PR, and scrubbing only ahead of truststore would be cosmetic: the same child then imports huggingface_hub, urllib3, requests and hf_xet with the secret still set, since nothing scrubs it in-child. Neither download worker touches the lease API.

Comment thread studio/prebuilt_core.py
Comment on lines +63 to +66
_flag = os.environ.get("UNSLOTH_STUDIO_NATIVE_TLS", "").strip().lower()
if _flag in {"1", "true", "yes"} or (
_flag not in {"0", "false", "no"} and sys.platform in ("darwin", "win32")
):

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 Honor installer TLS opt-outs in prebuilt downloads

Fresh evidence is that the standalone prebuilt inline gate added here never reads the installer opt-out variables: when setup.sh invokes install_llama_prebuilt.py/install_whisper_prebuilt.py, it inherits install.sh's documented UV_SYSTEM_CERTS=0 opt-out, but this branch still enables truststore on macOS/Windows unless UNSLOTH_STUDIO_NATIVE_TLS=0 is also set. Users opting out because their system store/proxy setup breaks downloads can still have these urllib prebuilt downloads verified against that store; treat false UV_SYSTEM_CERTS/UV_NATIVE_TLS values as disabling here or export the Studio opt-out before spawning.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These knobs govern different TLS stacks on purpose. UV_SYSTEM_CERTS / UV_NATIVE_TLS configure uv's rustls, which is why install.sh sets them and the README scopes that opt-out to uv; UNSLOTH_STUDIO_NATIVE_TLS governs Python's ssl. utils/native_tls.py encodes exactly that: it writes the uv variables and never reads them as an input, so UV_SYSTEM_CERTS=0 still injects there too. Honouring them in the vendored copy alone would diverge it from the helper it is required to mirror, and would take away the ability to keep uv on certifi while Python uses the OS store. The documented Studio opt-out works here: UNSLOTH_STUDIO_NATIVE_TLS=0 leaves prebuilt downloads on certifi, which I verified by importing prebuilt_core with the flag set each way.

Comment thread studio/prebuilt_core.py
Comment on lines +68 to +69
import truststore
truststore.inject_into_ssl()

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 Scrub lease secret before prebuilt TLS activation

The in-app llama/whisper update paths spawn these installer scripts with env = dict(os.environ, ...), and the read-only resolver inherits the parent environment too, so desktop sessions carrying UNSLOTH_STUDIO_NATIVE_PATH_LEASE_SECRET now run this new truststore import/injection before the child has scrubbed a secret it never needs. Use child_env_without_native_path_secret() (while preserving the required installer vars) for the prebuilt installer subprocesses, or otherwise remove the lease secret before importing this module.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same reasoning as the download-worker item, plus the ordering premise does not hold: truststore is not the first third-party import in this module, filelock is imported at prebuilt_core.py:53-56, above the new block. The installer children never touch the lease API, the inheritance predates this PR, and a child spawned by the backend runs as the same user, so the signing key grants it nothing it could not do directly. Scrubbing at those spawn sites would be a reasonable tidy-up of a pre-existing pattern gap, but it belongs in its own change rather than this one.

test_vision_subprocess_unions_sidecar_registry slices the embedded script at
its first 'try:' to exec the inlined helpers, so putting the TLS activation
above them left that slice empty. Move it below the helpers, still ahead of
AutoConfig.from_pretrained.
…#8108

Simulation findings on the branch:

- A failed injection logged a full traceback at warning level. On Python 3.9,
  where truststore is excluded by the dependency marker on purpose, that is one
  stack per worker start. Now one line carrying the reason.
- truststore's injection is client-side: an SSLContext built after it verifies a
  peer chain on every handshake, so it cannot serve TLS. Studio serves plain
  HTTP on loopback so nothing breaks today, but an in-process HTTPS listener
  added later would fail at handshake on the default-on platforms. Documented,
  and test_native_tls_entrypoints.py now fails if one appears.
@danielhanchen

Copy link
Copy Markdown
Member

I simulated this end to end rather than reasoning about it, since the unit tests stub truststore out and so never execute inject_into_ssl(). Pushed bdb7ca30e with the two things the simulations turned up. Harnesses are reproducible; happy to attach them if useful.

Reproducing the actual bug, then the fix. On a Linux box the corporate case is faithful: put the proxy CA in the OS store only (SSL_CERT_FILE, which is what truststore's OpenSSL backend consults via set_default_verify_paths) and leave requests on certifi, which is exactly the reported state.

BEFORE: OS-store CA is ignored, request fails      SSLError CERTIFICATE_VERIFY_FAILED
AFTER:  OS-store CA is honoured                    200
opt-out (UNSLOTH_STUDIO_NATIVE_TLS=0)              back to SSLError

So the issue is real, and the fix is what flips it. 19 checks in that harness, all passing: hostname mismatch still rejected, a CA absent from the OS store still rejected, verify=<path>, verify=False, mTLS client certificates, HTTPS through a CONNECT proxy, 64 concurrent handshakes, requests / httpx sync and async / urllib3 / stdlib urllib, and 31 ms per handshake, which is no worse than certifi.

Nothing old breaks. 32 more checks over the environment matrix: the platform default for darwin, win32, linux, cygwin and freebsd; every spelling of the flag including junk values falling back to the platform default; the full uv variable matrix; and the fail-open paths. An old Studio install whose venv predates this PR has no truststore, so activate_native_tls() returns False and the process keeps certifi, which is the behaviour it had yesterday. Same on Python 3.9, and I confirmed the marker is load-bearing rather than decorative: uv pip install truststore on 3.9 is genuinely unsatisfiable, so without python_version >= "3.10" the extra would fail to resolve for anyone still on 3.9. prebuilt_core.py also imports cleanly with truststore absent.

[Windows, Linux, WSL, macOS] x [NVIDIA, AMD, CPU], 18 cells, all passing: the gate resolves per platform and the spawned workers still import under each accelerator environment, including the training worker where the activation sits between the ROCDXG block and the hardware helpers. WSL reports linux and so stays opt-in, which is what we want given how varied WSL cert layouts are.

Browsers. Studio serves plain HTTP on loopback, so no browser ever negotiates TLS with it, but I checked rather than assumed. I booted the real FastAPI app twice, injection off and on, and the HTTP surface is identical across /api/health, /docs and /openapi.json. Then drove it from all three engines: Blink (Chrome and Edge), Gecko (Firefox) and WebKit (Safari), navigation and in-page fetch, 200 from each.

The whole backend suite with injection actually live, UNSLOTH_STUDIO_NATIVE_TLS=1: 17806 passed, 0 failed. Worth doing because CI cannot: the backend job is ubuntu-latest only and Linux is opt-in, so inject_into_ssl() never runs anywhere in CI, on precisely the two platforms where it is default-on.

Two things I changed as a result:

  1. A failed injection logged a full traceback at warning level. On Python 3.9, where truststore is excluded on purpose, that is a stack trace per worker start. Now a single line carrying the reason.
  2. truststore's injection is client-side only. An SSLContext built after activation runs peer-chain verification on every handshake, so it cannot serve TLS, and a server socket dies with AttributeError: 'NoneType' object has no attribute 'get_unverified_chain'. Studio serves plain HTTP and the MCP app is mounted on the same uvicorn instance, so nothing breaks today, but an in-process HTTPS listener added later would fail at handshake on macOS and Windows. Documented in the module, and test_native_tls_entrypoints.py now fails if PROTOCOL_TLS_SERVER or a uvicorn ssl_certfile appears in the backend.

Two behaviours worth stating rather than fixing, both consequences of the mechanism:

  • verify=<bundle> and REQUESTS_CA_BUNDLE become additive rather than exclusive, since truststore keeps the OS anchors alongside them (macOS calls SecTrustSetAnchorCertificatesOnly(trust, False), Windows tries the system engine first). They still work for adding a CA; they stop being a way to narrow trust. Same as pip since 24.2. Now in the docstring, and pinned in the harness so it cannot change silently.
  • Setting UV_NATIVE_TLS makes uv >= 0.11 print The UV_NATIVE_TLS environment variable is deprecated. I confirmed on uv 0.12.3 that it warns whenever the variable is set, even alongside UV_SYSTEM_CERTS. Dropping it would leave pre-0.11 uv without the fix, which is the tradeoff install.sh already settled, so I left it mirrored to match. Verified real installs work through both uv 0.10.7 (legacy variable only) and uv 0.12.3.

One upstream note for the record: truststore has an open issue about a race on context configuration (#209). My 64-thread test passes, and on Linux the OpenSSL backend never lowers verify_mode, so I could not provoke it, but it is worth knowing about given we now inject process-wide.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 8, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 8, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 8, 2026
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Aug 8, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 8, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 8, 2026
@unslothai unslothai deleted a comment from Cesarsk Aug 8, 2026
@unslothai unslothai deleted a comment from Cesarsk Aug 8, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 8, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 8, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 8, 2026
@unslothai unslothai deleted a comment from oobabooga Aug 8, 2026
danielhanchen and others added 2 commits August 8, 2026 11:15
truststore is pre-1.0 and 0.x minors are where it has changed verification
behaviour (0.9 to 0.10), while fixes land as patches inside a minor (0.10.1,
0.10.3, 0.10.4). Since activation applies process-wide to every TLS connection,
a semantic change should get a human look rather than arrive on the next
install. 0.10.4 has been the current release for a year, so nothing is held
back today. Mirrored in both declarations.
@danielhanchen

Copy link
Copy Markdown
Member

Measured the performance cost before and after, on the same box, each configuration in its own process so the irreversible global patch cannot contaminate the control.

Steady state is unchanged. Once a connection is up, there is no per-request cost:

pooled request, median   41.89 -> 41.86 ms   (-0.1%)
pooled request, p95      42.85 -> 42.17 ms   (-1.6%)
bulk over one connection  unchanged

That is the shape that matters for a model download: one connection carrying many MB.

The cost is per new connection, and on Linux I can attribute it exactly:

new connection, median   43.56 -> 59.62 ms   (+16.07 ms)
new connection, p95      44.12 -> 61.73 ms   (+17.61 ms)

truststore's OpenSSL backend calls ctx.set_default_verify_paths() inside _configure_context, so it runs on every wrap_socket. Timed directly on this machine: 16.03 ms, re-parsing 146 certificates from /usr/lib/ssl/cert.pem every handshake. That accounts for the entire delta. It is truststore's design rather than anything in this PR, and Linux is opt-in, so nobody pays it unless they ask for it. The macOS and Windows backends take a different route (they lower verify_mode for the handshake and then run an OS trust evaluation), which I cannot measure from here, so I am not claiming a number for the two default-on platforms.

Startup cost per spawned worker, which is the other place activation shows up:

activate_native_tls()                 4.6 -> 51.7 ms   (+195 modules)
hub.workers.hf_download              85.1 -> 113.7 ms  (+4.5 MB RSS)
core.data_recipe.jobs.worker         86.9 -> 115.2 ms  (+4.4 MB RSS)
core.training.worker                 89.0 -> 115.2 ms  (+4.5 MB RSS)
core.inference.stt_download_worker    8.7 -> 56.2 ms   (+12.1 MB RSS)

inject_into_ssl() eagerly imports urllib3 and requests to repoint their cached SSLContext references, which is where the 195 modules come from. Workers that already pull those in pay about 27 ms; the dictation download worker is the outlier in relative terms (+544%) only because it is a tiny module that otherwise imports neither, and 56 ms is still nothing next to the download it is about to start.

So: tens of milliseconds once per worker spawn, ~16 ms per new TLS connection on opt-in Linux, and nothing at all in steady state. Reasonable for the failure it fixes, but worth having the numbers on record rather than assumed.

One upstream observation, not actionable here: re-parsing the full system bundle on every handshake looks like something truststore could cache. Worth an issue against truststore if anyone wants to chase it.

danielhanchen and others added 2 commits August 8, 2026 14:12
The python -c probes and prebuilt_core.py cannot import backend modules, so
each carried its own hand-written copy of the UNSLOTH_STUDIO_NATIVE_TLS gate.
Three copies of the same platform defaults drift silently: a child would keep
downloading against certifi while everything else used the OS store.

native_tls.inline_gate_source() now renders the gate from the same constants
native_tls_enabled() reads. The probes concatenate it, and prebuilt_core.py
keeps a paste that test_native_tls_entrypoints.py asserts verbatim against the
generated text.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

ruff-format restyles the pasted gate in prebuilt_core.py (quote style, line
wrapping), so a substring assertion against inline_gate_source() fails the
moment the formatter runs, as it did on 668cd9f. Compare the parsed
statements instead: still catches a real edit to the platform defaults, and
ignores formatting that cannot change behaviour.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 8, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: fd80893d0e

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

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 9, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 9, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 9, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 9, 2026
danielhanchen added 2 commits August 9, 2026 07:39
truststore was a new third-party dependency for every Studio user, added to fix
CERTIFICATE_VERIFY_FAILED for the few behind a TLS-inspecting proxy. Nothing in
Unsloth required it before, directly or transitively.

It is MIT, six pure-Python files, no dependencies of its own, so vendor it at
studio/backend/vendor/ and drop both declarations. pip vendors it for the same
reason. utils/third_party_source.py is not an option here: it downloads over
urllib at first use, which behind the very proxy this fixes would itself fail to
verify. The copy has to exist before the network does.

Consumers append the vendor directory to sys.path and import the top-level name,
so a truststore the user installed themselves still wins. The directory is
deliberately not a package: a dotted import would load the same files under a
second module name, and each would wrap ssl again.

test_vendored_truststore.py pins the tree against the published 0.10.4 wheel and
scripts/sync_vendored_truststore.py re-syncs it, since vendored code is invisible
to the dependency scanners.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 4e9f55ce3c

ℹ️ 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 added 2 commits August 9, 2026 07:57
Nothing in Studio ever ran it: it only re-downloaded a wheel for a maintainer
bumping the pin, which implies a refresh story this repo does not have.

The vendored files are a static copy. truststore_manifest.json and
test_vendored_truststore.py stay, since they are what makes them static: they
pin the tree to the published 0.10.4 hashes and fail if anything edits it. A
version bump now means replacing the tree and updating the manifest in the same
commit, deliberately, which the README spells out.
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 4f37101f5f

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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants