Skip to content

P5 O10 follow-up: the built bundle's ws keeps to its JavaScript paths (masked frames of 48 bytes or more threw) - #301

Merged
SSFSKIM merged 2 commits into
masterfrom
p5-o10-ws-bundle
Oct 28, 2026
Merged

SSFSKIM merged 2 commits into
masterfrom
p5-o10-ws-bundle

Conversation

@SSFSKIM

@SSFSKIM SSFSKIM commented Oct 28, 2026

Copy link
Copy Markdown
Owner

What broke

Main's built bundle carries a broken ws. ws loads its optional native helpers, bufferutil and utf-8-validate, inside try { require(...) }, and neither is installed here. electron-vite (Vite) stands an empty object in for each uninstalled optional dependency, so the require succeeds and ws believes the helper is present. From then on, masking any frame of 48 bytes or more calls bufferUtil.mask, which does not exist, and throws bufferUtil$1.mask is not a function; unmasking a received frame of 32 bytes or more fails the same way. Every client-to-server frame is masked, so every frame of that size on main's remote links failed. The source ws that the unit tests import never meets the stand-in, which is how the bug got past them. The fix defines ws's own switches, WS_NO_BUFFER_UTIL and WS_NO_UTF_8_VALIDATE, in main's build, so the built ws keeps to its JavaScript paths. The bundle guard now fails if any optional-dependency stand-in appears in main's graph or mawsd's. A new guard case runs the emitted ws itself, client and server, against the source ws with frames from 31 bytes to 70 KB. It fails on master's build and passes with the defines.

This PR is split out of P5 O10 M10 (branch p5-o10-m10) so that it lands first. M10 carries the same two files byte for byte (git merge-tree reports no conflict).

Changes

  • electron.vite.config.ts: WS_NO_BUFFER_UTIL and WS_NO_UTF_8_VALIDATE are defined for every bundle (main, mawsd, the hosts). The built ws keeps to its JavaScript mask/unmask and its JavaScript UTF-8 validation, which still rejects malformed input.
  • src/engine-host/bundle-guard.test.ts:
    • The guard bars any optional-dependency stand-in (__viteOptionalPeerDep_) in main's and mawsd's graphs. On master mawsd's half is vacuous, because mawsd bundles no ws until M10.
    • A new case runs the emitted ws against the source ws, both ways, at 31, 32, 47, 48, 64 and 70,000 bytes. It finds ws by content, so it holds whether ws is inlined in out/main/index.js or sits in a shared chunk, as it does under M10.

Files outside src/endpoint/ and apps/org-protocol/: both files.

Validation Evidence

  • The test fails on master's build: with the defines reverted locally and the bundle rebuilt, 3 tests fail.
    • The stand-in bar finds 8 __viteOptionalPeerDep_ lines in out/main/index.js.
    • The client case fails with TypeError: bufferUtil$1.mask is not a function at out/main/index.js:5359.
    • The server case fails with bufferUtil$1.unmask is not a function.
  • It passes with the fix: bundle-guard.test.ts passes 11/11 locally. It also passes 11/11 against M10's build, where ws is in a chunk shared by main and mawsd.
  • Gate: class 1a plus the hosted groups whose processes load ws: ci-gate --gates static,unit,probes,e2e:machines,e2e:desk-web-hub,e2e:supervisor-daemon,e2e:daemon-unit --class1a pool --runner macos --lane hosted. Result: GREEN, run https://github.com/SSFSKIM/MAWS/actions/runs/40723847211, head 36cced3.
    • e2e:machines 12 passed, desk-web-hub 39 passed, supervisor-daemon and daemon-unit 1 passed each.
    • No flaky: line, and ci-gate gave no coverage warning.
  • Review: reviewer-medium found nothing material. It noted that the test's extraction is tied to the CommonJS factory names Rollup emits today (requireWebsocket, requireWebsocketServer), so a future layout change would fail loudly rather than pass.

Residue

  • O7 may want a packaged-app check of its remote link. This bug was invisible to every source-level test.

Sminos-Session: p5-desk-track-owner#b4948247 (doperpowers on macbook)

…bufferutil broke every masked frame of 48 bytes or more)

ws's optional native helpers, bufferutil and utf-8-validate, are installed nowhere; Vite stands an empty object in for each, which ws's try/require takes as present, so mask() and unmask() of a frame of 48 (32) bytes or more call an absent function. Main's remote links bundle ws, so every such frame on them failed. The main build defines WS_NO_BUFFER_UTIL and WS_NO_UTF_8_VALIDATE, so ws keeps to its own code; the bundle guard holds main's graph and mawsd's free of any such stand-in (mawsd's vacuously until O10 M10 bundles ws there).

Ported from p5-o10-m10 (37d55fd, 8744e93), these two files byte for byte, so M10 merges over it cleanly; M10's endpoint log-line rewording stays with M10 (master's mawsd graph does not reach it).

Sminos-Session: p5-desk-track-owner#b4948247 (doperpowers on macbook)
…ways

The source ws never meets Vite's stand-in for bufferutil, so a suite on source cannot see the bug the defines fix. Each built file of main's graph or mawsd's that carries ws gives up its client and server (its requireWebsocket and requireWebsocketServer and the top-level declarations they reach, run as emitted), and frames of 31 to 70,000 bytes cross each against the source ws, arriving intact. On master's build without the defines both cases fail (bufferUtil$1.mask, and unmask, is not a function); on M10's build the same cases find ws in its shared chunk and pass.

Sminos-Session: p5-desk-track-owner#b4948247 (doperpowers on macbook)
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-28T16:28:07.523666Z 36cced3 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@SSFSKIM
SSFSKIM merged commit 683ac3e into master Oct 28, 2026
SSFSKIM added a commit that referenced this pull request Oct 28, 2026
…t paths; a tracker row for the built app's RL2 link

Sminos-Session: GUI AI agent workspace charter#37052769 (MAWS on macbook)
SSFSKIM added a commit that referenced this pull request Oct 28, 2026
Sminos-Session: p5-desk-track-owner#b4948247 (doperpowers on macbook)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant