Skip to content

Conversation

@ricardogarim
Copy link
Contributor

@ricardogarim ricardogarim commented Oct 24, 2025

Related to RocketChat/homeserver#289 that implements updateConfig method.

Jira Issue: FDR-156.

Summary by CodeRabbit

  • New Features

    • Federation service now watches critical settings and automatically reinitializes when those settings change.
    • Lazy initialization ensures the federation runtime is created only once and updates its configuration thereafter.
  • Bug Fixes

    • Prevented redundant event registrations and duplicate initialization.
    • Strengthened domain validation with clearer error messages.
  • Chores

    • Service and route registration now occur only when federation is enabled.

@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Oct 24, 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

@changeset-bot
Copy link

changeset-bot bot commented Oct 24, 2025

⚠️ No Changeset found

Latest commit: 616c805

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 Oct 24, 2025

Walkthrough

Refactors federation startup and matrix setup to be settings-driven and idempotent: adds a CRITICAL_SETTINGS watcher and registration flags in federation.ts, and implements lazy container initialization, stronger domain validation, and config hot-update in setup.ts. (45 words)

Changes

Cohort / File(s) Summary
Federation Startup Service
apps/meteor/ee/server/startup/federation.ts
Added settings import and CRITICAL_SETTINGS; introduced serviceRegistered and watcherRegistered flags; moved StreamerCentral typing listener inside the enabled branch; register FederationMatrix service and routes only when enabled; attach a single settings watcher that reinvokes startup on CRITICAL_SETTINGS changes; concise error logging and rethrow.
Federation Matrix Setup
ee/packages/federation-matrix/src/setup.ts
Added containerInitialized flag to avoid reinitialization; expanded validateDomain with non-empty, lowercase, and URL checks plus error logs; early-exit when federation disabled or validation/license fails; replaced immediate ConfigService creation with configValues object; lazy createFederationContainer on first run with event handler registration; on subsequent runs use getAllServices to update in-memory config rather than re-registering events.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    actor Settings as Settings Service
    participant FedStartup as federation.ts:startFederationService
    participant FedSetup as setup.ts:setupFederationMatrix
    participant Container as Federation Container

    Note over Settings,FedStartup: CRITICAL_SETTINGS change triggers watcher
    Settings->>FedStartup: notify change
    FedStartup->>FedStartup: read enabled flag
    alt federation enabled
        FedStartup->>FedStartup: ensure serviceRegistered
        FedStartup->>FedSetup: call setupFederationMatrix()
        alt first initialization (containerInitialized = false)
            FedSetup->>FedSetup: validate domain & license
            FedSetup->>Container: createFederationContainer()
            Container-->>FedSetup: container created
            FedSetup->>FedSetup: create & register event handlers
            FedSetup->>FedSetup: set containerInitialized = true
        else already initialized
            FedSetup->>Container: getAllServices()
            Container-->>FedSetup: services returned
            FedSetup->>FedSetup: update in-memory config (no re-registration)
        end
        FedStartup->>FedStartup: register routes & streamer listener (if needed)
    else federation disabled
        FedStartup->>FedStartup: skip registration and listeners
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Notes for reviewers:

  • Verify correct single-time registration semantics for serviceRegistered, watcherRegistered, and containerInitialized.
  • Check domain validation edge cases and logging behavior.
  • Confirm getAllServices usage and that in-memory config updates are safe for concurrent runs.

Possibly related PRs

Suggested reviewers

  • ggazzo
  • sampaiodiego

Poem

