Skip to content

Session_runner cleanup and webrtc refresh fix - #495

Open
gtong-nv wants to merge 3 commits into
mainfrom
dev/gtong/session-runner-cleanup
Open

Session_runner cleanup and webrtc refresh fix#495
gtong-nv wants to merge 3 commits into
mainfrom
dev/gtong/session-runner-cleanup

Conversation

@gtong-nv

Copy link
Copy Markdown
Collaborator

No description provided.

@copy-pr-bot

copy-pr-bot Bot commented Aug 20, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@greptile-apps

greptile-apps Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR refactors session execution into SessionRunner, updates callers and documentation, and changes WebRTC replacement and disconnect handling.

  • Negotiates replacement peers before releasing the active connection.
  • Adds a five-second reconnection grace period before ending a disconnected session.
  • Refreshes browser playback and ICE-gathering behavior.
  • Migrates runtime, tests, and the red-screen example to the class-based session runner.

Confidence Score: 4/5

The PR is not yet safe to merge because a reconnect near the grace-period deadline can still close the recovered session.

Disconnect cleanup can wake during the replacement offer's awaited SDP negotiation, observe no installed peer, and enqueue a session-closing event before the reconnect cancels the timer.

Files Needing Attention: flashdreams/flashdreams/runtime_v2/serving/webrtc_server.py

Important Files Changed

Filename Overview
flashdreams/flashdreams/runtime_v2/serving/webrtc_server.py Adds safe pre-negotiation peer replacement and delayed disconnect cleanup, but reconnect negotiation can race the grace timer and close a recovered session.
flashdreams/flashdreams/runtime_v2/session_runner.py Refactors the module-level session loop into a stateful SessionRunner while preserving its threading, reset, backpressure, and cleanup behavior.
flashdreams/flashdreams/runtime_v2/serving/web/app.js Waits for ICE gathering and explicitly starts video playback to improve browser connection and refresh behavior.
integrations_v2/red_screen/README.md Correctly migrates the displayed integration example to construct and run SessionRunner.

Sequence Diagram

sequenceDiagram
    participant Browser
    participant Offer as WebRTC offer handler
    participant Timer as Disconnect timer
    participant Session
    Browser--xOffer: Existing peer disconnects
    Offer->>Timer: Start 5-second grace period
    Browser->>Offer: Submit replacement offer
    Offer->>Offer: Await SDP negotiation
    Timer->>Timer: Grace period expires
    Timer->>Session: CloseUserInputEventData
    Offer->>Timer: Cancel timer too late
    Offer->>Offer: Install replacement peer
Loading

Reviews (2): Last reviewed commit: "Address greptile comments" | Re-trigger Greptile

Comment thread flashdreams/flashdreams/runtime_v2/serving/webrtc_server.py Outdated
Comment thread flashdreams/flashdreams/runtime_v2/serving/webrtc_server.py
Comment on lines +61 to +62
@dataclass
class SessionRunner:

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.

P2 Red screen example uses removed API

The red_screen README still tells users to import and call the removed module-level run_session function, so copying the integration example now raises ImportError; update it to construct SessionRunner and call run_session() instead.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@gtong-nv

Copy link
Copy Markdown
Collaborator Author

/ok to test ba01d36

Comment on lines +377 to +378
self._cancel_disconnect_timer()
self._peer_connection = peer_connection

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.

P1 Reconnect races disconnect timer

When a browser starts reconnecting shortly before the five-second grace period expires, SDP negotiation can cross the deadline before _cancel_disconnect_timer() runs. The timer then observes that no replacement peer has been installed and enqueues CloseUserInputEventData, causing the session to shut down even though the replacement connection succeeds.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants