Expand description
§Application State Management
This module provides comprehensive application state management for the Air daemon, including configuration, service status, resource tracking, and connection management.
§Architecture Overview
The ApplicationState acts as the central coordination point for the Air daemon, tracking all active connections, service states, requests, and system resources. It follows the VSCode daemon state management pattern with thread-safe, async-friendly data structures.
§Core Responsibilities
-
Connection Management
- Track all connected clients (Mountain, Cocoon, Wind, etc.)
- Heartbeat monitoring and validation
- Connection pooling for Mountain clients
- Graceful disconnection handling
- Stale connection cleanup
-
Service Status Tracking
- Monitor authentication service
- Track update service state
- Monitor indexing service
- Track downloader service
- gRPC service status
-
Request Management
- Active request tracking
- Request lifecycle management
- Progress monitoring
- Request cancellation support
-
Resource Monitoring
- Memory usage tracking
- CPU usage monitoring
- Disk usage tracking
- Network usage monitoring
- Resource limit enforcement
-
Performance Metrics
- Request count tracking
- Success/failure rates
- Average response time calculation
- Uptime tracking
§Connection Types
- MountainMain: Main editor process connection
- MountainWorker: Background worker processes
- Cocoon: Deployment and build system
- Wind: Communication layer
- External: Third-party integrations
§TODO Items
- Implement connection pooling for Mountain clients with load balancing
- Add connection encryption and authentication
- Implement connection rate limiting
- Add connection-based resource quotas
- Implement connection health checks with automatic recovery
- Add connection-based feature flags
- Implement connection audit logging
- Add connection-based request prioritization
- Implement connection state persistence across restarts
- Add distributed connection support for multi-node deployments
§Thread Safety
All state access is protected by async-friendly locks:
RwLock<T>for read-heavy data (configuration, metrics, connections)Mutex<T>for write-heavy data (active requests, background tasks)
This ensures concurrent access from multiple async tasks and threads is safe and efficient.
§Performance Considerations
- Use read locks where possible to allow concurrent access
- Minimize lock duration
- Use async-friendly lock types to avoid blocking runtime
- Consider lock-free alternatives for high-frequency updates
§Error Handling
All methods return Result<T> with comprehensive error types:
Configuration: Invalid configuration valuesResourceLimit: Resource limits exceededInternal: Internal state inconsistencies
Structs§
- Application
State - Application state structure
- Connection
Health Report - Connection health report
- Connection
Info - Connection information for Mountain clients
- Performance
Metrics - Performance metrics
- Request
Status - Request status tracking
- Resource
Usage - Resource usage tracking
Enums§
- Connection
Type - Connection type enum
- Request
State - Request state enum
- Service
Status - Service status enum