🐰 In patches I hop, with code in my paw,
Settings now watched, no restart to gnaw.
One container wakes, events register neat,
Lazy and tidy, our startup’s complete.
Hop, hum, and cheer — federation’s on beat! 🎉

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Linked Issues Check ❓ Inconclusive The linked issue FDR-156 "Fix restart requirements when changing settings" is provided with only a title and no detailed requirements or acceptance criteria. The code changes in the PR logically align with this issue objective by introducing a settings watcher that dynamically reinitializes federation services when critical settings change, and implementing lazy container initialization to avoid unnecessary restarts. However, without explicit requirements from the issue to validate against, it is not possible to conclusively verify that all coding-related requirements have been met. Provide the full issue description and acceptance criteria for FDR-156 to enable a complete validation of whether all requirements have been met by the implementation in federation.ts and setup.ts.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "chore(federation): add settings watcher" is clear, concise, and directly related to the primary change in the changeset. The raw summary confirms that a settings watcher has been added to federation.ts that reacts to changes in CRITICAL_SETTINGS by re-invoking startFederationService. The title accurately conveys the main objective without vague terminology or unnecessary details, and the scope prefix clearly indicates this is a maintenance change to the federation module.
Out of Scope Changes Check ✅ Passed All code changes appear to be directly related to the PR objective of adding a settings watcher for federation and supporting the dynamic reconfiguration without restart. The changes to federation.ts implement the core settings watcher mechanism, while the changes to setup.ts introduce lazy container initialization and enhanced domain validation to support the new pattern. These modifications work together to enable the dynamic settings update capability described in the linked issue.
✨ 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 federation-settings-watch

📜 Recent review details

Configuration used: CodeRabbit 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 b48a1ae and 616c805.

📒 Files selected for processing (1)
  • apps/meteor/ee/server/startup/federation.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/meteor/ee/server/startup/federation.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: 📦 Build Packages
  • GitHub Check: CodeQL-Build
  • GitHub Check: CodeQL-Build

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.

@ricardogarim ricardogarim marked this pull request as ready for review October 24, 2025 11:45
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: 3

📜 Review details

Configuration used: CodeRabbit 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 d075db2 and b48a1ae.

📒 Files selected for processing (2)
  • apps/meteor/ee/server/startup/federation.ts (1 hunks)
  • ee/packages/federation-matrix/src/setup.ts (4 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-09-19T15:15:04.642Z
Learnt from: rodrigok
PR: RocketChat/Rocket.Chat#36991
File: apps/meteor/server/services/federation/infrastructure/rocket-chat/adapters/Settings.ts:219-221
Timestamp: 2025-09-19T15:15:04.642Z
Learning: The Federation_Matrix_homeserver_domain setting in apps/meteor/server/services/federation/infrastructure/rocket-chat/adapters/Settings.ts is part of the old federation system and is being deprecated/removed, so configuration issues with this setting should not be flagged for improvement.

Applied to files:

  • ee/packages/federation-matrix/src/setup.ts
  • apps/meteor/ee/server/startup/federation.ts
🧬 Code graph analysis (2)
ee/packages/federation-matrix/src/setup.ts (2)
packages/core-services/src/index.ts (1)
  • License (162-162)
ee/packages/federation-matrix/src/events/index.ts (1)
  • registerEvents (11-23)
apps/meteor/ee/server/startup/federation.ts (2)
ee/packages/federation-matrix/src/setup.ts (1)
  • setupFederationMatrix (41-124)
apps/meteor/ee/server/api/federation.ts (1)
  • registerFederationRoutes (43-52)
🪛 GitHub Actions: CI
ee/packages/federation-matrix/src/setup.ts

[error] 120-120: TS2339: Property 'updateConfig' does not exist on type 'ConfigService'.

🔇 Additional comments (7)
ee/packages/federation-matrix/src/setup.ts (3)

4-4: Verify SDK exports getAllServices.

The import looks correct. Ensure that getAllServices is exported from @rocket.chat/federation-sdk and matches the version referenced by the related homeserver PR #289.


12-13: LGTM!

The module-level flag correctly prevents duplicate container initialization across multiple invocations of setupFederationMatrix.


45-48: LGTM!

The early return correctly short-circuits when federation is disabled, avoiding unnecessary configuration work.

apps/meteor/ee/server/startup/federation.ts (4)

6-6: LGTM!

The import and CRITICAL_SETTINGS list are well-defined and cover all the essential federation configuration parameters that should trigger reinitialization.

Also applies to: 12-22


24-26: LGTM!

The flags correctly prevent duplicate service and watcher registrations.


48-53: Settings watcher implementation is correct.

The watcher is properly guarded and will correctly trigger reinitialization when critical settings change. However, ensure the duplicate registration issues flagged above (routes and StreamerCentral listener) are addressed to make this pattern safe.


54-57: LGTM!

The error handling is appropriate—logs the failure and rethrows to propagate the error.

Comment on lines +118 to 121
} else {
const services = getAllServices();
services.config.updateConfig(configValues);
}
Copy link
Contributor

