Skip to content

fix(serve): keep relay streams alive on the Cloudflare runtime - #2807

Merged
steipete merged 1 commit into
mainfrom
fix/serve-relay-cloudflare
Oct 13, 2026
Merged

steipete merged 1 commit into
mainfrom
fix/serve-relay-cloudflare

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Problem

The serve relay from #2797 failed on the production (Cloudflare) coordinator. A live Worker tail showed sessions minted (POST …/relay 200) and both …/client and …/agent WebSockets attaching, then both ending as canceled within ~2–3s. The client re-minted sessions in a loop and the SSH transport never came up. The same relay passed end to end on the Node runtime.

Root cause

workerd delivers binary WebSocket messages as Blob by default on accepted sockets; Node delivers bytes. The relay's synchronous frame parser (data/ack framing with a 32 KiB window) expects bytes, so acknowledgements never parsed and both sides tore the session down.

Fix

Set socket.binaryType = "arraybuffer" on each relay socket before acceptance. A regression test exercises the Cloudflare acceptance path with Blob-default sockets, full-size bidirectional frames, acknowledgements and close propagation; it fails without the fix and passes with it.

Verification

Worker gate (format, lint, check, check:node, test, build, build:node). Go vet/race for serve and the CLI relay subset. Local end to end on workerd (wrangler dev) and on Node: serve route: relay → RELAY_OK, and a held session cut on stop. Codex review (P1): scoped-clean. The production cross-machine relay test follows after deploy.

@clawsweeper

clawsweeper Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 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-13T06:49:09.023594Z 149a72a 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.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 149a72a8c8

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread worker/src/serve-relay.ts
Comment on lines +72 to +73
// Workerd defaults to Blob delivery; the synchronous frame parser requires bytes.
socket.binaryType = "arraybuffer";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Add the relay fix to the changelog

This restores production-visible Cloudflare relay behavior, but the commit does not add an entry under CHANGELOG.md's Unreleased fixes. Repository policy requires agents and maintainers to record user-visible fixes as they land, so add a concise relay-fix bullet there.

AGENTS.md reference: AGENTS.md:L60-L60

Useful? React with 👍 / 👎.

@steipete
steipete merged commit ef07634 into main Oct 13, 2026
32 checks passed
@steipete
steipete deleted the fix/serve-relay-cloudflare branch October 13, 2026 07:09
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