This repository was archived by the owner on Aug 31, 2026. It is now read-only.
fix(events): use the WebSocket global and drop the ws dependency - #370
Closed
georgeglarson wants to merge 1 commit into
Closed
fix(events): use the WebSocket global and drop the ws dependency#370georgeglarson wants to merge 1 commit into
georgeglarson wants to merge 1 commit into
Conversation
Both clients chose their implementation with a `window` check falling back to
`require('ws')`. `window` is undefined in Node on every version, so Node always
took the fallback, and `require` does not exist in an ESM module. The branch
never worked in the environment it was written for. It only looked like it did
under the CommonJS Jest runner, which is why the tests had to fake the failure
with `jest.doMock('ws', ...)`.
WebSocket has been a global in Node since 22.4 and the CI floor is above that,
so both clients now read `globalThis.WebSocket` and `ws` leaves dependencies.
The load-time invariant is unchanged: reading a missing global yields undefined
rather than throwing, and "no WebSocket implementation" still reaches the caller
through onError at start().
package-import.test.ts now deletes the global instead of mocking a module,
which is the condition a consumer actually hits, and gains two cases covering
the present-global path.
Verified against the packed tarball from a real ESM consumer on Node 24.20:
the barrel imports, RemoteWorkspace constructs, and the client opens through
globalThis.WebSocket.
georgeglarson
marked this pull request as ready for review
August 29, 2026 20:13
Contributor
|
🚦 CI is currently failing on this PR's latest commit. Please fix the failing checks before OpenHands reviews it - this is re-checked automatically once you push a new commit. (A maintainer can also request This is an automated check - no AI was used to generate this comment. |
This was referenced Aug 29, 2026
Closed
Draft
5 tasks
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
HUMAN:
Human verified, screenshot below.
Why
Both WebSocket clients picked their implementation like this:
windowis undefined in Node on every version, so Node always took the second branch, andrequiredoes not exist in an ESM module. The fallback never worked in the environment it was written for. It only appeared to work under the CommonJS Jest runner, which is why the existing tests had to fake the failure withjest.doMock('ws', ...).Meanwhile
WebSockethas been a global in Node since 22.4, and the CI floor is above that. So the fallback is dead code guarding a case that cannot happen.Summary
globalThis.WebSocket. Browsers and Node both provide it.wscomes out ofdependencies, so it stops shipping to consumers.package-import.test.tsdeletes the global instead of mocking a module, which is the condition a consumer would actually hit rather than a simulation of it. Two tests added for the present-global path.The load-time invariant is unchanged: reading a missing global yields
undefinedrather than throwing, and "no WebSocket implementation" still surfaces throughonErroratstart().Issue Number
No issue filed. Follows the Node 24 discussion in #proj-agent-canvas on 2026-08-29.
How to Test
18 suites, 311 tests, 0 lint errors on Node 24.20.
The suite runs under CommonJS Jest, which is the reason the old bug hid, so it cannot prove the ESM path on its own.
npm packthe branch, install the tarball into a project with"type": "module", and import the barrel:On
mainthat file throws before the first line runs. On this branch the barrel imports, the workspace constructs, and the client opens throughglobalThis.WebSocket.Video/Screenshots
Type
Notes
This subsumes #362. That PR changes the same
windowcheck toglobalThis, which is the first half of this one. Close #362 in favour of this, or land it first and this rebases to just the deletion and the dependency drop. Whichever you prefer.Independent of #368 and #369. The global exists on 22.12 as well as 24, so this does not depend on the floor moving.