cass

DocsInternals

Architecture & Engineering

On this page

cass uses frankensqlite as the durable source of truth and frankensearch as a derived speed layer, powered by a suite of integrated "franken" libraries.

The Pipeline#

  1. Discovery: franken_agent_detection auto-discovers sessions from 34 coding-agent connectors (Claude Code, Codex, Cursor, Gemini, Aider, Amp, Cline, OpenCode, ChatGPT, Pi Agent, Pi Durable, Prime Agent, Oh My Pi, Copilot, Copilot CLI, OpenClaw, Clawdbot, Vibe, Crush, Goose, Hermes, Kimi, Muse Code, Qwen, Factory, OpenHands, Antigravity, Grok Build, Grok Bot, Codebuff/Freebuff, Devin CLI, Shelley, Kiro CLI, Continue); cass capabilities --json lists them as connectors.
  2. Storage (frankensqlite): The Source of Truth. Data is persisted to a normalized SQLite schema (messages, conversations, agents) via frankensqlite — a pure-Rust SQLite reimplementation. cass turns on the engine's concurrent mode (PRAGMA fsqlite.concurrent_mode = ON), so a plain BEGIN runs as BEGIN CONCURRENT. Indexing still has one writer at a time, because index-run.lock admits a single indexer. BEGIN IMMEDIATE appears only in the daemon job queue and in logical-archive import/migrate. An experimental opt-in parallel persist path (CASS_INDEXER_BEGIN_CONCURRENT=1, off by default) exists but is not the default.
  3. Search Index (frankensearch): The Speed Layer. New messages are incrementally pushed to a unified search index via frankensearch which provides BM25 lexical search, semantic embeddings, RRF fusion, and cross-encoder reranking in a single library.
  • Fields: title, content, agent, workspace, created_at.
  • Prefix Fields: title_prefix and content_prefix use Index-Time Edge N-Grams (not stored on disk to save space) for instant prefix matching.
  • Deduping: Search results are deduplicated on an exact key tuple (source, source path, conversation, line number, timestamp, whitespace-invariant content hash) and tool-invocation noise is filtered.
Mermaid diagram source
flowchart LR
 classDef pastel fill:#f4f2ff,stroke:#c2b5ff,color:#2e2963;
 classDef pastel2 fill:#e6f7ff,stroke:#9bd5f5,color:#0f3a4d;
 classDef pastel3 fill:#e8fff3,stroke:#9fe3c5,color:#0f3d28;
 classDef pastel4 fill:#fff7e6,stroke:#f2c27f,color:#4d350f;
 classDef pastel5 fill:#ffeef2,stroke:#f5b0c2,color:#4d1f2c;

 subgraph Sources["Local Sources (35 connectors)"]
 A1[Claude Code]:::pastel
 A2[Codex]:::pastel
 A3[Cursor]:::pastel
 A4[Gemini]:::pastel
 A5["… 30 more\n(cass capabilities --json)"]:::pastel
 end

 subgraph Remote["Remote Sources"]
 R1["sources.toml"]:::pastel
 R2["SSH/rsync\nSync Engine"]:::pastel2
 R3["remotes/\nSynced Data"]:::pastel3
 end

 subgraph "Ingestion Layer"
 C1["franken_agent_detection\nAuto-Discover & Scan\nNormalize & Dedupe"]:::pastel2
 end

 subgraph "Storage + Search"
 S1["frankensqlite (WAL)\nSource of Truth\nBEGIN CONCURRENT\nMigrations"]:::pastel3
 T1["frankensearch\nBM25 + Semantic\nRRF Fusion\nReranking"]:::pastel4
 end

 subgraph "Presentation"
 U1["TUI (FrankenTUI)\nElm Architecture\nAnalytics Dashboard\nAsync Search"]:::pastel5
 U2["CLI / Robot\nJSON Output\nAutomation"]:::pastel5
 end

 A1 --> C1
 A2 --> C1
 A3 --> C1
 A4 --> C1
 A5 --> C1
 R1 --> R2
 R2 --> R3
 R3 --> C1
 C1 -->|Persist| S1
 C1 -->|Index| T1
 S1 -.->|Rebuild| T1
 T1 -->|Query| U1
 T1 -->|Query| U2

Background Indexing & Watch Mode#

  • Non-Blocking: The indexer runs in a background thread. You can search while it works.
  • Parallel Discovery: Connector detection and scanning run in parallel across all CPU cores using rayon, significantly reducing startup time when multiple agents are installed.
  • Watch Mode (cass index --watch, foreground): Uses file system watchers (notify) to detect changes in agent logs. When you save a file or an agent replies, cass re-indexes just that conversation. The TUI does not start a watcher on its own; see Keeping the Index Fresh below for what runs automatically.
  • Real-Time Progress: The TUI footer updates in real-time showing discovered agent count and conversation totals as a progress bar labelled "Indexing 150/2000 (7%)" (a spinner with the phase name while the total is still unknown).

Keeping the Index Fresh (Automatic)#

An index that is always a little behind is the most common complaint about any local search tool, so cass has three cooperating mechanisms. None of them block a search; all of them run cass index --background, which lowers its own CPU (nice 15) and I/O (ionice idle on Linux) priority before touching anything, and all of them respect the single index-run.lock — two indexers never run at once.

Layer What When it runs Enable
Read-triggered catch-up search, pack, and TUI launch can request a detached incremental cass index --background when the index is stale (> 30 min), partial, has pending sessions, or its last successful source scan is at least 5 min old, even when the lexical index is healthy. The current read returns its existing results; later reads see new sessions after the background run publishes them. On demand, with a separate 5 min spawn cooldown per data dir (CASS_AUTO_REFRESH_COOLDOWN_SECS). CASS_AUTO_REFRESH_SOURCE_SCAN_SECS changes the source-scan age threshold; 0 disables only that trigger. Never for data dirs under the OS temp dir, and never for search --no-maintenance. Failed catch-ups back off for 1 h, then 6 h; three failures trip the breaker until any run completes. On by default. CASS_AUTO_REFRESH=0 disables globally. --robot-meta reports index_freshness.auto_refresh.{outcome,trigger,pid,consecutive_failures,detail}; an overdue source scan uses trigger source-scan-overdue.
OS scheduler (cass schedule install) launchd LaunchAgents (macOS) or systemd user timers (Linux): an incremental job every 15 min and a nightly job (03:00) that performs a full source census with conditional lexical rebuilding, then one bounded models backfill --scheduled worker per tier (fast/hash always; quality/MiniLM when installed). Due remote-source syncs run first. Priority is delegated to the OS: launchd jobs set Nice=15 and ProcessType=Interactive, without LowPriorityIO: launchd throttles the I/O of Background jobs and of Standard ones (an unset ProcessType), which starved scheduled indexing on macOS (#538). systemd units set Nice=19, IOSchedulingClass=idle and CPUSchedulingPolicy=idle. On the timer, even when no cass process is running; survives reboots (Persistent=true / launchd). cass schedule install [--interval-mins 15] [--nightly-hour 3] [--no-nightly] [--no-semantic] [--dry-run]; cass schedule status; cass schedule uninstall.
Resident daemon timer The warm-model daemon (cass daemon, started by hand or auto-spawned by a human-mode semantic/hybrid search with --daemon; robot searches never spawn it) can also kick an incremental background index while it is resident. Every CASS_DAEMON_INDEX_INTERVAL_SECS seconds while the daemon lives (it exits after its idle timeout). Off by default; CASS_DAEMON_INDEX_INTERVAL_SECS=900 recommended.

Idle awareness: scheduled work skips a run when the machine is under severe load (Linux /proc/loadavg + PSI; macOS sysctl vm.loadavg). On macOS you can additionally require the console to have been idle — CASS_RESPONSIVENESS_MIN_USER_IDLE_SECS=600 makes the nightly job and scheduled semantic backfill wait until nobody has touched the keyboard for ten minutes (the gate fails open where idle time is unavailable). Foreground cass index is never gated.

The source-scan interval is separate from health's 30-minute stale threshold. It checks completed-scan metadata without walking provider directories on the read path. Five minutes is an eligibility threshold, not a timer or a completion guarantee: a read must occur, and the cooldown, archive lock and failed-run breaker still apply. A completed no-op scan resets the cadence too. For continuous updates, run cass index --watch; for indexing while no one searches, install the scheduler. Set CASS_AUTO_REFRESH_SOURCE_SCAN_SECS=0 to keep stale/partial/pending catch-up while disabling periodic source checks on reads; this does not disable the resident daemon timer.

Semantic catch-up in background runs. Search refuses a semantic index that is behind the archive, and every ingest moves the archive ahead. Before, semantic search stayed off after any catch-up until someone reran cass index --semantic. Now every cass index --background run (stale-on-read catch-up, the scheduler's incremental job, the daemon timer) also embeds the messages ingested since the semantic index's embed watermark, then republishes it. Three limits apply:

  • It runs only when that index already exists for the configured embedder and carries that embedder's own watermark. cass index --semantic sets it, and so does a cass models backfill batch that publishes its tier or finds it unchanged. It never starts a full semantic build.
  • It never uses the external embedder.
  • A semantic failure is logged and never fails the lexical run.

Each embedder keeps its own watermark, so a hash-tier run never vouches for an older MiniLM index. Deleting messages (forget, purge, dedup) or changing a conversation's identity clears every watermark: the next cass index --semantic then re-embeds in full, while the next backfill batch reconciles the tier against the archive and records a new one. Watermarks written by cass versions before per-embedder watermarks are not trusted, so after upgrading, the first cass index --semantic is a full pass, or the next backfill batch records the watermark.

After an upgrade, the storage engine repairs and migrates an existing archive once, on its first writable open; that pass copies and rewrites the whole archive. Background runs (stale-on-read catch-up and scheduled jobs) never start it on an archive larger than CASS_INDEX_INTEGRITY_PREFLIGHT_MAX_BYTES (default 2 GiB): they exit 7 with kind migration-repair-pending, touch nothing, and cass schedule status names the cause. Run cass index --full in the foreground at a quiet time to perform it once; it keeps the original as a .pre-migration-bak copy, so plan for that much free space.

For a slow hosted disk, start with cass schedule install --interval-mins 60 and measure before shortening the interval. On Linux, cass index --json reports indexing_stats.bytes_written: the process block-write counter increase during indexing, including final checkpointing. It measures physical writes across all indexing layers, not just new transcript bytes or lexical segments; a cache-backed filesystem can report zero. The field is omitted when the counter is unavailable, including on other platforms. Check this alongside elapsed_ms on both changed-source and unchanged-source runs.

Nightly indexing retains index --full source coverage because timestamp-only connectors can miss restored files with old modification times. Connectors with valid durable source observations can reuse unchanged sources. When a completed checkpoint matches the archive and the lexical index passes validation, new messages are indexed inline. Missing or invalid checkpoint evidence, sparse or corrupt lexical assets, deferred lexical updates, and provenance repairs retain authoritative rebuilding from SQLite. Explicit cass index --full and --full --force-rebuild keep their existing repair behavior.

The nightly census still pays for source discovery and archive integrity, salvage, analytics, and FTS maintenance where required. A run that resumes an interrupted lexical rebuild can finish canonical recovery before returning; source discovery resumes on a later indexing run. Disappearing source files do not erase the preserved canonical history.

Each semantic worker retains its loaded model across its admitted batches and releases the previous batch's messages, vectors, storage handle, and lock at every checkpoint. CASS_SCHEDULE_MAX_BACKFILL_BATCHES bounds total attempts across tiers. Standalone cass models backfill --max-batches N uses the same worker; its default remains one batch.

Everything a scheduled job did is recorded under <data_dir>/schedule/ (state.json, runs.jsonl, per-job logs) and the last stale-on-read spawn under <data_dir>/auto-refresh-state.json / auto-refresh.log; cass schedule status --json reads all of it.

bash
# See what would be registered, then register it
cass schedule install --dry-run
cass schedule install

# Run a job by hand (what the units invoke); --force ignores load/idle gates
cass schedule run --job incremental --json
cass schedule run --job nightly --force

# Inspect
cass schedule status --json
cass search "auth" --robot --robot-meta | jq '._meta.index_freshness.auto_refresh'

Stale-on-read catch-up handles an index that is behind. A search can also find the lexical index missing or unusable: a first run, a rebuild that never finished, a schema change. The search then has three choices: answer from what exists, rebuild before answering, or refuse. cass picks by the size of the job and by who is asking.

Situation What cass search does
A readable index exists but its checkpoint metadata is stale Searches the existing index and leaves the heavy repair to an index run
No usable index, and the archive is within the inline repair budget (CASS_INCREMENTAL_AUTHORITATIVE_LEXICAL_REPAIR_MAX_DB_BYTES, default 1 GiB, database plus WAL) Rebuilds from SQLite inline, then answers. Robot callers get a bounded refusal instead when the ingest-quarantine circuit breaker is active
No usable index, and the archive is over that budget Refuses with exit 5 maintenance-required and starts a detached cass index --full --background; the error hint names its pid
Robot caller, existing index whose incomplete checkpoint the cheap metadata refresh cannot reconcile Refuses with exit 5 checkpoint_incomplete and starts the matching background run (--full above the size budget, plain cass index below it)
A rebuild is already running and no searchable generation exists Robot callers get exit 7 index-busy immediately, with N of M conversations processed when the rebuild has recorded progress. Human callers wait up to CASS_SEARCH_ACTIVE_REBUILD_WAIT_MS (30 s) for it to publish

Why the search never runs a large rebuild itself. A rebuild inside the search process lives only as long as that process, and an agent's search is almost always wrapped in a timeout: cass's own robot budget, or the agent harness's command limit. On a large archive the rebuild commits nothing until its first batch completes, so a killed rebuild keeps no progress. On one real 11 GB archive, a search-driven rebuild reached 160 of 4,324 conversations in 30 seconds (19 of them spent waiting on the in-flight byte budget) with committed_offset still 0 when the search's budget ended it. The next search started again from zero. Telling the agent to run cass index --full itself failed the same way, because that command ran under the same timeout. The index never converged. A detached child in its own process group survives the search, so the rebuild finishes and the next search answers.

What the caller sees. The hint says what cass did and what to do next, so an agent never has to guess whether to run maintenance itself:

json
{"error": {"code": 5, "kind": "maintenance-required",
  "message": "Automatic lexical repair was not started after detecting searchable lexical metadata missing: ...",
  "hint": "cass started `cass index --full --json --background` as a detached process (pid 62704) to rebuild the search index. Retry this search after it finishes; `cass status --json` shows its progress under .rebuild. Do not run `cass index --full --json` yourself meanwhile: it would exit 7 (index-busy).",
  "retryable": true}}

When no child is started, the hint says why: a run already holds the index lock; a recent spawn is still inside its cooldown (it may still be starting, or it failed, with the log path); earlier spawns failed and the breaker backed off or tripped (with the failure detail); CASS_AUTO_REFRESH=0; or the spawn itself failed. Those hints name the foreground command and warn that it needs a process that is not killed by a short timeout.

Guard rails. The handoff reuses the stale-on-read machinery, so the same limits apply: one spawner at a time (a file lock), the 5-minute cooldown, the failure breaker (1 h, then 6 h, tripped after three failures), and the index-run.lock that keeps two indexers from ever running together. Data dirs under the OS temp dir and TUI_HEADLESS harnesses never spawn, and search --no-maintenance never spawns anything. Under --timeout, a wait for an active rebuild stops at nine tenths of the time remaining, so the caller receives the index-busy verdict rather than an empty timed-out result.

Measured end to end (release build, an isolated data dir with 30 sessions, lexical index moved aside, inline budget forced to one byte): the search answered in 0.09 s with the spawned pid in its hint, the background index published about 10 s later, and the next search reported all 60 matching messages (50 returned at --limit 50). With CASS_AUTO_REFRESH=0 the same sequence never recovered within 180 s, which is the behaviour every large archive had before.