Repository navigation
Make WorkerEntrypoint::construct() return a Rust WorkerEntrypoint - #8745
Draft
bartlomieju wants to merge 1 commit into
Draft
bartlomieju wants to merge 1 commit into
bartlomieju wants to merge 1 commit into
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## biwanczuk/rust-entrypoint-scheduled-event #8745 +/- ##
============================================================================
Coverage ? 67.44%
============================================================================
Files ? 836
Lines ? 212892
Branches ? 32486
============================================================================
Hits ? 143585
Misses ? 50246
Partials ? 19061 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
guybedford
approved these changes
Nov 20, 2026
guybedford
left a comment
Member
There was a problem hiding this comment.
LGTM. Verified locally:
RustWorkerEntrypointforwards all nineWorkerInterfacevirtuals, including the three with default bodies (abandonAlarm,test,bench).- Skipping
wrapWithCanceleron the Rust path is equivalent: the canceler is only set for actors, andassert_no_actorruns first. - Moving
entrypointNameintakeInvocation()rather than cloning is fine, nothing reads it after the one event, and the single-event check holds in both orders (Rust then C++, C++ then Rust). scheduled-test@/@all-autogates, bothserver/tests/scheduledtests,worker-entrypoint-test@all-autogatesandcpp-jsg-allowlist-testpass.
bartlomieju
force-pushed
the
biwanczuk/rust-entrypoint-scheduled-event
branch
from
November 23, 2026 10:28
56eda18 to
141f6c1
Compare
Behind the new RUST_WORKER_ENTRYPOINT autogate, which replaces
RUST_ENTRYPOINT_SCHEDULED, WorkerEntrypoint::construct() returns a Rust
entrypoint::WorkerEntrypoint that owns the C++ WorkerEntrypoint, in the
RequestObserver's wrapper in place of the C++ object. Events that Rust
implements are delivered by the Rust object; for now that is the
scheduled event, which C++ WorkerEntrypoint::runScheduled() no longer
gates. Later events move into it one at a time, and the C++ object
shrinks until it can go.
The C++ object is seen from Rust as an entrypoint::CxxEntrypoint
(io/entrypoint-invocation.h): a WorkerInterface whose takeInvocation()
hands over the Invocation of its one event. C++ callers reach the Rust
object through RustWorkerEntrypoint (entrypoint/ffi.c++), which sends
runScheduled() to Rust and every other event straight to the C++
object, through a reference it takes once when it is made. So request()
and connect() cross no FFI boundary and await no Rust future; the cost
of the gate on them is one allocation per event. The Rust object does
not implement worker::Interface yet: nothing in Rust calls it, and once
request() is in Rust, RustWorkerInterface can replace
RustWorkerEntrypoint.
The scheduled event takes the steps it took behind the old gate, from
the Rust object. Its checks differ only in their messages: the
invocation is taken once ("a WorkerEntrypoint delivers only one event")
and the request must not be an actor's, as runScheduled() asserts. That
check is a call on the request, so it is io-context's binding of
IoContext::IncomingRequest, next to the others the scheduled event
makes. The span WorkerEntrypoint::runScheduled() is emitted by
RustWorkerEntrypoint, so both paths still have it.
Every test's @all-autogates variant now delivers its events through the
Rust WorkerEntrypoint, which covers the forwarding of each event type;
api/tests:scheduled-test and server/tests/scheduled check the scheduled
event on both paths, and scheduled-perfetto-test the spans of each.
bartlomieju
force-pushed
the
biwanczuk/rust-entrypoint-scheduled-event
branch
from
November 23, 2026 14:13
141f6c1 to
9683966
Compare
bartlomieju
force-pushed
the
biwanczuk/rust-worker-entrypoint
branch
from
November 23, 2026 14:13
eb554bc to
7f8adcc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We're moving
WorkerEntrypoint(the C++ object that receives each eventfor a Worker's exported handler) to Rust one event at a time.
Until now each ported event needed its own gate inside the C++ object
and its own pair of bridge functions. This makes the Rust object the
entrypoint itself: behind the new
RUST_WORKER_ENTRYPOINTautogate,WorkerEntrypoint::construct()returns a Rustentrypoint::WorkerEntrypointthat owns the C++ one. Later eventsbecome methods of the Rust object, and the C++ object shrinks until it
can be removed. The new gate replaces
RUST_ENTRYPOINT_SCHEDULEDfrom#8734.
The C++ object is seen from Rust as an
entrypoint::CxxEntrypoint: aWorkerInterfacethat can also hand over theInvocationof its oneevent. C++ callers reach the Rust object through
RustWorkerEntrypoint,a small
WorkerInterfacein entrypoint/ffi.c++.Currently it sends
runScheduled()to Rust and every other eventstraight to the C++ object, through a reference it takes once when it is
created. So
request()andconnect()cross no FFI boundary and awaitno Rust future, and the gate costs them one allocation per event.
RustWorkerEntrypointtakes the C++ object's place in theRequestObserver's wrapper, so metrics see the same calls. The Rustobject doesn't implement
worker::Interfaceyet: nothing in Rust callsit, and once
request()is in Rust,RustWorkerInterfacecan replaceRustWorkerEntrypoint.The scheduled event takes the same steps as before, now from the Rust
object. Two checks moved with it and differ only in their messages,
which a Worker can't observe: the invocation can be taken only once ("a
WorkerEntrypointdelivers only one event", where C++ says"
runScheduled()can only be called once"), and the request must notbelong to an actor, which
runScheduled()also asserts. Both fail onlyon a bug in the runtime. The actor check is a call on the request, so it
is the io-context crate's binding of
IoContext::IncomingRequest, nextto the other calls the scheduled event makes on it. The span
WorkerEntrypoint::runScheduled()is now emitted byRustWorkerEntrypoint, so traces of both paths still have it.Every test's
@all-autogatesvariant now delivers its events throughthe Rust
WorkerEntrypoint, which covers forwarding of every eventtype. api/tests:scheduled-test and server/tests/scheduled check the
scheduled event on both paths, and scheduled-perfetto-test checks the
spans of each. I compared the request case of bench-global-scope, which
sends a fetch through
newWorkerEntrypoint(), with and without thischange: in 12 interleaved runs with all autogates on, the medians were
6.47 µs and 6.51 µs per request, within the noise. The full test suite
passes.