ControlCenter is the central orchestration engine of the Palyra Desktop application. It acts as a supervisor for background sidecar processes—specifically palyrad (the core daemon) and palyra-browserd (the headless browser service). It manages their full lifecycle, including automated startup, health monitoring, crash recovery with exponential backoff, and log aggregation.
The ControlCenter Struct
TheControlCenter struct maintains the runtime state of the desktop environment. It holds references to managed services, persistence layers, and communication clients required to interface with the supervised processes.
| Field | Type | Description |
|---|---|---|
gateway | ManagedService | Supervisor state for the palyrad process. |
browserd | ManagedService | Supervisor state for the palyra-browserd process. |
persisted | DesktopStateFile | Disk-backed configuration and onboarding state. |
runtime | RuntimeConfig | Port assignments and networking configuration. |
log_rx | mpsc::Receiver<LogEvent> | Channel for receiving aggregated logs from children. |
Code Entity Mapping: ControlCenter
The following diagram shows how theControlCenter struct integrates various system components into a single supervised unit.
Sources: apps/desktop/src-tauri/src/supervisor.rs#205-226, apps/desktop/src-tauri/src/supervisor.rs#101-111
ManagedService Tracking
Each sidecar process is wrapped in aManagedService struct. This entity tracks whether a service should be running (desired_running) versus its actual OS state.
- Liveness States: A service is reported as
running,restarting, orstoppedapps/desktop/src-tauri/src/supervisor.rs#132-141. - Port Tracking: It maintains a list of
bound_ports(e.g., 7142 for Admin, 7443 for gRPC) used for health probing apps/desktop/src-tauri/src/supervisor.rs#110-111. - Restart Logic: If a process exits unexpectedly while
desired_runningis true, the supervisor incrementsrestart_attemptand calculates a delay usingcompute_backoff_msapps/desktop/src-tauri/src/supervisor.rs#106-107.
Supervisor Loop & Exponential Backoff
The supervisor operates on a fixed-interval “tick” (defined bySUPERVISOR_TICK_MS, typically 500ms) apps/desktop/src-tauri/src/lib.rs#1. During each tick, the ControlCenter performs the following:
- Zombie Reaping: Checks if child processes have exited using non-blocking
try_wait(). - Backoff Enforcement: If a service is scheduled for restart, it compares the current timestamp against
next_restart_unix_ms. - Process Spawning: If a service is desired but not running (and backoff has expired), it invokes
Command::spawn()with the appropriate environment variables and flags (e.g.,CREATE_NO_WINDOWon Windows) apps/desktop/src-tauri/src/lib.rs#62-72.
Backoff Strategy
The system uses a jittered exponential backoff to prevent “thundering herd” issues when services fail repeatedly.- Initial Delay: 1,000ms.
- Multiplier: 2x per failure.
- Maximum Delay: 30,000ms.
Log Management & Aggregation
TheControlCenter captures stdout and stderr from all managed services using asynchronous readers apps/desktop/src-tauri/src/supervisor.rs#17-18.
- Log Streams: Logs are categorized into
Stdout,Stderr, orSupervisor(internal events) apps/desktop/src-tauri/src/supervisor.rs#68-72. - Ring Buffer: Each
ManagedServicemaintains aVecDeque<LogLine>limited toMAX_LOG_LINES_PER_SERVICE(400 lines) to prevent memory exhaustion apps/desktop/src-tauri/src/lib.rs#2. - Sanitization: Lines are passed through
sanitize_log_lineto redact sensitive information before being stored or sent to the UI apps/desktop/src-tauri/src/snapshot.rs#25-26. - Flow:
- Process outputs a line.
ControlCenterreads it and wraps it in aLogEvent.- Event is sent via
log_txto the main aggregation loop. - UI requests a snapshot, and the logs are serialized into the
ControlCenterSnapshot.
Snapshot Pipeline & Health Probing
The Desktop UI retrieves the system state via theget_snapshot Tauri command apps/desktop/src-tauri/src/commands.rs#55-63. This triggers a multi-stage pipeline to assemble the ControlCenterSnapshot.
Data Flow: Snapshot Assembly
Health Probing
The supervisor performs active probing of thepalyrad admin port (7142) and browserd health port (7143) apps/desktop/src-tauri/src/lib.rs#16-19. It parses the HealthEndpointPayload to determine:
status: (e.g., “healthy”)version: The binary version string.uptime_seconds: Process longevity.
Degraded or Down in the OverallStatus enum apps/desktop/src-tauri/src/snapshot.rs#169-173.
Sources: apps/desktop/src-tauri/src/snapshot.rs#176-185, apps/desktop/src-tauri/src/snapshot.rs#197-202, apps/desktop/src-tauri/src/commands.rs#55-63
Service Lifecycle Actions
The ControlCenter exposes async methods to transition service states, typically triggered by theLifecycleActionBar in the UI apps/desktop/ui/src/components/LifecycleActionBar.tsx.
start_palyra: Setsdesired_runningto true for bothgatewayandbrowserd(if enabled) apps/desktop/src-tauri/src/commands.rs#33.stop_palyra: Setsdesired_runningto false and sends termination signals to child processes apps/desktop/src-tauri/src/commands.rs#34.restart_palyra: A convenience sequence that stops and then immediately flags services for restart apps/desktop/src-tauri/src/commands.rs#30.