| 462 | return count |
| 463 | |
| 464 | def list_active(self, scope_id: str, limit: int = 100) -> list[MemoryUnit]: |
| 465 | with self._lock: |
| 466 | rows = self.conn.execute( |
| 467 | """ |
| 468 | SELECT * FROM memories |
| 469 | WHERE scope_id = ? AND status = ? |
| 470 | ORDER BY updated_at DESC |
| 471 | LIMIT ? |
| 472 | """, |
| 473 | (scope_id, MemoryStatus.ACTIVE.value, limit), |
| 474 | ).fetchall() |
| 475 | units = [self._row_to_unit(row) for row in rows] |
| 476 | # Filter out expired memories. |
| 477 | now_iso = _utc_now_iso() |
| 478 | return [u for u in units if not u.expires_at or u.expires_at > now_iso] |
| 479 | |
| 480 | def expire_stale(self, scope_id: str) -> int: |
| 481 | """Archive memories that have passed their expires_at timestamp. |