Skip to content

fix(id): bound collab WebSocket input (#1965) - #4051

Merged
dezren39 merged 3 commits into
mainfrom
queue/5056-1965-collab-ws-size
Nov 2, 2026
Merged

dezren39 merged 3 commits into
mainfrom
queue/5056-1965-collab-ws-size

Conversation

@dezren39

@dezren39 dezren39 commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Summary

-ws.on_upgrade(...)
+ws.max_message_size(MAX_FRAME_BYTES).on_upgrade(...)
+
+if steps.len() > MAX_STEPS_PER_MESSAGE { reject_without_mutation }

Applies the 1 MiB frame limit to collab and tags WebSockets, and caps each collab Steps batch at 1,000 before history/version/broadcast mutation.

Evidence

Merge Danger

Door: two-way. The limits can be adjusted or reverted; compliant clients remain unaffected.

Blast Radius: Narrow — collab and tags WebSocket input, plus the shared frame-limit documentation.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

@dezren39
dezren39 requested a review from a team as a code owner November 1, 2026 22:52
@coderabbitai

coderabbitai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 6 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2aeeb1e4-d158-4442-8c8e-a96d8a59fe10
Commits

Reviewing files that changed from the base of the PR and between 018fc39 and cea81a3.

Files selected for processing: 5
  • pkgs/id/src/frames.rs
  • pkgs/id/src/web/collab.rs
  • pkgs/id/src/web/tags_ws.rs
  • pkgs/id/web/src/collab.test.ts
  • pkgs/id/web/src/collab.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 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-11-02T02:08:09.141227Z cea81a3 New commits
ℹ️ 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: 8c8ec9d897

ℹ️ 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 pkgs/id/src/web/collab.rs
Comment on lines +641 to +644
if steps.len() > MAX_STEPS_PER_MESSAGE {
return Err(format!(
"Step batch exceeds maximum of {MAX_STEPS_PER_MESSAGE} steps"
));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Chunk legitimate editor transactions before enforcing the step limit

Selecting and indenting more than 1,000 code lines produces one step per line (web/src/indent.ts:152-156), but handleEditorChange in web/src/collab.ts sends all pending steps without chunking. This new rejection leaves those steps unconfirmed, and the client's error handler only recovers from version-mismatch/desynchronization errors. Every subsequent edit therefore resends the oversized pending batch and is rejected again, blocking synchronization for the rest of the editor session. Coordinate this server limit with client-side batching so legitimate large transactions can still synchronize.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in e3e95d4 — client-side batching, as suggested. handleEditorChange in pkgs/id/web/src/collab.ts now sends at most MAX_STEPS_PER_MESSAGE (1000, mirroring the server constant in collab.rs) per Steps message via the new stepBatch() helper; the remaining steps stay unconfirmed, and the Update handler flushes the next batch as soon as receiveTransaction confirms the previous one (no editor:change event fires for a confirmation, so without the flush the remainder would stall until the next local edit). A legitimate >1000-step transaction (e.g. indenting >1000 lines) now syncs in successive batches instead of wedging the session on the rejection.

Tests: 3 new stepBatch cases in collab.test.ts (at-cap, oversized chunking with order preserved, empty) — vitest collab.test.ts 6/6 pass, tsc --noEmit clean. The deferred server-side regression tests now run locally too: cargo test --lib --features web test_apply_steps — test_apply_steps_rejects_oversized_batch_without_mutation and test_apply_steps_accepts_small_batch_and_broadcasts_update both pass.

@dezren39

dezren39 commented Nov 2, 2026

Copy link
Copy Markdown
Member Author

🤖 Agent note · Codex gate analysis (queue task 5056, lane A)

The Codex P2 on collab.rs:644 (review comment 4437704656) is valid and blocks merge as-is: web/src/indent.ts produces one step per line, handleEditorChange in web/src/collab.ts sends all pending steps unchunked, and the client error handler only recovers from version-mismatch/desync errors — so a legitimate >1,000-step transaction is rejected, its steps stay unconfirmed, and every later edit resends the oversized batch and is rejected again: synchronization is wedged for the rest of the session. A server-only cap converts the DoS bound into a session poison for large legitimate edits.

Resume conditions for PR #4051 (task 5056 parked on these):

  1. Coordinate the limit with the client: chunk pending steps in web/src/collab.ts at or below the server bound (1000), or make the over-limit rejection a recoverable error class the client already handles — so legitimate large transactions still synchronize.
  2. Run the PR's regression tests (over-size refusal, over-bound Steps refusal with version/history unchanged, normal Steps apply/ack/broadcast) — they were deferred under laptop load in all prior attempts and have never passed on record.
  3. Re-run the Codex gate after the fix round, then merge and complete task 5056 as fixed_merged.

The server-side bound itself matches the packet (triage-pinned 1000, MAX_FRAME_BYTES 1 MiB); the gap is only the client coordination.

…ns still sync (#1965)

Codex P2 on PR #4051: indenting >1000 lines produces one step per line, and handleEditorChange sent the whole pending batch in one Steps message; the new server rejection left the steps unconfirmed with no recovery path, wedging sync for the session. The client now sends at most MAX_STEPS_PER_MESSAGE (1000, mirroring collab.rs) per message via stepBatch(), and the Update handler flushes the next batch once receiveTransaction confirms the previous one. Adds stepBatch unit tests in collab.test.ts.

@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: e3e95d45fc

ℹ️ 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 pkgs/id/src/web/collab.rs
state.identity,
)
})
ws.max_message_size(MAX_FRAME_BYTES)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Guard oversized edits before sending bounded messages

When a user pastes more than 1 MiB of text, ProseMirror can represent the insertion as a single replace step, so the new count-based stepBatch() still sends a message exceeding this limit. The server rejects it before applying the edit, and the client's reconnect path in web/src/collab.ts destroys the existing editor and initializes it from server state, silently discarding the paste. Coordinate the transport limit with client-side encoded-size handling, including individual oversized steps, so legitimate edits are split safely or rejected locally without losing their content.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in cea81a3 (client side, pkgs/id/web/src/collab.ts):

  • stepBatch is now size-aware, not just count-aware: it also stops at MAX_STEPS_MESSAGE_BYTES (the 1 MiB server frame cap minus an envelope reserve), measuring each step with the exact MessagePack encoder the send path uses. A batch of medium steps can no longer encode past the cap and be refused whole. Tests cover size chunking, the exact-fit boundary, and the oversized-first-step case.
  • A single step that alone exceeds the budget (the >1 MiB paste case) yields an empty batch, and handleEditorChange withholds it with an error log instead of sending it: the edit stays in the local document rather than being refused by the server and silently discarded by the reconnect re-init.

One part is deliberately not done by splitting steps on the wire: prosemirror-collab confirms unconfirmed steps by count from the server's echo, so turning one local step into several wire steps would corrupt confirmation bookkeeping. True chunked sync of a single oversized insertion has to happen at dispatch time in the editor (several transactions), which is a separate change — filed as a follow-up issue (linked below) rather than improvised here.

stepBatch chunked by step count only, so a batch of medium steps could
still encode past the 1 MiB server frame cap and be refused whole
(Codex P2 on PR #4051). stepBatch now also stops at
MAX_STEPS_MESSAGE_BYTES (frame cap minus envelope reserve) using the
exact MessagePack size of each step. A first step that alone exceeds
the budget yields an empty batch and handleEditorChange withholds it
with an error log: the edit stays in the local document instead of
being sent, refused, and silently discarded by the reconnect re-init.
Splitting one step into several wire steps is not safe here -
prosemirror-collab confirms unconfirmed steps by count from the
server echo.
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