FrankenTerm

Storage Schema and Migration Strategy

540 words2 min read6 subsectionsFrom the README at ft 0.15.21

On this page6
Current schema versionCore tablesWhy SQLite specificallySingle-writer integrityGC and VACUUMSchema migration safety

ft stores everything in a single SQLite database. The schema is versioned and migrations are tracked.

Current schema version

The current version is v51. The authoritative source is storage/schema_ddl.rs::SCHEMA_VERSION; documentation must follow that constant rather than becoming an independent version authority.

Core tables

Table Purpose
output_segments Append-only captured-output deltas with FTS5 index. The canonical source of truth for everything searchable.
events Detection + system events with categorical filters (rule_id, severity, handled flag, pane_id).
audit_actions Every action that went through the policy gate (allow / deny / approve / rate-limited / failed).
policy_denied_audit (schema v24+) Every Deny / RequireApproval decision from MCP gate helpers — see docs/security/policy-denial-audit-wiring-matrix.md.
approval_tokens Approval codes + scope (action, pane, fingerprint), with one-shot semantics.
workflow_executions Per-execution state and lifecycle for every workflow run.
pane_reservations Cross-process pane-edit reservations (advisory leases).
work_claims Native SQLite work-queue backing ft robot work claim / complete / list / ready.
pane_contexts + context_rotations Native context registry for ft robot context status / rotate / history.
agent_profiles + profiles_applied_log Profile definitions + per-apply receipts.
session_checkpoints + mux_pane_state Session persistence (snapshots, restore IDs).
prepared_plans + workflow_action_plans Tx prepare-phase state and pre-planned action records. Mission and Tx contracts themselves live as JSON files at .ft/mission/active.json and .ft/mission/tx-active.json; tx receipts (TxReceipt) are typed values persisted into those workspace contracts.
mux_sessions + agent_sessions + panes Live mux/session/pane registry.
notification_history + event_labels + event_notes + event_mutes Notification dedup history and event annotation.
output_gaps + segment_embeddings + fts_index_state + fts_pane_progress Capture gaps, semantic embeddings, FTS5 index health.
saved_searches + pane_bookmarks + accounts + action_undo + secret_scan_reports + usage_metrics + maintenance_log Operator-facing surfaces (saved queries, bookmarks, accounts, undo log, secret-scan reports, usage metrics, bounded operational advisories, and retained cleanup receipts).
ft_meta Single-row table holding schema_version, min_compatible_ft, created_by_ft.

Why SQLite specifically

  • No system dep. rusqlite bundles SQLite; no install step.
  • In-process I/O. No IPC overhead between ft and the store.
  • WAL mode lets multiple readers proceed while a single writer commits.
  • FTS5 is built-in and battle-tested.
  • Online backup API gives us consistent snapshots without stop-the-world.
  • Schema migrations are versioned + tracked + reversible (forensic_migration + rollback_execution support).

Single-writer integrity

A filesystem lock (fs2) ensures at most one watcher writes. The lock metadata records PID and start time. Read-only consumers (e.g., ft robot state from a second shell) acquire a shared lock and proceed without blocking the writer.

GC and VACUUM

The [gc] config controls periodic page-stat reporting. The cycle (configurable, default hourly) checks the free-page ratio and advises an explicit operator-run VACUUM when more than vacuum_threshold (default 20%) of pages are free. It never runs a full VACUUM automatically because that database rewrite can monopolize FrankenTerm's single writer during a large active session. Each cycle emits a bounded advisory report (log_report = true by default); global retention deletes only old cache_gc and fleet_scrollback_coordinator advisories in finite FIFO batches while preserving cleanup receipts and unknown maintenance classes.

Schema migration safety

  • Forward migrations are deterministic and idempotent. The migration engine in crates/frankenterm-core/src/storage/migrations.rs applies versioned steps; ft db migrate --status shows the plan, ft db migrate --dry-run previews, ft db migrate applies, and --to <version> targets a specific revision.
  • Health checks are available via ft db check (integrity + FTS + WAL + schema verdicts in auto/plain/json).
  • Repair is available via ft db repair (FTS rebuild, WAL checkpoint, vacuum); --dry-run previews before executing.
  • Compatibility window. ft_meta.min_compatible_ft records the minimum ft version that can read the current schema. A binary older than that refuses to open the DB rather than corrupting it.