# State Management

> State is a single JSON blob in DragonflyDB. The supervisor loads it at the start of every loop, mutates it only after validation, and persists immediately.

Source: https://bifrost5.com/foundry/docs/state-management/

# State Management

Information

Stop worrying about losing your state: Production-Grade keeps an encrypted copy in the cloud and restores it fast.

[See editions](/foundry/docs/editions)

State is a single JSON blob in DragonflyDB. The supervisor loads it at the start of every loop, mutates it only after validation, and persists immediately.

## Lifecycle Rules

- State is **initialized by the operator** (init-state).

- **Read-only** during task execution; **mutated only after validation**.

- **Persist immediately** after mutation; persistence failure **halts execution**.

- Provider CLIs **never access state directly**; the supervisor injects context into prompts.

## Main State Fields

| Section | Purpose |
| --- | --- |
| `goals` | Per-project goals (description, completed). Keyed by `project_id`. |
| `supervisor` | status (RUNNING \| HALTED \| COMPLETED \| BLOCKED), iteration, halt_reason |
| `active_tasks` | Currently running tasks and worker info |
| `completed_tasks` | Finished tasks and validation reports |
| `blocked_tasks` | Tasks that failed after max retries |
| `queue` | Queue name, exhausted flag, ready/waiting counts |
| `file_locks` | (Parallel) File path → task holding the lock |
| `execution_mode` | AUTO \| MANUAL |
| `active_sessions` | Helper sessions isolated under `helper:validation:

` |

Goals are **per project**. Set with: `set-goal --project-id <id> --description "..."`.

## Session Reuse

Session IDs resolved per feature (`task:prefix` or `project:<id>`) with caps and error thresholds. Helper sessions isolated under `helper:validation:<projectId>` and persisted in `state.active_sessions`. Toggle via `DISABLE_SESSION_REUSE` if rollback is required.
