fix(ddp-client): never queue non-method frames behind a wait block#40307
fix(ddp-client): never queue non-method frames behind a wait block#40307
Conversation
|
Looks like this PR is not ready to merge, because of the following issues:
Please fix the issues and try again If you have any trouble, please check the PR guidelines |
🦋 Changeset detectedLatest commit: e2b2d26 The changes in this PR will be included in the next version bump. This PR includes changesets to release 41 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (2)
📜 Recent review details⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
🧰 Additional context used📓 Path-based instructions (2)**/*.{ts,tsx,js}📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)
Files:
**/*.spec.ts📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)
Files:
🧠 Learnings (9)📓 Common learnings📚 Learning: 2025-11-24T17:08:17.065ZApplied to files:
📚 Learning: 2025-11-24T17:08:17.065ZApplied to files:
📚 Learning: 2025-11-24T17:08:17.065ZApplied to files:
📚 Learning: 2025-11-24T17:08:17.065ZApplied to files:
📚 Learning: 2026-02-24T19:22:48.358ZApplied to files:
📚 Learning: 2026-02-26T19:25:44.063ZApplied to files:
📚 Learning: 2026-02-26T19:25:44.063ZApplied to files:
📚 Learning: 2026-03-06T18:10:15.268ZApplied to files:
🔇 Additional comments (1)
WalkthroughFixes a bug in Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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. Comment |
54a2e5e to
82378f8
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/ddp-client/src/DDPDispatcher.ts (1)
19-38: Correct fix; consider trimming the inline rationale per project style.The branch on
payload.msg !== 'method'correctly partitions theOutgoingPayloadunion — onlyMethodPayloadcarriesmsg: 'method', so all protocol frames (connect,sub/unsub,ping/pong) bypass the wait queue while the existing serialization for methods is preserved unchanged. Behavior aligns with the consumer dispatch sites inMinimalDDPClient.ts(subscribe/connect/ping/pong).That said, the multi-line implementation comment at lines 20–26 conflicts with the project's "avoid code comments in the implementation" rule. The rationale would be better captured in the changeset/PR description (which already covers it) or in a unit test name, leaving the source terse.
♻️ Proposed style tweak
override dispatch(payload: OutgoingPayload, options?: { wait?: boolean }) { - // Only method payloads participate in the wait/queue serialization that - // implements Meteor's wait-method semantics. Protocol-level frames - // (connect, sub, unsub, ping, pong) must be delivered immediately: - // queueing a `connect` frame behind a wait `login` block, for example, - // wedges the DDP handshake — the socket opens but `connect` never - // reaches the server, so the server never replies `connected` and the - // session never establishes. if (payload.msg !== 'method') { this.emit('send', payload); return; }As per coding guidelines: "Avoid code comments in the implementation".
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/ddp-client/src/DDPDispatcher.ts` around lines 19 - 38, The multi-line implementation comment above the dispatch method is too verbose per the "avoid code comments in the implementation" guideline; keep the behavior but remove or replace the long rationale with a concise one-line comment (or move the detailed explanation to the PR description or a unit test name). Specifically, in dispatch (method signature dispatch(payload: OutgoingPayload, ...)) leave the short intent comment (or none), retain the existing logic that checks payload.msg !== 'method' and calls this.emit('send', payload), the options?.wait branch that calls this.wait(payload), and the this.pushItem(payload) branch unchanged; just trim the explanatory block to a single brief line or remove it entirely.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/ddp-client/src/DDPDispatcher.ts`:
- Around line 19-38: The multi-line implementation comment above the dispatch
method is too verbose per the "avoid code comments in the implementation"
guideline; keep the behavior but remove or replace the long rationale with a
concise one-line comment (or move the detailed explanation to the PR description
or a unit test name). Specifically, in dispatch (method signature
dispatch(payload: OutgoingPayload, ...)) leave the short intent comment (or
none), retain the existing logic that checks payload.msg !== 'method' and calls
this.emit('send', payload), the options?.wait branch that calls
this.wait(payload), and the this.pushItem(payload) branch unchanged; just trim
the explanatory block to a single brief line or remove it entirely.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 40d19712-78e1-4707-b629-f549b056354c
📒 Files selected for processing (3)
.changeset/ddp-dispatcher-non-method-frames.mdpackages/ddp-client/__tests__/DDPDispatcher.spec.tspackages/ddp-client/src/DDPDispatcher.ts
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: CodeQL-Build
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx,js}
📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)
**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation
Files:
packages/ddp-client/__tests__/DDPDispatcher.spec.tspackages/ddp-client/src/DDPDispatcher.ts
**/*.spec.ts
📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)
**/*.spec.ts: Use descriptive test names that clearly communicate expected behavior in Playwright tests
Use.spec.tsextension for test files (e.g.,login.spec.ts)
Files:
packages/ddp-client/__tests__/DDPDispatcher.spec.ts
🧠 Learnings (10)
📓 Common learnings
Learnt from: smirk-dev
Repo: RocketChat/Rocket.Chat PR: 39625
File: apps/meteor/app/api/server/v1/push.ts:85-97
Timestamp: 2026-03-14T14:58:58.834Z
Learning: In RocketChat/Rocket.Chat, the `push.token` POST/DELETE endpoints in `apps/meteor/app/api/server/v1/push.ts` were already migrated to the chained router API pattern on `develop` prior to PR `#39625`. `cleanTokenResult` (which strips `authToken` and returns `PushTokenResult`) and `isPushTokenPOSTProps`/`isPushTokenDELETEProps` validators already exist on `develop`. PR `#39625` only migrates `push.get` and `push.info` to the chained pattern. Do not flag `cleanTokenResult` or `PushTokenResult` as newly introduced behavior-breaking changes when reviewing this PR.
Learnt from: d-gubert
Repo: RocketChat/Rocket.Chat PR: 39857
File: apps/meteor/app/lib/server/lib/debug.js:87-91
Timestamp: 2026-04-23T18:14:24.851Z
Learning: In `apps/meteor/app/lib/server/lib/debug.js`, the `wrapMethods` function wraps Meteor DDP method handlers inside a `tracerActiveSpan` callback. The `end()` (summary timer) and `endHistogram()` (histogram timer) calls are placed after `await originalHandler.apply(this, originalArgs)` without a try/finally guard. This is intentional and safe: errors thrown by Meteor method handlers are caught by the route-handler action wrapper in `apps/meteor/app/api/server/ApiClass.ts` (around line 892-893), which converts them into proper response objects, so execution flow is never disrupted and the timer calls are always reached. Do not flag the missing try/finally as a bug for these timer calls in `debug.js`.
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Implement proper wait strategies for dynamic content in Playwright tests
Applied to files:
packages/ddp-client/__tests__/DDPDispatcher.spec.ts
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Ensure tests run reliably in parallel without shared state conflicts
Applied to files:
packages/ddp-client/__tests__/DDPDispatcher.spec.ts
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Use `page.waitFor()` with specific conditions instead of hardcoded timeouts in Playwright tests
Applied to files:
packages/ddp-client/__tests__/DDPDispatcher.spec.ts
📚 Learning: 2026-02-24T19:22:48.358Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 38493
File: apps/meteor/tests/e2e/omnichannel/omnichannel-send-pdf-transcript.spec.ts:66-67
Timestamp: 2026-02-24T19:22:48.358Z
Learning: In Playwright end-to-end tests (e.g., under apps/meteor/tests/e2e/...), prefer locating elements by translated text (getByText) and ARIA roles (getByRole) over data-qa attributes. If translation values change, update the corresponding test locators accordingly. Never use data-qa locators. This guideline applies to all Playwright e2e test specs in the repository and helps keep tests robust to UI text changes and accessible semantics.
Applied to files:
packages/ddp-client/__tests__/DDPDispatcher.spec.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.
Applied to files:
packages/ddp-client/__tests__/DDPDispatcher.spec.tspackages/ddp-client/src/DDPDispatcher.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.
Applied to files:
packages/ddp-client/__tests__/DDPDispatcher.spec.tspackages/ddp-client/src/DDPDispatcher.ts
📚 Learning: 2026-03-06T18:10:15.268Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 39397
File: packages/gazzodown/src/code/CodeBlock.spec.tsx:47-68
Timestamp: 2026-03-06T18:10:15.268Z
Learning: In tests (especially those using testing-library/dom/jsdom) for Rocket.Chat components, the HTML <code> element has an implicit ARIA role of 'code'. Therefore, screen.getByRole('code') or screen.findByRole('code') will locate <code> elements even without a role attribute. Do not flag findByRole('code') as invalid in reviews; prefer using the implicit role instead of adding role="code" unless necessary for accessibility.
Applied to files:
packages/ddp-client/__tests__/DDPDispatcher.spec.ts
📚 Learning: 2026-02-25T20:10:16.987Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 38913
File: packages/ddp-client/src/legacy/types/SDKLegacy.ts:34-34
Timestamp: 2026-02-25T20:10:16.987Z
Learning: In the RocketChat/Rocket.Chat monorepo, packages/ddp-client and apps/meteor do not use TypeScript project references. Module augmentations in apps/meteor (e.g., declare module 'rocket.chat/rest-typings') are not visible when compiling packages/ddp-client in isolation, which is why legacy SDK methods that depend on OperationResult types for OpenAPI-migrated endpoints must remain commented out.
Applied to files:
.changeset/ddp-dispatcher-non-method-frames.md
📚 Learning: 2026-03-16T21:50:37.589Z
Learnt from: amitb0ra
Repo: RocketChat/Rocket.Chat PR: 39676
File: .changeset/migrate-users-register-openapi.md:3-3
Timestamp: 2026-03-16T21:50:37.589Z
Learning: For changes related to OpenAPI migrations in Rocket.Chat/OpenAPI, when removing endpoint types and validators from rocket.chat/rest-typings (e.g., UserRegisterParamsPOST, /v1/users.register) document this as a minor changeset (not breaking) per RocketChat/Rocket.Chat-Open-API#150 Rule 7. Note that the endpoint type is re-exposed via a module augmentation .d.ts in the consuming package (e.g., packages/web-ui-registration/src/users-register.d.ts). In reviews, ensure the changeset clearly states: this is a non-breaking change, the major version should not be bumped, and the changeset reflects a minor version bump. Do not treat this as a breaking change during OpenAPI migrations.
Applied to files:
.changeset/ddp-dispatcher-non-method-frames.md
🔇 Additional comments (2)
packages/ddp-client/__tests__/DDPDispatcher.spec.ts (1)
75-101: Solid regression coverage.The test exercises the exact wedge scenario: a
{ wait: true }method at the queue head followed byconnect/subframes. Assertions verify both emission order/count via thesendlistener and the residual queue shape ([{ wait: true, items: [login] }]), confirming the non-method frames bypass the queue without consuming the pending wait block..changeset/ddp-dispatcher-non-method-frames.md (1)
1-5: Changeset is appropriately scoped.Patch bump matches the nature of the fix (no public API surface change), and the description concisely captures the symptom (handshake wedge) and the remediation.
DDPDispatcher's pushItem path runs for every payload that goes through dispatch — including connect, sub, unsub, and ping/pong. When the head of the queue is a wait block (e.g. a login), pushItem deliberately returns without sending so the next method waits. Applied to a non- method payload, that means the connect frame ws.onopen emits gets dropped on the floor: the socket sits open, the DDP handshake never happens, and any caller waiting on `connected` hangs forever. Visible failure mode: token-resume on page reload dispatched the wait login while the socket was still connecting; when ws.onopen later fired the connect frame, it was queued behind that login and never sent. Status stuck at "connecting". Fix: short-circuit dispatch for any payload whose msg is not 'method' — emit it straight away. Wait/queue serialization is a property of method calls, not protocol frames.
82378f8 to
e2b2d26
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #40307 +/- ##
===========================================
+ Coverage 69.81% 69.85% +0.03%
===========================================
Files 3296 3296
Lines 119173 119176 +3
Branches 21468 21476 +8
===========================================
+ Hits 83198 83246 +48
+ Misses 32675 32634 -41
+ Partials 3300 3296 -4
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
Summary
DDPDispatcherwas routing every outgoing payload (connect, sub, unsub, ping, pong, method) through the same wait-block serialization path. When the head of the queue was a wait method (e.g.login({resume})), a subsequentconnectframe got queued in a new non-wait block but never sent.connected, and anyone waiting onsdk.connectionhangs.DDPDispatcher.dispatchfor any payload whosemsgis not'method'— emit it straight through. Method serialization between methods is unchanged.Repro that motivated this
In a downstream branch I routed token-resume (
Meteor.loginWithToken) through@rocket.chat/ddp-clientbefore the SDK had finished its initial handshake.account.loginWithTokendispatches withwait: true; that occupied the queue head, so whenws.onopenfiredclient.connect()theconnectframe was swallowed in a non-wait block thatpushItemdeliberately does not send. Status stuck atconnectingindefinitely.Scope
packages/ddp-client/src/DDPDispatcher.ts: widen thedispatchsignature toOutgoingPayload, branch onmsg.msg === 'method'.packages/ddp-client/__tests__/DDPDispatcher.spec.tsassertsconnectandsubpayloads are emitted immediately while a waitloginblock sits in the queue.Test plan
yarn workspace @rocket.chat/ddp-client jest— 50 tests, 0 failures.🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests
Chores