Skip to main content

RevertX

Deterministic Execution Safety, Policy Enforcement, and Recovery Layer for AI Agents.

Release Status (v0.2.0): SQLite verified locally; PostgreSQL dialect-tested, live-cluster beta.

Verified scope: All 88 automated unit, integration, adversarial security, and OS kill -9 crash-recovery tests pass against local WAL-mode SQLite (aiosqlite), alongside FastMCP, FastAPI/HTMX, and clean-room wheel installation. PostgreSQL / live-cluster scope: Async URL normalization, SQLAlchemy postgresql+asyncpg DDL compilation, dialect-guarded SELECT ... FOR UPDATE locking, and asyncpg engine construction are unit-tested; end-to-end runtime execution against a live PostgreSQL server or multi-node cluster has not been run yet in local verification and should be validated in staging before production rollout.

RevertX sits strictly in the execution path between autonomous AI agents (MCP clients, LangGraph, CrewAI, or custom Python scripts) and live databases or external APIs:

AI Agent  ──▶  RevertX Safety Proxy  ──▶  Database / External API
                 ├─ Pre-State & OCC Snapshots (outside agent context)
                 ├─ 4-State Recovery Contracts & Policy Preconditions
                 ├─ Durable Sliding-Window Blast-Radius Breaker
                 ├─ Cryptographically Bound Telegram Approval Gate
                 └─ Idempotent Reverse-DAG Compensating Rollback

RevertX does not guess whether an LLM "hallucinated." It enforces deterministic policy thresholds, business-record preconditions, Optimistic Concurrency Control (OCC), and durable crash-safe Saga recovery.


Core Architecture Guarantees (v0.2.0)

  1. Explicit 4-State Recovery Contracts (policies/policy.yaml): Every tool is classified as read_only, transactional, compensatable, irreversible, or unsupported with operation_type (create | update | delete), optional dot-path created_id_field extraction for cross-system CREATE sagas, and optional verification.required: true readback confirmation after compensation. Unclassified write tools fail closed.
  2. Shadow Mode Dry-Run (--mode shadow / REVERTX_SHADOW_MODE): Executes read_only tools against live data while intercepting mutations after policy and isolated blast-radius checks into WOULD_EXECUTE, WOULD_REQUIRE_APPROVAL, or WOULD_BLOCK diff previews without touching external systems.
  3. Optimistic Concurrency Control (OCC): Captures version_before / version_after (falling back to canonical SHA-256 state_hash when integer versions are unavailable). Before rolling back, RevertX checks live state—if an external actor modified the record, it halts immediately as ROLLBACK_CONFLICT instead of silently overwriting newer data.
  4. Durable Compensation State Machine & Crash Recovery: Persists step states (PENDING → EXECUTING → EXECUTED → COMPENSATION_PENDING → COMPENSATING → COMPENSATED / COMPENSATION_FAILED / ROLLBACK_CONFLICT) in an isolated SQLite/PostgreSQL ledger and runs automatic startup recovery sweeps (recover_stranded_compensations()).
  5. Cryptographically Bound Single-Use Approvals & Two-Tier Redaction: Computes action_hash = sha256(canonical_json(tool_name, args, target_resource)) with hard expires_at, actor/chat allowlists, webhook secret checks, and atomic single-use consumption. Recursively redacts secrets before ledger persistence while also masking PII (email, phone, ssn) across Telegram prompts and dashboard views.
  6. Atomic Ledger-Backed Circuit Breaker & Transport Hardening: Enforces sliding-window write velocity, row count, and cumulative per-run (max_amount_per_run) budgets atomically per run lock, alongside DNS-pinned SSRF protection, Streamable HTTP Origin checks, and explicit REVERTX_TRUSTED_PROXIES IP resolution.

Quickstart (uv / uvx)

# 1. Install dependencies
uv sync

# 2. (Standalone projects) Scaffold starter policies/policy.yaml & .env.example
uv run revertx init

# 3. Validate policies/policy.yaml fail-closed
uv run revertx check-policy

