Skip to content

Fix #1677: raise tunnel H2 flow-control windows and disable ws deflate - #1678

Merged
amrmelsayed merged 14 commits into
mainfrom
builder/bugfix-1677
Sep 14, 2026
Merged

amrmelsayed merged 14 commits into
mainfrom
builder/bugfix-1677

Conversation

@amrmelsayed

@amrmelsayed amrmelsayed commented Sep 12, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

A tiny RPC on the VS Code management WebSocket (explorer resolve, ~100 B request / ~3 KB reply) took 39 s through the cloud relay while a 1.3 MB upload drained on the extension-host WebSocket. Both browser sockets are proxied as two streams on a single relay↔tower HTTP/2 session, and the tower ran that session with Node's default 64 KB flow-control windows, so a large transfer on one stream starved small RPCs on the other. This raises the tower's inbound H2 windows and drops tunnel-level compression.

Refs #1677 (partial fix: tower-side inbound H2 windows only; the relay's outbound half and the issue's end-to-end field re-test remain, so closure follows field verification per this workspace's verify-before-close discipline)

Root Cause

In packages/codev/src/agent-farm/lib/tunnel-client.ts the tower runs an HTTP/2 server over the tunnel WebSocket. Three defaults combined to cause head-of-line blocking at the session window:

  • http2.createServer({ settings: { enableConnectProtocol: true } }) set no initialWindowSize, so the tower advertised a 65535 B per-stream receive window.
  • The 'session' handler never called setLocalWindowSize(...), so the connection-level receive window stayed at Node's 64 KB default. With a ~150 ms relay↔tower RTT, a 1.3 MB upload exhausts the shared 64 KB window and a ~100 B RPC request can't reach the tower for many round-trips.
  • new WebSocket(...) used ws's default perMessageDeflate: true, so large H2 DATA frames were CPU-inflated on the event loop, delaying small outbound frames.

Fix

  • settings.initialWindowSize = TUNNEL_H2_STREAM_WINDOW_SIZE (1 MiB per stream).
  • session.setLocalWindowSize(TUNNEL_H2_SESSION_WINDOW_SIZE) (4 MiB connection window, kept larger than one stream so a big transfer can't consume the whole shared window and block a small RPC).
  • perMessageDeflate: false on the tunnel WebSocket.

Both windows stay under Node's default maxSessionMemory (10 MB), so no buffer-budget change is needed.

Scope note: these raise the tower's inbound windows (relay→tower), which is the half this repo owns and which removes the RPC-request starvation. The relay's own http2.connect (a separate Railway deployment) must raise its windows to fully fix the outbound reply direction.

Test Plan

  • Regression test added (bugfix-1677-tunnel-h2-window.test.ts): reads the tower's advertised windows back from the mock relay (H2 client) and asserts per-message deflate is not negotiated. Verified it fails at Node's 65535 B defaults and passes with the fix.
  • Build passes (porch check: build ✓)
  • All tests pass (porch check: tests ✓; existing tunnel suites — 202 tests — green; tsc --noEmit clean)

Both browser WebSockets (VS Code management + extension-host) are proxied as
two streams on one relay<->tower H2 session. Node's default 64 KB per-stream and
connection windows let a large transfer on one stream starve tiny RPCs on the
other (head-of-line blocking at the session window): the field trace saw a
~100 B management resolve take 39 s while a 1.3 MB upload drained.

Raise the tower's inbound H2 windows and drop tunnel-level compression in
packages/codev/src/agent-farm/lib/tunnel-client.ts:
- settings.initialWindowSize = 1 MiB (per-stream receive window)
- session.setLocalWindowSize(4 MiB) (connection receive window, larger than one
  stream so a big transfer can't consume the whole shared window)
- perMessageDeflate: false on the tunnel WebSocket, so large DATA frames aren't
  CPU-inflated on the event loop, delaying small outbound frames

Regression test reads the advertised windows back from the mock relay (H2 client)
and asserts deflate is not negotiated; it fails at Node's 65535 B defaults and
passes with the fix. The relay's own http2.connect must raise its windows for
the outbound direction (separate deployment).
…e assertion

- Add a SETTINGS settle guard to the per-stream window test (mirrors the
  connection-window test) to remove a theoretical ordering flake.
- Reframe the perMessageDeflate comment as defence-in-depth (the relay is the ws
  server, whose default is already off), not an established third root cause.
- Drop a redundant static-constant assertion in the connection-window test.
…ive fix

codev-cloud confirmed (2026-09-14) its /tunnel ws server runs ws defaults, so
deflate is never negotiated and this client-side decline is a no-op today. Keep
it as a documented guard against a future server-side enable; state that
verified fact in the comment instead of the earlier speculative framing.
…d re-test choreography noted; holding at gate
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