Skip to content

fix(mercury): gracefully handle mercury rebalancing - #5106

Merged
rsarika merged 7 commits into
webex:nextfrom
Shreyas281299:mercury-4000-fix
Aug 18, 2026
Merged

fix(mercury): gracefully handle mercury rebalancing#5106
rsarika merged 7 commits into
webex:nextfrom
Shreyas281299:mercury-4000-fix

Conversation

@Shreyas281299

@Shreyas281299 Shreyas281299 commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

COMPLETES #N/A

This pull request addresses

Mercury close code 4000 is not always a signal that the current SDK context should reconnect. According to Mercury connection behavior, 4000 with close reason Replaced means another connection already replaced the current registration, so this older connection should stand down. A 4000 with any other reason should be treated as an unexpected close and reconnect.

by making the following changes

  • Checks the Mercury close reason when handling close code 4000.
  • Preserves the existing no-reconnect behavior for 4000 with reason Replaced by emitting offline.replaced.
  • Reconnects the active socket for 4000 with any other reason by emitting offline.transient and calling _reconnect().
  • Adds unit coverage for 4000/Replaced, 4000 with an unknown reason, and non-active socket close handling.

Change Type

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Tooling change
  • Internal code refactor

The following scenarios were tested

  • Automated: yarn workspace @webex/internal-plugin-mercury test:unit --targets mercury.js passed with 100 passing.
  • Automated: yarn workspace @webex/internal-plugin-mercury test:style completed with no errors and one existing JSDoc warning in src/index.js.
  • Manual: Verified the Mercury rebalancing/4000 close-code behavior. Testing recording: https://app.vidcast.io/share/f7a115a2-2c8e-434f-aa0b-6f04984fd253

The GAI Coding Policy And Copyright Annotation Best Practices

  • GAI was not used (or, no additional notation is required)
  • Code was generated entirely by GAI
  • GAI was used to create a draft that was subsequently customized or modified
  • Coder created a draft manually that was non-substantively modified by GAI (e.g., refactoring was performed by GAI on manually written code)
  • Tool used for AI assistance (GitHub Copilot / Other - specify)
    • Github Copilot
    • Other - Cursor/GPT
  • This PR is related to
    • Feature
    • Defect fix
    • Tech Debt
    • Automation

I certified that

  • I have read and followed contributing guidelines
  • I discussed changes with code owners prior to submitting this pull request
  • I have not skipped any automated checks
  • All existing and new tests passed
  • I have updated the documentation accordingly

Make sure to have followed the contributing guidelines before submitting.

@Shreyas281299
Shreyas281299 requested review from a team as code owners July 20, 2026 09:00

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8e0f835eee

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/@webex/internal-plugin-mercury/src/mercury.js
@aws-amplify-us-east-2

Copy link
Copy Markdown

This pull request is automatically being deployed by Amplify Hosting (learn more).

Access this pull request here: https://pr-5106.d3m3l2kee0btzx.amplifyapp.com

@Shreyas281299 Shreyas281299 added the validated If the pull request is validated for automation. label Jul 27, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9c0d1145da

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/@webex/internal-plugin-mercury/src/mercury.js
@github-actions github-actions Bot removed the validated If the pull request is validated for automation. label Aug 14, 2026
@rsarika rsarika added the validated If the pull request is validated for automation. label Aug 14, 2026
@github-actions github-actions Bot removed the validated If the pull request is validated for automation. label Aug 17, 2026
@rsarika rsarika added the validated If the pull request is validated for automation. label Aug 17, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 56582c3011

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/@webex/internal-plugin-mercury/test/unit/spec/mercury.js
this.logger.info(`${this.namespace}: socket ${sessionId} replaced; will not reconnect`);
if (isActiveSocket) this._emit(sessionId, 'offline.replaced', event);
// If not active, nothing to do
if (reason === 'replaced') {

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.

Nitpick: The comparison reason === 'replaced' is case-sensitive. If there's any chance the server could send 'Replaced' or 'REPLACED', a safer check would be:
if (reason?.toLowerCase() === 'replaced')

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.

yes, its already there at declaration const reason = event.reason && event.reason.toLowerCase();

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

Left a minor comment, can you please address bot's comments

@github-actions github-actions Bot removed the validated If the pull request is validated for automation. label Aug 18, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 63518cacfa

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/@webex/internal-plugin-mercury/src/mercury.js Outdated
@rsarika rsarika added the validated If the pull request is validated for automation. label Aug 18, 2026
@rsarika
rsarika merged commit 2ddabdd into webex:next Aug 18, 2026
11 checks passed
@github-actions

Copy link
Copy Markdown
🎉 Your changes are now available!
Released in: v3.12.0-next.179
📖 View full changelog →
Packages Updated Version
webex 3.12.0-next.179
@webex/contact-center 3.12.0-next.104
@webex/internal-plugin-ai-assistant 3.12.0-next.44
@webex/internal-plugin-board 3.12.0-next.46
@webex/internal-plugin-calendar 3.12.0-next.46
@webex/internal-plugin-call-ai-summary 3.12.0-next.44
@webex/internal-plugin-conversation 3.12.0-next.46
@webex/internal-plugin-dss 3.12.0-next.44
@webex/internal-plugin-ediscovery 3.12.0-next.46
@webex/internal-plugin-encryption 3.12.0-next.44
@webex/internal-plugin-flag 3.12.0-next.46
@webex/internal-plugin-llm 3.12.0-next.47
@webex/internal-plugin-locus 3.12.0-next.44
@webex/internal-plugin-lyra 3.12.0-next.46
@webex/internal-plugin-mercury 3.12.0-next.44
@webex/internal-plugin-presence 3.12.0-next.44
@webex/internal-plugin-scheduler 3.12.0-next.44
@webex/internal-plugin-search 3.12.0-next.46
@webex/internal-plugin-support 3.12.0-next.46
@webex/internal-plugin-task 3.12.0-next.46
@webex/internal-plugin-team 3.12.0-next.46
@webex/internal-plugin-voicea 3.12.0-next.49
@webex/plugin-attachment-actions 3.12.0-next.46
@webex/plugin-device-manager 3.12.0-next.46
@webex/plugin-encryption 3.12.0-next.44
@webex/plugin-meetings 3.12.0-next.125
@webex/plugin-memberships 3.12.0-next.46
@webex/plugin-messages 3.12.0-next.46
@webex/plugin-people 3.12.0-next.44
@webex/plugin-presence 0.0.0-next.218
@webex/plugin-rooms 3.12.0-next.46
@webex/recipe-private-web-client 3.12.0-next.47
@webex/test-webex-node 0.0.1-next.2
@webex/webex-server 3.12.0-next.46
webex-node 3.12.0-next.51

Thank you for your contribution!
🤖 This is an automated message. For queries, please contact support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

validated If the pull request is validated for automation.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants