# CheckpointService

**Kind:** Class

**Source:** [`atloria-monorepo/packages/doc-automation/src/v2/pipeline/checkpoint.ts`](https://github.com/sherkety/atloria/blob/main/atloria-monorepo/packages/doc-automation/src/v2/pipeline/checkpoint.ts#L27)

## Methods

| Method | Signature | Returns |
|---|---|---|
| `save` | `save(jobState: JobState, stageData: Record<string, unknown>)` | `Promise<string>` |
| `load` | `load(jobId: string)` | `Promise<CheckpointData | null>` |
| `exists` | `exists(jobId: string)` | `Promise<boolean>` |
| `delete` | `delete(jobId: string)` | `Promise<void>` |
| `startAutoSave` | `startAutoSave(getState: () => { jobState: JobState; stageData: Record<string, unknown> })` | `void` |
| `stopAutoSave` | `stopAutoSave()` | `void` |
| `listJobs` | `listJobs()` | `Promise<string[]>` |
| `getHistory` | `getHistory(jobId: string)` | `Promise<{ path: string; timestamp: Date }[]>` |

## Where it refuses work

- `CheckpointService` stops the work with an early return when `(error as NodeJS.ErrnoException).code === 'ENOENT'`.
- `CheckpointService` stops the work with an early return when `files.length <= this.config.maxCheckpoints`.
- `CheckpointService` stops the work with an early return when `this.config.autoSaveInterval <= 0`.

## When something fails

- `CheckpointService` handles failure in 10 places: it discards it silently in 4, turns it into a return value in 3, lets it reach the caller in 2, and logs it and continues in 1.
