Skip to main content
Glama

Invariex infers what your code is supposed to do, writes it as a small formal model with invariants, bounded-checks that model for an execution that breaks an invariant, and then proves every finding with a real failing test before it reaches the report. No test, no finding.

It targets the bugs that slip past linters and unit tests: concurrency and distributed-systems defects — data races, thread-safety violations, check-then-act (TOCTOU) races, lease/consensus mistakes, lost updates, and double-charge bugs.

intent  →  check  →  triage  →  prove  →  fix
  │                     │                  │
  └── revise model ─────┘       re-check ──┘

✦ Why it's different

  • Proof, not suspicion — the report only contains bugs with a failing repro test.

  • Honest bounds — every finding states its checked bound; never a false "proven everywhere".

  • Language-agnostic core — reasons over an abstract interleaving model, not source text.

  • Driveable anywhere — CLI, MCP server, or importable library.

  • Resumable — job state in libSQL/Turso (local, remote, or embedded replica).

✦ What it catches

  • Data races & thread-safety violations

  • Check-then-act (TOCTOU) races

  • Lost updates (incl. lost money)

  • Lease / consensus revocation bugs

  • Double-charge / double-spend

  • …any invariant you can state

Status: alpha. The orchestrator, Turso-backed job store, agent tool-use loop, bounded checker, prove-it gate, SARIF/Markdown reporting, and the MCP server all run today. Formal lowering (code → model) and language-specific repro harnesses are wired as optional, gracefully-degrading backends.


🚀 Quick start

uv is the project manager.

git clone https://github.com/sudo-py-dev/invariex
cd invariex
uv sync                       # create the env + install dependencies
uv run invariex check toctou  # bounded-check a built-in example (no API key)

You'll see a concrete counterexample schedule — the exact interleaving that breaks the invariant.

Related MCP server: contradiction-mcp

👤 For users

uv run invariex specs                 # list built-in concurrency specs
uv run invariex check <spec>          # bounded-check one spec
uv run invariex languages             # supported languages + repro backends
uv run invariex languages --detect .  # detect a repo's languages

# Scan a repo (offline example — uses a built-in model):
uv run invariex scan . --hint "double charge on lease revoke" \
     --spec invariex.specs.lease_double_charge --out .invariex/out

uv run invariex jobs                  # resumable job list
uv run invariex report <job_id>       # re-emit SARIF + Markdown

With ANTHROPIC_API_KEY set and the LLM extra installed (uv sync --extra llm), the agent drives scan on real code; otherwise a deterministic offline agent checks the given --spec, so the whole pipeline runs with no network.

Connect it to your AI agent

Invariex is an MCP server — plug it into Claude Code, Cursor, and others:

claude mcp add invariex -- invariex mcp

Full setup for Claude Code, Claude Desktop, Cursor, Codex, Windsurf, Cline, and Zed is in docs/INTEGRATIONS.md.

Storage (Turso / libSQL)

Job state lives in libSQL. Three modes, chosen by environment — no code change:

Mode

How

Local file (default)

nothing to set

Remote Turso

TURSO_DATABASE_URL + TURSO_AUTH_TOKEN

Embedded replica

the above + INVARIEX_DB_SYNC=1

🛠 For developers

uv sync
uv run ruff format invariex tests
uv run ruff check invariex tests
uv run pytest

How it works

  1. Intent — write the code's intended behavior as a state-machine model with invariants.

  2. Check — bounded model checking: exhaustively explore every interleaving up to a size limit; return the first invariant violation as a trace.

  3. Triage — a counterexample is a lead, not a bug (misread → revise the model; real → candidate).

  4. Prove — write a deterministic test that reproduces it. No test, no finding.

  5. Fix — propose a minimal patch, then re-run the check and the test.

Project layout

invariex/
  config.py        env-driven Settings + DbConfig (local / remote / replica)
  models.py        Job, Candidate, Finding, Severity, ImpactClass, Phase
  serialize.py     domain <-> JSON wire format
  store.py         resumable job store on libSQL / Turso
  checker.py       dependency-free bounded interleaving enumerator
  orchestrator.py  drives the loop; owns the job record
  agent/           tool-use agent: base protocol, LLM loop, offline agent
  tools/           read_file, grep, write_lean, lean_build, run_check,
                   write_test, run_test, write_patch
  report/          sarif.py + markdown.py
  specs/           runnable corpus (lost_update, lease_double_charge,
                   toctou, bank_overdraft)
  languages.py     language registry + repro backends + repo detection
  mcp/             zero-dependency stdio JSON-RPC MCP server
  cli.py           scan / check / specs / languages / jobs / report / mcp

The checker is language-agnostic, so adding a concurrency pattern is just a new ConcurrencyModel in invariex/specs/. Run it with uv run invariex check <name>.

License

Apache-2.0.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      C
      maintenance
      Behavioral verification intelligence for AI coding agents. Reads a TypeScript or JavaScript repo, clusters functions into 25 semantic workflows (Authentication, Payments, Webhooks, Caching, Queue, and more), and emits concrete adversarial probes per workflow. 17 MCP tools, local SQLite state, zero cloud.
      17
      41 npm
      3
      MIT
    • A
      license
      A
      quality
      B
      maintenance
      Enables AI coding agents to maintain persistent working memory across sessions by capturing decisions, invariants, lessons, and bugs, retrieving them within token budgets, and auditing proposed diffs against active constraints. It also supports duplicate detection, supersession and invalidation lineage, and local SQLite-backed storage with optional PostgreSQL.
      5
      83
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables AI agents to bootstrap isolated QA projects, explore unfamiliar multi-tier systems from 0→1, keep a living code map, and execute deterministic Playwright suites with three-layer anti-fake-green audits over stdio, Streamable HTTP, or legacy SSE. It also exposes read-only hubs for observability, databases, CDP/API performance budgets, and OpenAPI contracts so agents can triage failures while blocking production targets, writes, and leaked credentials.
      1,959 npm
      1
      MIT