You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/persistence/overview.md
+30Lines changed: 30 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,6 +11,36 @@ storage primitives with sandbox and workflow extensions.
11
11
Persistence is optional middleware. A run with no persistence middleware behaves
12
12
exactly as before.
13
13
14
+
## Control ladder
15
+
16
+
Persistence has several control levers. Start at the lowest rung that gives
17
+
your app the durability it needs, then opt into more stores only when a feature
18
+
requires them.
19
+
20
+
| Lever | You control | TanStack AI provides | Use it when |
21
+
| --- | --- | --- | --- |
22
+
| No persistence | Nothing | Normal in-memory run behavior | A run can disappear after the request ends. |
23
+
| Client resume snapshot | Where the client stores `{ threadId, runId, cursor }`|`persistence.server`, `autoResume`, and `resume()` in the client hooks | A page refresh should reconnect to a still-durable server run. |
24
+
| Messages |`stores.messages.loadThread` and `saveThread`| Server-authoritative thread history loading/saving | The server owns the transcript instead of trusting the browser. |
25
+
| Durable replay |`stores.runs` and `stores.publicEvents`| Opaque cursors, run records, AG-UI event append, and replay | Reconnects must continue a run without calling the model again. |
26
+
| Interrupts |`stores.interrupts` plus replay stores | Durable pending human decisions and resume payload handling | A run can pause for approval, input, or another user action. |
27
+
| Internal checkpoints |`stores.internalEvents`| A separate non-UI event log | Packages or app workflows need checkpoints that should not replay to users. |
28
+
| Metadata |`stores.metadata`| Namespaced key/value access | Your app needs durable correlation, manifests, or integration state. |
29
+
| Locks |`stores.locks`| Shared lock capability consumed by integrations | Multiple workers can resume or mutate the same durable resource. |
30
+
| Artifacts and blobs |`stores.artifacts` and `stores.blobs`| Durable artifact refs for generated files and media | Runs create downloadable files, media, or workspace checkpoints. |
31
+
| SQL or platform backend | Database schema, migration timing, deployment topology | Backend factories that implement the same stores | You want TanStack primitives on top of your chosen database or platform. |
32
+
33
+
For production, prefer user-owned persistence through an `AIPersistence` object
34
+
created with `defineAIPersistence(...)` or a backend factory that returns the
35
+
same store contract. TanStack AI should call your existing storage boundary
36
+
through store callback methods; it should not be the part of your production
37
+
system that silently owns raw SQL schema lifecycle or data-retention policy.
38
+
39
+
Packaged backends such as SQLite, Postgres, Prisma, Drizzle, and Cloudflare are
40
+
useful primitives when they fit your stack. They still expose the same
41
+
`AIPersistence` stores, so you can start with a backend package, replace one
42
+
store at a time, or compose SQL metadata with object storage for artifacts.
0 commit comments