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
TheControlCenter struct acts as the supervisor for managed services. It maintains the runtime state, profile configurations, and communication channels for log events.
| Component | Role |
|---|---|
ManagedService | Tracks the state of a specific process, including its Child handle, PID, and restart logic. |
RuntimeConfig | Defines the network ports used by the gateway and browser services. |
ServiceKind | An enum identifying the service type: Gateway or Browserd. |
LogEvent | A message sent from process output readers to the supervisor’s internal log aggregator. |
Process Lifecycle State Machine
The supervisor manages services based on adesired_running flag. If a service is marked as desired but is not currently running, the supervisor attempts to spawn it.
Sources:
ControlCenterdefinition: apps/desktop/src-tauri/src/supervisor.rs#203-224ManagedServicedefinition: apps/desktop/src-tauri/src/supervisor.rs#99-109ServiceKinddefinition: apps/desktop/src-tauri/src/supervisor.rs#32-35
Supervisor Loop and Backoff
The supervisor runs a continuous loop governed bySUPERVISOR_TICK_MS (500ms). During each tick, it performs the following:
- Process Reaping: Checks if
Childhandles have exited and updatesManagedServicestate. - Backoff Calculation: If a service needs a restart, it uses an exponential backoff strategy to prevent rapid crash looping.
- Process Spawning: Spawns new processes for services that are
desired_runningand have passed their backoff period. - Log Aggregation: Drains the
log_rxchannel to update internalVecDequebuffers.
Exponential Backoff Logic
The backoff is calculated based on therestart_attempt counter. It ensures that subsequent failures result in longer wait times before the next attempt, capped at a maximum duration.
Sources:
SUPERVISOR_TICK_MS: apps/desktop/src-tauri/src/lib.rs#1-1- Tick logic in
ControlCenter: apps/desktop/src-tauri/src/supervisor.rs#440-460 (implied by usage incommands.rs) - Backoff computation: apps/desktop/src-tauri/src/supervisor.rs#56-59
Managed Services: palyrad and palyra-browserd
The supervisor handles two primary binaries. It resolves their paths usingresolve_binary_path and injects necessary environment variables for communication.
Environment Variable Injection
When spawningpalyrad, 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
| Service | Binary Name | Binary Override Env |
|---|---|---|
| Gateway | palyrad | PALYRA_DESKTOP_PALYRAD_BIN |
| Browserd | palyra-browserd | PALYRA_DESKTOP_BROWSERD_BIN |
ServiceKinddisplay/binary names: apps/desktop/src-tauri/src/supervisor.rs#45-54- Environment overrides: apps/desktop/src-tauri/src/supervisor.rs#56-61
- Binary path resolution: apps/desktop/src-tauri/src/supervisor.rs#44-46
Log Rotation and Aggregation
Logs are captured from thestdout and stderr of child processes. To prevent memory exhaustion, the ControlCenter implements a rotation policy.
- Capture:
tokio::process::Childpipes are wrapped inBufReader. - Channel: Lines are sent via an
mpscchannel withLOG_EVENT_CHANNEL_CAPACITY(2,048). - Storage: Each
ManagedServicemaintains aVecDeque<LogLine>. - Rotation: The buffer is capped at
MAX_LOG_LINES_PER_SERVICE(400 lines). When the limit is reached, the oldest logs are dropped.
MAX_LOG_LINES_PER_SERVICE: apps/desktop/src-tauri/src/lib.rs#2-2LOG_EVENT_CHANNEL_CAPACITY: apps/desktop/src-tauri/src/lib.rs#3-3- Log aggregation logic: apps/desktop/src-tauri/src/supervisor.rs#107-107
Tauri IPC Commands
The Desktop UI communicates with theControlCenter via Tauri’s invoke system. These commands allow the user to control the backend processes and view system health.
Command Reference
| IPC Command | Function | Description |
|---|---|---|
get_snapshot | commands::get_snapshot | Returns a ControlCenterSnapshot containing process status, logs, and diagnostics. |
start_palyra | commands::start_palyra | Sets desired_running to true for the gateway. |
stop_palyra | commands::stop_palyra | Sets desired_running to false and kills the gateway process. |
restart_palyra | commands::restart_palyra | Cycles the gateway process state. |
get_settings | commands::get_settings | Retrieves current runtime and profile settings. |
Data Flow: Snapshot Request
Sources:get_snapshotcommand: apps/desktop/src-tauri/src/commands.rs#55-63- UI
invokecalls: apps/desktop/ui/src/lib/desktopApi.ts#30-34 ControlCenterSnapshotstruct: apps/desktop/src-tauri/src/snapshot.rs#176-185