Skip to content

fix: Setup wizard forced back into registration on upgrade when Show_Setup_Wizard is env-overridden - #41254

Merged
dionisio-bot[bot] merged 5 commits into
developfrom
fix/setup-wizard-env-override-upgrade
Jul 11, 2026
Merged

fix: Setup wizard forced back into registration on upgrade when Show_Setup_Wizard is env-overridden#41254
dionisio-bot[bot] merged 5 commits into
developfrom
fix/setup-wizard-env-override-upgrade

Conversation

@KevLehman

@KevLehman KevLehman commented Jul 8, 2026

Copy link
Copy Markdown
Member

Proposed changes (including videos or screenshots)

On the first boot after a version upgrade, ensureCloudWorkspaceRegistered() flips Show_Setup_Wizard from completed to in_progress whenever Cloud_Workspace_Client_Id/Cloud_Workspace_Client_Secret are both empty. Air-gapped workspaces running offline licenses always meet this condition, so admins get redirected into a registration wizard they cannot complete online — even when OVERWRITE_SETTING_Show_Setup_Wizard=completed is explicitly set.

The env override is applied during settings init, before the version-change callback runs, so the flip wins for the life of that process (it self-heals on the next restart, when the override is re-applied and the version-change callback no longer fires).

The fix

ensureCloudWorkspaceRegistered() now skips the flip when the current value of Show_Setup_Wizard was authored by the env override: valueSource === 'processEnvValue' && value === processEnvValue. The value === processEnvValue part means a value changed after the override (by an admin or another process) invalidates the pin naturally, with no reset logic.

For that check to be reliable, two supporting changes in the settings machinery were needed — previously the processEnvValue source stamp was only persisted when the override changed the stored value, so a setting whose stored value already matched the env var never got stamped:

  • overrideGenerator now returns a stamped setting even when the env value equals the stored value (if not already stamped).
  • SettingsRegistry.add now persists the setting when only the source stamp changed (value equal, valueSource/processEnvValue differ). This converges: subsequent boots with the same env produce no writes.

A side effect of the stamping fix is that settings whose env override equals their stored value are now correctly marked as env-sourced (previously they kept valueSource: 'packageValue'), which also makes resetValueById and any other valueSource consumer see the accurate source.

Issue(s)

CORE-2377

Air-gapped/offline-license workspaces are pushed into the cloud registration step of the setup wizard after every upgrade, despite an explicit config directive to skip it.

Steps to test or reproduce

  1. Run a workspace with no cloud registration (Cloud_Workspace_Client_Id/Cloud_Workspace_Client_Secret empty) and OVERWRITE_SETTING_Show_Setup_Wizard=completed.
  2. Simulate an upgrade boot: db.migrations.updateOne({ _id: 'upgrade' }, { $set: { hash: 'fake' } }), then restart.
  3. Without this fix, Show_Setup_Wizard flips to in_progress and admins are redirected into the wizard. With the fix, it stays completed (and its document now carries valueSource: 'processEnvValue').

Unit tests cover the stamping behavior (overrideGenerator, SettingsRegistry persistence + cross-boot convergence) and the guard plus the pre-existing behaviors of ensureCloudWorkspaceRegistered (registered workspace, wizard not completed, diverged value, and the intended flip when unregistered with no pin).

Further comments

The bug was verified in a live manual test on both sides: with the guard the setting document receives no write at all on an upgrade boot; without it, it flips within ~300ms of the migration hash update.

Because the pin is persisted state (not a runtime env read), it also protects upgrade boots where the env var is no longer present — the operator's provisioning survives until the value is changed by someone else.

Summary by CodeRabbit

  • Bug Fixes
    • Prevented the setup wizard from reverting to the registration step after upgrades when it was already completed.
    • Refined environment override handling to avoid unnecessary rewrites and repeated updates, including correct detection when env-pinned values match the stored state.
    • Improved setup-wizard startup behavior to respect pinned values and only switch to in-progress when the stored value meaningfully diverges or the wizard completion state changes.
  • Tests
    • Added/updated unit coverage for setup wizard registration flows and environment override stamping behavior.

@changeset-bot

changeset-bot Bot commented Jul 8, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f4452a6

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

This PR includes changesets to release 3 packages
Name Type
@rocket.chat/meteor Patch
@rocket.chat/core-typings Patch
@rocket.chat/rest-typings 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

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7745b012-a305-42a7-b60f-3ffd0a98f3da

📥 Commits

Reviewing files that changed from the base of the PR and between ca3a5db and f4452a6.

📒 Files selected for processing (1)
  • apps/meteor/server/startup/cloudRegistration.ts
💤 Files with no reviewable changes (1)
  • apps/meteor/server/startup/cloudRegistration.ts
📜 Recent review details
⏰ Context from checks skipped due to timeout. (2)
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: Hacktron Security Check

Walkthrough

This PR fixes the setup wizard being forced back to registration on first start after upgrade when OVERWRITE_SETTING_Show_Setup_Wizard=completed. It updates overwrite detection, adjusts cloud registration logic, and adds tests plus a changeset.

Changes

Setup wizard env-override fix

Layer / File(s) Summary
Settings overwrite comparison
apps/meteor/app/settings/server/SettingsRegistry.ts, apps/meteor/app/settings/server/functions/overrideGenerator.ts, apps/meteor/tests/unit/app/settings/server/functions/overrideGenerator.tests.ts, apps/meteor/tests/unit/app/settings/server/functions/settings.tests.ts
Adds change detection for overwritten settings across value, valueSource, and processEnvValue, updates overwrite generation to avoid redundant rewrites, and expands unit coverage for env stamping behavior.
Cloud registration guard
apps/meteor/server/startup/cloudRegistration.ts, apps/meteor/tests/unit/server/startup/cloudRegistration.tests.ts
Loads Show_Setup_Wizard with value, valueSource, and processEnvValue, and skips forcing in_progress when the env-pinned value is already reflected; unit tests cover the conditional update paths.
Changeset entry
.changeset/setup-wizard-env-override-upgrade.md
Adds a patch changeset note for @rocket.chat/meteor describing the setup wizard override fix.

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

Sequence Diagram(s)

sequenceDiagram
  participant ensureCloudWorkspaceRegistered
  participant SettingsModel
  ensureCloudWorkspaceRegistered->>SettingsModel: findOneById(Show_Setup_Wizard, projection)
  SettingsModel-->>ensureCloudWorkspaceRegistered: value, valueSource, processEnvValue
  ensureCloudWorkspaceRegistered->>ensureCloudWorkspaceRegistered: check value !== completed
  ensureCloudWorkspaceRegistered->>ensureCloudWorkspaceRegistered: check env-pinned value matches processEnvValue
  ensureCloudWorkspaceRegistered->>SettingsModel: updateValueById(Show_Setup_Wizard, in_progress)
Loading

Suggested labels: type: bug

Suggested reviewers: cardoso

🚥 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 describes the upgrade bug and the env-overridden Show_Setup_Wizard fix.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • CORE-2377: Request failed with status code 401

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.

@dionisio-bot

dionisio-bot Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Looks like this PR is ready to merge! 🎉
If you have any trouble, please check the PR guidelines

@codecov

codecov Bot commented Jul 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.07%. Comparing base (ed63cfc) to head (f4452a6).
⚠️ Report is 25 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #41254      +/-   ##
===========================================
+ Coverage    69.06%   69.07%   +0.01%     
===========================================
  Files         3655     3655              
  Lines       143366   143372       +6     
  Branches     25725    25697      -28     
===========================================
+ Hits         99018    99040      +22     
+ Misses       40041    40033       -8     
+ Partials      4307     4299       -8     
Flag Coverage Δ
e2e 59.37% <ø> (+0.01%) ⬆️
e2e-api 50.33% <50.00%> (-0.42%) ⬇️
unit 69.97% <100.00%> (+0.04%) ⬆️

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.

