# ADR-017: Keep Recovery State Outside Replaceable Software ## Context Trial boot and service downgrade both depend on saved state. After a restart, the device needs to know which version is under trial, whether it was confirmed, and whether recovery is in progress. If that state exists only inside the software being replaced, installation or recovery may erase it. If boot control cannot read it before Linux starts, it cannot use it to handle an early startup failure. This example assumes that the platform provides storage accessible to boot control and persistent storage accessible to the OTA manager or service supervisor. These may be different areas. ## Decision Keep state required for recovery outside the software areas that the relevant update or recovery operation replaces. Keep boot selection, trial attempts, and confirmation in a location and format supported by boot control. The Linux component that requests a trial or confirms the system must use the platform's defined boot control interface. Keep installation progress, service recovery progress, failed version blocks, and pending reports in persistent storage accessible to the OTA manager or supervisor. Package installation, removal scripts, and cleanup must preserve these records while they are needed. Do not require one common file for every reader. Define who writes each record and how the readers agree on its meaning. Both retained software versions must understand any state they need after recovery. Use a storage method that handles interrupted writes. Readers must detect invalid or incomplete records. The platform must define a recovery action when no valid record remains; unreadable state must not be interpreted as successful confirmation. Define when each record may be removed. A report may be removed after its delivery is acknowledged. A failed version block follows the explicit removal policy in ADR-015. Recovery progress must remain available until the recorded operation has reached a known outcome. ## Decision Drivers - Restarting or replacing software must not erase the information needed to recover. - Boot control must make decisions before the OTA manager starts. - Offline recovery must retain progress and results locally. - Interrupted state writes must have a defined outcome. ## Alternatives Considered ### Store State Only Inside the Target System Slot Replacing that slot may erase the state. Boot control may also be unable to read it when the new system fails. This does not meet the recovery requirements. ### Store All State in the Application's Data Files This may be convenient for reporting. It is unsuitable when boot control cannot read those files or when package operations can remove them. Separate records are used according to their readers and lifetime. ### Keep the Authoritative State Only on the Server The server can track deployment progress, but it may be unreachable during boot or recovery. The device needs local state to complete those steps while offline. ## Consequences ### Positive - Boot and service recovery retain the information they need across replacement and restart. - Each reader has state it can access at the required time. - Reports can wait locally for the server connection to return. ### Negative - The platform needs tested methods for saving and reading state under power loss. - Boot control and Linux must agree on state formats and ownership. - Multiple records may need coordination if an operation is interrupted between writes. - Persistent storage needs space limits and retention rules. ## Applicability and Limits Use this approach when recovery decisions depend on state that must survive software replacement or an interrupted operation. This ADR defines where state belongs and who must read it. It does not select a filesystem, record format, or bootloader command. Those choices belong in the platform example and must be tested under power loss. Separating state from software does not guarantee that the state is valid. It also does not make several writes one atomic operation. The update design must handle the intermediate states those writes can leave behind. ## Related Documents - [Chapter 05: Storage Layout](../docs/05-storage-layout.md) - [ADR-014: Trial Boot and Confirmation for System Updates](ADR-014-trial-boot-and-confirmation.md) - [ADR-015: Service Checks and Package Downgrade](ADR-015-service-checks-and-package-downgrade.md) - [ADR-016: Separate System Software and Persistent Device Data](ADR-016-separate-system-software-and-persistent-device-data.md)