Skip to content

Conversation

@rocketchat-github-ci
Copy link
Collaborator

@rocketchat-github-ci rocketchat-github-ci commented Dec 19, 2025

Summary by CodeRabbit

  • Chores

    • Added multiple patch changesets and a security hotfix note; CI/workflow and Docker build tweaks to slim images and adjust node setup.
  • New Features

    • Presence: refreshes on heartbeat events, throttled client presence updates, and a new API to update individual connections.
    • Background reaper: periodically detects/removes stale sessions and triggers presence recalculation.
    • Users API: improved query validation and exposed default/full field sets for user lookups.
  • Tests

    • Added comprehensive tests for the reaper’s batching and stale-connection handling.

✏️ Tip: You can customize this high-level summary in your review settings.

You can see below a preview of the release change log:

7.13.2

Engine versions

  • Node: 22.16.0
  • Deno: 1.43.5
  • MongoDB: 5, 6, 7, 8
  • Apps-Engine: 1.58.0

Patch Changes

  • Bump @rocket.chat/meteor version.

  • (#37876 by @dionisio-bot) Security Hotfix (https://docs.rocket.chat/docs/security-fixes-and-updates)

  • (#37883 by @dionisio-bot) Ensures presence stays accurate by refreshing connections on heartbeats and removing stale sessions.

  • Updated dependencies [eef2b39]:
    • @rocket.chat/core-services@0.11.2
    • @rocket.chat/presence@0.2.46
    • @rocket.chat/federation-matrix@0.0.8
    • @rocket.chat/network-broker@0.2.25
    • @rocket.chat/omni-core-ee@0.0.11
    • @rocket.chat/omnichannel-services@0.3.43
    • @rocket.chat/core-typings@7.13.2
    • @rocket.chat/rest-typings@7.13.2
    • @rocket.chat/license@1.1.6
    • @rocket.chat/media-calls@0.1.2
    • @rocket.chat/pdf-worker@0.3.25
    • @rocket.chat/api-client@0.2.46
    • @rocket.chat/apps@0.5.25
    • @rocket.chat/cron@0.1.46
    • @rocket.chat/freeswitch@1.2.33
    • @rocket.chat/fuselage-ui-kit@25.0.2
    • @rocket.chat/gazzodown@25.0.2
    • @rocket.chat/http-router@7.9.13
    • @rocket.chat/message-types@0.0.1
    • @rocket.chat/model-typings@1.9.2
    • @rocket.chat/ui-avatar@21.0.2
    • @rocket.chat/ui-client@25.0.2
    • @rocket.chat/ui-contexts@25.0.2
    • @rocket.chat/web-ui-registration@25.0.2
    • @rocket.chat/models@1.8.2
    • @rocket.chat/server-cloud-communication@0.0.2
    • @rocket.chat/ui-theming@0.4.4
    • @rocket.chat/ui-video-conf@25.0.2
    • @rocket.chat/ui-voip@15.0.2
    • @rocket.chat/instance-status@0.1.46
    • @rocket.chat/omni-core@0.0.11

@changeset-bot
Copy link

changeset-bot bot commented Dec 19, 2025

🦋 Changeset detected

Latest commit: aba62ef

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 41 packages
Name Type
@rocket.chat/meteor Patch
@rocket.chat/core-services Patch
@rocket.chat/ddp-streamer Patch
@rocket.chat/presence Patch
@rocket.chat/account-service Patch
@rocket.chat/authorization-service Patch
@rocket.chat/omnichannel-transcript Patch
@rocket.chat/presence-service Patch
@rocket.chat/queue-worker Patch
@rocket.chat/stream-hub-service Patch
@rocket.chat/federation-matrix Patch
@rocket.chat/network-broker Patch
@rocket.chat/omni-core-ee Patch
@rocket.chat/omnichannel-services Patch
rocketchat-services Patch
@rocket.chat/core-typings Patch
@rocket.chat/rest-typings Patch
@rocket.chat/uikit-playground Patch
@rocket.chat/api-client Patch
@rocket.chat/apps Patch
@rocket.chat/cron Patch
@rocket.chat/ddp-client Patch
@rocket.chat/freeswitch Patch
@rocket.chat/fuselage-ui-kit Patch
@rocket.chat/gazzodown Patch
@rocket.chat/http-router Patch
@rocket.chat/livechat Patch
@rocket.chat/model-typings Patch
@rocket.chat/ui-avatar Patch
@rocket.chat/ui-client Patch
@rocket.chat/ui-contexts Patch
@rocket.chat/web-ui-registration Patch
@rocket.chat/license Patch
@rocket.chat/media-calls Patch
@rocket.chat/pdf-worker Patch
@rocket.chat/models Patch
@rocket.chat/mock-providers Patch
@rocket.chat/ui-video-conf Patch
@rocket.chat/ui-voip Patch
@rocket.chat/instance-status Patch
@rocket.chat/omni-core Patch

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

@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Dec 19, 2025

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 19, 2025

Walkthrough

Adds heartbeat typings and a Heartbeat class; wires heartbeat-triggered presence updates in Meteor startup and DDP client; implements PresenceReaper to detect/remove stale sessions (with tests); exposes Presence.updateConnection API and IPresence method; exposes user field projections and adjusts query validation; adds changeset files.

Changes

Cohort / File(s) Summary
Changesets
\.changeset/bump-patch-1766148726545\.md, \.changeset/spicy-nails-design\.md, \.changeset/fast-ligers-unite\.md
Add changeset metadata files recording patch bumps (including @rocket.chat/meteor, core-services, ddp-streamer, presence) and a security hotfix banner.
DDP typings
apps/meteor/definition/externals/meteor/ddp-common.d.ts, apps/meteor/definition/externals/meteor/meteor.d.ts
Add DDPCommon.Heartbeat type and HeartbeatOptions; tighten Meteor.server typing to include sessions: Map<string, { userId: string; heartbeat: DDPCommon.Heartbeat }> and explicit publish_handlers.
Meteor startup (presence)
apps/meteor/ee/server/startup/presence.ts
Wrap session.heartbeat.messageReceived to call Presence.updateConnection on unseen heartbeats before delegating to original handler.
DDP client (streamer)
ee/apps/ddp-streamer/src/Client.ts
Invoke a throttled Presence.updateConnection on message/heartbeat parsing; add throttling to limit update frequency.
Presence service & API
ee/packages/presence/src/Presence.ts, packages/core-services/src/types/IPresence.ts
Add PresenceReaper integration (constructed, started/stopped, handler), add public updateConnection(uid, connectionId) and add updateConnection to IPresence interface.
PresenceReaper implementation & tests
ee/packages/presence/src/lib/PresenceReaper.ts, ee/packages/presence/src/lib/PresenceReaper.spec.ts
New PresenceReaper scans UsersSessions for stale connections, batches removals via bulkWrite, invokes onUpdate; comprehensive Jest tests validating detection, batching, and mixed-state handling.
User query & fields
apps/meteor/app/api/server/lib/isValidQuery.ts, apps/meteor/app/api/server/v1/users.ts, apps/meteor/app/lib/server/functions/getFullUserData.ts
Generalize operator handling and recursive validation in isValidQuery; export defaultFields and fullFields; adjust users.list and users.autocomplete query validation to allow default regex queries and dynamic allowed fields based on permissions.
Tests (isValidQuery)
apps/meteor/tests/unit/app/api/server/v1/lib/isValidQuery.spec.ts
Adjust tests to permit $regex in shallow-keys test and add a test asserting nested disallowed operators produce an error.
CI / Docker build
.github/actions/build-docker/action.yml, .github/actions/setup-node/action.yml, apps/meteor/.docker/Dockerfile.alpine
Prune platform-specific native binaries during image slimming; reorder cache key components and add yarn architecture config steps; simplify sharp handling in Alpine Dockerfile (remove extra install/move steps).

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Client as DDP Client
  participant Meteor as Meteor Server (session.heartbeat)
  participant PresenceSvc as Presence Service
  participant DB as UsersSessions (DB)

  Note over Client,Meteor: Message / Heartbeat path
  Client->>Meteor: send message / heartbeat
  Meteor->>Meteor: session.heartbeat.messageReceived()
  Meteor->>PresenceSvc: updateConnection(uid, connectionId)
  activate PresenceSvc
  PresenceSvc->>DB: update UsersSessions._updatedAt for connection
  DB-->>PresenceSvc: update result
  PresenceSvc-->>Meteor: return { uid, connectionId }
  deactivate PresenceSvc

  Note over PresenceSvc,DB: Reaper periodic flow
  loop every 60s
    PresenceSvc->>PresenceSvc: PresenceReaper.run()
    PresenceSvc->>DB: find sessions with _updatedAt <= cutoff
    DB-->>PresenceSvc: cursor/documents
    PresenceSvc->>DB: bulkWrite to pull stale connections (batched)
    DB-->>PresenceSvc: bulkWrite result
    PresenceSvc->>PresenceSvc: onUpdate(userIds) -> handleReaperUpdates
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • Areas needing extra attention:
    • PresenceReaper.run(): cursor iteration, batching, bulkWrite construction, and cutoff guard correctness.
    • Concurrency/race conditions around _updatedAt <= cutoffDate and simultaneous updates.
    • Meteor startup wrapper: preserving original messageReceived semantics and error handling.
    • Throttling in ddp-streamer Client: ensure update frequency and leading/trailing semantics are correct.
    • Typings changes (DDPCommon.Heartbeat, Meteor.server, IPresence) for downstream compatibility.

Possibly related PRs

Suggested labels

stat: ready to merge, stat: QA assured

Suggested reviewers

  • ggazzo
  • rodrigok
  • sampaiodiego

Poem

🐇 I hopped on heartbeats in the night,
I nudged each session back to light,
I reaped stale crumbs with careful paw,
Throttled the chatter, updated the maw.
Hop, version bumped — a carrot for all!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Release 7.13.2' directly corresponds to the PR's purpose of releasing version 7.13.2, with changeset files and version bumps documented throughout the changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch release-7.13.2

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 and usage tips.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 19, 2025

📦 Docker Image Size Report

📈 Changes

Service Current Baseline Change Percent
sum of all images 1.2GiB 1.2GiB +44MiB
rocketchat 369MiB 347MiB +22MiB
omnichannel-transcript-service 141MiB 132MiB +9.3MiB
queue-worker-service 141MiB 132MiB +9.3MiB
ddp-streamer-service 127MiB 126MiB +582KiB
account-service 114MiB 113MiB +587KiB
stream-hub-service 111MiB 110MiB +585KiB
presence-service 111MiB 110MiB +581KiB
authorization-service 111MiB 111MiB +526KiB

📊 Historical Trend

---
config:
  theme: "dark"
  xyChart:
    width: 900
    height: 400
---
xychart
  title "Image Size Evolution by Service (Last 30 Days + This PR)"
  x-axis ["11/15 22:28", "11/16 01:28", "11/17 23:50", "11/18 22:53", "11/19 23:02", "11/21 16:49", "11/24 17:34", "11/27 22:32", "11/28 19:05", "12/01 23:01", "12/02 21:57", "12/03 21:00", "12/04 18:17", "12/05 21:56", "12/08 20:15", "12/09 22:17", "12/10 23:26", "12/11 21:56", "12/12 22:45", "12/13 01:34", "12/15 22:31", "12/16 22:18", "12/17 21:04", "12/18 23:12", "12/19 14:46", "12/19 16:22 (PR)"]
  y-axis "Size (GB)" 0 --> 0.5
  line "account-service" [0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11]
  line "authorization-service" [0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11]
  line "ddp-streamer-service" [0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12]
  line "omnichannel-transcript-service" [0.14, 0.14, 0.14, 0.14, 0.14, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.14]
  line "presence-service" [0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11]
  line "queue-worker-service" [0.14, 0.14, 0.14, 0.14, 0.14, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.14]
  line "rocketchat" [0.36, 0.36, 0.35, 0.35, 0.35, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.36]
  line "stream-hub-service" [0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11]
Loading

Statistics (last 25 days):

  • 📊 Average: 1.5GiB
  • ⬇️ Minimum: 1.2GiB
  • ⬆️ Maximum: 1.6GiB
  • 🎯 Current PR: 1.2GiB
ℹ️ About this report

This report compares Docker image sizes from this build against the develop baseline.

  • Tag: pr-37881
  • Baseline: develop
  • Timestamp: 2025-12-19 16:22:02 UTC
  • Historical data points: 25

Updated: Fri, 19 Dec 2025 16:22:02 GMT

…tale (#37883)

Co-authored-by: Matheus Cardoso <5606812+cardoso@users.noreply.github.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
ee/packages/presence/src/lib/PresenceReaper.spec.ts (1)

68-92: Good test coverage for PresenceReaper scenarios.

The tests correctly validate:

  • Empty cursor handling
  • Stale connection detection
  • Batch processing with correct grouping
  • Mixed connection states

Consider adding assertions on bulkWriteMock to verify the actual database operations match expectations (e.g., correct $pull operations with the expected connection IDs and cutoff dates).

🔎 Example assertion for bulkWrite verification
expect(bulkWriteMock).toHaveBeenCalledWith(
  expect.arrayContaining([
    expect.objectContaining({
      updateOne: expect.objectContaining({
        filter: { _id: 'user-789' },
      }),
    }),
  ]),
);
ee/packages/presence/src/lib/PresenceReaper.ts (1)

108-131: Race condition protection is well implemented.

The $pull operation correctly includes both id: { $in: plan.removeIds } and _updatedAt: { $lte: plan.cutoffDate }, ensuring only connections that haven't been refreshed since the scan are removed.

Consider wrapping bulkWrite in a try-catch to prevent onUpdate from being called if the database operation fails:

🔎 Suggested error handling
 	private async flushBatch(changeMap: Map<string, ReaperPlan>): Promise<void> {
 		const operations = [];
 		// ... build operations ...

 		if (isNonEmptyArray(operations)) {
-			await UsersSessions.col.bulkWrite(operations);
-			await this.onUpdate(operations.map((op) => op.updateOne.filter._id));
+			try {
+				await UsersSessions.col.bulkWrite(operations);
+				await this.onUpdate(operations.map((op) => op.updateOne.filter._id));
+			} catch (err) {
+				console.error('[PresenceReaper] flushBatch error:', err);
+				throw err;
+			}
 		}
 	}
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between c6261fe and eef2b39.

📒 Files selected for processing (9)
  • .changeset/spicy-nails-design.md (1 hunks)
  • apps/meteor/definition/externals/meteor/ddp-common.d.ts (1 hunks)
  • apps/meteor/definition/externals/meteor/meteor.d.ts (2 hunks)
  • apps/meteor/ee/server/startup/presence.ts (1 hunks)
  • ee/apps/ddp-streamer/src/Client.ts (5 hunks)
  • ee/packages/presence/src/Presence.ts (5 hunks)
  • ee/packages/presence/src/lib/PresenceReaper.spec.ts (1 hunks)
  • ee/packages/presence/src/lib/PresenceReaper.ts (1 hunks)
  • packages/core-services/src/types/IPresence.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .changeset/spicy-nails-design.md
🧰 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:

  • apps/meteor/ee/server/startup/presence.ts
  • packages/core-services/src/types/IPresence.ts
  • ee/packages/presence/src/lib/PresenceReaper.spec.ts
  • apps/meteor/definition/externals/meteor/ddp-common.d.ts
  • ee/packages/presence/src/Presence.ts
  • ee/packages/presence/src/lib/PresenceReaper.ts
  • apps/meteor/definition/externals/meteor/meteor.d.ts
  • ee/apps/ddp-streamer/src/Client.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.ts extension for test files (e.g., login.spec.ts)

Files:

  • ee/packages/presence/src/lib/PresenceReaper.spec.ts
🧠 Learnings (10)
📓 Common learnings
Learnt from: cardoso
Repo: RocketChat/Rocket.Chat PR: 36942
File: apps/meteor/client/lib/e2ee/keychain.ts:148-156
Timestamp: 2025-10-16T21:09:51.816Z
Learning: In the RocketChat/Rocket.Chat repository, only platforms with native crypto.randomUUID() support are targeted, so fallback implementations for crypto.randomUUID() are not required in E2EE or cryptographic code.
Learnt from: MartinSchoeler
Repo: RocketChat/Rocket.Chat PR: 37408
File: apps/meteor/client/views/admin/ABAC/useRoomAttributeOptions.tsx:53-69
Timestamp: 2025-11-10T19:06:20.146Z
Learning: In the Rocket.Chat repository, do not provide suggestions or recommendations about code sections marked with TODO comments. The maintainers have already identified these as future work and external reviewers lack the full context about implementation plans and timing.
Learnt from: d-gubert
Repo: RocketChat/Rocket.Chat PR: 37547
File: packages/i18n/src/locales/en.i18n.json:634-634
Timestamp: 2025-11-19T12:32:29.696Z
Learning: Repo: RocketChat/Rocket.Chat
Context: i18n workflow
Learning: In this repository, new translation keys should be added to packages/i18n/src/locales/en.i18n.json only; other locale files are populated via the external translation pipeline and/or fall back to English. Do not request adding the same key to all locale files in future reviews.
📚 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:

  • ee/packages/presence/src/lib/PresenceReaper.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 clean state for each test execution in Playwright tests

Applied to files:

  • ee/packages/presence/src/lib/PresenceReaper.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 : Utilize Playwright fixtures (`test`, `page`, `expect`) for consistency in test files

Applied to files:

  • ee/packages/presence/src/lib/PresenceReaper.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 : Maintain test isolation between test cases in Playwright tests

Applied to files:

  • ee/packages/presence/src/lib/PresenceReaper.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 `test.step()` for complex test scenarios to improve organization in Playwright tests

Applied to files:

  • ee/packages/presence/src/lib/PresenceReaper.spec.ts
📚 Learning: 2025-12-10T21:00:43.645Z
Learnt from: KevLehman
Repo: RocketChat/Rocket.Chat PR: 37091
File: ee/packages/abac/jest.config.ts:4-7
Timestamp: 2025-12-10T21:00:43.645Z
Learning: Adopt the monorepo-wide Jest testMatch pattern: <rootDir>/src/**/*.spec.{ts,js,mjs} (represented here as '**/src/**/*.spec.{ts,js,mjs}') to ensure spec files under any package's src directory are picked up consistently across all packages in the Rocket.Chat monorepo. Apply this pattern in jest.config.ts for all relevant packages to maintain uniform test discovery.

Applied to files:

  • ee/packages/presence/src/lib/PresenceReaper.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 `test.beforeAll()` and `test.afterAll()` for setup/teardown in Playwright tests

Applied to files:

  • ee/packages/presence/src/lib/PresenceReaper.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 : Implement proper wait strategies for dynamic content in Playwright tests

Applied to files:

  • ee/packages/presence/src/lib/PresenceReaper.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/**/*.{ts,spec.ts} : Follow Page Object Model pattern consistently in Playwright tests

Applied to files:

  • ee/packages/presence/src/lib/PresenceReaper.spec.ts
🧬 Code graph analysis (6)
apps/meteor/ee/server/startup/presence.ts (1)
ee/packages/presence/src/Presence.ts (1)
  • Presence (12-334)
ee/packages/presence/src/lib/PresenceReaper.spec.ts (2)
ee/packages/presence/src/lib/PresenceReaper.ts (1)
  • PresenceReaper (27-132)
packages/models/src/index.ts (1)
  • registerModel (138-138)
ee/packages/presence/src/Presence.ts (2)
ee/packages/presence/src/lib/PresenceReaper.ts (1)
  • PresenceReaper (27-132)
packages/models/src/index.ts (1)
  • UsersSessions (216-216)
ee/packages/presence/src/lib/PresenceReaper.ts (1)
packages/models/src/index.ts (1)
  • UsersSessions (216-216)
apps/meteor/definition/externals/meteor/meteor.d.ts (1)
ee/apps/ddp-streamer/src/configureServer.ts (1)
  • server (10-10)
ee/apps/ddp-streamer/src/Client.ts (1)
ee/packages/presence/src/Presence.ts (1)
  • Presence (12-334)
🔇 Additional comments (10)
packages/core-services/src/types/IPresence.ts (1)

16-16: LGTM!

The new updateConnection method signature is consistent with existing methods like newConnection and removeConnection, using the same return type pattern.

ee/apps/ddp-streamer/src/Client.ts (2)

185-195: Correct implementation of heartbeat-based presence tracking.

The logic properly ensures:

  1. Early return if packet was already seen or no userId (prevents duplicate updates)
  2. Sets _seenPacket = true before the async call to prevent races
  3. Error handling with logged context

206-211: Clean integration with the idle/heartbeat cycle.

The conditional _seenPacket = false reset only for authenticated users (this.userId exists) correctly scopes presence tracking to logged-in connections.

ee/packages/presence/src/lib/PresenceReaper.ts (1)

45-53: Lifecycle management is correct.

The running guard prevents multiple intervals, and the 60-second interval is reasonable for reaping stale connections.

apps/meteor/definition/externals/meteor/meteor.d.ts (1)

42-47: Good improvement replacing any with proper types.

The typed server structure enables compile-time checking for the heartbeat-related code in presence.ts. DDPCommon.Heartbeat includes both the _seenPacket property and messageReceived() method accessed in the presence startup code.

apps/meteor/ee/server/startup/presence.ts (1)

43-51: Code correctly implements presence tracking via Heartbeat interception.

The implementation is sound. While _seenPacket follows underscore naming convention, it's explicitly declared as a public property in Meteor's DDPCommon.Heartbeat class type definitions, making it part of the documented API. The pattern correctly binds the original handler, handles errors gracefully, and achieves efficient presence detection by triggering updates only on the first packet of each heartbeat cycle. No changes required.

apps/meteor/definition/externals/meteor/ddp-common.d.ts (1)

18-80: LGTM! Well-structured type definitions.

The HeartbeatOptions type and Heartbeat class declarations are accurate and complete. The types correctly model the heartbeat lifecycle management with appropriate timer handle types and callback signatures.

ee/packages/presence/src/Presence.ts (3)

34-38: LGTM! Reaper properly initialized.

The PresenceReaper is configured with reasonable thresholds (5-minute staleness) and batch size (500), with the callback correctly bound to the instance method.


84-85: LGTM! Clean lifecycle integration and error handling.

The reaper is properly started and stopped in the lifecycle hooks. The handleReaperUpdates method uses Promise.allSettled to handle batch updates gracefully, with appropriate logging for successes and failures.

Also applies to: 102-117, 119-120


168-188: LGTM! Correct implementation of connection timestamp update.

The updateConnection method correctly uses MongoDB's positional operator to update the matched connection's timestamp, then triggers presence recalculation. The early return when nothing is modified avoids unnecessary work.

dionisio-bot bot and others added 2 commits December 19, 2025 14:58
…#37887)

Co-authored-by: Matheus Cardoso <5606812+cardoso@users.noreply.github.com>
Co-authored-by: Julio Araujo <julio.araujo@rocket.chat>
Co-authored-by: Ricardo Garim <rswarovsky@gmail.com>
@julio-rocketchat julio-rocketchat requested a review from a team as a code owner December 19, 2025 15:45
@codecov
Copy link

codecov bot commented Dec 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.80%. Comparing base (4eeab1e) to head (f8154f1).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #37881      +/-   ##
==========================================
+ Coverage   67.78%   67.80%   +0.01%     
==========================================
  Files        3445     3445              
  Lines      113935   113928       -7     
  Branches    20844    20841       -3     
==========================================
+ Hits        77233    77245      +12     
+ Misses      34587    34566      -21     
- Partials     2115     2117       +2     
Flag Coverage Δ
e2e 57.45% <ø> (+0.05%) ⬆️
e2e-api 42.46% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Co-authored-by: Rodrigo Nascimento <234261+rodrigok@users.noreply.github.com>
@kodiakhq kodiakhq bot requested a review from a team as a code owner December 19, 2025 20:03
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between f8154f1 and aba62ef.

📒 Files selected for processing (3)
  • .github/actions/build-docker/action.yml (1 hunks)
  • .github/actions/setup-node/action.yml (2 hunks)
  • apps/meteor/.docker/Dockerfile.alpine (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: cardoso
Repo: RocketChat/Rocket.Chat PR: 36942
File: apps/meteor/client/lib/e2ee/keychain.ts:148-156
Timestamp: 2025-10-16T21:09:51.816Z
Learning: In the RocketChat/Rocket.Chat repository, only platforms with native crypto.randomUUID() support are targeted, so fallback implementations for crypto.randomUUID() are not required in E2EE or cryptographic code.
Learnt from: MartinSchoeler
Repo: RocketChat/Rocket.Chat PR: 37408
File: apps/meteor/client/views/admin/ABAC/useRoomAttributeOptions.tsx:53-69
Timestamp: 2025-11-10T19:06:20.146Z
Learning: In the Rocket.Chat repository, do not provide suggestions or recommendations about code sections marked with TODO comments. The maintainers have already identified these as future work and external reviewers lack the full context about implementation plans and timing.
Learnt from: d-gubert
Repo: RocketChat/Rocket.Chat PR: 37547
File: packages/i18n/src/locales/en.i18n.json:634-634
Timestamp: 2025-11-19T12:32:29.696Z
Learning: Repo: RocketChat/Rocket.Chat
Context: i18n workflow
Learning: In this repository, new translation keys should be added to packages/i18n/src/locales/en.i18n.json only; other locale files are populated via the external translation pipeline and/or fall back to English. Do not request adding the same key to all locale files in future reviews.
🔇 Additional comments (4)
.github/actions/setup-node/action.yml (2)

54-55: Cache key improvements look good.

The inclusion of .yarnrc.yml in the cache key ensures that yarn configuration changes properly invalidate the cache. The version bump to -v5 will invalidate existing caches, which is appropriate given the architecture configuration changes introduced in this PR.


78-83: Architecture configuration aligns with PR objective.

This configuration ensures that both arm64 and x64 (amd64) binaries are fetched, which should resolve the missing amd64 binaries issue mentioned in the PR objective. The step is correctly positioned before yarn install and appropriately conditional on inputs.install.

Note: This will increase installation time and cache size as binaries for multiple architectures will be downloaded.

.github/actions/build-docker/action.yml (1)

87-93: Verify sharp, pinyin, and esbuild binary removal patterns work correctly against actual bundle structure.

The find commands use specific patterns to remove unwanted platform binaries, but these need validation against the actual directory names created during npm install:

  • Line 87 (sharp): The pattern *-linuxmusl-${swc_arch} should match musl-variant distributions
  • Line 89 (pinyin): The pattern *-linux-${swc_arch}-* needs verification for correct napi-rs naming
  • Lines 91, 93 (esbuild): The pattern *-${swc_arch} should correctly match esbuild's platform packages

If patterns don't match the actual directory/package names installed, the wrong binaries may remain, potentially causing runtime failures. Consider testing these patterns against a sample bundle or adding verbose logging to confirm what directories are being matched and removed.

apps/meteor/.docker/Dockerfile.alpine (1)

11-12: Good simplification that correctly addresses the binary installation issue.

The removal of custom sharp handling in favor of standard npm install --omit=dev is the right approach. Sharp is a runtime dependency (used in FileUpload.ts, emoji-custom, assets.ts, and avatar utilities), and this change correctly handles it by:

  1. Running npm install --omit=dev in the builder stage where build tools (python3, make, g++, libc6-compat) are available to compile native modules
  2. Copying the compiled binaries to the final stage in the COPY command

This leverages Docker's multi-stage build pattern properly and lets npm handle platform-specific binaries automatically, which resolves the amd64 binary issue mentioned in the PR.

export DENO_VERSION="${{ inputs.deno-version }}"
# Removes unnecessary swc cores to reduce image sized
# Removes unnecessary swc cores and sharp binaries to reduce image size
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Update comment to include all removed binaries.

The comment mentions only "swc cores and sharp binaries" but the code also removes pinyin (line 89) and esbuild binaries (lines 91, 93). Update the comment to reflect all removal operations for clarity.

🔎 Suggested fix
-        # Removes unnecessary swc cores and sharp binaries to reduce image size
+        # Removes unnecessary swc cores, sharp, pinyin, and esbuild binaries to reduce image size
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Removes unnecessary swc cores and sharp binaries to reduce image size
# Removes unnecessary swc cores, sharp, pinyin, and esbuild binaries to reduce image size
🤖 Prompt for AI Agents
.github/actions/build-docker/action.yml around line 78: the existing comment
only mentions "swc cores and sharp binaries" but the removal block also removes
pinyin and esbuild binaries; update the comment to list all removed items (swc
cores, sharp, pinyin, and esbuild binaries) or use a generic phrase like
"unnecessary native binaries (swc cores, sharp, pinyin, esbuild)" so the comment
accurately reflects the cleanup operations.

@rocketchat-github-ci rocketchat-github-ci merged commit aba62ef into master Dec 19, 2025
14 checks passed
@rocketchat-github-ci rocketchat-github-ci deleted the release-7.13.2 branch December 19, 2025 20:13
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.

2 participants