Skip to content

feat: Safe Memory Lifecycle (v0.13.0) — soft delete, dynamic cap, CLI/API - #938

Merged
ajianaz merged 7 commits into
developfrom
feat/lifecycle-config
Aug 8, 2026
Merged

ajianaz merged 7 commits into
developfrom
feat/lifecycle-config

Conversation

@ajianaz

@ajianaz ajianaz commented Aug 8, 2026 •

Copy link
Copy Markdown
Collaborator

Safe Memory Lifecycle

A complete lifecycle system that prevents accidental data loss through automated processes. Every memory goes through a reviewable soft-delete state before eventual pruning.

Why

Agents accumulate stale memories over time: outdated facts, superseded decisions, duplicated knowledge. Without a lifecycle system, users have two bad options: manually prune (tedious, error-prone) or let the store grow unbounded (slower recall, higher memory).

This PR introduces a configurable lifecycle pipeline that automatically deprecates aged memories while keeping them restorable. Hard delete only happens through explicit, intentional paths (prune expired-after-TTL or forget with soft_delete_only=false).

Lifecycle Flow

remember() → ACTIVE → soft_deprecate() → DEPRECATED (hidden, restorable) → prune() → HARD DELETE

What Changed

Area Change
Core New LifecycleConfig struct with 11 conservative fields
Store deprecate_with_reason(), undeprecate(), deprecate_by_ids()
Safety ALL delete paths respect soft_delete_only = true (default)
Auto-cycle 2-phase lifecycle: deprecate aged (capped at 1%) → prune expired
Server Auto-aging thread → auto-lifecycle thread
CLI uteke lifecycle cycle | promote | status with --json support
API GET /lifecycle/status, POST /lifecycle/cycle, POST /lifecycle/promote
Docs New Memory Lifecycle page + updated config/CLI/API references

Hard Delete: Only 2 Paths

  1. prune() — Expired deprecated memories (past TTL, by design)
  2. forget() — Only when soft_delete_only = false (NOT default)

Everything else ( delete(), bulk_delete(), aging_cleanup(), consolidate()) redirects to soft-delete.

Testing

  • Unit tests: 466 passed, 26 ignored, 0 failed (10 test suites)
  • New tests: forget_tests updated for soft-delete expectations (3 tests verify deprecated=true after forget, not is_none)
  • CodeCora fixes: deprecate_with_reason() now returns Err for non-existent IDs, promote() response reflects actual bool, lifecycle_cycle respects soft_delete_only, CLI lifecycle commands support --json
  • API registry test: lifecycle routes (/lifecycle/cycle, /lifecycle/promote, /lifecycle/status) registered in ENDPOINTS
  • Clippy: zero warnings across workspace
  • Formatting: cargo fmt --all clean

Checklist

…I/API

Implements a complete safe memory lifecycle system that prevents
accidental data loss through automated processes.

Lifecycle flow:
  ACTIVE → soft_deprecate() → DEPRECATED (hidden, restorable) → prune() → HARD DELETE

