Skip to content

@anvia/durable ​

@anvia/durable runs Anvia agents with persisted model and tool checkpoints. Submit work, observe its progress, and recover unfinished runs after a process restart. It adds a durable lifecycle around existing agents: direct agent.generate() and agent.stream() remain available, and durable execution uses runtime.submit() and a DurableRun handle instead.

Experimental

The package is experimental and its database records may change. A SQLite database has one owner on one host. Postgres, Drizzle, and Prisma databases support one owning runtime or several shared workers, never both at once. Durable is not presented as production-ready. See Capabilities for the exact scope.

Install ​

sh
pnpm add @anvia/durable @anvia/core zod

Add a provider package such as @anvia/openai for the model. SQLite storage uses Node's built-in node:sqlite, so that backend requires Node.js 22.16 or newer. Durable requires core's agent execution protocol version 5 and declares @anvia/core >=1.19.1 <2; older core versions are rejected when a runtime opens.

To expose durable runs over HTTP, add @anvia/server (@anvia/server/durable) and @anvia/client (@anvia/client/durable). Reviewed Client 1.9.0 and Server 1.5.0 accept Durable >=0.8.0 <1.0.0. Steering requires Durable 0.8+, HTTP task agent binding requires 0.6+, and tracing requires 0.11+ (0.12+ for an observability session override). Remote memory-write reconciliation requires 0.14+; shared workers and the store-only client require 0.18+.

Storage and deployment roles ​

StoreImportOwnership
SQLite file@anvia/durable/sqliteOne owning runtime. readOnly: true for observation only.
Postgres@anvia/durable/postgresOne owning runtime, or shared workers with per-run claims.
Drizzle@anvia/durable/drizzleSame as Postgres; the schema is yours.
Prisma@anvia/durable/prismaSame as Postgres; the models are yours.
Customyour moduleImplement the async DurableStore contract.

Postgres accepts a pg pool or connection string; run with schema: 'create' once to create tables, or keep the default verification mode. Drizzle and Prisma use schemas you generate with anvia-durable-drizzle or anvia-durable-prisma, then verify them. pg, drizzle-orm, and @prisma/client are optional peers.

A deployment separates four roles that can run in different processes:

RoleAPILeaseExecutes
Owning runtimeDurableRuntime.open()Exclusive ownerIts own queued work.
Shared workerDurableRuntime.open({ worker }) or DurableWorker.start()Per-run claimsRuns, graphs, tasks, and goals.
Store-only clientDurableClient.connect({ store })NoneNothing; submits and controls only.
ObserverDurableObserver.connect({ store })None, read-onlyNothing; reads status, snapshots, events, and results.

An owning runtime and shared workers exclude each other on the same database. SQLite stores support only the owning runtime and a read-only observer.

What it provides ​

text
submit → queued request + event (atomic) → model/tool checkpoints → outcome
                  ↑ restart: reconstruct the loop from committed results ↓
CapabilitySummary
Storage backendsSQLite, Postgres, Drizzle, Prisma, or a custom async store.
Deduplicated submissionsOne run per (sessionId, requestId); changed content under the same ID conflicts.
CheckpointsNormalized model responses and tool results are committed and reused on recovery.
Restart recoveryruntime.resume() reschedules unfinished work; completed operations are never repeated.
Shared workersPostgres/Drizzle/Prisma workers claim runs and tasks with renewable leases and fencing.
Approvals and questionsCore interactions persist across restarts and accept one response per interaction ID.
Progress eventsCommitted, ordered events with cursors for reconnectable observation.
Agent streamingOpt-in persisted model deltas, grouped by unique attempt IDs.
Multimodal promptsStrings or core UserMessage values with image and file parts.
Queues and retryOpt-in session queues, bounded concurrency, and persisted model backoff.
Runtime registrationAdd agents without a restart; remove idle registrations safely.
Custom tasksVersioned, schema-validated tasks with checkpoints, owned children, timers, signals, and effects.
Static task graphsPersisted DAGs of registered-agent tasks with committed dependency outputs.
GoalsVerified objectives across bounded sessions, with continuing rounds and persisted controls.
SteeringDeduplicated user input queued at safe model/tool boundaries.
CompactionRecoverable model-context summaries between runs and inside tool loops.
TracingOne trace per durable run across attempts, with application session grouping.
OperationsFail-closed storage, readiness, metrics, limits, and offline backup and restore.

Entry points ​

ImportPurpose
@anvia/durableRuntime, worker, client, observer, handles, tasks, goals, errors, and types.
@anvia/durable/sqliteSqliteDurableStore. Kept separate so the root never imports node:sqlite.
@anvia/durable/postgresPostgresDurableStore over a pg pool or connection string.
@anvia/durable/drizzleDrizzleDurableStore, schema exports, and its generator.
@anvia/durable/prismaPrismaDurableStore, schema exports, and its generator.
@anvia/durable/protocolBrowser-safe validators and types used by the HTTP client.
@anvia/durable/maintenanceOffline backupSqlite and restoreSqlite for SQLite.

Continue ​

Built for Anvia.