Skip to content

fix(server): bound live sideband websocket frames - #1381

Closed
luvs01 wants to merge 0 commit into
lidge-jun:devfrom
luvs01:agent/bound-live-sideband-frames
Closed

fix(server): bound live sideband websocket frames#1381
luvs01 wants to merge 0 commit into
lidge-jun:devfrom
luvs01:agent/bound-live-sideband-frames

Conversation

@luvs01

@luvs01 luvs01 commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Apply the existing 50 MiB WebSocket frame ceiling to both directions of Live/Realtime sideband relays.
  • Cap client frames retained while the upstream socket connects at 32 frames and 1 MiB total.
  • Clear pending-byte accounting on open, close, and finalization, with deterministic boundary regressions.

Verification

  • bun test tests/server-live.test.ts — 29 passed, 0 failed.
  • bun run typecheck — passed.
  • bun run privacy:scan — passed.
  • git diff --check HEAD^ HEAD — passed.
  • bun run test was attempted once; unrelated current-dev Windows baseline failures appeared in API usage, CLI restore/auth, catalog, and history paths, then Bun 1.3.14 panicked after 1,089 seconds. All changed Live tests passed before the crash.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.

Review readiness checklist

This PR stays in draft until every box below is ticked. Tick all four boxes once the requirements are met:

  • All CI tests are green on my local testing.

  • I pushed my PR to the latest dev commit.

  • I resolved all correct Codex and CodeRabbit findings.

  • My PR is ready for review.

Summary by CodeRabbit

  • Bug Fixes
    • Enforced a 50 MiB maximum WebSocket message size.
    • Added safeguards for oversized live-sideband frames and pending data.
    • Connections now close appropriately when message or pending-buffer limits are exceeded.
    • Improved handling of pending data limits by tracking both frame count and total bytes.

@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Live sideband WebSocket handling now enforces a 50 MiB payload limit and a cumulative pending-buffer byte limit. It tracks pending bytes, rejects frame-count and byte overflows, closes oversized frames with code 1009, resets accounting during lifecycle transitions, and adds boundary and relay tests.

Changes

Live sideband limits

Layer / File(s) Summary
Limit contracts and pending state
src/server/index.ts, src/server/ws-bridge.ts
Adds MAX_WS_FRAME_BYTES, frame and pending-byte predicates, LiveSidebandPendingEnqueueResult, the enqueue helper, and WsData.livePendingBytes.
Bidirectional frame enforcement
src/server/index.ts
Configures Bun’s WebSocket payload limit, checks client-to-upstream and upstream-to-client frames, closes oversized frames with code 1009, and resets pending-byte accounting during lifecycle transitions.
Limit and queue validation
tests/server-live.test.ts
Tests exact frame and pending-byte limits, binary relay behavior at the 50 MiB ceiling, and count or byte queue rejection without retaining rejected frames.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant WebSocketClient
  participant LiveSideband
  participant LiveUpstream
  WebSocketClient->>LiveSideband: Send client frame
  LiveSideband->>LiveSideband: Check frame and pending-byte limits
  LiveSideband->>LiveUpstream: Forward accepted or queued frame
  LiveUpstream->>LiveSideband: Send upstream frame
  LiveSideband->>LiveSideband: Check upstream frame size
  LiveSideband->>WebSocketClient: Forward accepted frame
Loading

Possibly related PRs

  • lidge-jun/opencodex#379: Adds limits and overflow handling to the live-sideband WebSocket relay introduced by this PR.
  • lidge-jun/opencodex#1241: Adds related byte-based buffering and overflow protection for WebSocket/SSE frame retention.

Suggested labels: review-ready

Suggested reviewers: lidge-jun, wibias, ingwannu

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding bounds to live sideband WebSocket frames and relay behavior.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Aug 9, 2026
@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

⏳ DRAFT

  • review readiness checklist open (3/4 boxes ticked).

What to do

  • Tick all four boxes in the PR description once you're done (currently 3/4).

Review readiness checklist

  • ✅ All CI tests are green on my local testing.
  • ⬜ I pushed my PR to the latest dev commit.
  • ✅ I resolved all correct Codex and CodeRabbit findings.
  • ✅ My PR is ready for review.

3/4 boxes ticked.

This PR stays in draft until every box above is ticked.