Core changes:
- LifecycleConfig struct with 11 conservative fields (#928)
- Store: deprecate_with_reason, undeprecate, deprecate_by_ids (#929)
- aging_cleanup: conditional soft-delete when soft_delete_only (#930)
- consolidate/dream dedup: soft-delete duplicates (#931)
- forget/bulk_forget: redirect to soft-delete (#932)
- lifecycle_cycle(): 2-phase (deprecate + prune) with percentage cap (#933)
- Server: auto-aging thread → auto-lifecycle thread (#934)
- CLI: lifecycle cycle/promote/status/restore commands (#935)
- API: GET /lifecycle/status, POST /lifecycle/cycle, POST /lifecycle/promote (#936)
- Docs: configuration.md, cli-reference.md, api-reference.md, memory-lifecycle.md (#937)

Hard delete only in 2 controlled paths: prune() (expired TTL) and
forget() (only when soft_delete_only=false).

Migration: deprecate_reason column via column_exists() pattern.
No schema version bump, no manual migration required.
@github-actions

github-actions Bot commented Aug 8, 2026 •

Copy link
Copy Markdown

🔍 Cora AI Code Review

❌ Blocked — critical issues found.

🔴 Error (5)

  • crates/uteke-core/src/maintenance.rs:347 — The aging_cleanup method manually computes the percentage cap with rounding ((total as f64 * lc.max_deprecate_percent / 100.0).round() as usize), while lifecycle_cycle uses truncation (as usize without .round()), and neither uses the LifecycleConfig::cycle_deprecate_cap() method defined in lib.rs. This means three different code paths compute the cap differently, leading to inconsistent behavior. The cycle_deprecate_cap method in lib.rs is dead code.
  • crates/uteke-core/src/maintenance.rs:487 — In the prune phase of lifecycle_cycle, expired_ids is returned as pruned_ids regardless of whether delete_by_ids actually deleted all of them. If some IDs were already deleted between the find_deprecated_for_prune query and the delete_by_ids call (TOCTOU), the returned pruned_ids will contain IDs that weren't actually pruned, and pruned_count may be less than pruned_ids.len().
  • crates/uteke-core/src/operations.rs:1010 — In soft_forget, the recall cache is invalidated AFTER releasing the index write lock. Between the index lock release and cache invalidation, a concurrent recall could serve stale cached results that include the just-deprecated memory. The cache invalidation should happen before or under the same lock scope as the deprecation.
  • crates/uteke-core/src/memory/bulk.rs:191 — The deprecate_by_ids method manually constructs placeholders (?3, ?4, ...) for the IN clause. SQLite has a default limit of 999 parameters (SQLITE_MAX_VARIABLE_NUMBER). If ids contains more than ~997 entries, this query will fail at runtime. There's no batching or guard against this.
  • crates/uteke-core/src/consolidate.rs:282 — When dream_dedup_soft_delete is true, the consolidate path calls deprecate_with_reason but then proceeds to acquire the index write lock and remove from the vector index. However, the code after the if/else block unconditionally tries to remove from the index. Looking at the code flow, after the soft-delete branch, the code continues to self.index.write() and index.remove(to_remove). This is actually correct, but the reason string is constructed even in the hard-delete path where it's unused (minor waste). More importantly, the hard-delete path doesn't invalidate the recall cache.

Review powered by cora-code · BYOK · MIT

ajianaz added 4 commits August 8, 2026 12:10
Humanizer/copy-editing fixes across 4 lifecycle docs:
- Replace 16 em dashes with colons/periods (humanizer §14)
- Remove promotional bold on 'safe' (memory-lifecycle.md, configuration.md)
- Fix version string 0.12.0 → 0.13.0 (cli-reference.md, README.md)
- Fix ConsolidateRequest schema ordering bug (api-reference.md)
- Update test count 431 → 460+ (README.md)

README local-first + Docker positioning:
- Reframe tagline: 'Local-first by default. Docker ready.'
- Reframe Quick Start: remove misleading 'No Docker' claim
- Add Docker callout blockquote in Quick Start section
- Add new 'Deployment Modes' section (local-first vs Docker/server)
- Add 'Docker Ready' row to Performance & Privacy table
- Reframe 'Single Binary' description (drop 'No Docker needed')
Comparison table & FAQ: brand names → generic labels (Tool A-G)
to avoid legal exposure from typos or outdated claims. Added
disclaimer noting capabilities assessed from public docs as of Aug 2026.

Humanizer fixes across README + coordination docs:
- README.md: 14 em dashes → colons/periods (banner alt, headings,
  prose, FAQ, license, star CTA)
- docs/rooms.md: 8 em dashes fixed (title, intro, bullets, links)
- docs/multi-agent.md: 11 em dashes fixed (namespaces, bullets,
  best practices, global docs)
- docs/configuration.md: 1 em dash fixed (update check section)

Memory lifecycle docs confirmed clean (fixed in prior commit).
docs/comparison.md was already clean (generic archetypes).
blog/comparison-2026.md:
- 14 em dashes fixed (prose, categories, bullet lists, table cells)
- Added date stamp: Published August 2026
- Added disclaimer: verify current specs before making decisions

This blog post was already archetype-based (no brand names).
Em dashes were the remaining humanizer issue.
1. Test: forget_tests expectations updated for soft-delete behavior
   - Tests now assert deprecated=true (not is_none) after forget()
   - deprecate_with_reason() returns Err for non-existent IDs

2. CodeCora: 3 alerts fixed
   - lifecycle_cycle respects soft_delete_only config (skips hard prune)
   - promote() response reflects actual restored bool (not hardcoded true)
   - CLI lifecycle commands accept --json flag via cli param

3. API Docs: regenerated docs/api-reference.md via docgen

4. API Registry: added lifecycle routes to ENDPOINTS
   (/lifecycle/cycle, /lifecycle/promote, /lifecycle/status)

All 466 tests pass, 0 clippy warnings.
CodeCora correctly identified that blocking prune with soft_delete_only
contradicts the documented design. soft_delete_only only restricts forget()
from hard-deleting ACTIVE memories. The prune phase operates on memories
that are already DEPRECATED and past their TTL, which is the intended
hard-delete path regardless of soft_delete_only.
format!("dream dedup: superseded by {to_keep} (similarity ≥ threshold)");
self.store
.deprecate_with_reason(to_remove, &reason)
.map_err(|e| Error::db("consolidate soft-delete", e))?;
return Ok(CleanupResult { deleted: 0 });
}

if lc.soft_delete_only {
0
};

// Remove deprecated from vector index.
"Memory with id='{id}' not found in store. Nothing was deprecated."
)));
}
// Already deprecated: idempotent success
self.store.deprecate_with_reason(id, reason)?;
// Remove from vector index so it doesn't appear in recall.
let mut index = self
.index
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants