Skip to content

Run WorkerEntrypoint's scheduled event from Rust behind an autogate - #8734

Merged
bartlomieju merged 5 commits into
mainfrom
biwanczuk/rust-entrypoint-scheduled-event
Nov 26, 2026
Merged

bartlomieju merged 5 commits into
mainfrom
biwanczuk/rust-entrypoint-scheduled-event

Conversation

@bartlomieju

@bartlomieju bartlomieju commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

We're moving the C++ WorkerInterface implementations to Rust, and the
largest of them, WorkerEntrypoint, delivers events to a Worker's
handlers. This adds src/workerd/io/entrypoint, a crate through which
WorkerEntrypoint hands an event to Rust to deliver, and makes the
scheduled event its first user, behind the new
RUST_ENTRYPOINT_SCHEDULED autogate. The gate covers only the scheduled
event: each event that production requests reach gets a gate of its own,
while test() and bench(), which only workerd's own commands deliver,
need none. A second commit writes down the ground rules for this kind of
port in docs/reference/rust-seam.md: how the runtime and its embedders
meet, and what each side can rely on while the runtime side moves to
Rust.

An event goes through Invocation, Delivered and Running, each
consumed by the step that leads to the next, so that the steps happen
once and in order, and a delivered event that's dropped drains its
request. Every step calls C++ when it is called, not when its future is
first polled, and runScheduled() is split into a synchronous start and
an async finish, so that an exception before the wait is thrown, as in
C++. The calls on IoContext::IncomingRequest are bound once, in the
io-context crate. The JavaScript half of the event, startScheduled()
with its ScheduledController, stays in C++ in
startScheduledInWaitUntil(), which both paths call, so they can't
drift apart, and the crate's C++ shims use no C++ JSG.

With the gate on, a Worker sees the event delivered as before. One
failure differs, and only a runtime bug reaches it: an exception from
finishScheduled()'s assertions rejects the promise rather than being
thrown. A request whose step fails after delivery is destroyed without
draining, as in C++, and delivered() records the Rust caller's
location for the "no current IncomingRequest" warnings. The perfetto
spans keep their names on the Rust path, where the steps in Rust emit
theirs through the Rust perfetto bindings, and a new span,
entrypoint::runScheduled(), marks it. The new
api/tests:scheduled-test covers rejected handlers, ctx.waitUntil(),
a missing handler and Service Workers syntax, along with what tail
workers receive, and its @all-autogates variant takes the Rust path.
server/tests/scheduled runs workerd with the autogates off and on to
check the async trace, how failures are logged and the spans, and
io-context-test checks the location that delivered() records. The
full test suite passes.

@bartlomieju
bartlomieju requested review from a team as code owners November 20, 2026 11:13

@clanky-the-clanker clanky-the-clanker 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.

Superseded by the review of f39f7cf9.

This review, of 8373c12a

💬 Approved with comments — No correctness, security or performance problems on the gated Rust scheduled path; one INFO note about tests that poll for traces.

Findings: 1 info (1 is an inline comment on the diff)

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


📋 Code Quality: 💬 1 info

The gated Rust path matches the C++ path; one INFO note about tests that poll for traces.

Recommendation: 💬 Optional Nits

  • [INFO] Tail tests poll for at most ~2s; a late trace on a slow build would fail as a confusing deepStrictEqual mismatch, not a timeout. (src/workerd/api/tests/scheduled-test-legacy-tail.js:50)
View full review

The Rust scheduled path matches the C++ path it replaces in these respects:

  • Handler lookup: getExportedHandler() is called with the same name, version info, props and actor.
  • Exceptions: a KJ exception from startScheduled() passes through as RunError::Kj; a JavaScript error stays pending in V8 and is thrown on as JsExceptionThrown.
  • Ending the request: a Delivered that is dropped without finish_scheduled drains the request.
  • Cancellation: the result is still wrapped with the canceler.

The tests cover the gate both off and on (@all-autogates, and server/tests/scheduled).

Timing-dependent tests (INFO): scheduled-test-legacy-tail.js and scheduled-test-tail.js wait at most about 2s for traces. On a slow build such as ASAN, a late trace would show up as a deepStrictEqual mismatch, not as a timeout.


✅ All other checks passed

🔒 Security: ✅ LGTM

