Skip to content

Backend fal v4#393

Draft
emranemran wants to merge 11 commits intomainfrom
backend-fal-v4
Draft

Backend fal v4#393
emranemran wants to merge 11 commits intomainfrom
backend-fal-v4

Conversation

@emranemran
Copy link

No description provided.

@mjh1 mjh1 force-pushed the backend-fal-v4 branch 2 times, most recently from 7274117 to 5b13c80 Compare February 3, 2026 19:01
@emranemran emranemran force-pushed the backend-fal-v4 branch 6 times, most recently from a689d88 to ab5e27c Compare February 3, 2026 21:04
Add fal.ai serverless wrapper (fal_app.py) that runs Scope server
on fal.ai GPU infrastructure (H100):

- Start Scope server as subprocess on fal runner
- WebSocket endpoint for WebRTC signaling and API proxying
- Session data cleanup on disconnect (prevents data leakage)
- Connection ID for correlating logs across client and server
- Base64 encoding for binary file uploads/downloads
- Assets directory configuration for fal environment

Signed-off-by: emranemran <emran.mah@gmail.com>
Signed-off-by: Max Holland <max@livepeer.org>
Add modules enabling local Scope server to act as WebRTC client
to fal.ai cloud for GPU processing:

- FalConnectionManager: WebSocket connection with request/response correlation
- FalWebRTCClient: Peer connection from local server to fal cloud
- FalRelayTrack: MediaStreamTrack for bidirectional video through fal
- Request keyframe (PLI) on track received for VP8 decoder stability
- Fal-related Pydantic schemas for API requests/responses

Signed-off-by: emranemran <emran.mah@gmail.com>
Signed-off-by: Max Holland <max@livepeer.org>
Modify FrameProcessor to support client mode (cloud processing):

- Route frames to fal.ai via WebRTC when connected
- Receive processed frames from fal.ai callback
- Spout sender/receiver work transparently in both modes
- WebRTC manager handles client mode offers
- Fix Spout integration in client mode

Signed-off-by: emranemran <emran.mah@gmail.com>
Signed-off-by: Max Holland <max@livepeer.org>
Add REST API endpoints for cloud connection management:

- POST /api/v1/fal/connect - Connect to fal.ai cloud
- POST /api/v1/fal/disconnect - Disconnect from cloud
- GET /api/v1/fal/status - Get connection status
- Proxy model download requests to fal in cloud mode
- Proxy hardware API calls to fal
- Reference image upload handling in cloud mode
- Recording download support in cloud mode

Signed-off-by: emranemran <emran.mah@gmail.com>
Signed-off-by: Max Holland <max@livepeer.org>
Add UI components for managing cloud connection:

- CloudModeToggle: Connection status, connect/disconnect buttons
- Connection ID display with copy-to-clipboard
- Disable controls during cloud connection attempt
- Disable LoRA selection in cloud mode (not supported)
- Show connecting/disconnecting state with spinner

Signed-off-by: emranemran <emran.mah@gmail.com>
Signed-off-by: Max Holland <max@livepeer.org>
Add React hooks and utilities for cloud mode WebRTC:

- useUnifiedWebRTC: Unified hook supporting both local and cloud modes
- useWebRTCFal: Fal-specific WebRTC handling
- useApi: API request hook with cloud mode support
- usePipelines: Refresh pipeline list on cloud mode toggle
- usePipeline: Remove duplicate status polling
- falAdapter/falContext: Fal.ai SDK integration (legacy, for reference)

Signed-off-by: emranemran <emran.mah@gmail.com>
Signed-off-by: Max Holland <max@livepeer.org>
Pipeline changes for text-to-video mode:

- Skip video input for text-to-video pipelines
- Input mode detection in wan2_1 pipeline

Signed-off-by: emranemran <emran.mah@gmail.com>
Signed-off-by: Max Holland <max@livepeer.org>
Add GitHub Actions workflow to build Docker images for feature branches.

Signed-off-by: emranemran <emran.mah@gmail.com>
Signed-off-by: Max Holland <max@livepeer.org>
emranemran and others added 3 commits February 3, 2026 13:30
Rename all "Fal" references to "Cloud" and replace "relay mode" with
"cloud mode" to make the cloud integration more generic and clarify
terminology.

Python changes:
- Rename files: fal_connection.py → cloud_connection.py,
  fal_relay_track.py → cloud_track.py,
  fal_webrtc_client.py → cloud_webrtc_client.py
- Rename classes: FalConnectionManager → CloudConnectionManager,
  FalRelayTrack → CloudTrack, FalWebRTCClient → CloudWebRTCClient
- Update API endpoints: /api/v1/fal/* → /api/v1/cloud/*
- Update CLI options: --fal-app-id → --cloud-app-id,
  --fal-api-key → --cloud-api-key
- Update env vars: SCOPE_FAL_* → SCOPE_CLOUD_*

TypeScript changes:
- Rename files: falAdapter.ts → cloudAdapter.ts,
  falContext.tsx → cloudContext.tsx
- Rename classes/hooks: FalAdapter → CloudAdapter,
  FalProvider → CloudProvider, useFalContext → useCloudContext
- Update all imports and references

Signed-off-by: emranemran <emran.mah@gmail.com>
Signed-off-by: Max Holland <max@livepeer.org>
…connections

Implements a maximum connection duration limit to control cloud GPU costs.
Connections are automatically closed after 60 minutes regardless of activity.

Changes:
- Add MAX_CONNECTION_DURATION_SECONDS (3600s) and TIMEOUT_CHECK_INTERVAL_SECONDS (60s) constants
- Track connection_start_time when WebSocket connects
- Add check_max_duration_exceeded() helper that sends a graceful "closing" message with reason "max_duration" before disconnect
- Use asyncio.wait_for() with timeout on ws.receive_text() to enable periodic duration checks during idle periods
- Also check duration after each received message to catch high-activity scenarios

The client receives a JSON message {"type": "closing", "reason": "max_duration", "elapsed_seconds": ...} before disconnection, allowing graceful handling.

Signed-off-by: emranemran <emran.mah@gmail.com>
Signed-off-by: Max Holland <max@livepeer.org>
Integrates Daydream authentication and adds comprehensive event tracking
via Kafka for both local and cloud modes.

Frontend:
- Add OAuth sign-in flow with Daydream authentication
- Show cloud mode toggle only when authenticated
- Pass user ID to backend for log correlation

Backend:
- Add kafka_publisher module for async Kafka event publishing
- Publish stream lifecycle events (stream_started, stream_stopped, stream_error)
- Track user_id through cloud connections for log correlation

Cloud (fal_app.py):
- Add KafkaPublisher class for WebSocket event tracking
- Publish websocket_connected/disconnected events with user context
- Support set_user_id message for log correlation

Signed-off-by: emranemran <emran.mah@gmail.com>
Signed-off-by: Max Holland <max@livepeer.org>
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