Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Environment:AIPentest CyberStrikeAI SQLite

From Leeroopedia
Knowledge Sources
Domains Infrastructure, Persistence
Last Updated 2026-10-19 00:00 GMT

Overview

Embedded SQLite (WAL mode) database providing all durable persistence for CyberStrikeAI conversations, audit logs, vulnerabilities, projects, RBAC, C2, and attack-chain graphs.

Description

CyberStrikeAI does not require an external database server. It embeds SQLite via the `github.com/mattn/go-sqlite3` cgo driver and opens every database file in WAL journal mode with foreign keys enabled, a 30s busy timeout, `NORMAL` synchronous, and `IMMEDIATE` transaction locking. The connection pool is capped at 8 open / 4 idle connections, and a background goroutine runs `PRAGMA wal_checkpoint(PASSIVE)` every 5 minutes to keep `-wal` files bounded. A `journal_size_limit` of 256MB and `wal_autocheckpoint` of 1000 pages prevent unbounded WAL growth.

Usage

Use this environment for any implementation that reads or writes durable engagement evidence: conversations/messages, audit logs, vulnerabilities, projects and blackboard facts, RBAC decisions, C2 domains, attack-chain nodes/edges, and skill/plan-task state. It is the mandatory prerequisite for DB_reconcileSchema, DB_CreateConversation, and Audit_Service.

System Requirements

Category Requirement Notes
OS Any SQLite is pure C; bundled via cgo
Hardware Disk with fsync support WAL durability depends on working fsync
Disk Sufficient space for engagement data SSD recommended; WAL + main DB can reach 256MB journal + data
Software C compiler (gcc/clang) Required to build `go-sqlite3` cgo

Dependencies

System Packages

  • `gcc` or `clang` (cgo build of `go-sqlite3`)
  • `sqlite3` CLI (optional, for manual inspection)

Go Modules

  • `github.com/mattn/go-sqlite3` v1.14.18 (cgo SQLite driver)

SQLite Pragmas (applied at open)

  • `_journal_mode=WAL` (write-ahead logging for concurrent readers)
  • `_foreign_keys=1` (enforce FK constraints)
  • `_busy_timeout=30000` (30s lock-wait before SQLITE_BUSY)
  • `_synchronous=NORMAL` (WAL-safe reduced fsync)
  • `_txlock=immediate` (reserve writer at Begin)
  • `PRAGMA wal_autocheckpoint=1000` (~4MB @ 4KB pages)
  • `PRAGMA journal_size_limit=268435456` (256MB WAL cap)
  • `PRAGMA wal_checkpoint(PASSIVE)` every 300s (background loop)

Credentials

No credentials. SQLite is a file-based embedded database; access is governed by filesystem permissions on the DB file and its `-wal`/`-shm` siblings.

Quick Install

# No separate install — SQLite is compiled in via go-sqlite3.
# Ensure a C toolchain is present (already required by Go_1_25_Plus):
sudo apt-get install build-essential   # Debian/Ubuntu
# or: xcode-select --install            # macOS

# Build fetches go-sqlite3 automatically:
go build -o cyberstrike-ai ./cmd/server

# Optional CLI for inspection:
sudo apt-get install sqlite3
sqlite3 ./data/conversations.db "PRAGMA wal_checkpoint(TRUNCATE);"

Code Evidence

WAL DSN configuration from `internal/database/database.go:16-34`:

const (
    sqliteMaxOpenConns  = 8
    sqliteMaxIdleConns  = 4
    sqliteBusyTimeoutMS = 30000
    sqliteWALAutoCheckpointPages = 1000
    sqliteJournalSizeLimitBytes = 256 * 1024 * 1024
    sqlitePassiveCheckpointInterval = 300 * time.Second
)

func sqliteOpenDSN(path string) string {
    return fmt.Sprintf("%s?_journal_mode=WAL&_foreign_keys=1&_busy_timeout=%d&_synchronous=NORMAL&_txlock=immediate", path, sqliteBusyTimeoutMS)
}

Connection pool + pragma configuration from `internal/database/database.go:37-52`:

func configureDBPool(db *sql.DB) {
    db.SetMaxOpenConns(sqliteMaxOpenConns)
    db.SetMaxIdleConns(sqliteMaxIdleConns)
    db.SetConnMaxLifetime(30 * time.Minute)
}

func configureSQLitePragmas(db *sql.DB) error {
    if _, err := db.Exec(fmt.Sprintf("PRAGMA wal_autocheckpoint=%d", sqliteWALAutoCheckpointPages)); err != nil {
        return fmt.Errorf("设置 wal_autocheckpoint 失败: %w", err)
    }
    if _, err := db.Exec(fmt.Sprintf("PRAGMA journal_size_limit=%d", sqliteJournalSizeLimitBytes)); err != nil {
        return fmt.Errorf("设置 journal_size_limit 失败: %w", err)
    }
    return nil
}

Passive checkpoint loop from `internal/database/database.go:73-97`:

go func() {
    defer close(db.checkpointDone)
    ticker := time.NewTicker(sqlitePassiveCheckpointInterval)
    defer ticker.Stop()
    db.runPassiveCheckpoint("startup")
    for {
        select {
        case <-db.checkpointStop:
            return
        case <-ticker.C:
            db.runPassiveCheckpoint("ticker")
        }
    }
}()

Common Errors

Error Message Cause Solution
`SQLITE_BUSY` / `database is locked` Writer contention exceeding busy_timeout Increase pool headroom; avoid long write transactions; ensure `_txlock=immediate`
`-wal` file grows unbounded Checkpoint not keeping up under heavy writes Confirm passive checkpoint loop is running; manually run `PRAGMA wal_checkpoint(TRUNCATE)`
`cgo: C compiler "gcc" not found` Missing C toolchain for go-sqlite3 Install `build-essential` (Linux) or Xcode CLT (macOS)
`FOREIGN KEY constraint failed` Deleting a row with dependent children Ensure `ON DELETE CASCADE` is declared; delete children first

Compatibility Notes

  • WAL mode: Concurrent readers are unlimited but only one writer at a time. The pool reserves connections so writes never starve readers.
  • Network filesystems: SQLite WAL is not safe on NFS / shared network drives — fsync semantics are unreliable. Keep the DB on local disk.
  • Backup: Use `sqlite3 <db> '.backup ...'` or stop the server before copying the `.db` file; a live copy may miss WAL contents.
  • cgo requirement: Pure-Go SQLite drivers are not used; a C compiler is mandatory at build time.

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment