Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Zg/resume on reconnect#330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
zgreathouse wants to merge9 commits intomain
base:main
Choose a base branch
Loading
fromzg/resume-on-reconnect
Draft

Conversation

@zgreathouse
Copy link
Member

@zgreathousezgreathouse commentedApr 11, 2025
edited
Loading

Summary of Changes Made

EmpathicVoice Client

Adds built-in support for resuming a Chats when reconnecting

  • Adds optionalshouldAttemptReconnect callback argument inReconnectingWebSocket for implementing custom logic for when to try to reconnect.
  • Add means for setting and deleting query params that are included in the url when the ReconnectingWebSocket connects for the purpose of adding theresumed_chat_group_id query param to the handshake url to support resume on reconnect.)
  • UpdateChatSocket to extractchatGroupId from chat_metadata message and update query param overrides onReconnectingWebSocket by default to support resume on reconnect.
  • Add optionalshouldResumeChat option forChatClient
  • UpdateChat client to accept optionalshouldResumeChat argument (escape hatch for default resume on reconnect behavior)
  • Add static method onChat client for reconnect logic, only attempting a reconnect when WebSocket was closed with one of the followingWebSocket close codes:
    • 1006 (Abnormal Closure)
    • 1011 (Internal Error)
    • 1012 (Service Restart)
    • 1013 (Try Again Later)
    • 1014 (Bad Gateway)

volskaya reacted with thumbs up emoji
@zgreathousezgreathouse marked this pull request as draftApril 11, 2025 03:47
Copy link
Contributor

@twitchardtwitchard left a comment

Choose a reason for hiding this comment

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

LGTM. We should add a test or manually test both paths before release though

zgreathouse reacted with thumbs up emoji
}
}

constshouldResumeChat=args.shouldResumeChat??true;
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO defaulting to true is "breaking" enough that we should highlight it by releasing minor instead of patch wdyt?

Copy link
MemberAuthor

@zgreathousezgreathouseApr 11, 2025
edited
Loading

Choose a reason for hiding this comment

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

@twitchard I agree! Although, I am now leaning toward defaulting tofalse.

It is likely true, in nearly all cases, that users would want to resume a Chat when reconnecting after an unexpected disconnect. However, this current implementation actually breaks when attempting to resume on reconnect if zero data retention is enabled.

There is currently no field in the API which we can leverage to determine whether or not zero data retention has been enabled on the account. Since we are always adding theresumed_chat_group_id query param toReconnectingWebSocket._queryParamOverrides upon receiving thechat_metadata message, when anew chat unexpectedly disconnects and we try to reconnect it will fail with aE0720 error instead of reconnecting. When receiving this error we need to remove the query param from theReconnectingWebSocket._queryParamOverrides so when it tries to reconnect it won't fail.

Apart from that fix, defaulting tofalse would make the changes here purely additive, while giving users the option to enable resuming on reconnect.

@volskaya
Copy link

I feel like this might suffer from a server restriction, where it doesn't let you resume the group ID if it didn't detect a close, because a socket closing client side doesn't guarantee that it closed server side too.

Like if there's a network drop or switch, or on mobile if the app running this code was suspended or some other factor broke it, leaving the server hanging waiting for response, until its own networking library times it out or the EVI's inactivity timeout gets triggered.

🙇In my opinion the server should allow the client to resume when ever it wants, the behavior should be that if it sees an attempt to establish a new websocket with an already used group id, the old connection should be disposed and it should proceed with the new one.

It should let a test case like this pass to fully support resumes:

it("Chat group ID can take over an older connection",async()=>{consthume=newHumeClient({accessToken:"<>",});letresolveNewerSocket:(socket:ChatSocket)=>void|undefined;letresolveSuccess:()=>void|undefined;letrejectSuccess:()=>void|undefined;constpromiseNewerSocket=newPromise<ChatSocket>((res)=>(resolveNewerSocket=res));constpromiseSuccess=newPromise<void>((res,rej)=>((resolveSuccess=res),(rejectSuccess=rej)));constolderSocket=hume.empathicVoice.chat.connect({debug:false,reconnectAttempts:30,});awaitolderSocket.tillSocketOpen();olderSocket.on("message",(message)=>{if(message.type==="chat_metadata"){resolveNewerSocket(hume.empathicVoice.chat.connect({debug:false,reconnectAttempts:30,resumedChatGroupId:message.chatGroupId,}),);}});constnewerSocket=awaitpromiseNewerSocket;newerSocket.on("close",()=>rejectSuccess());newerSocket.on("message",(message)=>{if(message.type==="chat_metadata")resolveSuccess();});awaitnewerSocket.tillSocketOpen();awaitpromiseSuccess;olderSocket.close();newerSocket.close();},100000);

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

Reviewers

@twitchardtwitchardtwitchard approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@zgreathouse@volskaya@twitchard

[8]ページ先頭

©2009-2025 Movatter.jp