@coderabbitai coderabbitai bot Oct 24, 2025

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Fix TypeScript compilation error: updateConfig method does not exist.

The pipeline failure indicates that updateConfig is not a property of ConfigService. According to the PR description, this relies on homeserver PR #289 which implements the method.

Verify the following:

Additionally, check the package version of @rocket.chat/federation-sdk to ensure it includes the updateConfig method:

If the method doesn't exist yet, this PR should either:

  1. Wait for the SDK to be updated with the updateConfig method
  2. Update the SDK dependency version to include the new method
  3. Add a type assertion or type extension as a temporary workaround (not recommended)

🏁 Script executed:

#!/bin/bash
# Check if updateConfig method exists in ConfigService type definition
ast-grep --pattern $'class ConfigService {
  $$$
  updateConfig($$$) {
    $$$
  }
  $$$
}'

Length of output: 0


🏁 Script executed:

#!/bin/bash
# Check the version of federation-sdk in package.json files
fd -e json -x cat {} | jq -r 'select(.dependencies["@rocket.chat/federation-sdk"] or .devDependencies["@rocket.chat/federation-sdk"]) | {file: input_filename, version: (.dependencies["@rocket.chat/federation-sdk"] // .devDependencies["@rocket.chat/federation-sdk"])}'

Length of output: 66


I need to take a different approach with simpler, more targeted searches. Let me verify the codebase more directly:


---

🏁 Script executed:

```shell
#!/bin/bash
# Search for ConfigService definition (could be class, interface, or type)
rg -nA5 "ConfigService\s*[=\{:]" --type ts --type tsx

Length of output: 27


🏁 Script executed:

#!/bin/bash
# Search for getAllServices function definition
rg -nA3 "function getAllServices\|const getAllServices" --type ts --type tsx

Length of output: 27


🏁 Script executed:

#!/bin/bash
# Look at the actual setup.ts file around the problematic lines
cat ee/packages/federation-matrix/src/setup.ts | head -130 | tail -30

Length of output: 568


🏁 Script executed:

#!/bin/bash
# Search for updateConfig method definition anywhere
rg -nB2 -A5 "updateConfig\s*\(" --type ts --type tsx

Length of output: 27


🏁 Script executed:

#!/bin/bash
# Simple check of federation-sdk version in main package.json
grep -A2 -B2 "federation-sdk" package.json

Length of output: 0


Let me fix the commands and retry with corrected search patterns:


---

🏁 Script executed:

```shell
#!/bin/bash
# Search for ConfigService definition with simpler pattern
rg -nA5 "class ConfigService|interface ConfigService|type ConfigService" --type ts

Length of output: 0


🏁 Script executed:

#!/bin/bash
# Search for getAllServices function with simpler pattern
rg -nA3 "getAllServices" --type ts | head -50

Length of output: 3057


🏁 Script executed:

#!/bin/bash
# Check package.json in the federation-matrix directory
find ee/packages/federation-matrix -name "package.json" -exec grep -l "federation-sdk" {} \;

Length of output: 42


🏁 Script executed:

#!/bin/bash
# Look for updateConfig definition
rg -nB2 -A5 "updateConfig" --type ts | head -100

Length of output: 1426


🏁 Script executed:

#!/bin/bash
# Check federation-matrix package.json for dependencies
cat ee/packages/federation-matrix/package.json | grep -A5 -B5 "dependencies\|federation"

Length of output: 642



---

🏁 Script executed:

```shell
#!/bin/bash
# Search for federation-sdk in node_modules or check if it's installed
find . -path "*/node_modules/@rocket.chat/federation-sdk*" -type d | head -5

Length of output: 0


🏁 Script executed:

#!/bin/bash
# Search for federation-sdk source files or look for ConfigService type definitions
rg -l "federation-sdk" --type ts | grep -E "(node_modules|dist)" | head -10

Length of output: 0


🏁 Script executed:

#!/bin/bash
# Check if there's a federation-sdk package source in the workspace
find ee/packages -name "federation-sdk*" -o -name "*federation*sdk*" | head -20

Length of output: 0


🏁 Script executed:

#!/bin/bash
# Search for any type definitions or imports of ConfigService to understand its type
rg "ConfigService" --type ts -B2 -A2 | head -80

Length of output: 903



---

🌐 Web query:

```web
@rocket.chat/federation-sdk updateConfig method ConfigService

💡 Result:

Do you want the method signature, usage example, or the source code for ConfigService.updateConfig? I can look it up — shall I search the repo/npm docs now?



---

🌐 Web query:

```web
@rocket.chat/federation-sdk version 0.2.0 npm package

💡 Result:

I couldn't find a published @rocket.chat/federation-sdk version 0.2.0 on the public registries. The package appears to have 0.1.x releases (latest listed ~0.1.18); no 0.2.0 release is shown. See registry listings. [1][2]

If you intended to install the latest published release, use:
npm install @rocket.chat/federation-sdk@latest
(Replace @latest with a specific 0.1.x version if you need one.) [1][2]

Sources:
[1] Socket.dev package page for @rocket.chat/federation-sdk (versions list).
[2] Libraries.io npm listing for @rocket.chat/federation-sdk.


Dependency blocker: @rocket.chat/federation-sdk v0.2.0 does not exist yet.

The package appears to have 0.1.x releases; no 0.2.0 release is shown. The code at line 120 calls services.config.updateConfig(configValues), but this method does not exist in any publicly available version of the SDK. Since the PR description references an unreleased homeserver PR (#289) that implements updateConfig, this indicates v0.2.0 is still in development.

Action required:

  • Wait for @rocket.chat/federation-sdk v0.2.0 to be released with the updateConfig method, or
  • Update the version constraint in ee/packages/federation-matrix/package.json once the SDK is published
🧰 Tools
🪛 GitHub Actions: CI

[error] 120-120: TS2339: Property 'updateConfig' does not exist on type 'ConfigService'.

🤖 Prompt for AI Agents
In ee/packages/federation-matrix/src/setup.ts around lines 118 to 121, the code
calls services.config.updateConfig(configValues) which depends on
@rocket.chat/federation-sdk v0.2.0 that is not yet released; either remove or
guard this call until the SDK is published: replace the direct call with a
runtime check like if (typeof services.config.updateConfig === 'function')
services.config.updateConfig(configValues) or comment/remove the call and add a
TODO and revert to the last supported SDK behavior; additionally update
ee/packages/federation-matrix/package.json to pin the dependency to the correct
released SDK version (or update the constraint to ^0.2.0 once the SDK is
published) so the code and package.json remain consistent.

Copy link
Contributor Author

@ricardogarim ricardogarim Oct 27, 2025

Choose a reason for hiding this comment

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

@coderabbitai, the library exists in the Homeserver project (PR #289), and once it’s reviewed there, we’ll release an update to bump the library version here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

@sampaiodiego
Copy link
Member

replaced by #37357

@sampaiodiego sampaiodiego deleted the federation-settings-watch branch November 26, 2025 19:34
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.

3 participants