# 4. Run the MCP safety proxy against the local demo e-commerce store (live or shadow)
uv run revertx proxy --target demo
uv run revertx proxy --target demo --mode shadow

# 5. Launch the FastAPI + HTMX Safety Console (1-click Undo & OCC Conflicts)
uv run revertx dashboard

When published to PyPI, run zero-install via uvx revertx or install via pip install revertx.


Python @protect SDK Quickstart

import asyncio
from revertx import RevertXClient
from revertx.core.ledger import LedgerStore
from revertx.core.models import RecoveryContract, SnapshotData
from revertx.core.policy import load_policy

async def main() -> None:
    ledger = LedgerStore("sqlite+aiosqlite:///./revertx_ledger.db")
    await ledger.init_schema()
    policy = load_policy("policies/policy.yaml")
    client = RevertXClient(ledger, policy=policy)

    async def snapshot_order(args: dict, phase: str) -> SnapshotData:
        # Read live record state & version from your DB before/after mutation
        ...

    async def restore_order(args: dict, before_state: dict) -> None:
        # Idempotent compensator restoring prior state
        ...

    @client.protect(
        tool_name="update_order_status",
        recovery_contract=RecoveryContract.COMPENSATABLE,
        snapshot_fn=snapshot_order,
        compensator_fn=restore_order,
    )
    async def update_order_status(order_id: int, new_status: str) -> str:
        ...

    async with client.session("billing-agent") as run_id:
        await update_order_status(402, "Cancelled")
        # Trigger manual reverse-DAG rollback if needed:
        await client.rollback(run_id)

    await ledger.close()

Golden Scenarios Verified Continuously

  • Scenario A (Policy Gate + Verified Rollback): Agent updates Order #402 (Shipped → Cancelled), then attempts issue_refund(order_id=402, amount=15000). Deterministic policy checks (15000 > approval_required_above: 1000 and 15000 > verified order amount 1500) freeze the call in PENDING_APPROVAL with an action_hash-bound Telegram alert. Tapping 🛑 Reject & Undo blocks the payout permanently and restores Order #402 back to Shipped.
  • Scenario B (Blast-Radius Circuit Breaker): Attempting >5 row mutations or >5 write calls within 60 seconds trips the durable circuit breaker before hitting the database, logs BLOCKED, and dispatches a Telegram safety alert.

Telegram Setup

Copy .env.example to .env and configure:

REVERTX_TELEGRAM_BOT_TOKEN=your_bot_token
REVERTX_TELEGRAM_CHAT_ID=your_chat_id
REVERTX_APPROVAL_TIMEOUT_SECONDS=120

Never commit .env.


Verification

uv run ruff check .
uv run mypy src/
uv run pytest -v
uv build

Metadata

Release files for revertx 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for revertx 0.2.0
File Size Uploaded Provenance Actions
revertx-0.2.0.tar.gz 231.3 kB Without provenance Details for revertx-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for revertx 0.2.0
File Interpreter ABI Platform Actions
revertx-0.2.0-py3-none-any.whl Python 3 none any Details for revertx-0.2.0-py3-none-any.whl

Total release size: 301.6 kB

Release files / revertx-0.2.0.tar.gz

Download URL revertx-0.2.0.tar.gz
Size 231.3 kB
Tags Source
SHA-256 checksum
How to use checksums
8731c2f64218cd2b2b1195389fded777fc047d3892ee420ae7336796a96e9478
BLAKE2b-256 checksum
How to use checksums
31fecf331c56cea37e74d06949bf1fe9bdd72ee7f0a13f02c83e620fdb77e176
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / revertx-0.2.0-py3-none-any.whl

Download URL revertx-0.2.0-py3-none-any.whl
Size 70.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3ad6013e5421397c570022b82aa6fa1663b91378becea128a9750b9880ee5165
BLAKE2b-256 checksum
How to use checksums
3323d1e880e3d7bee33d4ffc5c8a5b4f668a4e9f72eb0dbfc2f327b794c05f06
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for revertx 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page