---
epic: 13
story: 13.4
title: "Crash Recovery"
status: draft
---

## Epic 13 — Performance & Reliability
**Goal:** Instant evaluation, never lose work.

### Story 13.4: Crash Recovery

As a CalcPad user,
I want my work to be auto-saved continuously,
So that I never lose more than 2 seconds of work after a crash or unexpected quit.

**Acceptance Criteria:**

**Given** the user is actively editing a sheet on macOS
**When** the application is running
**Then** NSDocument auto-save is leveraged to persist the document state at least every 2 seconds
**And** the auto-saved state includes all sheet content, variable values, and cursor position

**Given** the user is actively editing a sheet on Windows
**When** the application is running
**Then** a journal file is written to `%APPDATA%/CalcPad/recovery/` at least every 2 seconds
**And** the journal file contains the full sheet content and metadata needed for restoration

**Given** the user is actively editing a sheet on the web
**When** the application is running
**Then** sheet state is persisted to localStorage at least every 2 seconds
**And** if the user is logged in with cloud sync enabled, the state is also queued for server sync

**Given** CalcPad crashes or is force-quit
**When** the user relaunches the application
**Then** the recovery file is detected and the user is prompted to restore their session
**And** the restored session contains all content from no more than 2 seconds before the crash
**And** the user can choose to discard the recovered state and start fresh

**Given** multiple sheets were open at the time of a crash
**When** the user relaunches the application
**Then** all sheets with recovery data are listed for restoration
**And** the user can selectively restore individual sheets
