popoto.fields.tombstone_store¶
popoto.fields.tombstone_store
¶
TombstoneStore — field-layer keeper of the tombstone keyspace (#649).
Relocates the raw-Redis tombstone bookkeeping that used to live inline in
popoto.recipes.memory_lifecycle (issue #491) into the field layer, as
part of the #630 "route recipes through the field layer" series. This is a
relocation, not a redesign: every method here issues the exact same Redis
commands, in the same order, as the recipe code it replaces, so wire
behavior is byte-identical.
The tombstone keyspace is deliberately kept OUTSIDE the model's own
keyspace ($TOMB:{Model}:data / $TOMB:{Model}:index rather than any
{Model}:* key) so that no query, index scan, or key-set walk can ever
surface a tombstoned record. That property must be preserved exactly —
tombstones are NOT a popoto Model; that was explicitly considered and
rejected.
Keyspace
$TOMB:{Model}:data — hash, redis_key -> msgpack-packed entry bytes
$TOMB:{Model}:index — zset, redis_key -> death timestamp (score)
Tombstone
dataclass
¶
Durable record that a memory was forgotten, and what it looked like.
Forgetting tombstones rather than deletes so an aggressive low-confidence forget policy stays reversible (Risk 6) and so each death becomes negative evidence a future write path can consult (#494).
Attributes:
| Name | Type | Description |
|---|---|---|
redis_key |
str
|
The forgotten record's Redis key. Restore handle. |
fingerprint |
str
|
ExistenceFilter fingerprint of the dead record — the identity token #494 matches new writes against. |
tier |
str
|
Tier the record held at death. |
importance_at_death |
float
|
Importance score at the moment of forgetting. |
confidence_at_death |
Optional[float]
|
ConfidenceField value at death, or None if the model carries no confidence signal. |
evidence_count |
int
|
Observations backing that confidence. |
dismissal_count |
int
|
Contradiction/dismissal count at death. |
tombstoned_at |
float
|
Unix timestamp of the forgetting. |
reason |
str
|
Free-form marker for what triggered it. |
Source code in src/popoto/fields/tombstone_store.py
TombstoneStore
¶
Owns the $TOMB:{Model}:* keyspace for a single model class.
Field-layer keeper of tombstone reads/writes. Every method issues the
exact same Redis commands, in the same order, as the raw-Redis recipe
code it replaces (see the table in issue #649). Callers (e.g.
MemoryLifecycle) are responsible for msgpack-packing entries before
calling archive() and for unpacking what get_entry/get_entries
return — this store deals in raw bytes at that boundary, matching where
the recipe drew the line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_class
|
Any
|
The Popoto Model class whose tombstones this store
manages. Only |
required |
Source code in src/popoto/fields/tombstone_store.py
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 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 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | |
keys()
¶
Return the (data hash, recency index) Redis keys for tombstones.
Source code in src/popoto/fields/tombstone_store.py
archive(redis_key, entry_bytes, ts)
¶
Write a tombstone entry: HSET the data hash, ZADD the recency index.
Both commands are queued in one transactional pipeline (HSET then
ZADD, matching the original write order) and executed together.
Source code in src/popoto/fields/tombstone_store.py
count()
¶
Return the number of retained tombstones (ZCARD on the index).
Source code in src/popoto/fields/tombstone_store.py
oldest_keys(n)
¶
Return up to n oldest tombstoned keys (ZRANGE 0..n-1).
Source code in src/popoto/fields/tombstone_store.py
newest_keys(stop)
¶
Return keys newest-death-first up to stop (ZREVRANGE 0..stop).
Source code in src/popoto/fields/tombstone_store.py
evict(keys)
¶
Remove tombstones for keys: HDEL data + ZREM index.
Both commands are queued in one transactional pipeline (HDEL then
ZREM, matching the original eviction order) and executed together.
Source code in src/popoto/fields/tombstone_store.py
get_entry(redis_key)
¶
Return the raw stored entry bytes for one key (HGET), or None.
Source code in src/popoto/fields/tombstone_store.py
get_entries(keys)
¶
Return raw stored entry bytes for keys (HMGET).
Preserves argument order, with None holes for missing members —
callers rely on positional correspondence with keys.
Source code in src/popoto/fields/tombstone_store.py
purge(redis_key)
¶
Drop one tombstone permanently: HDEL data + ZREM index.
Both commands are queued in one transactional pipeline and executed together. Returns True if a tombstone was actually removed.
Source code in src/popoto/fields/tombstone_store.py
purge_all()
¶
Drop every retained tombstone for this model: one DEL over both keys.
The count read is best-effort and its failure is swallowed: the caller
this was relocated from (MemoryLifecycle.purge_all_tombstones) read
the count through an error-swallowing helper and issued the DEL
regardless. A failed count must not leave the tombstones in place — the
return value is a report, the delete is the job.