Skip to content

Conversation

@nazabucciarelli
Copy link
Contributor

@nazabucciarelli nazabucciarelli commented Jan 22, 2026

Proposed changes (including videos or screenshots)

A regression was inserted with this PR trying to fix the issue of versions mismatching when upgrading/downgrading the server version. That PR introduced a function that creates a copy of the last statistics record when the onVersionChange hook was triggered, but modifying the data related to deployment and versions. The problem was that Rocket.Chat sends workspace statistics to the cloud and it sends back data in a string token that is saved in statistics as statsToken and this token was being copied from the latest record to the new one but with an updated createdAt property, so the sendUsageReport function from meteor/app/statistics/server/functions/sendUsageReport.ts in some specific cases where the version is constantly upgraded/downgraded (in less than 24 hours), it wouldn't create a new statistics record with the statsToken given from cloud, and therefore the system would assume that the workspace is air-gapped.

Proposed solution:

  • Remove previous updateDeploymentData() implemented function.
  • Simplify and centralize the statistics save logic in the meteor/app/statistics/server/functions/sendUsageReport.ts file.
  • Tests were added to validate the new behavior where statistics are regenerated when the stored version differs from the current platform version, ensuring accurate usage reporting across upgrades.

Issue(s)

CORE-1736 : Statistics token timestamp stagnation causing false air-gapped state detection

Steps to test or reproduce

Further comments

Summary by CodeRabbit

  • Bug Fixes

    • Usage statistics now regenerate when the application version changes, preventing stale reports.
  • Refactor

    • Simplified statistics collection by removing redundant deployment-data gathering.
  • Tests

    • New tests cover generation/retention of statistics across version and missing-data scenarios.

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

@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Jan 22, 2026

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

  • This PR is missing the 'stat: QA assured' label

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link

changeset-bot bot commented Jan 22, 2026

⚠️ No Changeset found

Latest commit: d6e31c2

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 22, 2026

Walkthrough

Added a version-based freshness check to sendUsageReport (uses Info.version) to trigger new statistics when version differs or data is older than 24 hours; removed statistics.updateDeploymentData and its startup invocation.

Changes

Cohort / File(s) Summary
Statistics freshness & report flow
apps/meteor/app/statistics/server/functions/sendUsageReport.ts
Import Info.version; compare currentVersion to last saved stats' version; trigger generation when versions differ or last is older than 24 hours; adjusted conditional control flow.
Remove deployment-data updater
apps/meteor/app/statistics/server/lib/statistics.ts
Deleted updateDeploymentData method and removed SystemLogger usage/import; eliminated code that assembled and saved deployment OS/process/Mongo/migration details.
Startup migration cleanup
apps/meteor/server/startup/migrations/xrun.ts
Removed statistics import and eliminated call to statistics.updateDeploymentData() from onServerVersionChange.
Tests for new behavior
apps/meteor/app/statistics/server/functions/sendUsageReport.spec.ts
Added Info mock and three test cases covering version-mismatch generation, same-version no-generation, and generation when no prior stats exist; stubbed Statistics.findLast and statistics.save.

Sequence Diagram(s)

sequenceDiagram
    participant Send as SendUsageReport
    participant Stats as StatisticsStore
    participant Local as LocalSave
    participant Collector as RemoteCollector

    Send->>Stats: findLast()
    alt last exists and last.version == currentVersion and <24h
        Send->>Send: return existing token
    else
        Send->>Send: generate new statistics
        Send->>Local: save locally
        alt collector configured
            Send->>Collector: post statistics
            Collector-->>Send: collector response
        end
        Send-->>Stats: save new stats (with currentVersion and token)
        Send-->>Send: return token
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

stat: ready to merge, stat: QA assured

Suggested reviewers

  • KevLehman
  • rodrigok
  • cardoso

Poem

🐰 I chewed a carrot, found a version new,
Hopped through stats to see what it would do.
Old data refreshed, the token hops along,
A rabbit's tiny drumbeat joins the stats song! 🥕✨

🚥 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main fix: removing the problematic updateDeploymentData() call that was causing statistics to be incorrectly copied with stale timestamps during version changes, leading to false air-gapped state detection.
Linked Issues check ✅ Passed Changes directly address CORE-1736 by removing updateDeploymentData() that caused timestamp stagnation, centralizing statistics generation in sendUsageReport with version-based triggers, and adding tests validating regeneration on version mismatch.
Out of Scope Changes check ✅ Passed All changes are focused on resolving the statistics token timestamp stagnation issue; no unrelated modifications detected outside the scope of fixing the regression introduced by PR #38127.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/statistics-version-change

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.

@nazabucciarelli nazabucciarelli added this to the 8.1.0 milestone Jan 22, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Jan 22, 2026

📦 Docker Image Size Report

➡️ Changes

Service Current Baseline Change Percent
sum of all images 0B 0B 0B
account-service 0B 0B 0B
authorization-service 0B 0B 0B
ddp-streamer-service 0B 0B 0B
omnichannel-transcript-service 0B 0B 0B
presence-service 0B 0B 0B
queue-worker-service 0B 0B 0B
rocketchat 0B 0B 0B

📊 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/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 23:27", "12/20 21:03", "12/22 18:54", "12/23 16:16", "12/24 19:38", "12/25 17:51", "12/26 13:18", "12/29 19:01", "12/30 20:52", "01/22 21:39 (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, 0.11, 0.11, 0.11, 0.11, 0.00]
  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, 0.11, 0.11, 0.11, 0.11, 0.00]
  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, 0.12, 0.12, 0.12, 0.12, 0.00]
  line "omnichannel-transcript-service" [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.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.00]
  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, 0.11, 0.11, 0.11, 0.11, 0.00]
  line "queue-worker-service" [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.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.00]
  line "rocketchat" [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.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.00]
Loading

Statistics (last 30 days):

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

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

  • Tag: pr-38298
  • Baseline: develop
  • Timestamp: 2026-01-22 21:39:14 UTC
  • Historical data points: 30

Updated: Thu, 22 Jan 2026 21:39:15 GMT

@nazabucciarelli
Copy link
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 22, 2026

✅ Actions performed

Review triggered.

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.

@nazabucciarelli nazabucciarelli changed the title fix: save updated statistics on version change without causing air-gapped state assumption regression: save updated statistics on version change without causing air-gapped state assumption Jan 22, 2026
@codecov
Copy link

codecov bot commented Jan 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (release-8.1.0@dee9618). Learn more about missing BASE report.

Additional details and impacted files

Impacted file tree graph

@@               Coverage Diff                @@
##             release-8.1.0   #38298   +/-   ##
================================================
  Coverage                 ?   70.71%           
================================================
  Files                    ?     3142           
  Lines                    ?   108948           
  Branches                 ?    19608           
================================================
  Hits                     ?    77038           
  Misses                   ?    29907           
  Partials                 ?     2003           
Flag Coverage Δ
e2e 60.23% <ø> (?)
e2e-api 48.06% <ø> (?)
unit 71.85% <100.00%> (?)

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.

@nazabucciarelli nazabucciarelli force-pushed the fix/statistics-version-change branch from 9023259 to d6e31c2 Compare January 22, 2026 21:24
@nazabucciarelli nazabucciarelli changed the title regression: save updated statistics on version change without causing air-gapped state assumption regression: save statistics on version change causing air-gapped state assumption Jan 22, 2026
@nazabucciarelli nazabucciarelli changed the title regression: save statistics on version change causing air-gapped state assumption regression: save statistics on version change causes air-gapped state assumption Jan 22, 2026
@nazabucciarelli nazabucciarelli marked this pull request as ready for review January 22, 2026 21:49
@nazabucciarelli nazabucciarelli requested a review from a team as a code owner January 22, 2026 21:49
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 4 files

@nazabucciarelli
Copy link
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 22, 2026

✅ Actions performed

Review triggered.

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.

@tassoevan tassoevan merged commit 822a896 into release-8.1.0 Jan 23, 2026
48 checks passed
@tassoevan tassoevan deleted the fix/statistics-version-change branch January 23, 2026 21:46
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.

5 participants