Skip to content

WebRTC Talk: TypeError 'this.peer is null' when calling addTrack on null RTCPeerConnection #89434

@losts1

Description

@losts1

Bug Report

Summary

TypeError: can't access property "addTrack", this.peer is null — error in OpenClaw control-ui dashboard when using the Realtime Talk (voice) feature.

Description

In the WebRTC Talk transport (PH class in dist/control-ui/assets/index-*.js), this.peer.addTrack(e, this.media) is called without a null guard. If the peer connection is closed/nulled before track addition completes (race condition between stop() and start()), the method throws.

Root Cause

In PH.start():

this.peer = new RTCPeerConnection;
// ...
this.media = await navigator.mediaDevices.getUserMedia({audio: true});
for (let e of this.media.getAudioTracks()) this.peer.addTrack(e, this.media);  // ← crash if this.peer is null

The stop() method sets this.peer = null. If stop() runs concurrently (e.g., user cancels, session teardown) after this.peer is constructed but before addTrack is called, this.peer is null and the error is thrown.

Reproduction

  1. Start a Realtime Talk session in the dashboard
  2. Stop/cancel the session quickly, or have microphone permission denied
  3. Start another Talk session
  4. Error: can't access property "addTrack", this.peer is null

Expected Behavior

Null guard should prevent the crash; the session should handle teardown gracefully.

Fix

Add null check before addTrack:

for (let e of this.media.getAudioTracks()) {
  if (this.peer) this.peer.addTrack(e, this.media);
}

Or better, guard the entire start() method against concurrent stop().

Environment

  • OpenClaw version: 2026.5.28 (e932160)
  • Component: control-ui (WebRTC Talk handler)
  • Browser: any (WebRTC API)

Impact

Non-blocking for text chat users. Only affects users attempting Realtime Talk (voice input) in the dashboard.

Metadata

Metadata

Assignees

Labels

P2Normal backlog priority with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:otherThis issue has meaningful maintainer-visible impact outside the owned taxonomy.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions