← Back to Pull requests

Send a Blob passed to WebSocket send() as a binary message #8850

Merged
littledivy merged 10 files (162 lines) on Nov 25, 2026 13:21 UTC
View on GitHub
littledivy littledivy commented on Nov 24, 2026 04:04 UTC
Author

The WHATWG WebSockets spec says send(Blob) sends the Blob's bytes as a binary message, in order with the other messages sent. workerd's send() takes an ArrayBuffer, an ArrayBufferView or a string, so a Blob is converted to a string and sent as a text message such as "[object Blob]". The WPT case Send-binary-blob was disabled because of this, since the echo server never sent a binary message back and the test hung.

In this patch send() also takes a Blob. A Blob's bytes are always in memory, so send() copies them and queues them like any other binary message, which keeps the order with the send() calls around it. They count toward bufferedAmount and the isolate's external memory the same way.

There is no compat flag. The one thing that changes is that send(blob), which used to send the text "[object Blob]" (or "[object Object]" on older compatibility dates), now sends the Blob's bytes as a binary message. Nothing should depend on that text.

websocket-send-blob-test covers a Blob, an empty Blob, a File, a sliced Blob, ordering against string and ArrayBuffer sends, and bufferedAmount. It fails without the fix. The second commit runs Send-binary-blob, which passes.

Diff: 162 lines (+152 / -10) across 10 files Reviewer: npaun Review duration: 1996m
All Vouch review confidence checks passed
Residual risk 0.06 = Change Risk (0.47) × (1 − Review Confidence (0.87)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.47 · 162 lines diff across 10 files
0.47
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.83 · 2 substantive comment(s)
0.83
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
87%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.305
Real PR Conversation Timeline
7 items
clanky-the-clanker[bot] clanky-the-clanker[bot] commented on Nov 24, 2026 04:06 UTC
Reviewer

<!-- durable-reviewer:review run=5f28aaa2-b4b9-4a8d-a953-69041a5df9e3 -->

Superseded by the review of 276bdc66.

<details>
<summary>This review, of <code>3915480b</code></summary>

✅ Approved — I found no issues. With the compat flag on, a Blob is sent as a binary message in order with other sends; without the flag, nothing changes, and the tests and the WPT case cover both.

<details>
<summary>Not opened by the correctness review: 1 changed file it was meant to read</summary>

  • types/generated-snapshot/experimental/index.ts
  • </details>

    <sub>The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.</sub>

    ---

    <details>
    <summary>✅ All checks passed</summary>

    🔒 Security: ✅ LGTM

    No issues found.

    ---

    📖 AGENTS.md: ✅ LGTM

    No issues found.

    ---

    📋 Code Quality: ✅ LGTM

    No issues found.

    ---

    ⚡ Performance: ✅ LGTM

    The Blob's bytes are copied once, the same way the existing ArrayBuffer send path copies its data.

    ---

    📝 Documentation: ✅ LGTM

    No issues found.

    </details>

    ---
    <sub>Reviewed commit: 3915480b</sub>

    </details>

    codecov-commenter codecov-commenter commented on Nov 24, 2026 04:29 UTC
    Contributor

    Codecov Report


    :x: Patch coverage is 91.66667% with 1 line in your changes missing coverage. Please review.
    :white_check_mark: Project coverage is 67.53%. Comparing base (28068ef) to head (276bdc6).
    :warning: Report is 161 commits behind head on main.

    | Files with missing lines | Patch % | Lines |
    |---|---|---|
    | src/workerd/api/web-socket.c++ | 91.66% | 0 Missing and 1 partial :warning: |

    <details><summary>Additional details and impacted files</summary>

    @@            Coverage Diff             @@
    ##             main    #8850      +/-   ##
    ==========================================
    - Coverage   67.73%   67.53%   -0.20%     
    ==========================================
      Files         848      871      +23     
      Lines      215725   220345    +4620     
      Branches    32511    32955     +444     
    ==========================================
    + Hits       146121   148814    +2693     
    - Misses      50404    52076    +1672     
    - Partials    19200    19455     +255     
    

    </details>

    :umbrella: View full report in Codecov by Harness.
    :loudspeaker: Have feedback on the report? Share it here.
    <details><summary> :rocket: New features to boost your workflow: </summary>

  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

  • </details>

    npaun npaun approved these changes on Nov 24, 2026 15:31 UTC
    Approved Reviewer

    Does this really need a compat flag? Who's going to be complaining that we're no longer sending [object Blob] anymore?

    jasnell jasnell commented on code on Nov 24, 2026 20:52 UTC
    Code Review
    src/workerd/api/web-socket.h:1
    @@ -307,7 +311,11 @@ class WebSocket: public EventTarget {
       JSG_RESOURCE_TYPE(WebSocket, CompatibilityFlags::Reader flags) {
         JSG_INHERIT(EventTarget);
         JSG_METHOD(accept);
    -    JSG_METHOD(send);
    +    if (flags.getWebsocketSendBlob()) {
    +      JSG_METHOD_NAMED(send, sendWithBlob);
    +    } else {
    +      JSG_METHOD(send);
    +    }

    Compat flag really is not required in this one

    clanky-the-clanker[bot] clanky-the-clanker[bot] commented on Nov 25, 2026 06:44 UTC
    Reviewer

    <!-- durable-reviewer:review run=92bcd411-791a-4930-a1bb-50863c0ab81b -->

    ✅ Approved — No issues found. A Blob passed to send() is copied and queued on the existing binary path, so send order and buffer accounting work as before, and dropping the compat flag is reasonable for a change that only replaces the "[object Blob]" text.

    <details>
    <summary>Not opened by the correctness review: 2 changed files it was meant to read</summary>

  • types/generated-snapshot/experimental/index.ts

  • types/generated-snapshot/index.ts
  • </details>

    <sub>The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.</sub>

    ---

    <details>
    <summary>✅ All checks passed</summary>

    🔒 Security: ✅ LGTM

    No issues found. The Blob's bytes go through the same size accounting and bufferedAmount handling as an ArrayBuffer send.

    ---

    📖 AGENTS.md: ✅ LGTM

    No issues found.

    ---

    📋 Code Quality: ✅ LGTM

    No issues found. The Blob case copies getData(js) into the existing binary send path. The internal Impl::send signature stays as it was, and the tests cover a Blob, an empty Blob, a File, a sliced Blob, ordering and bufferedAmount.

    ---

    ⚡ Performance: ✅ LGTM

    The Blob's bytes are copied once, the same way the ArrayBuffer send path copies its data.

    ---

    📝 Documentation: ✅ LGTM

    No issues found.

    </details>

    ---
    <sub>Reviewed commit: 276bdc66</sub>

    edmundhung edmundhung approved these changes on Nov 25, 2026 13:16 UTC
    Approved Reviewer

    Approved these changes.

    Reviewers
    Assignees
    littledivy littledivy
    Labels
    risk: low confidence: 87.2% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 46.7% (MEDIUM) · Higher = larger blast radius
    46.7%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 87.2% · Lower = rushed or shallow review
    87.2%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 6.0% · Safe to merge
    6.0%