No security issues found.


📖 AGENTS.md: ✅ LGTM

No AGENTS.md issues found.


⚡ Performance: ✅ LGTM

No performance issues found.


📝 Documentation: ✅ LGTM

No documentation issues found.


Reviewed commit: 8373c12a

@bartlomieju
bartlomieju marked this pull request as draft November 20, 2026 11:36
Comment thread src/rust/jsg/cpp-jsg-allowlist.txt Resolved
Comment thread src/workerd/io/entrypoint/ffi.c++ Resolved
Comment thread src/workerd/io/worker-entrypoint.c++ Resolved
@bartlomieju
bartlomieju force-pushed the biwanczuk/rust-entrypoint-scheduled-event branch 2 times, most recently from 9e1e37b to 38ea0fa Compare November 20, 2026 12:37
@bartlomieju
bartlomieju force-pushed the biwanczuk/rust-entrypoint-scheduled-event branch from 38ea0fa to 56eda18 Compare November 20, 2026 16:48

@guybedford guybedford left a comment

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.

Looks good as the first slice. Tests pass locally with the gate off and on, including repeated runs. Three non-blocking notes inline.

Comment thread src/workerd/io/entrypoint/lib.rs Resolved
Comment thread src/workerd/io/entrypoint/ffi.c++ Resolved
Comment thread src/workerd/io/entrypoint/ffi.rs Resolved
@bartlomieju
bartlomieju force-pushed the biwanczuk/rust-entrypoint-scheduled-event branch 2 times, most recently from 141f6c1 to 9683966 Compare November 23, 2026 14:13
@bartlomieju
bartlomieju force-pushed the biwanczuk/rust-entrypoint-scheduled-event branch from 9683966 to f39f7cf Compare November 25, 2026 09:00
@bartlomieju
bartlomieju marked this pull request as ready for review November 25, 2026 09:00

@clanky-the-clanker clanky-the-clanker 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.

Superseded by the review of a5576bee.

This review, of f39f7cf9

💬 Approved with comments — No correctness, security or performance problems on the gated Rust scheduled path; only INFO/SUGGESTION notes on design choices later events will inherit, and on one absolute parity claim in the new seam doc.

Findings: 3 info · 1 suggestion (4 are inline comments on the diff)

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


📋 Code Quality: 💬 2 info · 1 suggestion

Rust path matches C++ for scheduled; three non-blocking design notes carried from the approver's review.

Recommendation: 💬 Optional Nits

  • [INFO] Drain-on-drop differs from the C++ destroy-on-failure behaviour, and every later event inherits it. (src/workerd/io/entrypoint/lib.rs:84)
  • [INFO] deliveredLocation is always this shim line on the Rust path, so the "no current IncomingRequest" warnings stop showing which event delivered the request. (src/workerd/io/io-context/ffi.c++:32)
  • [SUGGESTION] incoming_request_delivered may not need unsafe, the &'static CStr or both NUL checks if delivered() doesn't keep the event type. (src/workerd/io/io-context/ffi.rs:526)
View full review

The Rust scheduled path matches C++ in every case checked. The earlier tail-test timing note is fixed: the legacy tail test is gone, and scheduled-test-tail.js polls with no deadline.

  • Drain-on-drop (INFO): when a step fails after delivery, Request::drop drains the request. C++ destroys it instead, which cancels its waitUntil tasks. Scheduled never reaches this, but every event ported later inherits it as the default.
  • Delivery location (INFO): on the Rust path, deliveredLocation is always the shim line in io-context/ffi.c++. That weakens the "no current IncomingRequest" warnings as more events move over.
  • unsafe (SUGGESTION): incoming_request_delivered requires a &'static CStr and two NUL checks. It doesn't seem to need them if delivered() copies the event type, as @​guybedford [approver] says.

📝 Documentation: 💬 1 info

The seam doc states exact parity between the paths, which this pull request does not keep.

Recommendation: 💬 Optional Nits

  • [INFO] "Both paths behave identically" is contradicted by the two differences this pull request accepts. (docs/reference/rust-seam.md:49)
View full review
  • docs/reference/rust-seam.md:49: "Both paths behave identically" doesn't hold for this pull request, which knowingly lets the paths differ in two places.

✅ All other checks passed

