Skip to content

Fix stale supported-versions cache outranking fresh builtin fallback - #3388

Merged
jeanfbrito merged 1 commit into
masterfrom
fix/stale-supported-versions-cache-block
Jul 1, 2026
Merged

jeanfbrito merged 1 commit into
masterfrom
fix/stale-supported-versions-cache-block

Conversation

@jeanfbrito

@jeanfbrito jeanfbrito commented Jul 1, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes #3385. Server on a fully supported version (8.5.1 LTS) got permanently blocked with "unsupported version" on 4.15.0. Workaround reported by user: deleting AppData\Roaming\Rocket.Chat (the app's userData/cache dir) fixed it.

Root cause: in updateSupportedVersionsData (src/servers/supportedVersions/main.ts), when both the server-embedded and cloud supported-versions fetches fail, the fallback chain picked the persisted disk cache unconditionally over the app's own bundled builtin list. A cache entry written by an older app version — before the server's version was added to the supported list — permanently outranks a freshly-shipped builtin list that already supports it, with no TTL or freshness check. The SupportedVersions.timestamp field exists specifically for this purpose but was never read.

What changed

  • Compare timestamp on the cached payload vs the builtin payload and use whichever is more recent, instead of a fixed cache-first priority.
  • Added parseTimestamp helper: missing/invalid timestamps sort as oldest, so a corrupt timestamp can't spuriously win the comparison.
  • Collapsed the previously-duplicated cache/builtin dispatch blocks into one, since they now share the same fallback path.

Not touched: the exception/version-matching logic from #3323 (still correct), and #3371 (role-targeted messages, unrelated to the block verdict).

Test plan

  • Added regression test: stale cache (old timestamp, would incorrectly mark 8.5.1 unsupported) + fresh builtin (correct timestamp, marks it supported) + failed server/cloud fetch → verdict follows builtin, not cache.
  • Full main.main.spec.ts suite passes (77/77).
  • eslint clean on both changed files.
  • tsc --noEmit shows no new errors introduced by this change (14 pre-existing errors in the worktree are unrelated React 18/19 type mismatches, confirmed present with git stash).

Summary by CodeRabbit

  • Bug Fixes
    • Improved fallback behavior for supported-version checks when live data can’t be reached.
    • The app now prefers the freshest available source between cached and built-in version data, avoiding stale results after updates.
    • Missing or invalid timestamps are handled safely so older data won’t override newer information.
    • Updated status notifications now reflect whether the chosen data came from built-in or cloud sources.

…fallback

Fixes #3385. When server and cloud fetches both fail, the fallback chain
trusted a persisted disk cache unconditionally over the app's bundled
builtin supported-versions list. A cache entry written before an app
update - before the server's version was added to the supported list -
would outrank a freshly-shipped builtin list that already supports it,
producing a permanent false "unsupported version" block until the user
manually wiped the app's userData cache.

Compare the `timestamp` field on cached vs builtin payloads and use
whichever is more recent, instead of a fixed cache-first priority.
@coderabbitai

coderabbitai Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The fallback logic in the supported versions module was reworked to compare timestamps between cached and builtin supported-version data, selecting the fresher source instead of always preferring cache. A regression test validates that builtin data is used over a stale cache.

Changes

Freshness-based supported versions fallback

Layer / File(s) Summary
Timestamp comparison and fallback selection
src/servers/supportedVersions/main.ts
Adds parseTimestamp() to normalize missing/malformed timestamps to 0, and replaces the cache-first fallback with logic that compares builtin vs cached timestamp values, selects fallbackVersions and fallbackSource accordingly, optionally updates the cache, and dispatches the verdict with the chosen source.
Regression test for builtin-over-cache preference
src/servers/supportedVersions/main.main.spec.ts
Adds a test mocking a stale cache and fresh builtin payload, asserting the dispatched verdict and WEBVIEW_SERVER_SUPPORTED_VERSIONS_UPDATED action use 'builtin' as the source.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
    participant App
    participant FallbackLogic as SupportedVersionsFallback
    participant Cache
    participant Builtin as BuiltinData

    App->>FallbackLogic: server and cloud unreachable
    FallbackLogic->>Cache: load cached supported versions
    FallbackLogic->>Builtin: load builtin supported versions
    FallbackLogic->>FallbackLogic: parseTimestamp(cache), parseTimestamp(builtin)
    FallbackLogic->>FallbackLogic: compare timestamps, choose fresher source
    alt builtin is fresher
        FallbackLogic->>App: dispatch verdict with source='builtin'
    else cache is fresher
        FallbackLogic->>Cache: update cache
        FallbackLogic->>App: dispatch verdict with source='cloud'
    end
