Stateful Simulation · TypeScript, JavaScript, Python

Unit tests check one call. Outages take three.

Coding agents ship billing, auth, and webhook code fast — and pass single-call unit tests while leaving double-refund races, token-refresh deadlocks, and cross-tenant leaks behind. SafeState explores thousands of interleaved call sequences deterministically, shrinks failures to the shortest failing sequence, and gives your coding agent a standalone Vitest repro it can fix.

$0 LLM deterministic core Offline DB & SDK simulation Zero runtime deps in repros
billing/refunds.ts · seed 42
DOUBLE_REFUND
Shrunk 3-step counterexample (16 shrinks) SafeState / Check
1CreateCharge(ch_2, amountCents: 2500)
2RequestRefund(ch_2, 2500) [yield @ fetch]
3DeliverWebhook(refund.succeeded, ch_2, 2500)
⚠ Invariant failed: NO_OVER_REFUND billing/refunds.ts:48
refundedCents = 5000 > amountCents = 2500
Exported standalone billing-double-refund.spec.ts (0 SafeState imports).
Root cause pinned to async yield pointrequestRefund() reads refunded_cents before calling the payment provider, then writes back after the webhook already incremented it.
## Copy for your coding agent

Invariant NO_OVER_REFUND failed on seed 42 after shrinking to 3 steps.
1. CreateCharge("ch_2", 2500)
2. RequestRefund("ch_2", 2500) yields while awaiting outbound refund call
3. DeliverWebhook("refund.succeeded", "ch_2", 2500) commits before step 2 resumes

Fix the read-modify-write race in billing/refunds.ts:48 (reserve refund capacity atomically before calling the external gateway and deduplicate by webhook event ID).
Verify with: vitest run billing-double-refund.spec.ts
After push with atomic reservation + event dedupe: 10,000 TRACES · 0 BUGS
Anti-tautology mutation gatePlanted refund-cap removal mutant caught by NO_OVER_REFUND before trusting the invariant.
1/1 KILLED
Byte-identical deterministic replaySeed 42 produced identical SHA-256 trace digest across independent worker runs.
VERIFIED
Offline network lockdownOutbound sockets blocked during simulation; external gateway calls routed to deterministic twin.
OFFLINE
Zero runtime lock-inEmitted repro file imports only your code and Vitest — zero SafeState packages required.
0 DEPS
Measured across real repositories and deterministic benchmarks
65 bugs · 26 repos
verified stateful failures across production codebases
Empirically reproduced across 26 real TypeScript, JavaScript, and Python repositories — covering billing, auth, webhook idempotency, quotas, and local SQLite/Postgres workflows. Read study notes →
372 traces/s
deterministic simulation with byte-identical SHA-256 replay
Measured over 10,000 multi-step traces with in-memory database snapshot/restore, virtual clock, and seeded PRNG — at $0 LLM cost on every check. Benchmark →
100%
anti-tautology mutation gate before trusting any invariant
Hollow checks that always pass are useless. SafeState injects planted P0 faults into the target module and rejects any invariant that fails to catch broken code. See walkthrough →
01 / What Unit Tests Miss

Three calls in the wrong order. Every unit test stays green.

Single-call unit tests prove each function works in isolation. Production outages happen when retries, duplicate webhooks, concurrent requests, and clock skew collide across state transitions.

01 · Billing TOCTOUbilling/refunds.ts
1. CreateCharge(ch_2, 2500) 2. RequestRefund(ch_2, 2500) [yield @ fetch] 3. DeliverWebhook(refund.succeeded, 2500)

Double-refund slips past a clean unit suite

The refund handler checks remaining balance, awaits an external gateway, and then updates the database. A concurrent webhook commits first and doubles the refunded total.

02 · Auth Revocation Raceauth/sessions.ts
1. CreateSession(user_1, tok_a) 2. RefreshToken(tok_a) [yield @ db] 3. RevokeSession(user_1) → step 2 mints tok_b

Revoked user keeps a live access token

Logout deletes the session while a refresh request is mid-flight. When the refresh resumes, it inserts a brand-new active session for an already logged-out user.

03 · Differential Driftledger/v2-refactor.ts
1. Credit(acct_1, 500) 2. Debit(acct_1, 500) + Retry(idem_9) v1 balance = 0 != v2 balance = -500

Refactored code silently diverges on retries

SafeState runs the exact same seeded sequence against your baseline and refactored implementations side by side and surfaces the shortest trace where state diverges.

02 / How It Works

Verify stateful backends before merge — without hand-writing harnesses.

Connect through the GitHub App, the hosted OpenAPI 3.1 API, or the remote Code-Mode MCP server. No npm packages to install into your production repo.

01

Connect GitHub App or MCP

Request a free check on one module, connect the read-only GitHub App, or point your coding agent at https://api.safestate.dev/mcp.

02

Simulate thousands of sequences

SafeState drives your exported operations against in-memory PostgreSQL (PGlite), SQLite, and deterministic HTTP/SDK twins under virtual time and seeded interleavings.

03

Shrink to a standalone repro

Collapses a 40-step failure to 2–4 steps and emits a zero-dependency Vitest file plus a copy-paste prompt for your coding agent.

04

Confirm with mutation gating

Before going green, SafeState injects planted P0 faults to prove your invariants fail on broken code and re-verifies 10,000 traces on your fix.

03 / Trust & Honest Boundaries

Deterministic core. Clear scope limits.

No LLM reads your code during deterministic checks, and we state our V1 database simulation boundary upfront.

