Repository navigation
Compile service worker scripts in their first Worker's context - #8513
Conversation
A script's contexts are all created with its module registry and schema loader, and each caller spelled both out. Create them through one method instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A service worker script is compiled independent of any context, but compiling it, reporting its errors and converting its globals need an entered one, so the Script created a throwaway context to compile in. That cost every service worker script an extra context, created before the one its first Worker runs in. Create the context the first Worker will run in instead, compile in it, and hand it to that Worker. Later Workers of the same Script still create their own contexts. A Script whose context no Worker took disposes of it, like the shared context of a modules script. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
💬 Approved with comments — The context hand-off and disposal paths look correct. The only finding is an INFO about missing tests for the second-Worker and no-Worker paths.
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
Ownership hand-off looks correct; the new lifecycle paths have no tests.
Recommendation: 💬 Optional Nits
- [INFO] No tests cover the second-Worker and no-Worker paths of the new firstWorkerContext hand-off (
src/workerd/io/worker.c++:2427)
View full review
The new firstWorkerContext hand-off looks correct:
- First Worker: it takes the context and clears it.
- Later Workers: they create their own context through
newContext(). - No Worker takes the context:
~Scriptand the constructor's failure path dispose of it. - Script fails to compile: the context still goes to the first Worker, which stores
permanentExceptionand returns early.
The usual service worker tests only exercise the first-Worker path, so the other paths have no test coverage.
✅ All other checks passed
📝 Documentation: ✅ LGTM
The new comments describe what the code does now, and the header comment on newContext() is accurate.
Reviewed commit: 75e2b3f3
A service worker script is compiled independent of any context, but compiling it, reporting its errors and converting its globals need an entered one, so
Worker::Scriptcreated a throwaway context to compile in. That cost every service worker script an extra context, created before the one its first Worker runs in.This PR has two commits:
Worker::Script::newContext(): all of a script's contexts are created with its module registry and schema loader, and each caller spelled both out. They now go through one method.🤖 Generated with Claude Code