Skip to content

feat(calling): keepalive flow refactor#4869

Open
Kesari3008 wants to merge 2 commits intowebex:mobius-socketfrom
Kesari3008:keeplive-flow-refactor
Open

feat(calling): keepalive flow refactor#4869
Kesari3008 wants to merge 2 commits intowebex:mobius-socketfrom
Kesari3008:keeplive-flow-refactor

Conversation

@Kesari3008
Copy link
Copy Markdown
Contributor

COMPLETES

This pull request addresses

Updated webworker logic of sending keepalives in a way so that we can use wbsocket to send messages along with HTTP

by making the following changes

Moved the actual send out of the webworker but timer is controlled in webworker

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

< ENUMERATE TESTS PERFORMED, WHETHER MANUAL OR AUTOMATED >

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 - Please Specify
  • 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.

@Kesari3008 Kesari3008 requested a review from a team as a code owner April 16, 2026 21:16
@Kesari3008 Kesari3008 added the validated If the pull request is validated for automation. label Apr 16, 2026
Copy link
Copy Markdown

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

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: aadf329da6

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +25 to +29
if (!APIRequest.instance) {
APIRequest.instance = new APIRequest(config);
}

return APIRequest.instance;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Scope APIRequest to each CallingClient instance

APIRequest.getInstance() returns a process-wide singleton that preserves the first webex object forever, so later CallingClient/Registration/Call instances reuse the wrong SDK context. In multi-client scenarios (different users/orgs/devices in the same runtime), subsequent requests are sent with the first client's credentials/session, which can route traffic to the wrong account and break registration/call flows. This regression is introduced by the new static singleton in request.ts; the previous code always used each instance’s own this.webex.request(...) path.

Useful? React with 👍 / 👎.

Comment on lines +993 to +996
this.webWorker?.postMessage({
type: WorkerMessageType.KEEPALIVE_RESULT,
statusCode: res.status,
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Bind keepalive replies to the worker that issued them

The keepalive handler posts KEEPALIVE_RESULT back through this.webWorker, which is mutable and may already point to a newly created worker after failover/re-registration. If an old in-flight keepalive resolves late, its failure can be delivered to the new worker and incorrectly increment retry counters, triggering spurious reconnect/unregister behavior. This race was introduced by moving keepalive I/O out of the worker while still routing results via the current shared worker reference.

Useful? React with 👍 / 👎.

@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-4869.d3m3l2kee0btzx.amplifyapp.com

@rarajes2 rarajes2 changed the base branch from next to mobius-socket April 17, 2026 09:54
Comment on lines +493 to +526
private async postKeepAlive(
accessToken: string,
deviceUrl: string,
url: string,
trackingId: string
): Promise<{status: number}> {
const mobiusSocket = this.mobiusSocket;

if (this.isMobiusSocketEnabled && mobiusSocket?.isConnected?.()) {
await mobiusSocket.send({
type: 'status',
deviceUrl,
trackingId,
});

return {status: 200};
}

const response = await fetch(`${url}/status`, {
method: HTTP_METHODS.POST,
headers: {
[CISCO_DEVICE_URL]: deviceUrl,
[SPARK_USER_AGENT]: CALLING_USER_AGENT,
Authorization: `${accessToken}`,
trackingId,
},
});

if (!response.ok) {
throw response;
}

return response;
}
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.

We can replace this whole thing with makeRequest --- it takes care of making http or socket request

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

same comment

extension?: string,
voicemail?: string
voicemail?: string,
registrationOptions?: TransportLayer
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.

We might not need to pass this information. MobiusSocket is singleton and we can use feature flag util

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

same comment

isMobiusSocketEnabled?: boolean;
mobiusSocket?: {
isConnected?: () => boolean;
send: (payload: Record<string, unknown>) => Promise<unknown>;
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.

We won't be calling this send directly. The type TransportLayer might not be required

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Same comment

Comment on lines +817 to +844
const line = this.isMobiusSocketEnabled
? new Line(
this.webex.internal.device.userId,
this.webex.internal.device.url,
this.mutex,
this.primaryMobiusUris,
this.backupMobiusUris,
this.getLoggingLevel(),
this.sdkConfig?.serviceData,
this.sdkConfig?.jwe,
undefined,
undefined,
undefined,
{
isMobiusSocketEnabled: this.isMobiusSocketEnabled,
mobiusSocket: this.mobiusSocket,
}
)
: new Line(
this.webex.internal.device.userId,
this.webex.internal.device.url,
this.mutex,
this.primaryMobiusUris,
this.backupMobiusUris,
this.getLoggingLevel(),
this.sdkConfig?.serviceData,
this.sdkConfig?.jwe
);
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.

We don't have to create line object conditionally with mobiusSocket and feature flag info. We will be using the makeRequest method to make api call and it will take care of the transport type

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

These are temp changes done only to test the flow, final changes will be adjusted based on other PRs being merged

Copy link
Copy Markdown

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

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: c569723e83

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +997 to +1000
} catch (err: any) {
this.webWorker?.postMessage({
type: WorkerMessageType.KEEPALIVE_RESULT,
err,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Serialize keepalive errors before posting to worker

When postKeepAlive() gets a non-2xx HTTP response it throws the raw Response object, and this catch block forwards that object directly via Worker.postMessage. Response is not reliably structured-cloneable across worker boundaries, so postMessage can throw DataCloneError on keepalive failures; in that case no KEEPALIVE_RESULT is delivered, the worker stays keepaliveInFlight = true, and keepalive/reconnect handling stops after the first failed tick.

Useful? React with 👍 / 👎.

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

Labels

mobius-wss validated If the pull request is validated for automation.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants