Skip to content

fix(browser): complete extension relay handshake on connect.challenge#22571

Closed
pandego wants to merge 3 commits intoopenclaw:mainfrom
pandego:fix/22553-extension-connect-challenge
Closed

fix(browser): complete extension relay handshake on connect.challenge#22571
pandego wants to merge 3 commits intoopenclaw:mainfrom
pandego:fix/22553-extension-connect-challenge

Conversation

@pandego
Copy link
Contributor

@pandego pandego commented Feb 21, 2026

Summary

Fixes Chrome extension relay sessions getting stuck at badge by implementing the required gateway handshake flow in the bundled extension background worker.

Closes #22553

Root cause

Gateway now emits a pre-connect connect.challenge event. The extension websocket client did not handle that event and never sent a connect request, so the relay session never became authenticated/ready.

What changed

  • Handle type=event,event=connect.challenge in assets/chrome-extension/background.js
  • Send a proper gateway connect request from the extension with token auth and client metadata
  • Wait for successful connect response before considering relay setup complete
  • Ensure message listener is bound early so the first challenge frame cannot be missed
  • Cleanly reject pending handshake promise on disconnect/timeouts

Validation

  • node --check assets/chrome-extension/background.js

AI assistance

AI-assisted; change reviewed and validated locally.

Greptile Summary

Implemented the required gateway handshake flow to fix Chrome extension relay sessions getting stuck at the connecting badge (). The extension now properly handles the connect.challenge event sent by the gateway server and responds with a connect request containing authentication credentials and client metadata. The message handler is bound early (before WebSocket open) to prevent race conditions where the challenge could be missed, and the connection waits for successful handshake completion before proceeding with relay operations.

  • Added state variables to track handshake progress (relayGatewayToken, relayConnectRequestId, relayConnectResolve/Reject, relayConnectTimer, relayChallengeSeen)
  • Implemented waitForGatewayConnect() to create a promise-based handshake with 8-second timeout
  • Added ensureGatewayHandshakeStarted() to send the connect request with proper protocol parameters
  • Handle connect.challenge event and successful/failed connect responses in onRelayMessage
  • Clean up handshake state on disconnect/errors via clearRelayConnectState()
  • Bound ws.onmessage before the WebSocket opens to prevent missing the initial challenge event

Confidence Score: 5/5

  • Safe to merge - addresses a critical bug with proper error handling and timeout protection
  • Implementation correctly follows the gateway protocol as documented and matches patterns from the TypeScript client. The handshake flow includes proper timeout handling (8s), early message binding to prevent race conditions, clean state management on errors/disconnects, and appropriate promise-based async flow. The fix directly addresses the reported issue and includes validation.
  • No files require special attention

Last reviewed commit: 6d012ed

@openclaw-barnacle openclaw-barnacle bot added size: S channel: msteams Channel integration: msteams labels Feb 21, 2026
@pandego
Copy link
Contributor Author

pandego commented Feb 21, 2026

Follow-up fix pushed for CI stability:

  • Stabilized extensions/msteams/src/messenger.test.ts OneDrive fallback mention test by mocking loadWebMedia deterministically in-test, removing filesystem/temp-path dependence across platforms.
  • This keeps the test focused on mention+fallback-link behavior and avoids platform-specific path/IO variance.

Local validation run:

  • pnpm vitest run extensions/msteams/src/messenger.test.ts
  • pnpm oxfmt --check extensions/msteams/src/messenger.test.ts

@pandego pandego force-pushed the fix/22553-extension-connect-challenge branch 2 times, most recently from 7df8591 to af52d6b Compare February 21, 2026 12:43
@openclaw-barnacle openclaw-barnacle bot removed the channel: msteams Channel integration: msteams label Feb 21, 2026
@pandego pandego force-pushed the fix/22553-extension-connect-challenge branch from 5e6e302 to 404a2e5 Compare February 21, 2026 13:21
@openclaw-barnacle openclaw-barnacle bot added the channel: msteams Channel integration: msteams label Feb 21, 2026
steipete added a commit that referenced this pull request Feb 26, 2026
Bind relay WS message handling before onopen and add non-blocking connect.challenge response support without forcing handshake waits on current relay protocol.
Landed from contributor @pandego (PR #22571).

Co-authored-by: pandego <7780875+pandego@users.noreply.github.com>
@steipete
Copy link
Contributor

Landed on main via 65d5a9124.

What landed from this PR (adapted for current relay architecture):

  • early WS message binding before onopen so immediate first frames are not missed
  • non-blocking connect.challenge compatibility handling in the extension worker
  • handshake-failure handling that closes/retries without forcing a blocking connect wait on current local relay protocol
  • changelog attribution for PR fix(browser): complete extension relay handshake on connect.challenge #22571

Note: I intentionally did not land the unrelated extensions/msteams/src/messenger.test.ts change from this PR branch.

SHA mapping:

  • original browser fix commit: 9c9d24f0a9c5c4c0133c9fb749efe37cbbf3b8ad
  • landed commit: 65d5a9124

Thanks for the fix direction, @pandego.

@steipete steipete closed this Feb 26, 2026
wanjizheng pushed a commit to wanjizheng/openclaw that referenced this pull request Feb 27, 2026
…ndling

Bind relay WS message handling before onopen and add non-blocking connect.challenge response support without forcing handshake waits on current relay protocol.
Landed from contributor @pandego (PR openclaw#22571).

Co-authored-by: pandego <7780875+pandego@users.noreply.github.com>
wanjizheng pushed a commit to wanjizheng/openclaw that referenced this pull request Feb 27, 2026
…ndling

Bind relay WS message handling before onopen and add non-blocking connect.challenge response support without forcing handshake waits on current relay protocol.
Landed from contributor @pandego (PR openclaw#22571).

Co-authored-by: pandego <7780875+pandego@users.noreply.github.com>
(cherry picked from commit 03e1b2a)
wanjizheng pushed a commit to wanjizheng/openclaw that referenced this pull request Feb 27, 2026
…ndling

Bind relay WS message handling before onopen and add non-blocking connect.challenge response support without forcing handshake waits on current relay protocol.
Landed from contributor @pandego (PR openclaw#22571).

Co-authored-by: pandego <7780875+pandego@users.noreply.github.com>
(cherry picked from commit 03e1b2a)
wanjizheng pushed a commit to wanjizheng/openclaw that referenced this pull request Feb 27, 2026
…ndling

Bind relay WS message handling before onopen and add non-blocking connect.challenge response support without forcing handshake waits on current relay protocol.
Landed from contributor @pandego (PR openclaw#22571).

Co-authored-by: pandego <7780875+pandego@users.noreply.github.com>
(cherry picked from commit 03e1b2a)
wanjizheng pushed a commit to wanjizheng/openclaw that referenced this pull request Feb 27, 2026
…ndling

Bind relay WS message handling before onopen and add non-blocking connect.challenge response support without forcing handshake waits on current relay protocol.
Landed from contributor @pandego (PR openclaw#22571).

Co-authored-by: pandego <7780875+pandego@users.noreply.github.com>
(cherry picked from commit 03e1b2a)
wanjizheng pushed a commit to wanjizheng/openclaw that referenced this pull request Feb 27, 2026
…ndling

Bind relay WS message handling before onopen and add non-blocking connect.challenge response support without forcing handshake waits on current relay protocol.
Landed from contributor @pandego (PR openclaw#22571).

Co-authored-by: pandego <7780875+pandego@users.noreply.github.com>
(cherry picked from commit 03e1b2a)
execute008 pushed a commit to execute008/openclaw that referenced this pull request Feb 27, 2026
…ndling

Bind relay WS message handling before onopen and add non-blocking connect.challenge response support without forcing handshake waits on current relay protocol.
Landed from contributor @pandego (PR openclaw#22571).

Co-authored-by: pandego <7780875+pandego@users.noreply.github.com>
r4jiv007 pushed a commit to r4jiv007/openclaw that referenced this pull request Feb 28, 2026
…ndling

Bind relay WS message handling before onopen and add non-blocking connect.challenge response support without forcing handshake waits on current relay protocol.
Landed from contributor @pandego (PR openclaw#22571).

Co-authored-by: pandego <7780875+pandego@users.noreply.github.com>
mylukin pushed a commit to mylukin/openclaw that referenced this pull request Feb 28, 2026
…ndling

Bind relay WS message handling before onopen and add non-blocking connect.challenge response support without forcing handshake waits on current relay protocol.
Landed from contributor @pandego (PR openclaw#22571).

Co-authored-by: pandego <7780875+pandego@users.noreply.github.com>
wanjizheng pushed a commit to wanjizheng/openclaw that referenced this pull request Feb 28, 2026
…ndling

Bind relay WS message handling before onopen and add non-blocking connect.challenge response support without forcing handshake waits on current relay protocol.
Landed from contributor @pandego (PR openclaw#22571).

Co-authored-by: pandego <7780875+pandego@users.noreply.github.com>
(cherry picked from commit 03e1b2a)
wanjizheng pushed a commit to wanjizheng/openclaw that referenced this pull request Feb 28, 2026
…ndling

Bind relay WS message handling before onopen and add non-blocking connect.challenge response support without forcing handshake waits on current relay protocol.
Landed from contributor @pandego (PR openclaw#22571).

Co-authored-by: pandego <7780875+pandego@users.noreply.github.com>
(cherry picked from commit 03e1b2a)
wanjizheng pushed a commit to wanjizheng/openclaw that referenced this pull request Feb 28, 2026
…ndling

Bind relay WS message handling before onopen and add non-blocking connect.challenge response support without forcing handshake waits on current relay protocol.
Landed from contributor @pandego (PR openclaw#22571).

Co-authored-by: pandego <7780875+pandego@users.noreply.github.com>
(cherry picked from commit 03e1b2a)
wanjizheng pushed a commit to wanjizheng/openclaw that referenced this pull request Feb 28, 2026
…ndling

Bind relay WS message handling before onopen and add non-blocking connect.challenge response support without forcing handshake waits on current relay protocol.
Landed from contributor @pandego (PR openclaw#22571).

Co-authored-by: pandego <7780875+pandego@users.noreply.github.com>
(cherry picked from commit 03e1b2a)
vincentkoc pushed a commit to Sid-Qin/openclaw that referenced this pull request Feb 28, 2026
…ndling

Bind relay WS message handling before onopen and add non-blocking connect.challenge response support without forcing handshake waits on current relay protocol.
Landed from contributor @pandego (PR openclaw#22571).

Co-authored-by: pandego <7780875+pandego@users.noreply.github.com>
vincentkoc pushed a commit to rylena/rylen-openclaw that referenced this pull request Feb 28, 2026
…ndling

Bind relay WS message handling before onopen and add non-blocking connect.challenge response support without forcing handshake waits on current relay protocol.
Landed from contributor @pandego (PR openclaw#22571).

Co-authored-by: pandego <7780875+pandego@users.noreply.github.com>
hughdidit pushed a commit to hughdidit/DAISy-Agency that referenced this pull request Mar 1, 2026
…ndling

Bind relay WS message handling before onopen and add non-blocking connect.challenge response support without forcing handshake waits on current relay protocol.
Landed from contributor @pandego (PR openclaw#22571).

Co-authored-by: pandego <7780875+pandego@users.noreply.github.com>
(cherry picked from commit 65d5a91)

# Conflicts:
#	CHANGELOG.md
#	assets/chrome-extension/background.js
steipete added a commit to Sid-Qin/openclaw that referenced this pull request Mar 2, 2026
…ndling

Bind relay WS message handling before onopen and add non-blocking connect.challenge response support without forcing handshake waits on current relay protocol.
Landed from contributor @pandego (PR openclaw#22571).

Co-authored-by: pandego <7780875+pandego@users.noreply.github.com>
robertchang-ga pushed a commit to robertchang-ga/openclaw that referenced this pull request Mar 2, 2026
…ndling

Bind relay WS message handling before onopen and add non-blocking connect.challenge response support without forcing handshake waits on current relay protocol.
Landed from contributor @pandego (PR openclaw#22571).

Co-authored-by: pandego <7780875+pandego@users.noreply.github.com>
hughdidit pushed a commit to hughdidit/DAISy-Agency that referenced this pull request Mar 3, 2026
…ndling

Bind relay WS message handling before onopen and add non-blocking connect.challenge response support without forcing handshake waits on current relay protocol.
Landed from contributor @pandego (PR openclaw#22571).

Co-authored-by: pandego <7780875+pandego@users.noreply.github.com>
(cherry picked from commit 65d5a91)

# Conflicts:
#	CHANGELOG.md
#	assets/chrome-extension/background.js
dorgonman pushed a commit to kanohorizonia/openclaw that referenced this pull request Mar 3, 2026
…ndling

Bind relay WS message handling before onopen and add non-blocking connect.challenge response support without forcing handshake waits on current relay protocol.
Landed from contributor @pandego (PR openclaw#22571).

Co-authored-by: pandego <7780875+pandego@users.noreply.github.com>
zooqueen pushed a commit to hanzoai/bot that referenced this pull request Mar 6, 2026
…ndling

Bind relay WS message handling before onopen and add non-blocking connect.challenge response support without forcing handshake waits on current relay protocol.
Landed from contributor @pandego (PR openclaw#22571).

Co-authored-by: pandego <7780875+pandego@users.noreply.github.com>
thebenjaminlee pushed a commit to escape-velocity-ventures/openclaw that referenced this pull request Mar 7, 2026
…ndling

Bind relay WS message handling before onopen and add non-blocking connect.challenge response support without forcing handshake waits on current relay protocol.
Landed from contributor @pandego (PR openclaw#22571).

Co-authored-by: pandego <7780875+pandego@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: msteams Channel integration: msteams size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Chrome extension stuck on "…" badge — gateway sends connect.challenge but extension has no handler

3 participants