Skip to main content
The Desktop Control Center serves as the primary supervisor for the Palyra sidecar processes. It manages the lifecycle of palyrad (the Gateway) and palyra-browserd (the Browser Service), ensuring they are configured correctly, restarted upon failure with exponential backoff, and monitored via health checks.

ControlCenter Orchestration

The ControlCenter struct is the central orchestrator within the Tauri application. It maintains the runtime state of all managed services, handles configuration persistence, and provides the data source for UI snapshots.

Key Components

ComponentResponsibility
ManagedServiceTracks a single process (PID, child handle, restart attempts, and log buffer).
RuntimeConfigDefines the static port assignments used by sidecars.
DesktopStateFilePersisted JSON state (state.json) tracking onboarding progress and preferences.
DesktopSecretStoreSecure storage for sensitive tokens (Admin and Browser Auth).
Diagram: ControlCenter Entity Mapping Sources: apps/desktop/src-tauri/src/supervisor.rs#201-218, apps/desktop/src-tauri/src/supervisor.rs#97-107, apps/desktop/src-tauri/src/supervisor.rs#140-146

Process Lifecycle and ManagedService

Each sidecar is wrapped in a ManagedService struct. The supervisor ensures that if a service is marked as desired_running, it is kept alive.

Exponential Backoff

When a process exits unexpectedly, the supervisor calculates a backoff delay before the next restart attempt using compute_backoff_ms. This prevents tight-loop crashing from consuming system resources.
  • Initial Delay: 1,000ms.
  • Multiplier: 2x per attempt.
  • Maximum Delay: 30,000ms.

Port Assignments

The supervisor enforces specific port assignments for local inter-process communication: Sources: apps/desktop/src-tauri/src/supervisor.rs#97-137, apps/desktop/src-tauri/src/lib.rs#16-20

Supervisor Loop Logic

The supervisor_loop runs as a background task, ticking every 500ms (SUPERVISOR_TICK_MS). Diagram: Supervisor Tick Flow

Log Redaction and Aggregation

Logs from stdout and stderr are piped into the supervisor. The function sanitize_log_line is applied to all incoming lines to redact sensitive information (like Auth tokens or specific URLs) before they are stored in the ManagedService.logs buffer, which is capped at 400 lines (MAX_LOG_LINES_PER_SERVICE). Sources: apps/desktop/src-tauri/src/lib.rs#1-3, apps/desktop/src-tauri/src/supervisor.rs#352-400, apps/desktop/src-tauri/src/snapshot.rs#33-33

Persistence and State Management

state.json

The DesktopStateFile manages the high-level application state. It includes:
  • Onboarding Progress: Tracks steps from Welcome through Completion.
  • Companion State: Stores notifications, offline drafts, and UI preferences.
  • Migration: The DESKTOP_STATE_SCHEMA_VERSION (currently 4) ensures that as the state structure evolves, old files are migrated or re-initialized.

DesktopSecretStore

Sensitive tokens are never stored in the plain-text state.json. Instead, the DesktopSecretStore utilizes palyra-vault to interact with platform-specific secure storage (e.g., macOS Keychain, Windows DPAPI).
  • desktop_admin_token: Used for the Desktop Control Center to authenticate against palyrad.
  • desktop_browser_auth_token: Used for the Browser Service authentication.
Sources: apps/desktop/src-tauri/src/desktop_state.rs#15-17, apps/desktop/src-tauri/src/desktop_state.rs#209-219, apps/desktop/src-tauri/src/lib.rs#9-12

Snapshot Aggregation

The UI retrieves the current system status via the get_snapshot Tauri command. This function calls build_snapshot_from_inputs, which aggregates data from multiple sources:
  1. Process Stats: PID, uptime, and liveness from ManagedService.
  2. Health Probes: Active HTTP requests to the sidecars’ health endpoints (e.g., HealthEndpointPayload).
  3. Diagnostic Errors: A collection of recent system errors, limited to 25 entries (MAX_DIAGNOSTIC_ERRORS).
  4. Quick Facts: Summary of versions, git hashes, and dashboard access modes (Local vs Remote).
Sources: apps/desktop/src-tauri/src/commands.rs#54-62, apps/desktop/src-tauri/src/snapshot.rs#173-182, apps/desktop/src-tauri/src/lib.rs#4