← Back to Pull requests

Load the Pyodide bundle in Rust #8202

Closed
unknown closed this pull request without merging on Nov 06, 2026 00:39 UTC
View on GitHub
unknown unknown commented on Nov 03, 2026 23:28 UTC
Author

The workerd server now fetches, caches and verifies the Pyodide bundle
a Python worker needs in Rust (server/server/pyodide.rs) instead of
in C++ (server/pyodide.c++).

preloadPython() in the worker factory returns early if the bundle
is already loaded. Otherwise it awaits the server's
pyodide_bundle_fetch() for the verified bytes and passes them to
PyodideBundleManager::setPyodideBundleData(), unless another
worker loaded the same bundle meanwhile. The Rust side makes no
calls back into C++.
pyodide_bundle_fetch() returns an empty Vec when there is no
bundle (an uncached "dev"), since the cxx fork's KjMaybe cannot
hold a Vec yet; a TODO marks the switch to KjMaybe<Vec<u8>>. An
empty bundle file is an error rather than no bundle.
The bundle is read from pyodide_<version>.capnp.bin in
--pyodide-bundle-disk-cache-dir, or else downloaded from the same
URL as before. The download is one HTTP/1.1 GET over hyper on the
loop's tokio runtime. The result is written to the cache through a
temporary file that is synced to disk and renamed. The cache is
read and written on tokio's blocking pool, as a bundle is tens of
MB.
Unchanged: "dev" is never downloaded, a status other than 200
fails, the cache is written only after a download that passed the
integrity check, and the integrity rules (SHA-256 subresource
integrity, required for every bundle but "dev") are the same. The
cache directory is still resolved against the working directory at
startup, as kj resolved it.
The C++ fetcher, computePyodideBundleIntegrity(),
verifyPyodideBundleIntegrity() and
PythonConfig::pyodideDiskCacheRoot are removed. Their C++ tests
are now Rust unit tests in server/server/pyodide-test.rs, which
also cover the cache and the download against a local hyper server,
over plain HTTP and over TLS with a test CA (SNI, Host and an
untrusted certificate included).
Nothing in the workerd binary depends on kj-tls any more. The
second commit drops it from workerd-api, along with a stale
include.

Behaviour that changes:

The trust store. kj's useSystemTrustStore loaded BoringSSL's
default paths (SSL_CERT_FILE, else /etc/ssl/cert.pem, and
SSL_CERT_DIR, else /etc/ssl/certs), plus the system store on
Windows. The download now uses kj-hyper's rustls with
rustls-platform-verifier 0.7: Security.framework (the Keychain) on
macOS, the Windows certificate store on Windows, and
rustls-native-certs on Linux, which still honors SSL_CERT_FILE
and SSL_CERT_DIR and otherwise probes the usual bundle locations.
On macOS, roots added to the Keychain now count, and
SSL_CERT_FILE / SSL_CERT_DIR no longer do; on Windows the two
variables no longer count either.
Two Python workers (dynamic workers, say) that both download the
same version at once no longer fail on a duplicate insert into the
bundle manager; the second one finds the bundle loaded and drops
its copy.
Whether the cache directory exists is checked on each load, not
once at startup.
Network errors, resolving and connecting included, name the
Pyodide bundle URL and keep the underlying exception type.

  • A --pyodide-bundle-disk-cache-dir that resolves to a path that is

  • not UTF-8 (a relative path under such a working directory) fails at
    startup, as the server takes the directory as a string.

    This adds no new JS-visible API and no compatibility flag.

    Diff: 433 lines (+324 / -109) across 5 files Reviewer: ryanking13 Review duration: 2951m
    All Vouch review confidence checks passed
    Residual risk 0.20 = Change Risk (0.45) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 433 lines diff across 5 files
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.363
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #8202"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.2% (MEDIUM) · Higher = larger blast radius
    45.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 19.5% · Safe to merge
    19.5%