🔒 Security: ✅ LGTM

No security issues found. The gated path adds no new entry point. The event type crossing the bridge is checked for a trailing NUL and for interior NULs. The lambda captures in the new shims run synchronously or follow existing C++ patterns.


📖 AGENTS.md: ✅ LGTM

No issues found in the new AGENTS.md files.


⚡ Performance: ✅ LGTM

No issues: the path is gated and runs once per cron event.


Reviewed commit: f39f7cf9

Comment thread src/workerd/io/entrypoint/lib.rs Resolved
Comment thread src/workerd/io/io-context/ffi.c++ Resolved
Comment thread docs/reference/rust-seam.md Resolved
Comment thread src/workerd/io/io-context/ffi.rs Resolved
@bartlomieju
bartlomieju force-pushed the biwanczuk/rust-entrypoint-scheduled-event branch from f39f7cf to a5576be Compare November 25, 2026 09:40

@clanky-the-clanker clanky-the-clanker 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.

Superseded by the review of 71d1d122.

This review, of a5576bee

💬 Approved with comments — No correctness, security or performance problems on the gated Rust scheduled path, and every earlier note is fixed. Two remaining wording notes: a stale parameter name in a comment, and one parity line in the crate's AGENTS.md.

Findings: 1 info · 1 suggestion (2 are inline comments on the diff)

Not opened by the correctness review: 14 changed files it was meant to read
  • src/workerd/io/entrypoint-invocation.h
  • src/workerd/io/entrypoint/BUILD.bazel
  • src/workerd/io/entrypoint/ffi.c++
  • src/workerd/io/entrypoint/ffi.h
  • src/workerd/io/entrypoint/ffi.rs
  • src/workerd/io/entrypoint/lib.rs
  • src/workerd/io/entrypoint/scheduled.rs
  • src/workerd/io/io-context/BUILD.bazel
  • src/workerd/io/io-context/ffi.c++
  • src/workerd/io/io-context/ffi.h
  • src/workerd/io/io-context/ffi.rs
  • src/workerd/io/io-context/lib.rs
  • src/workerd/io/worker-entrypoint.c++
  • src/workerd/util/autogate.h

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


📖 AGENTS.md: 💬 1 info

The entrypoint AGENTS.md still asks for identical behaviour on both paths.

Recommendation: 💬 Optional Nits

  • [INFO] "Keep the two paths' behaviour identical" is stricter than rule 3 in rust-seam.md, and this pull request already accepts a difference. (src/workerd/io/entrypoint/AGENTS.md:30)
View full review
  • src/workerd/io/entrypoint/AGENTS.md:30 says "Keep the two paths' behaviour identical". docs/reference/rust-seam.md rule 3 was narrowed to Worker-visible behaviour, so the two now disagree.

📋 Code Quality: 💬 1 suggestion

Earlier notes fixed; one stale parameter name in a doc comment.

Recommendation: 💬 Optional Nits

  • [SUGGESTION] The doc comment on runScheduled() still uses the old name event for the parameter invocation. (src/workerd/io/entrypoint/ffi.h:34)
View full review

The earlier notes on drain-on-drop, the delivered location and unsafe are all fixed at this commit. Checked with no problem found: errors thrown before the wait still reach C++ synchronously, cron is copied before scheduled_event_start returns, and skipping wrapWithCanceler is safe because runScheduled() asserts there is no canceler.

  • src/workerd/io/entrypoint/ffi.h:34: the comment still calls the parameter event, a leftover from before the rename to Invocation.

✅ All other checks passed

🔒 Security: ✅ LGTM

No security issues. The gated path adds no new entry point. The event type and the cron string are copied with kj::str(). The location strings that kj::SourceLocation keeps are checked for a trailing NUL and come from static Rust strings.


⚡ Performance: ✅ LGTM

No issues. The path is gated and runs once per cron event. Its only extra cost is a few small string copies and FFI calls.


📝 Documentation: ✅ LGTM

Rule 3 of docs/reference/rust-seam.md now matches the differences this pull request accepts.


Reviewed commit: a5576bee

Comment thread src/workerd/io/entrypoint/AGENTS.md Resolved
Comment thread src/workerd/io/entrypoint/ffi.h Resolved
This adds src/workerd/io/entrypoint, a crate through which a C++
WorkerEntrypoint hands an event to Rust to deliver, and makes the
scheduled event its first user, behind the RUST_ENTRYPOINT_SCHEDULED
autogate. The gate covers the scheduled event only: each event that
production requests reach gets an autogate of its own, which later
changes don't rename or widen.

WorkerEntrypoint passes the crate an Invocation
(io/entrypoint-invocation.h): the IncomingRequest, the waitUntil tasks,
and what finds the exported handler. An invocation goes through three
types, each consumed by the step that leads to the next, so each step
happens once and in order: an Invocation is reported to the tracer and
delivered under an event type, which gives a Delivered; starting its
handler in a waitUntil task gives a Running; finish_scheduled() finishes
it with finishScheduled(). A Delivered or Running dropped without being
finished, as when a step fails, destroys the request without draining
it, as C++ does when an exception leaves runScheduled(). Every step
calls C++ when it is called, not when a future it returns is first
polled.

The steps call IoContext::IncomingRequest through the io-context crate,
which binds it with delivered(), finishScheduled() and the tracer's
setEventInfo() for a scheduled event, as C++ has them. delivered()
copies the event type, and records where Rust delivered the request:
io_context::delivered_location!() gives the caller's file, line and
module, which the "no current IncomingRequest" warnings report as the
last delivered location. The entrypoint crate's own C++ calls only reach
into its Invocation and start the handler. This follows the rule for
porting C++ to Rust that io/AGENTS.md now states: a port keeps the C++
boundaries, and each C++ type has one Rust binding, in the crate
matching its header, which other crates reuse.

With the gate enabled, runScheduled() hands the event to the crate,
which takes the steps of the C++ path in its order. With the gate
disabled, the C++ path is untouched but for one move: its
IoContext::run() lambda, which calls
ServiceWorkerGlobalScope::startScheduled() on the exported handler, is
now entrypoint::startScheduledInWaitUntil()
(io/entrypoint-invocation.c++), which both paths call. The JavaScript
half thus stays in C++, in one place, so ScheduledController, the
Service Workers syntax path, the warnings and setNoRetryScheduled() are
unchanged, and an exception reaches IoContext::run() as before. The
crate's C++ side uses none of the C++ JSG constructs that the Rust JSG
allowlist check counts, which now covers it with no entries; it reaches
the handler only through that io function.

runScheduled() is split into a synchronous start, which takes every
step but the wait, and an asynchronous finish. An exception before the
wait is then thrown from runScheduled(), as in C++, rather than
rejecting the promise. The event does not go through worker::Interface
and RustWorkerInterface: a one-shot Interface per event would need stubs
for request(), connect() and runAlarm(), and the trait belongs on a
Rust WorkerEntrypoint as a whole, which can then replace these entry
points.

The promise is not wrapped with the canceler, which is set only for an
actor's events, and scheduled events never reach actors. Dropping the
promise cancels the event: it drops the Rust future, then the promise of
finishScheduled(), which owns the IncomingRequest.

A panic in the synchronous start reaches C++ as a KJ exception, as the
cxx bridge makes every panic in an extern "Rust" function. kj-rs turns a
panic while polling the finish's future into a KJ exception, and one
while dropping it into a log line.

One failure that only a bug reaches differs from the C++ path: an
exception that finishScheduled() throws (it asserts that the request
has no actor and is the only one) rejects the promise rather than being
thrown from runScheduled(), because cxx can't carry a synchronous throw
out of an async function.

The perfetto spans of the C++ path keep their names on the Rust path.
WorkerEntrypoint::runScheduled() run stays in the C++ code that starts
the handler, which both paths share. waitForFinished() is emitted from
Rust with util/perfetto, around the call that starts finishing the
request, as the C++ path's span is. A new span,
entrypoint::runScheduled(), also emitted from Rust, marks the Rust
path.

With the gate on, the event is delivered the same way. The tests:
- api/tests:scheduled-test covers what http-test does not: a handler
  that rejects or uses ctx.waitUntil(), an entrypoint without
  scheduled(), and Service Workers syntax with and without a listener.
  It checks the results and what a tail worker and a streaming tail
  worker receive, waiting until they have received every event rather
  than for a fixed time. Its @all-autogates variant takes the Rust
  path, as do those of http-test, tail-worker-test and
  service-binding-dispose-cancels-test.
- server/tests/scheduled runs workerd with the autogates off and on,
  and checks the request's async trace name and that the error for a
  missing handler is logged once, as a KJ exception.
- io-context-test checks that a request Rust delivers records the Rust
  caller's file, line, column and module, as the "no current
  IncomingRequest" warnings report them.
- server/tests/scheduled:scheduled-perfetto-test checks that both runs
  have the C++ path's spans and that only the run with the autogates
  has the Rust path's, which shows that the gate takes effect. It
  matches each span name exactly, so that the bare
  WorkerEntrypoint::runScheduled() isn't found inside the longer names
  that start with it; removing that span makes the test fail.
The runtime is moving to Rust while the workerd server and other
embedders keep using its C++ interfaces. The rules that keep that
working have so far been applied in review, one port at a time: a Rust
trait with an adapter in each direction, C++ interfaces treated as a
contract with embedders, behaviour changes behind an autogate, no
executor dependency in runtime code, and no C++ JSG in the shims.

More ports now cross this boundary, so this writes the rules down in
one place, docs/reference/rust-seam.md, and documents the requests-in
side as it exists today in src/rust/worker/AGENTS.md. The root, io and
entrypoint AGENTS.md files point to it rather than repeating it.
@bartlomieju
bartlomieju force-pushed the biwanczuk/rust-entrypoint-scheduled-event branch from a5576be to 71d1d12 Compare November 25, 2026 09:58

@clanky-the-clanker clanky-the-clanker 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.

Superseded by the review of 1fa9161a.

This review, of 71d1d122

✅ Approved — Both earlier wording notes are fixed, and the files changed since the last review have no correctness, security or performance problems.

Not opened by the correctness review: 13 changed files it was meant to read
  • src/workerd/io/entrypoint-invocation.h
  • src/workerd/io/entrypoint/BUILD.bazel
  • src/workerd/io/entrypoint/ffi.c++
  • src/workerd/io/entrypoint/ffi.h
  • src/workerd/io/entrypoint/ffi.rs
  • src/workerd/io/entrypoint/lib.rs
  • src/workerd/io/entrypoint/scheduled.rs
  • src/workerd/io/io-context/BUILD.bazel
  • src/workerd/io/io-context/ffi.c++
  • src/workerd/io/io-context/ffi.h
  • src/workerd/io/io-context/ffi.rs
  • src/workerd/io/io-context/lib.rs
  • src/workerd/util/autogate.h

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🔒 Security: ✅ LGTM

No security issues. The gated path adds no new entry point, and the strings that cross the FFI are copied or are static.


📖 AGENTS.md: ✅ LGTM

src/workerd/io/entrypoint/AGENTS.md now uses the wording of rule 3 in docs/reference/rust-seam.md: a Worker sees the same behaviour on both paths, and any difference no Worker can observe is documented where the Rust path makes it.


📋 Code Quality: ✅ LGTM

The runScheduled() doc comment in src/workerd/io/entrypoint/ffi.h now says "the scheduled event of invocation". The doc comments in src/workerd/io/entrypoint/lib.rs match what the code does: dropping a Delivered or Running destroys the request without draining it, and finish_scheduled() notes that an exception from finishScheduled() rejects the promise. finish_scheduled() takes the request out of the invocation before it returns the future, and an error before the wait still reaches C++ synchronously.


⚡ Performance: ✅ LGTM

No issues. The path is gated and runs once per cron event.


📝 Documentation: ✅ LGTM

The doc comments in the files changed since the last review match the code.


Reviewed commit: 71d1d122

@clanky-the-clanker clanky-the-clanker 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.

Superseded by the review of 7079f083.

This review, of 1fa9161a

✅ Approved — Both earlier wording notes are fixed, and the files changed since the last review have no correctness, security or performance problems.

Not opened by the correctness review: 13 changed files it was meant to read
  • src/workerd/io/entrypoint-invocation.h
  • src/workerd/io/entrypoint/BUILD.bazel
  • src/workerd/io/entrypoint/ffi.c++
  • src/workerd/io/entrypoint/ffi.h
  • src/workerd/io/entrypoint/ffi.rs
  • src/workerd/io/entrypoint/lib.rs
  • src/workerd/io/entrypoint/scheduled.rs
  • src/workerd/io/io-context/BUILD.bazel
  • src/workerd/io/io-context/ffi.c++
  • src/workerd/io/io-context/ffi.h
  • src/workerd/io/io-context/ffi.rs
  • src/workerd/io/io-context/lib.rs
  • src/workerd/util/autogate.h

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🔒 Security: ✅ LGTM

