saveContainerState

open suspend override fun saveContainerState(userId: String, state: KarlContainerState)(source)

Persists the current learning state for a specific user with transactional safety.

This method provides atomic persistence of the complete machine learning state, ensuring that model weights, training progress, and associated metadata are saved consistently. The operation uses Room's transaction capabilities to guarantee atomic updates and prevent partial state corruption.

Persistence Strategy:

  • Atomic Operations: Uses Room transactions for consistency guarantees

  • Binary Efficiency: Stores model state as efficient binary data

  • Version Tracking: Maintains state version for migration compatibility

  • User Isolation: Ensures complete separation between user data

Data Integrity: The method employs upsert semantics, automatically handling both insert and update scenarios. This ensures that subsequent saves for the same user overwrite previous state while maintaining referential integrity.

Error Handling: Database errors are propagated as exceptions, allowing upstream components to implement appropriate retry logic and error recovery strategies.

Parameters

userId

Unique identifier for the user whose state is being persisted

state

Complete learning state including model weights and metadata

Throws

SQLException

If database operation fails due to connectivity or constraint issues