Skip to content

Implement WorkerInterface::fromException() in Rust behind an autogate - #8732

Merged
bartlomieju merged 1 commit into
mainfrom
biwanczuk/rust-failure-worker-interface
Nov 23, 2026
Merged

bartlomieju merged 1 commit into
mainfrom
biwanczuk/rust-failure-worker-interface

Conversation

@bartlomieju

@bartlomieju bartlomieju commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

WorkerInterface::fromException() makes the worker that stands in for
one that couldn't be had: every event on it fails with the given
exception. As part of moving the WorkerInterface implementations that
don't need the isolate to the Rust worker::Interface trait, this adds
a Rust version of it in src/rust/worker/failure.rs, used instead of
the C++ ErrorWorkerInterface when the RUST_FAILURE_WORKER_INTERFACE
autogate is enabled.

The Rust worker behaves like the C++ one, except where the C++ behaviour
is incidental: it fails every event with a copy of the exception rather
than moving it out at the first failure, test() fails with the
exception rather than returning a null promise, and its failures are
rejected promises rather than thrown from the call. A Worker sees the
same error either way.

Tests run fromException() in both variants: the default one exercises
the C++ worker and @all-autogates the Rust one.

@codecov-commenter

codecov-commenter commented Nov 20, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 62.50000% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.73%. Comparing base (1adff5d) to head (edcfbea).

Files with missing lines Patch % Lines
src/rust/worker/failure.rs 52.00% 12 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8732      +/-   ##
==========================================
- Coverage   68.01%   67.73%   -0.28%     
==========================================
  Files         846      847       +1     
  Lines      219198   215027    -4171     
  Branches    32587    32588       +1     
==========================================
- Hits       149081   145653    -3428     
+ Misses      50876    50133     -743     
  Partials    19241    19241              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@bartlomieju
bartlomieju force-pushed the biwanczuk/rust-worker-kj-exception branch from 3900b4c to 9bb840e Compare November 20, 2026 11:19
Comment thread src/rust/cxx/kj-hyper/client.rs Resolved
@bartlomieju
bartlomieju force-pushed the biwanczuk/rust-worker-kj-exception branch from 9bb840e to 9ab7718 Compare November 21, 2026 08:11
Base automatically changed from biwanczuk/rust-worker-kj-exception to main November 21, 2026 09:10
With the RUST_FAILURE_WORKER_INTERFACE autogate enabled, fromException()
makes the Rust worker of src/rust/worker/failure.rs instead of the C++
ErrorWorkerInterface. Like it, the Rust worker fails every event with the
exception, succeeds at prewarm() and tells a custom event the exception with
failed() before failing it. It differs where the C++ one is wrong or
incidental:

- It fails each event with a copy of the exception, made with
  kj::Exception::clone(). The C++ one moves the exception out at its first
  failure, so a second event on the same worker fails with an empty one.
- test() fails with the exception. The C++ one inherits the base class's
  test(), which returns a null promise.
- Its failures are rejected promises. The C++ one throws from the call
  itself, which only a caller that chains on the returned promise without
  evaluating the call inside a promise or coroutine can tell apart.

bench() is the base class's UNIMPLEMENTED in both.

worker-interface.c++ now calls into the Rust worker crate, which itself
depends on worker-interface.h, so the header gets a header-only
:worker-interface-hdrs target for the crate, as worker-factory.h has.

The tests run fromException() in both variants: the default one checks the
C++ worker and @all-autogates the Rust one.
@bartlomieju
bartlomieju force-pushed the biwanczuk/rust-failure-worker-interface branch from a3a191e to edcfbea Compare November 23, 2026 08:16
@bartlomieju
bartlomieju marked this pull request as ready for review November 23, 2026 08:16
@bartlomieju
bartlomieju requested review from a team as code owners November 23, 2026 08:16

@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 — The autogated Rust failure worker matches the C++ ErrorWorkerInterface, the build wiring avoids a dependency cycle, and tests cover both variants; no issues found.

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

The change adds no trust boundary, input handling, secret or access-control change.


📖 AGENTS.md: ✅ LGTM

The existing Rust and I/O guidance already covers this change, and it needs no new instructions.


📋 Code Quality: ✅ LGTM

The Rust worker behaves like the C++ ErrorWorkerInterface: prewarm() succeeds, every other event fails with a clone of the stored exception, and a custom event is passed the exception through failed() first. The build wiring avoids a dependency cycle by depending on the header-only worker-interface-hdrs. When the autogate is off, fromException() still returns the C++ worker, and the tests cover both variants.


⚡ Performance: ✅ LGTM

No performance concerns.


📝 Documentation: ✅ LGTM

The doc comments describe the current behaviour accurately.


Reviewed commit: edcfbead

@bartlomieju
bartlomieju merged commit af42dbf into main Nov 23, 2026
38 of 39 checks passed
@bartlomieju
bartlomieju deleted the biwanczuk/rust-failure-worker-interface branch November 23, 2026 09:12
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.

3 participants