Loading

Possibly related PRs

Suggested labels: type: bug

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main fix: stale cache no longer outranks fresh builtin supported versions.
Linked Issues check ✅ Passed The change addresses #3385 by preventing stale local supported-version cache from overriding newer builtin support data.
Out of Scope Changes check ✅ Passed The diff stays focused on supported-versions fallback logic and its regression test, with no clear unrelated scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/servers/supportedVersions/main.ts`:
- Around line 669-671: The fallback provenance is being misreported because the
cache path in supportedVersions/main.ts still maps reused cached entries to
supportedVersionsSource = 'cloud'. Update the fallback handling around
fallbackSource so cached results are tagged distinctly (for example, with a new
cache source) or carry through the original source alongside the cached payload.
Make the change in the code that builds and dispatches the supported versions
source so the UI can distinguish cache reuse from a true cloud fetch.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0fce8ce4-6f6f-4351-8d5b-f09cd2b69a44

📥 Commits

Reviewing files that changed from the base of the PR and between 99a330d and 22e1b52.

📒 Files selected for processing (2)
  • src/servers/supportedVersions/main.main.spec.ts
  • src/servers/supportedVersions/main.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (3)
  • GitHub Check: check (macos-latest)
  • GitHub Check: check (ubuntu-latest)
  • GitHub Check: check (windows-latest)
🧰 Additional context used
📓 Path-based instructions (6)
**/*.ts

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.ts: Use TypeScript for all new code unless explicitly told otherwise
Use optional chaining with fallbacks for platform-specific APIs instead of mocking when possible. Example: const uid = process.getuid?.() ?? 1000;

Files:

  • src/servers/supportedVersions/main.main.spec.ts
  • src/servers/supportedVersions/main.ts
**/*.{tsx,ts}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{tsx,ts}: MANDATORY: Use Fuselage components for all UI work. Only create custom components when Fuselage doesn't provide what's needed
Import UI components from @rocket.chat/fuselage and check Theme.d.ts for valid color tokens
Use React functional components with hooks
Use PascalCase for component file names

Files:

  • src/servers/supportedVersions/main.main.spec.ts
  • src/servers/supportedVersions/main.ts
**/*.spec.ts

📄 CodeRabbit inference engine (CLAUDE.md)

Use *.spec.ts file naming for Renderer process tests

Files:

  • src/servers/supportedVersions/main.main.spec.ts
**/*.main.spec.ts

📄 CodeRabbit inference engine (CLAUDE.md)

Use *.main.spec.ts file naming for Main process tests

Files:

  • src/servers/supportedVersions/main.main.spec.ts
**/*.{spec.ts,main.spec.ts}

📄 CodeRabbit inference engine (CLAUDE.md)

Only mock platform-specific APIs when defensive coding isn't possible. Linux-only APIs requiring mocks: process.getuid(), process.getgid(), process.geteuid(), process.getegid()

Files:

  • src/servers/supportedVersions/main.main.spec.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx}: Redux actions must follow FSA (Flux Standard Action) pattern
Avoid unnecessary comments — write self-documenting code through clear naming
Always verify libraries by checking official docs and .d.ts files in node_modules/. Never assume props, tokens, or APIs work without verification
Avoid subjective descriptors ('smart', 'excellent', 'dumb') in documentation and comments
Use measurable descriptions in code documentation: 'reduced memory usage', 'improved by X%' instead of subjective claims
NEVER invent metrics — don't include estimated time spent or speculated user counts. Only include numbers from actual logs, error messages, or documented sources

Files:

  • src/servers/supportedVersions/main.main.spec.ts
  • src/servers/supportedVersions/main.ts
🔇 Additional comments (2)
src/servers/supportedVersions/main.ts (1)

93-98: LGTM!

src/servers/supportedVersions/main.main.spec.ts (1)

1342-1432: LGTM!

Comment on lines +669 to +671
const fallbackSource: 'cloud' | 'builtin' = useBuiltinOverCache
? 'builtin'
: 'cloud';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Inspect the valid supportedVersionsSource values and how the label is consumed.
rg -nP "supportedVersionsSource\??\s*:" src/servers/common.ts src/servers/supportedVersions/types.ts 2>/dev/null
fd -e ts | xargs rg -nP "supportedVersionsSource" -C2

Repository: RocketChat/Rocket.Chat.Electron

Length of output: 2412


🏁 Script executed:

#!/bin/bash
sed -n '640,700p' src/servers/supportedVersions/main.ts
rg -n "useBuiltinOverCache|fallbackSource|supportedVersionsSource|supportedVersions" src/servers/supportedVersions src/servers -C 2

Repository: RocketChat/Rocket.Chat.Electron

Length of output: 50387


🏁 Script executed:

#!/bin/bash
rg -n "supportedVersionsSource" src -C 3
rg -n "useBuiltinOverCache|fallbackSource|cachedVersions|cache.*builtin|builtinOverCache" src/servers/supportedVersions/main.main.spec.ts src/servers/supportedVersions/main.ts -C 3

Repository: RocketChat/Rocket.Chat.Electron

Length of output: 22584


🏁 Script executed:

#!/bin/bash
sed -n '560,640p' src/servers/supportedVersions/main.ts
sed -n '1338,1490p' src/servers/supportedVersions/main.main.spec.ts
rg -n "saveToCache\\(|dispatchSupportedVersionsUpdated\\(" src/servers/supportedVersions/main.ts src/servers/supportedVersions/main.main.spec.ts -C 2

Repository: RocketChat/Rocket.Chat.Electron

Length of output: 12117


Cache fallback should not be labeled as cloud. The fallback path reuses persisted cache entries from any prior source, but supportedVersionsSource is still dispatched as 'cloud', so the UI shows the wrong provenance. Add a distinct cache source or persist the original source with the cached payload.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/servers/supportedVersions/main.ts` around lines 669 - 671, The fallback
provenance is being misreported because the cache path in
supportedVersions/main.ts still maps reused cached entries to
supportedVersionsSource = 'cloud'. Update the fallback handling around
fallbackSource so cached results are tagged distinctly (for example, with a new
cache source) or carry through the original source alongside the cached payload.
Make the change in the code that builds and dispatches the supported versions
source so the UI can distinguish cache reuse from a true cloud fetch.

