← Back to Pull requests

Add Rust interop for Fetcher and DurableObjectClass #8617

Closed
unknown closed this pull request without merging on Nov 20, 2026 10:01 UTC
View on GitHub
unknown unknown commented on Nov 18, 2026 15:01 UTC
Author

Rust APIs can't take or return service bindings or Durable Object
classes yet: Fetcher and DurableObjectClass are C++ JSG resources,
and nothing exposes them to Rust. This adds per-type jsg-cpp shims
for both, in a new src/workerd/api/channel-interop package.
Following src/rust/jsg/README.md safety rule 3, the shims live with
the API code rather than in Rust JSG. This is the first production use
of jsg-cpp.

Planned users: the Rust ports of the Worker Loader binding and the
container binding. Also two in-progress ports that currently carry
their own Fetcher shims: the Rust ExecutionContext
(ctx.mapVirtualHost) and an internal project's cache-purge binding.
Both will switch to this package once it lands.

API

Rust takes and returns these as jsg_cpp::Ref<Fetcher> and
jsg_cpp::Ref<DurableObjectClass>. They work as method parameters,
#[jsg_struct] fields, Option, Nullable and Vec. Unwrapping
goes through the isolate's TypeHandler, so subclasses such as
ExtendedFetcher are accepted, with the pointer adjusted to the base
class, and anything else is rejected as C++ jsg::Ref parameters do.

  • Fetcher::subrequest_channel() returns its SubrequestChannel.

  • Fetcher::from_channel() wraps a SubrequestChannel in a new

  • Fetcher, with the defaults worker-loader.c++ uses.
  • Fetcher::from_channel_number(channel, RequiresHostAndProtocol,

  • InHouse)
    is the constructor most bindings use: KV, R2, cache purge,
    global-scope, and the env builders. Both options are Rust enums.
  • Fetcher::map_virtual_host(port) forwards to C++

  • Fetcher::mapVirtualHost, which ctx.mapVirtualHost and
    cloudflare:workers also call.
  • DurableObjectClass::channel() returns its ActorClassChannel, as

  • ctx.facets.get() needs.
  • DurableObjectClass::from_channel() wraps one in a new class, as

  • Worker Loader's getDurableObjectClass() and the ctx.exports
    loopback classes need.
  • require_allows_transfer() on both channel types.
  • The C++ channel types are exposed through aliases and held as
    kj_rs::KjRc. KjRc is neither Send nor Sync, so a channel can't
    move to another thread, into an await_io future, or into resource
    state. A compile test asserts this with static_assertions. Dropping
    a channel after its request has ended is safe, as in C++.

    Rust code holds an IoContext by id. To get from that id back to the
    C++ IoContext the shims need, a new io-context:current-with-id
    library adds currentWithId(), visible to //src/workerd/api only.
    Ids come from a process-unique counter, so a stale id fails a
    KJ_REQUIRE instead of matching a newer context.

    Not included yet

  • Creating a Fetcher from a Fetcher::OutgoingFactory (dynamic

  • dispatch, container getTcpPort, facets): deferred until a port
    needs it.
  • What Worker Loader needs beyond this: a subrequest channel with no

  • outbound connection, and WorkerStubChannel::getEntrypoint /
    getActorClass.
  • Channel tokens.
  • Diff: 372 lines (+279 / -93) across 4 files Reviewer: bartlomieju Review duration: 2579m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.43) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.43 · 372 lines diff across 4 files
    0.43
    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%
    60%
    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.354
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #8617"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% 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: 42.8% (MEDIUM) · Higher = larger blast radius
    42.8%
    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: 60.5% · Lower = rushed or shallow review
    60.5%
    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: 16.9% · Safe to merge
    16.9%