No security issues. The gated path adds no new entry point, and the strings that cross the FFI are copied or are static.


📖 AGENTS.md: ✅ LGTM

src/workerd/io/entrypoint/AGENTS.md now uses the wording of rule 3 in docs/reference/rust-seam.md: a Worker sees the same behaviour on both paths, and any difference no Worker can observe is documented where the Rust path makes it.


📋 Code Quality: ✅ LGTM

The runScheduled() doc comment in src/workerd/io/entrypoint/ffi.h now says "the scheduled event of invocation". The doc comments in src/workerd/io/entrypoint/lib.rs match what the code does: dropping a Delivered or Running destroys the request without draining it, and finish_scheduled() notes that an exception from finishScheduled() rejects the promise. finish_scheduled() takes the request out of the invocation before it returns the future, and an error before the wait still reaches C++ synchronously.


⚡ Performance: ✅ LGTM

No issues. The path is gated and runs once per cron event.


📝 Documentation: ✅ LGTM

The doc comments in the files changed since the last review match the code.


Reviewed commit: 1fa9161a — same changes as 71d1d122, so this is that commit's review (no new review was run; line numbers are as of 71d1d122)

@clanky-the-clanker clanky-the-clanker 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.

Superseded by the review of 5846e1d4.

This review, of 7079f083

✅ Approved — Both earlier wording notes are fixed, and the files changed since the last review have no correctness, security or performance problems.

Not opened by the correctness review: 13 changed files it was meant to read
  • src/workerd/io/entrypoint-invocation.h
  • src/workerd/io/entrypoint/BUILD.bazel
  • src/workerd/io/entrypoint/ffi.c++
  • src/workerd/io/entrypoint/ffi.h
  • src/workerd/io/entrypoint/ffi.rs
  • src/workerd/io/entrypoint/lib.rs
  • src/workerd/io/entrypoint/scheduled.rs
  • src/workerd/io/io-context/BUILD.bazel
  • src/workerd/io/io-context/ffi.c++
  • src/workerd/io/io-context/ffi.h
  • src/workerd/io/io-context/ffi.rs
  • src/workerd/io/io-context/lib.rs
  • src/workerd/util/autogate.h

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🔒 Security: ✅ LGTM

No security issues. The gated path adds no new entry point, and the strings that cross the FFI are copied or are static.


📖 AGENTS.md: ✅ LGTM

src/workerd/io/entrypoint/AGENTS.md now uses the wording of rule 3 in docs/reference/rust-seam.md: a Worker sees the same behaviour on both paths, and any difference no Worker can observe is documented where the Rust path makes it.


📋 Code Quality: ✅ LGTM

The runScheduled() doc comment in src/workerd/io/entrypoint/ffi.h now says "the scheduled event of invocation". The doc comments in src/workerd/io/entrypoint/lib.rs match what the code does: dropping a Delivered or Running destroys the request without draining it, and finish_scheduled() notes that an exception from finishScheduled() rejects the promise. finish_scheduled() takes the request out of the invocation before it returns the future, and an error before the wait still reaches C++ synchronously.


⚡ Performance: ✅ LGTM

No issues. The path is gated and runs once per cron event.


📝 Documentation: ✅ LGTM

The doc comments in the files changed since the last review match the code.


Reviewed commit: 7079f083 — same changes as 71d1d122, so this is that commit's review (no new review was run; line numbers are as of 71d1d122)

bartlomieju added a commit that referenced this pull request Nov 25, 2026
Let Rust code that opened an IoContext::IncomingRequest, and holds it
outside any IoContext, use it as C++ hosts do:

- incoming_request_delivered(), with delivered_location!() for where
  Rust delivered it, taken from #8734.
- incoming_request_run(): IoContext::run() of the request's context,
  for a Rust function that returns a future, as a ReentryCallback's
  function does. It reuses that machinery: the body of
  ReentryCallback's run() lambda becomes runReentryFn(), which both
  call, each with its own panic message.
