Repository navigation
feat(workers): report why a worker failed or a request was cancelled - #743
Merged
Merged
Conversation
johnstonmatt
marked this pull request as ready for review
September 22, 2026 04:00
A cancelled request was reported as WorkerRequestCancelled whatever the cause, so a worker that used up its own CPU or memory budget and one the host reclaimed mid-request were indistinguishable to the caller. An embedder wanting to attribute the failure had nothing to go on but the message text. The supervisor already computes the cause and sends it to the event worker as a ShutdownEvent, but it never reached the request path. The worker task receives that same event when the isolate finishes, so it now records the reason on WorkerExit alongside the uncaught-exception status it already tracks, and the pool reads it when deciding how to fail an in-flight request. WorkerResourceExhausted covers CPUTime, Memory and WallClockTime. WorkerReclaimed covers EarlyDrop and TerminationRequested. Anything else, including a worker stopped before a reason was recorded, keeps reporting WorkerRequestCancelled, so callers that only know the old name are unaffected.
johnstonmatt
force-pushed
the
FUNC-921/report-cancellation-reason
branch
from
September 22, 2026 04:07
c73a51f to
30f0f2e
Compare
…ed module InvalidWorkerCreation covered three unrelated outcomes: the pool dropped the sender, the worker did not come up before the pool gave up, and the module threw while being evaluated. Only the last is the caller's own code failing, and an embedder had no way to tell them apart. The pool now sends a typed WorkerCreationTimeout instead of a message built from a string, so the two cases where no worker was produced can be matched on and reported as WorkerUnavailable. InvalidWorkerCreation keeps its name and now means only that evaluating the module failed. The request path lists the new variant explicitly rather than widening its match to a wildcard, so a future variant still has to be decided there. Two integration tests asserted the old creation-timeout message and now expect the new name.
…d in JS
An op error whose class isn't registered reaches JS as a plain Error
("Unregistered error class"), so callers matching on e.name never saw
either name.
…son' into tmp/744
Without it the error reaches JS as a plain Error ("Unregistered error
class"), which is why req_failure_case_timeout never saw the new name.
A request cancelled while its worker was running still failed with the unqualified WorkerRequestCancelled, because send_user_worker_request built that error itself instead of using cancellation_error. The shutdown reason was also recorded only after the worker loop ended, later than the cancelled requests read it. The supervisor now records the reason before it cancels the requests, without overwriting an uncaught exception, and every cancellation site uses cancellation_error. The CPU, memory and wall-clock integration tests now expect WorkerResourceExhausted, and unit tests cover the reclaimed case and the precedence of an uncaught exception.
…FUNC-921/report-cancellation-reason
feat(workers): report a failed worker creation separately from a failed module
nyannyacha
approved these changes
Nov 26, 2026
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.
This fix lets platform operators judge the health of the service.
A request that fails for lack of a worker reports a single error no matter why it failed, so operators can't tell the function's own fault from the platform's. Two cases are affected:
WorkerRequestCancelled. A function that used up its own CPU, memory or wall-clock budget looks the same as a worker the supervisor reclaimed in the middle of a request.InvalidWorkerCreationcovers a module that threw during evaluation, and also two cases where no worker was ever produced: the pool dropped the sender, or the worker didn't come up in time.Changes:
WorkerExitStatus::Terminated(ShutdownReason)andWorkerExit::shutdown_reason().Shutdownevent it already observes on isolate exit.cancellation_errorhelper inpool.rspicks the error:WorkerResourceExhausted.WorkerReclaimed.RequestCancelledBySupervisor, which surfaces asWorkerRequestCancelled.WorkerCreationTimeoutinstead ofanyhow!("worker did not respond in time").op_user_worker_createreports both no-worker cases asWorkerUnavailable, and the message still tells them apart.InvalidWorkerCreationnow means only that evaluating the module failed.WorkerResourceExhausted,WorkerReclaimedandWorkerUnavailableare registered inext/runtime/js/errors.jsand declared intypes/global.d.ts.Error, so without registratione.namewould never match.WorkerCreationTimeoutexplicitly, mapped toInvalidWorkerResponse, rather than using a wildcard. It can't occur there, but listing it makes the compiler force a decision when someone adds the next variant.Embedders
This is a breaking change for any embedder that maps these errors:
WorkerResourceExhausted,WorkerReclaimedandWorkerUnavailable. An embedder that doesn't know them sends those requests down its unhandled-error path, which typically means a generic 5xx and sometimes a logged exception per request.InvalidWorkerCreationnarrows. Code that keys on it for creation timeouts or unavailable workers stops seeing those cases.An embedder has to handle the new names before it runs this runtime. Supabase's own embedder already handles all three.
Verification
pool.rscover each shutdown reason, the fallback, and an uncaught exception winning over a recorded reason.InvalidWorkerCreation: worker did not respond in timenow expectWorkerUnavailable. Theworker boot errorassertions are unchanged because that case keeps its name.