@jeanfbrito
jeanfbrito merged commit 8f00849 into master Jul 1, 2026
8 checks passed
@jeanfbrito
jeanfbrito deleted the fix/stale-supported-versions-cache-block branch July 1, 2026 19:47
@jeanfbrito jeanfbrito mentioned this pull request Jul 1, 2026
2 tasks done
@johnyb0y

johnyb0y commented Jul 2, 2026

Copy link
Copy Markdown

@jeanfbrito Thank you for the quick fix :-)

jeanfbrito added a commit that referenced this pull request Jul 10, 2026
…nfo contract; try both fallback sources

The desktop's ServerInfo type declared fields the server never returns
to unauthenticated callers (verified against the server source,
apps/meteor/server/api/lib/getServerInfo.ts):

- Remove the fictional uniqueId field. No server version includes it in
  /api/info; the workspace uniqueID comes from settings.public and is
  resolved on demand by withExceptionScopeUniqueId. Remove the dead
  serverInfoResult.uniqueId fallback in updateSupportedVersionsData.
- Mark build, marketplaceApiVersion, and commit optional and document
  that they only appear for authenticated view-statistics callers; the
  desktop always calls /api/info unauthenticated. The sha-exception
  path uses the persisted server.gitCommitHash pushed by the injected
  script instead.
- Rebuild the default test fixture to mirror the real unauthenticated
  wire shape (trimmed major.minor version, no uniqueId/commit/info) so
  the suite can no longer validate assumptions against fields real
  servers do not send — the gap that let the exception-scope defect
  pass CI. Switch beforeEach to jest.resetAllMocks(), fixing latent
  cross-test mock leakage the honest fixtures surfaced.

Also rework the offline fallback to try BOTH remaining sources instead
of picking one by timestamp: the bundled builtin payload never carries
tenant exceptions, so preferring a fresher builtin over a cache that
holds the tenant's exception blocked a workspace that should stay
usable. Candidates are checked in freshness order and the first source
that supports the server wins; blocking requires every available source
to fail. This keeps the stale-cache rescue from #3388 while never
losing a cached exception to it.
jeanfbrito added a commit that referenced this pull request Jul 10, 2026
…nfo contract; try both fallback sources

The desktop's ServerInfo type declared fields the server never returns
to unauthenticated callers (verified against the server source,
apps/meteor/server/api/lib/getServerInfo.ts):

- Remove the fictional uniqueId field. No server version includes it in
  /api/info; the workspace uniqueID comes from settings.public and is
  resolved on demand by withExceptionScopeUniqueId. Remove the dead
  serverInfoResult.uniqueId fallback in updateSupportedVersionsData.
- Mark build, marketplaceApiVersion, and commit optional and document
  that they only appear for authenticated view-statistics callers; the
  desktop always calls /api/info unauthenticated. The sha-exception
  path uses the persisted server.gitCommitHash pushed by the injected
  script instead.
- Rebuild the default test fixture to mirror the real unauthenticated
  wire shape (trimmed major.minor version, no uniqueId/commit/info) so
  the suite can no longer validate assumptions against fields real
  servers do not send — the gap that let the exception-scope defect
  pass CI. Switch beforeEach to jest.resetAllMocks(), fixing latent
  cross-test mock leakage the honest fixtures surfaced.

Also rework the offline fallback to try BOTH remaining sources instead
of picking one by timestamp: the bundled builtin payload never carries
tenant exceptions, so preferring a fresher builtin over a cache that
holds the tenant's exception blocked a workspace that should stay
usable. Candidates are checked in freshness order and the first source
that supports the server wins; blocking requires every available source
to fail. This keeps the stale-cache rescue from #3388 while never
losing a cached exception to it.
jeanfbrito added a commit that referenced this pull request Jul 10, 2026
…tion-aware fallback (#3406)

* fix: align supported-versions types and fixtures with the real /api/info contract; try both fallback sources

The desktop's ServerInfo type declared fields the server never returns
to unauthenticated callers (verified against the server source,
apps/meteor/server/api/lib/getServerInfo.ts):

- Remove the fictional uniqueId field. No server version includes it in
  /api/info; the workspace uniqueID comes from settings.public and is
  resolved on demand by withExceptionScopeUniqueId. Remove the dead
  serverInfoResult.uniqueId fallback in updateSupportedVersionsData.
- Mark build, marketplaceApiVersion, and commit optional and document
  that they only appear for authenticated view-statistics callers; the
  desktop always calls /api/info unauthenticated. The sha-exception
  path uses the persisted server.gitCommitHash pushed by the injected
  script instead.
- Rebuild the default test fixture to mirror the real unauthenticated
  wire shape (trimmed major.minor version, no uniqueId/commit/info) so
  the suite can no longer validate assumptions against fields real
  servers do not send — the gap that let the exception-scope defect
  pass CI. Switch beforeEach to jest.resetAllMocks(), fixing latent
  cross-test mock leakage the honest fixtures surfaced.

Also rework the offline fallback to try BOTH remaining sources instead
of picking one by timestamp: the bundled builtin payload never carries
tenant exceptions, so preferring a fresher builtin over a cache that
holds the tenant's exception blocked a workspace that should stay
usable. Candidates are checked in freshness order and the first source
that supports the server wins; blocking requires every available source
to fail. This keeps the stale-cache rescue from #3388 while never
losing a cached exception to it.

* test: add live /api/info wire-contract spec

Asserts the unauthenticated /api/info response shape against a real
server (open.rocket.chat): trimmed major.minor version, no uniqueId,
no commit/info blocks, string minimumClientVersions, JWT-shaped
supportedVersions.signed. Skips only on genuine network failure or
SKIP_CONTRACT_TESTS=1, so contract drift between the desktop and the
server cannot hide behind mocks that agree with themselves.
jeanfbrito added a commit that referenced this pull request Jul 10, 2026
* fix: honor uniqueId-scoped support exceptions on server-signed path

The exception scope check introduced in #3323 requires
exceptions.uniqueId to equal server.uniqueID, but the server-signed
validation path returns before getUniqueId() ever runs and /api/info
does not include a uniqueId field, so the local uniqueID is missing on
that path and uniqueId-scoped exceptions were always disqualified.

Resolve the workspace uniqueID from the server before validating when
the payload carries a uniqueId-scoped exceptions block, persist it via
WEBVIEW_SERVER_UNIQUE_ID_UPDATED so subsequent runs (including offline
cache validation) keep working, and keep rejecting when the fetched
value does not match. Also compare exceptions.domain case-insensitively
(DNS names are case-insensitive per RFC 4343).

* fix: harden supported-versions validation and recovery paths

Audited the supported-versions subsystem end to end after the
uniqueId-scope escalation and fixed the confirmed defects:

- Wrap the cache/builtin fallback validation in a helper with try/catch
  so a malformed cached payload can no longer reject the update before
  the error state is dispatched, which left fetchState stuck at
  'loading' and suppressed the UnsupportedServer block gate.
- Catch rejections at all four fire-and-forget validation call sites.
- Fall back to the persisted workspace uniqueID when the fresh fetch
  fails so the cloud lookup is not skipped for previously-known servers.
- Switch uniqueID/version/gitCommitHash reducer cases from upsert to
  update so a late identity dispatch cannot resurrect a server deleted
  while a validation was in flight.
- Guard getExpirationMessageTranslated against payloads whose i18n
  dictionary lacks both the user language and 'en'; the missing guard
  crashed the async check and silently suppressed the expiring-
  workspace warning dialog.
- Revalidate all servers on powerMonitor 'resume' (the window 'online'
  event does not fire when waking with the same network connected).
- Use the real currentView state in SupportedVersionDialog's effect
  dependencies; the previous dependency was the imported reducer
  function, which never changes, so the dialog never re-checked on
  view switches.
- Add a 'Check again' button to the unsupported-workspace screen so
  users can re-trigger validation without restarting the app.
- Fix logRequestError printing a literal ${description}.

Also relax the exception scope check for UNKNOWN local identity: an
unfetchable workspace uniqueID (e.g. settings.public restricted by
enterprise API ACLs) no longer disqualifies a domain-matched exception;
a PROVEN uniqueID mismatch still rejects. The gate is client-side UX
enforcement rather than a security boundary, and wrongly blocking a
legitimate workspace is the worse failure mode.

* fix: honor tenant-scoped exceptions from self-scoped payload sources

Server, cloud, and cache supported-versions payloads are fetched from or
for the server being validated, so their exceptions block cannot belong
to another tenant. For these sources a domain/uniqueId scope mismatch is
now logged as a diagnostic warning instead of disqualifying the
exception. The bundled builtin payload is the only source that could
carry another deployment's exceptions and keeps the strict scope
requirement.

This removes the remaining paths where a valid, unexpired exception
could be rejected over unverifiable or drifted identity data (restricted
settings.public API, rotated workspace uniqueID, stale persisted
state).

* fix: do not block when enforcementStartDate is missing or malformed

A missing or unparseable enforcementStartDate previously produced an
Invalid Date that failed the future-date comparison and fell through to
the unsupported verdict — blocking the workspace based on incomplete
payload data. Blocking now requires a valid, past enforcement date:
uncertain data keeps the server usable until a payload with a valid
enforcement date proves enforcement is active.

* fix: align supported-versions types and fixtures with the real /api/info contract; try both fallback sources

The desktop's ServerInfo type declared fields the server never returns
to unauthenticated callers (verified against the server source,
apps/meteor/server/api/lib/getServerInfo.ts):

- Remove the fictional uniqueId field. No server version includes it in
  /api/info; the workspace uniqueID comes from settings.public and is
  resolved on demand by withExceptionScopeUniqueId. Remove the dead
  serverInfoResult.uniqueId fallback in updateSupportedVersionsData.
- Mark build, marketplaceApiVersion, and commit optional and document
  that they only appear for authenticated view-statistics callers; the
  desktop always calls /api/info unauthenticated. The sha-exception
  path uses the persisted server.gitCommitHash pushed by the injected
  script instead.
- Rebuild the default test fixture to mirror the real unauthenticated
  wire shape (trimmed major.minor version, no uniqueId/commit/info) so
  the suite can no longer validate assumptions against fields real
  servers do not send — the gap that let the exception-scope defect
  pass CI. Switch beforeEach to jest.resetAllMocks(), fixing latent
  cross-test mock leakage the honest fixtures surfaced.

Also rework the offline fallback to try BOTH remaining sources instead
of picking one by timestamp: the bundled builtin payload never carries
tenant exceptions, so preferring a fresher builtin over a cache that
holds the tenant's exception blocked a workspace that should stay
usable. Candidates are checked in freshness order and the first source
that supports the server wins; blocking requires every available source
to fail. This keeps the stale-cache rescue from #3388 while never
losing a cached exception to it.

* test: add live /api/info wire-contract spec

Asserts the unauthenticated /api/info response shape against a real
server (open.rocket.chat): trimmed major.minor version, no uniqueId,
no commit/info blocks, string minimumClientVersions, JWT-shaped
supportedVersions.signed. Skips only on genuine network failure or
SKIP_CONTRACT_TESTS=1, so contract drift between the desktop and the
server cannot hide behind mocks that agree with themselves.

* fix(CORE-2400): remove startup screen capture enumeration that opens Wayland picker (#3308) (#3400)

* chore: bump version to 4.15.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4.15.0 - Faulty "unsupported version" block still happening

2 participants