- incoming_request_register_pending_event():
  IoContext::registerPendingEvent(), so that a context that waits for
  its host is not taken for hung.
- incoming_request_drain(): IncomingRequest::drain(), then the
  waitUntil() tasks it leaves, resolving to whether
  waitUntilStatus() is OK.

incoming_request_run() reaches throwPendingToRun() through
runReentryFn(). IoContext::run() runs it, as rule 3 of
src/rust/jsg/README.md requires, so the README and the allowlist list
it with the other two callers; the count does not change.

The REPL, whose session moves to Rust, opens one request for the
session and runs each input in it.

@clanky-the-clanker clanky-the-clanker 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.

✅ Approved — Both earlier wording notes are fixed, and the files changed since the last review have no correctness, security or performance problems.

Not opened by the correctness review: 13 changed files it was meant to read
  • src/workerd/io/entrypoint-invocation.h
  • src/workerd/io/entrypoint/BUILD.bazel
  • src/workerd/io/entrypoint/ffi.c++
  • src/workerd/io/entrypoint/ffi.h
  • src/workerd/io/entrypoint/ffi.rs
  • src/workerd/io/entrypoint/lib.rs
  • src/workerd/io/entrypoint/scheduled.rs
  • src/workerd/io/io-context/BUILD.bazel
  • src/workerd/io/io-context/ffi.c++
  • src/workerd/io/io-context/ffi.h
  • src/workerd/io/io-context/ffi.rs
  • src/workerd/io/io-context/lib.rs
  • src/workerd/util/autogate.h

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🔒 Security: ✅ LGTM

No security issues. The gated path adds no new entry point, and the strings that cross the FFI are copied or are static.


📖 AGENTS.md: ✅ LGTM

src/workerd/io/entrypoint/AGENTS.md now uses the wording of rule 3 in docs/reference/rust-seam.md: a Worker sees the same behaviour on both paths, and any difference no Worker can observe is documented where the Rust path makes it.


📋 Code Quality: ✅ LGTM

The runScheduled() doc comment in src/workerd/io/entrypoint/ffi.h now says "the scheduled event of invocation". The doc comments in src/workerd/io/entrypoint/lib.rs match what the code does: dropping a Delivered or Running destroys the request without draining it, and finish_scheduled() notes that an exception from finishScheduled() rejects the promise. finish_scheduled() takes the request out of the invocation before it returns the future, and an error before the wait still reaches C++ synchronously.


⚡ Performance: ✅ LGTM

No issues. The path is gated and runs once per cron event.


📝 Documentation: ✅ LGTM

The doc comments in the files changed since the last review match the code.


Reviewed commit: 5846e1d4 — same changes as 71d1d122, so this is that commit's review (no new review was run; line numbers are as of 71d1d122)

bartlomieju added a commit that referenced this pull request Nov 26, 2026
Let Rust code that opened an IoContext::IncomingRequest, and holds it
outside any IoContext, use it as C++ hosts do:

- incoming_request_delivered(), with delivered_location!() for where
  Rust delivered it, taken from #8734.
- incoming_request_run(): IoContext::run() of the request's context,
  for a Rust function that returns a future, as a ReentryCallback's
  function does. It reuses that machinery: the body of
  ReentryCallback's run() lambda becomes runReentryFn(), which both
  call, each with its own panic message.
- incoming_request_register_pending_event():
  IoContext::registerPendingEvent(), so that a context that waits for
  its host is not taken for hung.
- incoming_request_drain(): IncomingRequest::drain(), then the
  waitUntil() tasks it leaves, resolving to whether
  waitUntilStatus() is OK.

incoming_request_run() reaches throwPendingToRun() through
runReentryFn(). IoContext::run() runs it, as rule 3 of
src/rust/jsg/README.md requires, so the README and the allowlist list
it with the other two callers; the count does not change.

The REPL, whose session moves to Rust, opens one request for the
session and runs each input in it.
@bartlomieju
bartlomieju merged commit 595f199 into main Nov 26, 2026
38 of 39 checks passed
@bartlomieju
bartlomieju deleted the biwanczuk/rust-entrypoint-scheduled-event branch November 26, 2026 10:33
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.

2 participants