@KevLehman KevLehman added this to the 8.7.0 milestone Jul 8, 2026
@KevLehman

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

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.

@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 `@apps/meteor/server/startup/cloudRegistration.ts`:
- Around line 20-21: Remove the implementation comments in cloudRegistration.ts
so the guard logic remains comment-free and compliant with the coding guideline.
Keep the existing conditional behavior around the env override check in the
startup flow, but delete the explanatory lines above the guard since the
variable names and condition already make the intent clear.
🪄 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: 95db733e-7f7b-41a2-9e80-215deddbe865

📥 Commits

Reviewing files that changed from the base of the PR and between ed63cfc and ca3a5db.

📒 Files selected for processing (7)
  • .changeset/setup-wizard-env-override-upgrade.md
  • apps/meteor/app/settings/server/SettingsRegistry.ts
  • apps/meteor/app/settings/server/functions/overrideGenerator.ts
  • apps/meteor/server/startup/cloudRegistration.ts
  • apps/meteor/tests/unit/app/settings/server/functions/overrideGenerator.tests.ts
  • apps/meteor/tests/unit/app/settings/server/functions/settings.tests.ts
  • apps/meteor/tests/unit/server/startup/cloudRegistration.tests.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (2)
  • GitHub Check: 🔨 Test UI (CE) / MongoDB 8.0 (1/4)
  • GitHub Check: 🔨 Test API (EE) / MongoDB 8.0 coverage (1/1)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{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/app/settings/server/functions/overrideGenerator.ts
  • apps/meteor/tests/unit/server/startup/cloudRegistration.tests.ts
  • apps/meteor/tests/unit/app/settings/server/functions/settings.tests.ts
  • apps/meteor/server/startup/cloudRegistration.ts
  • apps/meteor/app/settings/server/SettingsRegistry.ts
  • apps/meteor/tests/unit/app/settings/server/functions/overrideGenerator.tests.ts
🧠 Learnings (4)
📚 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/setup-wizard-env-override-upgrade.md
📚 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:

  • apps/meteor/app/settings/server/functions/overrideGenerator.ts
  • apps/meteor/tests/unit/server/startup/cloudRegistration.tests.ts
  • apps/meteor/tests/unit/app/settings/server/functions/settings.tests.ts
  • apps/meteor/server/startup/cloudRegistration.ts
  • apps/meteor/app/settings/server/SettingsRegistry.ts
  • apps/meteor/tests/unit/app/settings/server/functions/overrideGenerator.tests.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:

  • apps/meteor/app/settings/server/functions/overrideGenerator.ts
  • apps/meteor/tests/unit/server/startup/cloudRegistration.tests.ts
  • apps/meteor/tests/unit/app/settings/server/functions/settings.tests.ts
  • apps/meteor/server/startup/cloudRegistration.ts
  • apps/meteor/app/settings/server/SettingsRegistry.ts
  • apps/meteor/tests/unit/app/settings/server/functions/overrideGenerator.tests.ts
📚 Learning: 2026-05-06T12:21:44.083Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 40256
File: apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx:121-149
Timestamp: 2026-05-06T12:21:44.083Z
Learning: Field wrappers in rocket.chat/fuselage-forms (Field, FieldLabel, FieldRow, FieldError, FieldHint) auto-create htmlFor/id associations, aria-describedby, and role="alert" for errors. Do not manually set htmlFor, id, aria-describedby, or role attributes when using these wrappers. This automatic wiring does not apply to plain rocket.chat/fuselage components, which require explicit ID wiring per the accessibility docs. In code reviews, prefer using fuselage-forms wrappers for form fields and verify there is no unnecessary manual ID/aria wiring in files that use these wrappers. If a component uses plain fuselage components, ensure proper id wiring as per docs.

Applied to files:

  • apps/meteor/app/settings/server/functions/overrideGenerator.ts
  • apps/meteor/tests/unit/server/startup/cloudRegistration.tests.ts
  • apps/meteor/tests/unit/app/settings/server/functions/settings.tests.ts
  • apps/meteor/server/startup/cloudRegistration.ts
  • apps/meteor/app/settings/server/SettingsRegistry.ts
  • apps/meteor/tests/unit/app/settings/server/functions/overrideGenerator.tests.ts
🔇 Additional comments (7)
.changeset/setup-wizard-env-override-upgrade.md (1)

1-5: LGTM!

apps/meteor/app/settings/server/SettingsRegistry.ts (1)

86-90: LGTM!

Also applies to: 183-183

apps/meteor/app/settings/server/functions/overrideGenerator.ts (1)

43-43: LGTM!

apps/meteor/tests/unit/app/settings/server/functions/overrideGenerator.tests.ts (1)

22-32: LGTM!

Also applies to: 34-43

apps/meteor/tests/unit/app/settings/server/functions/settings.tests.ts (1)

144-186: LGTM!

apps/meteor/server/startup/cloudRegistration.ts (1)

6-18: LGTM!

apps/meteor/tests/unit/server/startup/cloudRegistration.tests.ts (1)

1-75: LGTM!

Comment thread apps/meteor/server/startup/cloudRegistration.ts Outdated
KevLehman and others added 2 commits July 8, 2026 12:59
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@KevLehman
KevLehman marked this pull request as ready for review July 8, 2026 22:13
@KevLehman
KevLehman requested a review from a team as a code owner July 8, 2026 22:13

@cubic-dev-ai cubic-dev-ai 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.

1 issue found across 7 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/meteor/app/settings/server/functions/overrideGenerator.ts">

<violation number="1" location="apps/meteor/app/settings/server/functions/overrideGenerator.ts:43">
P2: Env-pinned settings can still remain unmarked as env-sourced when `processEnvValue` already matches but `valueSource` is stale or missing. Since the guard returns before writing `valueSource: 'processEnvValue'`, consider only skipping when the source stamp is already correct too.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread apps/meteor/app/settings/server/functions/overrideGenerator.ts
@KevLehman KevLehman added the stat: QA assured Means it has been tested and approved by a company insider label Jul 9, 2026
@dionisio-bot dionisio-bot Bot added the stat: ready to merge PR tested and approved waiting for merge label Jul 9, 2026
@dionisio-bot
dionisio-bot Bot added this pull request to the merge queue Jul 10, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 10, 2026
@dionisio-bot
dionisio-bot Bot added this pull request to the merge queue Jul 10, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 10, 2026
@KevLehman KevLehman removed this from the 8.7.0 milestone Jul 11, 2026
@dionisio-bot dionisio-bot Bot removed the stat: ready to merge PR tested and approved waiting for merge label Jul 11, 2026
@KevLehman KevLehman added this to the 8.7.0 milestone Jul 11, 2026
@dionisio-bot dionisio-bot Bot added the stat: ready to merge PR tested and approved waiting for merge label Jul 11, 2026
@dionisio-bot
dionisio-bot Bot added this pull request to the merge queue Jul 11, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 11, 2026
@dionisio-bot
dionisio-bot Bot added this pull request to the merge queue Jul 11, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 11, 2026
@dionisio-bot
dionisio-bot Bot added this pull request to the merge queue Jul 11, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 11, 2026
@dionisio-bot
dionisio-bot Bot added this pull request to the merge queue Jul 11, 2026
Merged via the queue into develop with commit edbaeef Jul 11, 2026
84 of 86 checks passed
@dionisio-bot
dionisio-bot Bot deleted the fix/setup-wizard-env-override-upgrade branch July 11, 2026 14:09
This was referenced Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stat: QA assured Means it has been tested and approved by a company insider stat: ready to merge PR tested and approved waiting for merge type: bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants