Fix buffered worker send failures escape the WorkerError channel - #7114
Conversation
🦋 Changeset detectedLatest commit: 0c926cc The changes in this PR will be included in the next version bump. This PR includes changesets to release 30 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Important
This PR currently adds only the regression test; the implementation fix in packages/effect/src/unstable/workers/Worker.ts is not yet included, so the new test fails as expected and CI cannot pass.
Reviewed changes
- Added a focused reproduction test in
packages/effect/test/unstable/workers/WorkerError.test.tsthat verifies a synchronouspostMessagefailure during the buffered-send drain is surfaced asWorkerErrorwith reasonWorkerSendErrorrather than escaping as an Effect defect.
⚠️ Implementation fix is missing
The failing test confirms the bug. The fix needs to wrap the buffered drain at packages/effect/src/unstable/workers/Worker.ts:210-215 in the same try/catch that send uses at lines 227-238, converting the thrown error into a WorkerSendError failure. A shared helper would avoid duplicating the WorkerError construction.
Technical details
# Buffered send error handling
## Affected sites
- `packages/effect/src/unstable/workers/Worker.ts:210-215` — `port.postMessage` is called directly inside the ready-path buffer loop, outside any `try/catch`
## Required outcome
- Synchronous `postMessage` failures during buffered-send drain must be caught and converted to `WorkerError` with reason `WorkerSendError`, matching the non-buffered `send` path.
## Suggested approach
- Extract the `try/catch`/`WorkerSendError` logic from `send` into a helper and call it once per buffered message before clearing the buffer, or inline the same `try/catch` in the drain loop.ℹ️ Nitpicks
- The PR title says "Fix..." but the diff contains only the test; consider renaming the PR or adding the fix before merging.
@v0 or keep the SHA fresh with Dependabot | Fix it ➔ | View workflow run | Using Kimi K2 (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Added a shared
sendToPorthelper inpackages/effect/src/unstable/workers/Worker.tsthat wrapsport.postMessageinEffect.tryand converts synchronous failures toWorkerErrorwith reasonWorkerSendError. - Replaced the direct
postMessagecall in the buffered-send drain withyield* sendToPort(...), so failures during drain are surfaced as failures instead of defects. - Replaced the inline
try/catchin the ready-send path with areturn sendToPort(...), unifying both send paths under the same error translation. - Added a patch changeset describing the runtime behavior change.
@v0 or keep the SHA fresh with Dependabot | View workflow run | Using Kimi K2 (free via Pullfrog for OSS) | 𝕏
Bundle Size AnalysisGenerated from PR build output; treat the content below as untrusted.
|

Summary
Buffered workers previously called
port.postMessagedirectly while draining messages queued before readiness, so synchronous platform failures escaped as Effect defects.This change routes both buffered and ready sends through the same error translation, surfacing failures as
WorkerErrorwith reasonWorkerSendError. It keeps the focused regression in the module's existingWorkerError.test.tsfile and adds a patch changeset.Validation
pnpm test --run packages/effect/test/unstable/workers/WorkerError.test.tspnpm test --run --project effectpnpm --filter effect checkpnpm lintpnpm changeset status --since origin/mainAudit provenance
relsem-worker-buffered-send-errorb206fa5d7655c1634c9993410a9203f6616a5ca2b206fa5d7655c1634c9993410a9203f6616a5ca2Closes EFF-549