@luvs01
luvs01 force-pushed the agent/bound-live-sideband-frames branch from b5000d5 to 5d37fc3 Compare August 9, 2026 23:25
@Wibias
Wibias marked this pull request as ready for review August 10, 2026 00:40
@github-actions
github-actions Bot marked this pull request as draft August 10, 2026 00:48
@luvs01
luvs01 force-pushed the agent/bound-live-sideband-frames branch from 5d37fc3 to 48a99aa Compare August 10, 2026 00:54
@luvs01
luvs01 marked this pull request as ready for review August 10, 2026 01:18

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/server-live.test.ts`:
- Line 573: Remove the duplicate const declarations for byteBounded and
countBounded within the same test callback, retaining one declaration of each
and preserving their existing initial values and usage.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 7eaaace6-4779-4401-bc29-072e926be138

📥 Commits

Reviewing files that changed from the base of the PR and between 4ef5350 and 48a99aa.

📒 Files selected for processing (3)
  • src/server/index.ts
  • src/server/ws-bridge.ts
  • tests/server-live.test.ts

Comment thread tests/server-live.test.ts Outdated
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

@github-actions[bot] The readiness gate for #1381 is complete. I am replying to the latest comment only because the earlier comment chain is unavailable. I will review the current pull request changes.

⚠️ Action not completed

Already reviewed.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

@github-actions[bot] The readiness gate is complete. I will review the pull request.

⚠️ Action not completed

Already reviewed.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@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: 48a99aaa6b

ℹ️ 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 src/server/index.ts Outdated
@Wibias
Wibias marked this pull request as draft August 10, 2026 01:24
@github-actions
github-actions Bot marked this pull request as ready for review August 10, 2026 01:28
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '=== Changed files ==='
git diff --name-status HEAD^ HEAD

echo '=== src/server/index.ts structure ==='
ast-grep outline src/server/index.ts --items all --type function --match 'LiveSideband|liveSideband|enqueue|final' || true

echo '=== Relevant implementation ==='
rg -n -C 8 'LIVE_SIDEBAND|LiveSideband|livePending|livePendingBytes|enqueueLiveSideband|finalize|\.close\s*\(|\.open\s*\(' \
  src/server/index.ts src/server/ws-bridge.ts

echo '=== Focused tests ==='
rg -n -C 5 'LiveSideband|livePending|frame.*limit|pending.*limit|1009' tests/server-live.test.ts

echo '=== Current diff ==='
git diff --no-ext-diff --unified=80 HEAD^ HEAD -- \
  src/server/index.ts src/server/ws-bridge.ts tests/server-live.test.ts

Length of output: 89809


@github-actions[bot] Review complete. I found no correctness issues in the current diff.

src/server/index.ts applies the 50 MiB limit to client-to-upstream frames and upstream-to-client frames. It closes the sideband with code 1009 when a frame exceeds the limit.

enqueueLiveSidebandPendingFrame enforces both pending limits. It rejects the 33rd frame and frames that exceed the 1 MiB aggregate limit. Rejected frames do not modify livePending or livePendingBytes.

The cleanup paths clear livePendingBytes on upstream open, close initiation, and finalization. This prevents stale accounting from affecting later processing.

tests/server-live.test.ts covers exact limits, one-byte overflow, and queue state after rejection.

I did not run tests in the inspection sandbox.

You are interacting with an AI system.

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

@github-actions[bot] Acknowledged. PR #1381 is marked ready for review. The current CodeRabbit review found no correctness issues.

You are interacting with an AI system.

@github-actions
github-actions Bot marked this pull request as draft August 10, 2026 01:37
@github-actions
github-actions Bot marked this pull request as ready for review August 10, 2026 01:37
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

@github-actions[bot] Acknowledged. PR #1381 is ready for review. The current CodeRabbit review is complete and found no correctness issues.

You are interacting with an AI system.

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

@github-actions[bot] Acknowledged. PR #1381 is ready for maintainer review. The readiness gate reports all checklist items as complete.

You are interacting with an AI system.

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

@github-actions[bot] Acknowledged. PR #1381 is ready for maintainer review. The current CodeRabbit review found no correctness issues.

You are interacting with an AI system.

@Wibias Wibias self-assigned this Aug 10, 2026
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

@github-actions[bot] Acknowledged. PR #1381 is ready for maintainer review. The readiness checklist and deterministic hygiene checks are complete.

You are interacting with an AI system.

@github-actions
github-actions Bot marked this pull request as draft August 10, 2026 03:34
@Wibias
Wibias marked this pull request as ready for review August 10, 2026 03:36
@github-actions
github-actions Bot marked this pull request as draft August 10, 2026 03:36
@Wibias
Wibias marked this pull request as ready for review August 10, 2026 03:37
@github-actions
github-actions Bot marked this pull request as draft August 10, 2026 03:38
@Wibias Wibias closed this Aug 10, 2026
@Wibias
Wibias force-pushed the agent/bound-live-sideband-frames branch from c76fee0 to dc4dd45 Compare August 10, 2026 03:40
@Wibias

Wibias commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Superseded by #1398 — merged to dev.

Thank you for the work on this. The live sideband relay path needed explicit bounds on both directions: without them, oversized WebSocket frames or unbounded pending buffers while the upstream socket connects could let a client pin memory or pass frames the proxy was never meant to retain.

This fix is useful because it:

  • applies the existing 50 MiB frame ceiling to client→upstream and upstream→client sideband traffic
  • caps queued client frames while upstream connects (32 frames / 1 MiB)
  • keeps request logs and wire behavior aligned when limits are hit

Closing in favor of #1398.

Wibias added a commit that referenced this pull request Aug 10, 2026
Supersedes #1381. Rebased onto latest dev.

- Apply 50 MiB WebSocket frame ceiling to both directions
- Cap pending client frames at 32 frames and 1 MiB total
- Raise macOS CI test timeout for 50 MiB frame relay test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants