Repository navigation
fix(id): bound collab WebSocket input (#1965) - #4051
Conversation
|
Warning Review limit reachedYou'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. View limit details
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. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 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".
| if steps.len() > MAX_STEPS_PER_MESSAGE { | ||
| return Err(format!( | ||
| "Step batch exceeds maximum of {MAX_STEPS_PER_MESSAGE} steps" | ||
| )); |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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.
|
🤖 Agent note · Codex gate analysis (queue task 5056, lane A) The Codex P2 on Resume conditions for PR #4051 (task 5056 parked on these):
The server-side bound itself matches the packet (triage-pinned 1000, |
…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.
There was a problem hiding this comment.
💡 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".
| state.identity, | ||
| ) | ||
| }) | ||
| ws.max_message_size(MAX_FRAME_BYTES) |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
Fixed in cea81a3 (client side, pkgs/id/web/src/collab.ts):
stepBatchis now size-aware, not just count-aware: it also stops atMAX_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
handleEditorChangewithholds 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.
Summary
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
rustfmt --edition 2024 --checkandgit diff --checkpass. Local cargo tests were not run because the laptop had 66 Rust compiler processes and high load; CI is the test gate.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.
Need help on this PR? Tag
@codesmith-botwith what you need.