# Auto-Heal & Watchdog

Exaplay 3 includes a built-in crash recovery system designed for unattended operation in permanent installations, trade-show booths, and touring productions that run 24/7.

## Components

| Component            | Description                                                                             |
| -------------------- | --------------------------------------------------------------------------------------- |
| **Watchdog Service** | A Windows Service (`exaplay3-service.exe`) that monitors the main application           |
| **Auto-Heal**        | Logic inside the engine that saves playback state so it can be restored after a restart |

## How It Works

```
1. Exaplay 3 writes a periodic "heartbeat" + playback state to disk
        ↓
2. Watchdog monitors the heartbeat
        ↓
3. If heartbeat stops (crash / hang detected), Watchdog:
   a. Terminates the hung process if still running
   b. Waits a configurable delay
   c. Restarts Exaplay 3 with the -autoheal-restore flag
        ↓
4. Exaplay 3 reads the saved state and resumes playback
   at (approximately) the timecode where it stopped
```

## Enabling Auto-Heal

Auto-Heal is enabled by default. To disable it for a session, launch Exaplay 3 with the `-fresh` flag.

## Watchdog Service

The Watchdog is installed as a Windows Service and starts automatically with Windows. You do not need to interact with it directly.

To check its status:

```powershell
Get-Service -Name "Exaplay3Watchdog"
```

To restart it manually:

```powershell
Restart-Service -Name "Exaplay3Watchdog"
```

## Auto-Heal Configuration

| Setting                | Description                                                 | Default |
| ---------------------- | ----------------------------------------------------------- | ------- |
| **Heartbeat interval** | How often the engine writes its heartbeat (ms)              | `500`   |
| **Miss threshold**     | Number of missed heartbeats before restart is triggered     | `10`    |
| **Restart delay**      | Seconds to wait before restarting after a crash             | `5`     |
| **Max restarts**       | Maximum automatic restarts within a rolling 5-minute window | `3`     |

Configure these in **Config → System → Auto-Heal**.

## Manual Recovery

If the system does not recover automatically:

1. Check the Watchdog Service status (see above).
2. Look at the log file in `Documents\Exaplay3\logs\` for the error.
3. Start Exaplay 3 manually; Auto-Heal will still restore the last saved state.

## Skipping Auto-Heal Restore

To start with a clean state (ignoring any saved auto-heal data), launch Exaplay 3 with:

```
exaplay3.exe -fresh
```

This is useful after a major project change or when debugging.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.exaplay.one/v3/features/auto-heal.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
