teff.checkpoint¶
teff.checkpoint
¶
Modules:
| Name | Description |
|---|---|
base |
Checkpointing primitives for durable graph execution. |
file |
JSON-file checkpointing — zero dependencies, atomic via tempfile + rename. |
from_config |
Build a :class: |
history |
Time-travel checkpoints: keep every per-iteration snapshot. |
pg |
PostgreSQL checkpointing — requires |
sqlite |
SQLite checkpointing — stdlib only, shared file format with the RAG store. |
Classes:
| Name | Description |
|---|---|
Checkpoint |
A snapshot of execution that can be resumed from. |
Checkpointer |
Interface for persisting execution checkpoints. |
JSONFileCheckpointer |
Store checkpoints as one JSON file per (owner, checkpoint ID). |
PGCheckpointer |
Store checkpoints in a PostgreSQL table. |
PGHistoryCheckpointer |
PostgreSQL checkpointer that also keeps the full per-step history. |
SQLiteCheckpointer |
Store checkpoints in a SQLite database. |
SQLiteHistoryCheckpointer |
SQLite checkpointer that also keeps the full per-step history. |
Functions:
| Name | Description |
|---|---|
checkpoint_from_dict |
Reconstruct a checkpoint from a dict produced by :func: |
checkpoint_to_dict |
Convert a checkpoint to a JSON-serializable dict. |
Checkpoint
dataclass
¶
A snapshot of execution that can be resumed from.
Attributes:
| Name | Type | Description |
|---|---|---|
state |
dict
|
Workflow state data (JSON-serializable dict). |
next_node_id |
str | None
|
ID of the node to execute on resume.
|
iteration |
int
|
Number of completed node executions so far. |
Source code in teff/checkpoint/base.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 | |
Checkpointer
¶
Bases: Protocol
Interface for persisting execution checkpoints.
Implementations must be safe to call concurrently for different checkpoint IDs and must persist atomically enough that a crash never leaves a partially-written checkpoint.
The optional owner scopes a checkpoint to a user/session/tenant.
Two checkpoints with the same ID but different owners never collide.
When omitted the default owner (:data:DEFAULT_OWNER, "default")
is used, keeping single-tenant callers unchanged.
Use a distinct owner per end-user (e.g. a user id or session id) so
every tenant's runs are isolated from the others and can be listed
with :meth:list.
Methods:
| Name | Description |
|---|---|
cleanup |
Delete stale checkpoints; returns how many were removed. |
delete |
Remove a saved checkpoint. No-op if it does not exist. |
list |
Return all checkpoint IDs persisted for owner. |
load |
Return the saved checkpoint for owner, or |
save |
Persist checkpoint under checkpoint_id for owner. |
Source code in teff/checkpoint/base.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
cleanup
async
¶
cleanup(*, owner=None, max_age=None, keep_last=None)
Delete stale checkpoints; returns how many were removed.
owner=None cleans up every owner; otherwise only that owner.
max_age removes checkpoints last written more than that many
seconds ago. keep_last retains the N most recently written
checkpoints per owner (after any max_age pruning) and deletes
the rest. When both are omitted nothing is deleted.
Source code in teff/checkpoint/base.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
delete
async
¶
delete(checkpoint_id, *, owner=DEFAULT_OWNER)
Remove a saved checkpoint. No-op if it does not exist.
Source code in teff/checkpoint/base.py
59 60 61 | |
list
async
¶
list(owner=DEFAULT_OWNER)
Return all checkpoint IDs persisted for owner.
Source code in teff/checkpoint/base.py
63 64 65 | |
load
async
¶
load(checkpoint_id, *, owner=DEFAULT_OWNER)
Return the saved checkpoint for owner, or None if never saved.
Source code in teff/checkpoint/base.py
53 54 55 56 57 | |
save
async
¶
save(checkpoint_id, checkpoint, *, owner=DEFAULT_OWNER)
Persist checkpoint under checkpoint_id for owner.
Source code in teff/checkpoint/base.py
47 48 49 50 51 | |
JSONFileCheckpointer
¶
Bases: Checkpointer
Store checkpoints as one JSON file per (owner, checkpoint ID).
Writes go to a temp file in the same directory and are atomically
renamed over the target, so a crash never leaves a corrupt file.
Each owner gets its own subdirectory, so IDs only need to be
unique within an owner. See :class:~teff.checkpoint.Checkpointer
for how to pick an owner.
Methods:
| Name | Description |
|---|---|
cleanup |
Delete stale checkpoints; returns how many were removed. |
list |
Return all checkpoint IDs persisted for owner. |
Source code in teff/checkpoint/file.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
cleanup
async
¶
cleanup(*, owner=None, max_age=None, keep_last=None)
Delete stale checkpoints; returns how many were removed.
Source code in teff/checkpoint/file.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
list
async
¶
list(owner=DEFAULT_OWNER)
Return all checkpoint IDs persisted for owner.
Source code in teff/checkpoint/file.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 | |
PGCheckpointer
¶
Bases: Checkpointer
Store checkpoints in a PostgreSQL table.
Requires asyncpg (install via teff[pg-checkpoint]). The
table checkpoints is created lazily on first use. Connections are
drawn from a lazily-created async connection pool, so checkpoint saves
reuse warm connections instead of paying the handshake per operation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dsn
|
str
|
PostgreSQL connection string. |
required |
table
|
str
|
Table name (default |
'checkpoints'
|
pool_size
|
int
|
Maximum pooled connections (default 5). |
5
|
Methods:
| Name | Description |
|---|---|
cleanup |
Delete stale checkpoints; returns how many were removed. |
close |
Close the connection pool (idempotent). |
list |
Return all checkpoint IDs persisted for owner. |
Source code in teff/checkpoint/pg.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |
cleanup
async
¶
cleanup(*, owner=None, max_age=None, keep_last=None)
Delete stale checkpoints; returns how many were removed.
Source code in teff/checkpoint/pg.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |
close
async
¶
close()
Close the connection pool (idempotent).
Source code in teff/checkpoint/pg.py
58 59 60 61 62 | |
list
async
¶
list(owner=DEFAULT_OWNER)
Return all checkpoint IDs persisted for owner.
Source code in teff/checkpoint/pg.py
119 120 121 122 123 124 125 126 127 128 | |
PGHistoryCheckpointer
¶
Bases: _HistoryMixin, PGCheckpointer
PostgreSQL checkpointer that also keeps the full per-step history.
Requires asyncpg (install via teff[pg-checkpoint]). Mirrors
:class:PGCheckpointer but appends every save to a
checkpoint_history table, exposing history / load_at for
time travel in production.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dsn
|
str
|
PostgreSQL connection string. |
required |
table
|
str
|
Table name for the current checkpoints (default
|
'checkpoints'
|
Source code in teff/checkpoint/history.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
SQLiteCheckpointer
¶
Bases: Checkpointer
Store checkpoints in a SQLite database.
Uses one row per (owner, checkpoint_id) pair — a composite primary
key, so the same ID can belong to different owners (users/tenants)
without colliding. Each save is a single INSERT .. ON CONFLICT
REPLACE transaction, so a crash leaves either the old or the new row,
never a mix. Existing single-owner databases are migrated in place:
their rows move under :data:~teff.checkpoint.DEFAULT_OWNER, and an
updated_at column is added for TTL cleanup.
All database work runs in a worker thread (asyncio.to_thread) behind
a lock, so checkpoint saves never block the event loop — important when
many parallel branches checkpoint through the same store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the SQLite database file. |
required |
Methods:
| Name | Description |
|---|---|
cleanup |
Delete stale checkpoints; returns how many were removed. |
close |
Close the underlying SQLite connection. |
list |
Return all checkpoint IDs persisted for owner. |
Source code in teff/checkpoint/sqlite.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | |
cleanup
async
¶
cleanup(*, owner=None, max_age=None, keep_last=None)
Delete stale checkpoints; returns how many were removed.
Source code in teff/checkpoint/sqlite.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | |
close
¶
close()
Close the underlying SQLite connection.
Source code in teff/checkpoint/sqlite.py
90 91 92 93 | |
list
async
¶
list(owner=DEFAULT_OWNER)
Return all checkpoint IDs persisted for owner.
Source code in teff/checkpoint/sqlite.py
164 165 166 167 168 169 170 171 172 173 174 | |
SQLiteHistoryCheckpointer
¶
Bases: _HistoryMixin, SQLiteCheckpointer
SQLite checkpointer that also keeps the full per-step history.
A drop-in for :class:teff.checkpoint.SQLiteCheckpointer that, on every
save, additionally appends the snapshot to a checkpoint_history
table — so the current checkpoint can be overwritten without losing the
earlier ones. history / load_at expose the timeline for time
travel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the SQLite database file. |
required |
Source code in teff/checkpoint/history.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |
checkpoint_from_dict
¶
checkpoint_from_dict(data)
Reconstruct a checkpoint from a dict produced by :func:checkpoint_to_dict.
Source code in teff/checkpoint/base.py
94 95 96 97 98 99 100 | |
checkpoint_to_dict
¶
checkpoint_to_dict(cp)
Convert a checkpoint to a JSON-serializable dict.
Source code in teff/checkpoint/base.py
85 86 87 88 89 90 91 | |