Skip to content

Fix worker runner cleanup - #6680

Merged
tim-smart merged 1 commit into
mainfrom
agent/codex-engineer/2e5cc854
Jul 28, 2026
Merged

Fix worker runner cleanup#6680
tim-smart merged 1 commit into
mainfrom
agent/codex-engineer/2e5cc854

Conversation

@tim-smart

@tim-smart tim-smart commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Summary

  • clean up the exact browser and Bun messageerror listeners that were registered
  • emit browser SharedWorker disconnect IDs and remove Node worker listeners on scope close
  • correct the Node error-event diagnostic and add browser lifecycle regression coverage

Testing

  • nix develop -c pnpm lint-fix
  • nix develop -c pnpm check
  • nix develop -c pnpm --filter @effect/platform-browser test --run test/BrowserWorkerRunner.test.ts

Closes EFF-158

Summary by CodeRabbit

  • Bug Fixes

    • Improved worker shutdown handling across browser, Bun, and Node environments.
    • Worker disconnect events are now reported reliably.
    • Corrected cleanup of message and error event handlers to prevent lingering listeners.
    • Improved error reporting for worker communication failures.
  • Tests

    • Added coverage for worker disconnect notifications and event-listener cleanup.

@github-project-automation github-project-automation Bot moved this to Discussion Ongoing in PR Backlog Jul 28, 2026
@changeset-bot

changeset-bot Bot commented Jul 28, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b9edc67

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 28 packages
Name Type
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-node Patch
effect Patch
@effect/opentelemetry Patch
@effect/platform-node-shared Patch
@effect/vitest Patch
@effect/ai-anthropic Patch
@effect/ai-openai-compat Patch
@effect/ai-openai Patch
@effect/ai-openrouter Patch
@effect/atom-react Patch
@effect/atom-solid Patch
@effect/atom-vue Patch
@effect/sql-clickhouse Patch
@effect/sql-d1 Patch
@effect/sql-libsql Patch
@effect/sql-mssql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-pglite Patch
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-do Patch
@effect/sql-sqlite-node Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/docgen Patch
@effect/openapi-generator Patch

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

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Worker runner implementations now emit browser disconnect notifications and correctly remove message error listeners. Node workers add scoped cleanup for message, messageerror, and error handlers. Browser tests cover listener removal and disconnect events, with patch changesets added for the affected packages.

Changes

Worker runner lifecycle updates

Layer / File(s) Summary
Browser disconnect signaling and listener cleanup
packages/platform-browser/src/BrowserWorkerRunner.ts, packages/platform-browser/test/BrowserWorkerRunner.test.ts
Browser runners enqueue disconnected port IDs, remove the correct messageerror handler, and test both behaviors with in-memory worker fakes.
Bun messageerror listener cleanup
packages/platform-bun/src/BunWorkerRunner.ts
Bun cleanup now removes the named onMessageError handler and uses it for messageerror handling.
Node scoped event lifecycle
packages/platform-node/src/NodeWorkerRunner.ts, .changeset/fix-worker-runner-cleanup.md
Node workers use named event handlers, remove listeners through a scope finalizer, distinguish messageerror and error messages, and record patch releases for the affected platform packages.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested labels: bug

Suggested reviewers: gcanti

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot added the bug Something isn't working label Jul 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

File Name Current Size Previous Size Difference
basic.ts 6.63 KB 6.63 KB 0.00 KB (0.00%)
batching.ts 9.37 KB 9.37 KB 0.00 KB (0.00%)
brand.ts 6.26 KB 6.26 KB 0.00 KB (0.00%)
cache.ts 10.12 KB 10.12 KB 0.00 KB (0.00%)
config.ts 19.22 KB 19.22 KB 0.00 KB (0.00%)
differ.ts 18.42 KB 18.42 KB 0.00 KB (0.00%)
http-client.ts 20.76 KB 20.76 KB 0.00 KB (0.00%)
logger.ts 10.28 KB 10.28 KB 0.00 KB (0.00%)
metric.ts 8.55 KB 8.55 KB 0.00 KB (0.00%)
optic.ts 7.41 KB 7.41 KB 0.00 KB (0.00%)
pubsub.ts 14.20 KB 14.20 KB 0.00 KB (0.00%)
queue.ts 11.09 KB 11.09 KB 0.00 KB (0.00%)
schedule.ts 10.27 KB 10.27 KB 0.00 KB (0.00%)
schema-class.ts 18.16 KB 18.16 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 28.02 KB 28.02 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 24.34 KB 24.34 KB 0.00 KB (0.00%)
schema-string-transformation.ts 12.69 KB 12.69 KB 0.00 KB (0.00%)
schema-string.ts 10.35 KB 10.35 KB 0.00 KB (0.00%)
schema-template-literal.ts 14.49 KB 14.49 KB 0.00 KB (0.00%)
schema-toArbitraryLazy.ts 20.93 KB 20.93 KB 0.00 KB (0.00%)
schema-toCodeDocument.ts 23.38 KB 23.38 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 18.32 KB 18.32 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 18.00 KB 18.00 KB 0.00 KB (0.00%)
schema-toFormatter.ts 17.88 KB 17.88 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 21.52 KB 21.52 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 18.56 KB 18.56 KB 0.00 KB (0.00%)
schema.ts 17.43 KB 17.43 KB 0.00 KB (0.00%)
stm.ts 12.05 KB 12.05 KB 0.00 KB (0.00%)
stream.ts 9.37 KB 9.37 KB 0.00 KB (0.00%)

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
packages/platform-node/src/NodeWorkerRunner.ts (1)

77-116: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add regression tests for Bun/Node listener cleanup, mirroring the new Browser tests.

This PR adds regression coverage only for BrowserWorkerRunner (listener removal + disconnect emission). The equivalent fixes in Bun and Node — arguably the more complex change given Node's new scoped multi-listener finalizer — ship without any test verifying listeners are actually detached on scope close.

  • packages/platform-node/src/NodeWorkerRunner.ts#L77-L116: add a test asserting message, messageerror, and error listeners registered on WorkerThreads.parentPort/process are removed when the run scope finalizes (mirroring the Browser "removes the registered messageerror listener" test).
  • packages/platform-bun/src/BunWorkerRunner.ts#L69-L84: add a test asserting the messageerror listener added via onMessageError is removed with the same reference on scope finalization.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/platform-node/src/NodeWorkerRunner.ts` around lines 77 - 116, Add
regression tests for both listener-cleanup implementations: in
packages/platform-node/src/NodeWorkerRunner.ts:77-116, verify the run scope
removes the registered message, messageerror, and error listeners from
WorkerThreads.parentPort/process on finalization; in
packages/platform-bun/src/BunWorkerRunner.ts:69-84, verify the messageerror
listener registered through onMessageError is removed using the same function
reference during scope finalization. Mirror the existing BrowserWorkerRunner
cleanup tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/platform-node/src/NodeWorkerRunner.ts`:
- Around line 77-116: Add regression tests for both listener-cleanup
implementations: in packages/platform-node/src/NodeWorkerRunner.ts:77-116,
verify the run scope removes the registered message, messageerror, and error
listeners from WorkerThreads.parentPort/process on finalization; in
packages/platform-bun/src/BunWorkerRunner.ts:69-84, verify the messageerror
listener registered through onMessageError is removed using the same function
reference during scope finalization. Mirror the existing BrowserWorkerRunner
cleanup tests.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b720d262-bed7-428b-abb0-67f792d27f03

📥 Commits

Reviewing files that changed from the base of the PR and between 9f02491 and b9edc67.

📒 Files selected for processing (5)
  • .changeset/fix-worker-runner-cleanup.md
  • packages/platform-browser/src/BrowserWorkerRunner.ts
  • packages/platform-browser/test/BrowserWorkerRunner.test.ts
  • packages/platform-bun/src/BunWorkerRunner.ts
  • packages/platform-node/src/NodeWorkerRunner.ts

@tim-smart
tim-smart merged commit 23e176a into main Jul 28, 2026
15 checks passed
@tim-smart
tim-smart deleted the agent/codex-engineer/2e5cc854 branch July 28, 2026 03:29
@github-project-automation github-project-automation Bot moved this from Discussion Ongoing to Done in PR Backlog Jul 28, 2026
@effect-slopcop effect-slopcop Bot added the 4.0 label Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.0 bug Something isn't working

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant