Add Rust interop for Fetcher and DurableObjectClass #8617
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
bartlomieju
Rust APIs can't take or return service bindings or Durable Object
classes yet:
FetcherandDurableObjectClassare C++ JSG resources,and nothing exposes them to Rust. This adds per-type
jsg-cppshimsfor both, in a new
src/workerd/api/channel-interoppackage.Following
src/rust/jsg/README.mdsafety rule 3, the shims live withthe 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
Fetchershims: the RustExecutionContext(
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>andjsg_cpp::Ref<DurableObjectClass>. They work as method parameters,#[jsg_struct]fields,Option,NullableandVec. Unwrappinggoes through the isolate's
TypeHandler, so subclasses such asExtendedFetcherare accepted, with the pointer adjusted to the baseclass, and anything else is rejected as C++
jsg::Refparameters do.Fetcher::subrequest_channel()returns itsSubrequestChannel.Fetcher::from_channel()wraps aSubrequestChannelin a newFetcher, with the defaultsworker-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, whichctx.mapVirtualHostandcloudflare:workersalso call.DurableObjectClass::channel()returns itsActorClassChannel, asctx.facets.get()needs.DurableObjectClass::from_channel()wraps one in a new class, asWorker Loader's
getDurableObjectClass()and thectx.exportsloopback classes need.
require_allows_transfer()on both channel types.The C++ channel types are exposed through aliases and held as
kj_rs::KjRc.KjRcis neitherSendnorSync, so a channel can'tmove to another thread, into an
await_iofuture, or into resourcestate. A compile test asserts this with
static_assertions. Droppinga channel after its request has ended is safe, as in C++.
Rust code holds an
IoContextby id. To get from that id back to theC++
IoContextthe shims need, a newio-context:current-with-idlibrary adds
currentWithId(), visible to//src/workerd/apionly.Ids come from a process-unique counter, so a stale id fails a
KJ_REQUIREinstead of matching a newer context.Not included yet
Fetcherfrom aFetcher::OutgoingFactory(dynamicdispatch, container
getTcpPort, facets): deferred until a portneeds it.
outbound connection, and
WorkerStubChannel::getEntrypoint/getActorClass.