Skip to content

fix(autotranslate): always remove existing callback before re-registering#41330

Open
prathamesh04 wants to merge 1 commit into
RocketChat:developfrom
prathamesh04:fix/autotranslate-provider-switch
Open

fix(autotranslate): always remove existing callback before re-registering#41330
prathamesh04 wants to merge 1 commit into
RocketChat:developfrom
prathamesh04:fix/autotranslate-provider-switch

Conversation

@prathamesh04

@prathamesh04 prathamesh04 commented Jul 12, 2026

Copy link
Copy Markdown

Proposed changes

When switching AutoTranslate providers while enabled, translations continue using the old provider until the server is restarted.

Root cause: In TranslationProviderRegistry.registerCallbacks(), the old afterSaveMessage callback was only removed when auto-translate was disabled. When the provider changed, callbacks.add() was called with the existing id autotranslate, but callbacks.add() silently returns a removal function instead of replacing when the id already exists. So the old callback (capturing the previous provider in its closure) was never replaced.

Fix: Always call callbacks.remove('afterSaveMessage', 'autotranslate') before adding the new callback, regardless of whether auto-translate is being enabled or the provider is being changed.

Issue(s)

Fixes #41197

Steps to test or reproduce

  1. Enable Auto-Translate with the default provider (google-translate)
  2. Switch Service Provider to libre-translate (or any other) while Auto-Translate remains enabled
  3. Send a message in a channel with auto-translate enabled for a member
  4. Before fix: Message is translated by the old provider (google-translate)
  5. After fix: Message is correctly translated by the new provider (libre-translate)

Further comments

  • Changed file: apps/meteor/app/autotranslate/server/autotranslate.ts
  • Change is minimal: moved callbacks.remove() call to always execute before callbacks.add(), instead of only when disabling
  • This is consistent with how other callback-based systems handle re-registration

Summary by CodeRabbit

  • Bug Fixes
    • Fixed duplicate automatic translations that could occur after repeated configuration updates.
    • Improved callback handling when automatic translation is disabled or reconfigured.

…ring

When switching AutoTranslate providers, the old callback was not being
removed because callbacks.add() with an existing ID silently returns
a removal function instead of replacing. This caused translations to
continue using the old provider until server restart.

Fixes RocketChat#41197
@changeset-bot

changeset-bot Bot commented Jul 12, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 027da2a

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

@dionisio-bot

dionisio-bot Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

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

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Auto-translate callback registration now removes the existing callback before evaluating whether auto-translate is enabled, allowing provider changes to replace stale message translation callbacks.

Changes

Auto-translate callback lifecycle

Layer / File(s) Summary
Reset callback before provider registration
apps/meteor/app/autotranslate/server/autotranslate.ts
registerCallbacks removes the existing afterSaveMessage callback before the enabled check, while disabled mode still exits without registering a replacement.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Suggested labels: type: bug

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The change matches #41197 by rebinding AutoTranslate after provider changes and avoiding stale provider callbacks.
Out of Scope Changes check ✅ Passed The PR is narrowly scoped to the callback re-registration fix and adds no unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main fix: removing the existing auto-translate callback before re-registering it.

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.

@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.

No issues found across 1 file

Re-trigger cubic

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.

AutoTranslate: switching Service Provider while enabled silently keeps translating with the old provider

1 participant