Skip to content

Fix WebSocket handler service requirements - #6664

Open
Hona wants to merge 2 commits into
Effect-TS:mainfrom
Hona:fix/websocket-handler-service
Open

Fix WebSocket handler service requirements#6664
Hona wants to merge 2 commits into
Effect-TS:mainfrom
Hona:fix/websocket-handler-service

Conversation

@Hona

@Hona Hona commented Jul 27, 2026

Copy link
Copy Markdown

Type

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Description

Socket.fromWebSocket provides the active Socket.WebSocket service while message handlers run, but its returned Socket type previously left that service in each handler effect's external requirements.

This change returns a refined Socket.WebSocketSocket from Socket.fromWebSocket and Socket.makeWebSocket. Its run, runString, and runRaw methods exclude the internally provided WebSocket service while preserving every unrelated handler requirement. The base Socket and Socket.make contracts remain unchanged for implementations that do not provide this service.

Runtime coverage verifies that handlers receive the exact acquired WebSocket for text and binary messages and that interruption still releases it. Type tests cover both WebSocket constructors, all three handler methods, generic handler effects, unrelated requirements, and custom sockets.

Validation

  • corepack pnpm check
  • corepack pnpm test-types Socket.tst.ts
  • corepack pnpm --filter effect test --run test/unstable/socket/Socket.test.ts
  • corepack pnpm --filter @effect/platform-node test --run test/NodeSocket.test.ts -t "messages"
  • corepack pnpm --filter @effect/platform-node test --run test/NodeSocket.test.ts -t "close codes are errors by default"
  • corepack pnpm jsdocs
  • corepack pnpm exec oxlint -f unix
  • corepack pnpm exec dprint check

Related

  • Related Issue: N/A
  • Closes: N/A

Summary by CodeRabbit

  • Bug Fixes
    • Fixed WebSocket message handling so effects no longer require an unnecessary WebSocket environment dependency.
    • Improved WebSocket socket typing so handler requirements are more precise and accurate.
    • Ensured acquired WebSocket instances are released properly when raw message processing is interrupted.
  • Tests
    • Added coverage for both text and binary message handling, cleanup behavior on interruption, and WebSocket typing expectations.

Copilot AI review requested due to automatic review settings July 27, 2026 06:45
@github-project-automation github-project-automation Bot moved this to Discussion Ongoing in PR Backlog Jul 27, 2026
@changeset-bot

changeset-bot Bot commented Jul 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: eb38642

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

This PR includes changesets to release 28 packages
Name Type
effect Patch
@effect/opentelemetry Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-node-shared Patch
@effect/platform-node 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

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3aef3174-d921-4418-9cbc-7d425f7b0f16

📥 Commits

Reviewing files that changed from the base of the PR and between 8923031 and eb38642.

📒 Files selected for processing (1)
  • packages/effect/src/unstable/socket/Socket.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/effect/src/unstable/socket/Socket.ts

📝 Walkthrough

Walkthrough

WebSocketSocket now excludes the runtime-provided WebSocket service from handler effect requirements. Constructors, context typing, runtime behavior, release handling, type tests, runtime tests, and the patch changeset were updated accordingly.

Changes

WebSocket handler environment

Layer / File(s) Summary
WebSocket socket contract
packages/effect/src/unstable/socket/Socket.ts, packages/effect/typetest/unstable/socket/Socket.tst.ts
Adds WebSocketSocket, updates constructor return types and context handling, and verifies handler environment and custom-socket typing.
WebSocket runtime behavior and validation
packages/effect/src/unstable/socket/Socket.ts, packages/effect/test/unstable/socket/Socket.test.ts, .changeset/fix-websocket-handler-service.md
Types the raw handler implementation, validates message delivery and release on interruption, and records a patch release.

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

Suggested labels: bug

🚥 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 4.0 bug Something isn't working labels Jul 27, 2026
@coderabbitai coderabbitai Bot removed the 4.0 label Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Status: Discussion Ongoing

Development

Successfully merging this pull request may close these issues.

2 participants