# Data and persistence Devii's durable state lives in the main DevPlace SQLite database, every table scoped by owner. See also [Architecture and sessions](/docs/devii-architecture.html) and [Tools and scopes](/docs/devii-tools.html). ## Tables | Table | Scope | Purpose | |---|---|---| | `devii_conversations` | `(owner_kind, owner_id)` | The full message list (JSON) per owner. Upserted after each turn for **users only**; loaded back on reconnect so a conversation survives reloads and restarts. | | `devii_usage_ledger` | `(owner_kind, owner_id, created_at)` | One row per turn: token counts, `cost_usd`, model. The **authoritative source** for the rolling 24h spend cap. | | `devii_turns` | `(owner_kind, owner_id, started_at)` | Per-turn audit: truncated prompt and reply, iterations, tool-call count, cost, error. | | `devii_tasks` | `(owner_kind, owner_id)` | Autonomous tasks (schedule, status, next run). Owner-scoped. | | `devii_lessons` | `(owner_kind, owner_id)` | The self-learning memory: observation, conclusion, next action, tags. BM25-searched, owner-isolated. | Indexes for these are created idempotently in `database.init_db()`. ## Persistent vs ephemeral - **Signed-in users:** conversations, tasks, and lessons persist in the main DB, survive restarts, and rehydrate on reconnect. - **Guests:** tasks and lessons use a fresh **in-memory** database per session, never written to disk; conversations are not persisted at all. State is gone when the guest session ends. ## Owner isolation Every store filters reads and writes by the owner tuple. The lesson store is built per session over the owner's scope, so one account's lessons are never visible to another - a hard isolation boundary, see [Security and limits](/docs/devii-security.html). ## Display vs source of truth The in-memory `CostTracker` shows a live per-session figure but resets on reboot; it is **not** used for the cap. The 24h limit and all spend reporting read `devii_usage_ledger`, so the financial ceiling is correct across restarts and matches the admin analytics endpoint. The cap and pricing themselves are set in [Configuration and CLI](/docs/devii-config.html).