Skip to main content
The ControlCenter is the central orchestrator of the Palyra desktop application. It manages the lifecycle of the core daemon (palyrad) and the browser automation service (palyra-browserd), handling their configuration, execution, health monitoring, and log aggregation within a Tauri-based environment.

ControlCenter Architecture

The ControlCenter struct acts as the supervisor for managed services. It maintains the runtime state, profile configurations, and communication channels for log events.
ComponentRole
ManagedServiceTracks the state of a specific process, including its Child handle, PID, and restart logic.
RuntimeConfigDefines the network ports used by the gateway and browser services.
ServiceKindAn enum identifying the service type: Gateway or Browserd.
LogEventA message sent from process output readers to the supervisor’s internal log aggregator.

Process Lifecycle State Machine

The supervisor manages services based on a desired_running flag. If a service is marked as desired but is not currently running, the supervisor attempts to spawn it. Sources:

Supervisor Loop and Backoff

The supervisor runs a continuous loop governed by SUPERVISOR_TICK_MS (500ms). During each tick, it performs the following:
  1. Process Reaping: Checks if Child handles have exited and updates ManagedService state.
  2. Backoff Calculation: If a service needs a restart, it uses an exponential backoff strategy to prevent rapid crash looping.
  3. Process Spawning: Spawns new processes for services that are desired_running and have passed their backoff period.
  4. Log Aggregation: Drains the log_rx channel to update internal VecDeque buffers.

Exponential Backoff Logic

The backoff is calculated based on the restart_attempt counter. It ensures that subsequent failures result in longer wait times before the next attempt, capped at a maximum duration. Sources:

Managed Services: palyrad and palyra-browserd

The supervisor handles two primary binaries. It resolves their paths using resolve_binary_path and injects necessary environment variables for communication.

Environment Variable Injection

When spawning palyrad, the supervisor injects:
  • PALYRA_ADMIN_TOKEN: For Tauri-to-Daemon IPC authentication.
  • PALYRA_BROWSER_AUTH_TOKEN: For Daemon-to-Browserd communication.
  • Port configurations (e.g., PALYRA_GATEWAY_ADMIN_PORT).

Service Definitions

ServiceBinary NameBinary Override Env
GatewaypalyradPALYRA_DESKTOP_PALYRAD_BIN
Browserdpalyra-browserdPALYRA_DESKTOP_BROWSERD_BIN
Sources:

Log Rotation and Aggregation

Logs are captured from the stdout and stderr of child processes. To prevent memory exhaustion, the ControlCenter implements a rotation policy.
  1. Capture: tokio::process::Child pipes are wrapped in BufReader.
  2. Channel: Lines are sent via an mpsc channel with LOG_EVENT_CHANNEL_CAPACITY (2,048).
  3. Storage: Each ManagedService maintains a VecDeque<LogLine>.
  4. Rotation: The buffer is capped at MAX_LOG_LINES_PER_SERVICE (400 lines). When the limit is reached, the oldest logs are dropped.
Sources:

Tauri IPC Commands

The Desktop UI communicates with the ControlCenter via Tauri’s invoke system. These commands allow the user to control the backend processes and view system health.

Command Reference

IPC CommandFunctionDescription
get_snapshotcommands::get_snapshotReturns a ControlCenterSnapshot containing process status, logs, and diagnostics.
start_palyracommands::start_palyraSets desired_running to true for the gateway.
stop_palyracommands::stop_palyraSets desired_running to false and kills the gateway process.
restart_palyracommands::restart_palyraCycles the gateway process state.
get_settingscommands::get_settingsRetrieves current runtime and profile settings.

Data Flow: Snapshot Request

Sources: