Skip to content

Data tracks: establish data channels - #987

Merged
ladvoc merged 7 commits into
ladvoc/data-track-signalingfrom
ladvoc/data-track-channel
Oct 21, 2026
Merged

ladvoc merged 7 commits into
ladvoc/data-track-signalingfrom
ladvoc/data-track-channel

Conversation

@ladvoc

@ladvoc ladvoc commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Adds the _data_track data channel alongside the existing lossy and reliable channels, forwards incoming packets to the room, and adds a sender that paces frames onto the channel while keeping only the freshest one. This is not integrated with anything yet.

Closes BOT-541

@ladvoc
ladvoc force-pushed the ladvoc/data-track-channel branch from eea8c6e to 1b8aa1a Compare September 4, 2026 15:07
@ladvoc
ladvoc marked this pull request as ready for review September 4, 2026 16:06
@ladvoc
ladvoc requested a review from a team as a code owner September 4, 2026 16:06
@ladvoc
ladvoc requested a review from boks1971 September 4, 2026 16:07

@devin-ai-integration devin-ai-integration 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.

Note

This report is out of date. Scroll down for Devin Review's latest report on this PR.

🔍 Devin Review: 1 flag

Not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)

Devin Review

Comment thread datatracksender.go Outdated
}

func (s *dataTrackSender) send(frame dataTrackFramePackets) {
s.once.Do(func() { go s.run() })

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.

probably make a start() call? It does only once, but has to check on every send if this is already done.

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.

guess it can be started from the constructor too. Makes things simple.

Comment thread datatracksender.go Outdated
Comment thread engine.go
e.dataTrackDC.OnMessage(e.handleDataTrackPacket)
e.dataTrackDC.SetBufferedAmountLowThreshold(dataTrackBufferedAmountLowThreshold)
e.dataTrackDC.OnBufferedAmountLow(e.dataTrackSender.wake)
e.dataTrackDC.OnOpen(e.dataTrackSender.wake)

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.

I made a note about starting the data track sender, this is another place it can be started I think.

Comment thread datatracksender.go Outdated

for {
if current := s.dc(); current != dc {
dc, inFlight = current, nil

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.

this is clearing inFlight on a data channel change.

Not sure if we want to keep checking for data channel. Maybe, it can be set and updated on change or even newDataTrackSender created by engine on data channel change. Would be good to keep this simple.

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.

I've made some changes to data channel sender in 5bbc090 to address your comments. This clarifies that in-flight packets for a particular frame should be dropped when data channel changes, and the data channel itself is set after the sender is created. For the latter point, please let me know if this is what you had in mind.

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.

Looks good to me. I would add some logs for the following

  • when a data channel changes in datatracksender (can log in setDC and also in run loop when that change is picked up)
  • when inFlight is dropped, what/how much is dropped
  • the current dropped can be Infow (could be spammy though if somebody just keeps sending at high rate on a narrow channel)

@ladvoc
ladvoc force-pushed the ladvoc/data-track-channel branch from 1b8aa1a to 7fd40fd Compare September 4, 2026 22:57

@devin-ai-integration devin-ai-integration 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.

Devin Review found 1 new potential issue.

1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)

Devin Review

Comment thread datatracksender.go
Comment on lines +115 to +121
s.lock.Lock()
current := s.dc
s.lock.Unlock()
if current != dc {
// A partially sent frame cannot be completed on a new channel.
dc, inFlight = current, nil
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Channel replacement sends stale frames

When setDataChannel replaces the channel during an active send loop, run continues writing the current frame to the old channel. It snapshots dc only before the inner loop. Packets can reach the obsolete session or be discarded.

Prompt for agents
In datatracksender.go, dataTrackSender.run snapshots s.dc once before entering the packet-send loop. setDataChannel can replace s.dc concurrently and wake the sender, but run does not consume that wake or observe the replacement until the current inner loop exits. Preserve the intended rule that a partially sent frame cannot continue on a replacement channel by rechecking the synchronized channel pointer before each packet send. When it changes, switch channels, clear inFlight, and re-evaluate readiness before sending anything else.
Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

@ladvoc
ladvoc force-pushed the ladvoc/data-track-channel branch from 4895448 to b0427c6 Compare September 8, 2026 21:55
Comment thread engine.go
e.dataTrackDC.OnMessage(e.handleDataTrackPacket)
e.dataTrackDC.SetBufferedAmountLowThreshold(dataTrackBufferedAmountLowThreshold)
e.dataTrackDC.OnBufferedAmountLow(e.dataTrackSender.wake)
e.dataTrackDC.OnOpen(e.dataTrackSender.wake)

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.

Maybe move the data channel configuration statements (SetBufferedAmountLowThreshold, OnBufferedAmountLow, OnOpen) into the sender.setDataChannel

@ladvoc
ladvoc force-pushed the ladvoc/data-track-channel branch from b0427c6 to d851f36 Compare September 14, 2026 21:40
@ladvoc
ladvoc force-pushed the ladvoc/data-track-channel branch from d851f36 to c069ebd Compare September 22, 2026 16:46
@ladvoc ladvoc changed the title Add data track data channel Data tracks: establish data channels Sep 22, 2026
@ladvoc
ladvoc force-pushed the ladvoc/data-track-channel branch from c069ebd to d5287c0 Compare October 5, 2026 22:15
@ladvoc
ladvoc force-pushed the ladvoc/data-track-channel branch from d5287c0 to b2cfec2 Compare October 19, 2026 19:13
@ladvoc
ladvoc force-pushed the ladvoc/data-track-channel branch from b2cfec2 to 64e0334 Compare October 19, 2026 20:05
@ladvoc
ladvoc merged commit f095063 into main Oct 21, 2026
9 checks passed
@ladvoc
ladvoc deleted the ladvoc/data-track-channel branch October 21, 2026 00:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants