# Continuity Backup Specification

Continuity backup is an optional feature (planned) that allows agents to store encrypted audit receipts and minimal state snapshots in customer-owned storage. This helps agents survive context window resets and maintain continuity across sessions.

**Status:** Planned, not yet available.

**Model:** Encrypted agent-provided state. Restore requires private key.

**Constraints:**
- Agent-initiated only
- Embassy cannot read contents
- Storage costs apply

## Design Principles

- **Customer-owned storage:** Receipts are written to customer-controlled destinations (filesystem, S3, webhook)
- **Encrypted at rest:** All stored data is encrypted before writing
- **Explicit consent:** Agents must opt-in to continuity backup
- **Deletion on demand:** Customers can delete stored data at any time
- **No training use:** Stored data is not used for training or model improvement

## Storage Destinations

### Filesystem

Local reference build may write to disk. Hosted service can write to customer-owned destination.

**Configuration:**
- `CONTINUITY_SINK=file`
- `CONTINUITY_PATH=/path/to/storage` (customer-controlled)

### S3

Write to customer-owned S3 bucket.

**Configuration:**
- `CONTINUITY_SINK=s3`
- `CONTINUITY_S3_BUCKET=customer-bucket`
- `CONTINUITY_S3_PREFIX=embassy/receipts/`
- AWS credentials provided by customer

### Webhook

POST receipts to customer-owned endpoint.

**Configuration:**
- `CONTINUITY_SINK=webhook`
- `CONTINUITY_WEBHOOK_URL=https://customer-endpoint/receipts`
- `CONTINUITY_WEBHOOK_SECRET=shared-secret` (for verification)

## Retention Modes

### Ring Buffer

Overwrite oldest receipts when buffer is full. Fixed-size storage.

**Configuration:**
- `CONTINUITY_RETENTION=ring`
- `CONTINUITY_RING_SIZE=1000` (number of receipts)

### Archive

Append-only storage. Receipts are never overwritten.

**Configuration:**
- `CONTINUITY_RETENTION=archive`
- Receipts stored with timestamp-based paths

## Encryption

All stored data is encrypted at rest using AES-256-GCM. Encryption keys are managed by the customer or derived from customer-provided secrets.

## Receipt Format

Receipts include:
- Visa decision (permit/refuse)
- Timestamp
- Agent hash (not identity)
- Scope granted
- Constraints applied
- Signature verification status

No internal agent state, no conversations, no user data.

## Opt-In

Agents must explicitly request continuity backup by including `continuity: true` in the visa request. Platforms must respect this opt-in and only enable backup with explicit consent.

## Deletion

Customers can delete stored data at any time:
- Filesystem: Delete files directly
- S3: Delete objects via S3 API
- Webhook: Customer controls endpoint behavior

Embassy does not retain copies after deletion.

## Local vs Hosted

**Local reference build:**
- May write to local filesystem (`data/receipts/`)
- For testing and development only
- Not encrypted (local only)

**Hosted service:**
- Writes to customer-owned destination
- Encrypted at rest
- Customer controls access and deletion