Verification controls & honest V1 scope

Built to produce reproducible engineering evidence, never hand-wavy scores.

  • 01Anti-tautology mutation gate: Every invariant must catch a planted P0 bug mutant before it is trusted. Vacuous checks are rejected automatically.
  • 02Byte-identical seed replay: Virtual clock, seeded PRNG, and deterministic scheduler guarantee that re-running a failing seed reproduces the exact same bug.
  • 03Zero-dependency repro files: Generated Vitest repros import only your module and Vitest — commit them directly into your repository without adding SafeState dependencies.
  • 04Honest V1 PostgreSQL boundary: In-memory PGlite catches application-level async races (Promise.all, yields around fetch/SDK calls, duplicate webhooks, stale read-modify-write) over a single connection. True multi-connection PostgreSQL MVCC lock contention (FOR UPDATE, SERIALIZABLE retries) requires a multi-connection Postgres target rather than single-connection PGlite.

Private by design & least privilege

Minimal permissions, offline execution, and transparent data retention.

  • 01$0 LLM deterministic engine: Exploration, interleaving, shrinking, differential comparison, and mutation gating run as fixed deterministic code — no AI model reads your code on PR runs.
  • 02Least-privilege GitHub App: Requests only contents: read, checks: write, pull_requests: read, and metadata: read. Cannot push commits, merge PRs, or alter settings.
  • 03Offline simulation sandbox: Outbound internet is locked down during trace execution so simulation code cannot leak data or hit live payment APIs.
  • 0430-day retention & fast removal: Ephemeral source checkouts are deleted immediately after each run. Stored check summaries expire after 30 days, or email remove@safestate.dev for immediate deletion.
04 / Pricing

Start with a free check. Then one flat monthly price.

No per-seat fees, no per-minute cloud meter surprises, and no sales call. Every paid plan includes unlimited developers on one GitHub account.

Free Check Try Free
$0 no credit card required

Submit one public repository or stateful module for a complete deterministic check before paying anything.

  • ✓Full stateful module audit across TypeScript, JavaScript, or Python
  • ✓Shrunk counterexample trace + standalone zero-dependency Vitest repro
  • ✓Copy-paste fix prompt ready for your coding agent
  • ✓Free, no commitment, and zero PR noise without your approval
Request Free Check →
Public repositories first; private repo pilots available on request.
Team High Volume
$199 / month per GitHub org

Built for multi-repo backend teams shipping billing, ledger, auth, and workflow refactors every day.

  • ✓Unlimited developers across all selected repositories in your org
  • ✓Up to 500 burst runs / month with higher parallel shard fan-out
  • ✓Differential refactor mode (old vs new implementation equivalence)
  • ✓Remote Code-Mode MCP + OpenAPI 3.1 API + direct onboarding support
  • ✓30-day first-month refund on request — cancel anytime
Start Team Plan →
Need custom concurrency or self-hosted Postgres MVCC? Email us.
Billing & cancellation: Paid subscriptions are sold through Link using Stripe Managed Payments (Merchant of Record), which handles checkout, applicable transaction taxes, and receipts. Manage or cancel your subscription anytime in the Stripe billing portal, reply to any SafeState email, or write to hello@safestate.dev.
05 / Questions

Straight answers before you connect.

Do I need to install an npm package in my repository?

No. SafeState connects via a read-only GitHub App, a hosted OpenAPI 3.1 API (https://api.safestate.dev/v1/openapi.json), and a Remote Code-Mode MCP server (https://api.safestate.dev/mcp). Emitted Vitest repro files have zero SafeState imports, so you never add a runtime or dev dependency to your project.

Does any AI model read or train on my source code?

No AI model reads your code during deterministic PR checks. Stateful exploration, interleaving, shrinking, differential comparison, and anti-tautology mutation gating are all deterministic code running offline. Your own coding agent — never SafeState — edits your repository. See security and data handling.

What is the honest V1 boundary for PostgreSQL concurrency?

In V1, SafeState runs PostgreSQL modules against in-memory PGlite for fast sub-second snapshot/restore across thousands of traces. PGlite faithfully catches application-level async interleavings (concurrent Promise.all handlers, yields around fetch or payment SDK calls, duplicate webhooks, and non-atomic read-modify-write logic) over one database connection. True multi-connection PostgreSQL MVCC lock contention (SELECT ... FOR UPDATE waits or SERIALIZABLE conflicts) requires a multi-connection Postgres server rather than single-connection PGlite.

Which languages, databases, and ORMs are supported?

TypeScript, JavaScript, and Python backends. SafeState supports Drizzle, Prisma, raw SQL PostgreSQL, SQLite / Cloudflare D1, and pure ORM-free stateful modules (in-memory caches, auth token managers, queues, and workflow engines). See the documentation.

How does SafeState compare to mutation testing?

They catch complementary bug classes. Diff-scoped mutation testing verifies that your existing unit tests catch single-line logic flips (>= vs >, inverted guards). SafeState verifies multi-step stateful behavior across retries, out-of-order webhooks, concurrent requests, and database transitions — and uses a mutation gate internally so your stateful invariants cannot be vacuous.

How do cancellation and refunds work?

Manage or cancel your subscription directly in the Stripe billing portal (enter your billing email for a login link), reply to any SafeState email, or write to hello@safestate.dev. Your first month is refunded on request within 30 days.

Catch multi-step outages before they hit production.

Start with a free deterministic check on one stateful module. Receive a shrunk trace, a standalone zero-dependency Vitest repro, and a prompt ready for your coding agent.