HITLConcepts

Stores

Where pending approvals, grants, limits, history and receipts live, and how to keep them across restarts.

A store holds the gate's state: approvals, grants, limit reservations, invariant history and (optionally) receipts. The gate itself is stateless, so any number of processes can share one store: a worker suspends an action, a web server receives the Slack click, and a third process resumes the agent.

StorePythonTypeScriptUse it for
Memory (default)hitl.memory()memory() from @viewportai/hitlTests and single-process tools. Gone on restart
SQLitehitl.sqlite(".viewport/hitl.sqlite")sqlite(".viewport/hitl.sqlite") from @viewportai/hitl/sqliteOne machine, durable. WAL mode with synchronous=FULL, so a commit reaches disk before it returns
Postgreshitl.postgres(dsn) (extra viewport-hitl[postgres])postgres(dsn) from @viewportai/hitl/postgres (peer pg)Many processes and machines. LISTEN/NOTIFY wakes waiters

Pass it when you build the gate: store=hitl.sqlite(...) in Python, { store: sqlite(...) } in TypeScript. A shared store (SQLite or Postgres) also needs a redaction key, VIEWPORT_REDACT_KEY or redact_key / redactKey, or the gate refuses to start (hitl.config_invalid); see the redaction key in Approvals. SQLite uses the standard library in Python (on a worker thread) and node:sqlite in Node, falling back to the optional peer better-sqlite3 (pass driver: "better-sqlite3" to choose it). Postgres uses psycopg 3 in Python and pg in Node; both create their tables (prefix hitl_) on first use.

better-sqlite3 13 needs Node 22.14 or later (it crashes on Node 22.12 and 22.13); 12.x works on older Node 22.

What the store guarantees

  • Compare-and-set on every transition, by the record's version: two answers or two consumers can never both win.
  • Idempotent creation by the idempotency key, so a resumed run finds its approval instead of asking again.
  • Atomic limit reservations that commit when the tool succeeds, release when it fails, and expire if the process dies (reservation_ttl, default 15 minutes).
  • Push or poll: a waiting call is woken by the store when it can push (memory, Postgres) and polls with backoff otherwise. Every wait sleeps on the gate's clock.

A store that cannot be reached denies: hitl.store_unavailable. It never allows.

Receipts in the store

receipts=True (Python) / receipts: true (TypeScript) writes the receipt chain to the store's own table (SQLite and Postgres), so viewport-hitl receipts verify .viewport/hitl.sqlite or a Postgres DSN verifies it. receipts="path.jsonl" writes a JSONL file instead, with an exclusive lock on the chain head.

Your own store

A store implements the HitlStore interface (approvals, limits, grants, history, optional receipts). The package ships the conformance suite it must pass, the same one the built-in stores run: store_contract(make_store) in viewportai.hitl.testing and storeContract(name, makeStore) in @viewportai/hitl/vitest. It covers races with many concurrent writers, idempotency, expiry, limit reservations and receipt chain heads.

On this page