Skip to content

feat: aging_cleanup() β€” soft-delete instead of hard-delete when soft_delete_only=trueΒ #930

Closed

Description

@ajianaz

Overview

πŸ”΄ CRITICAL SAFETY: aging_cleanup() saat ini melakukan HARD DELETE (delete_by_ids()). Ubah ke deprecate_with_reason() ketika soft_delete_only=true.

Current Behavior (DANGEROUS)

// maintenance.rs ~line 303
pub fn aging_cleanup(...) -> Result<CleanupResult, Error> {
    let aged = self.store.find_aged(...)?;
    const MAX_DELETE_PER_CYCLE: usize = 100;
    let ids: Vec<String> = aged.into_iter()
        .take(MAX_DELETE_PER_CYCLE)
        .map(|m| m.id)
        .collect();
    let deleted = self.store.delete_by_ids(&ids)?;  // ← HARD DELETE ❌
}

Memory penting yang jarang diakses (passwords, architecture decisions) bisa hilang permanen.

Target Behavior (SAFE)

pub fn aging_cleanup(...) -> Result<CleanupResult, Error> {
    let aged = self.store.find_aged(...)?;

    if self.lifecycle_config.soft_delete_only {
        // SOFT DELETE: deprecate instead of delete
        let max = MAX_DELETE_PER_CYCLE.min(aged.len());
        for mem in aged.iter().take(max) {
            self.deprecate_with_reason(&mem.id, "aging_cleanup")?;
        }
        // Return result with deprecated count
        Ok(CleanupResult { deprecated: max, deleted: 0, .. })
    } else {
        // OLD BEHAVIOR: hard delete (only when explicitly disabled)
        let deleted = self.store.delete_by_ids(&ids)?;
        Ok(CleanupResult { deprecated: 0, deleted, .. })
    }
}

Changes

File Change
crates/uteke-core/src/maintenance.rs Modify aging_cleanup() β€” conditional soft/hard delete
crates/uteke-core/src/maintenance.rs Update CleanupResult struct β€” add deprecated field

Acceptance Criteria

  • When soft_delete_only=true: aging_cleanup calls deprecate_with_reason() instead of delete_by_ids()
  • When soft_delete_only=false: preserves old behavior (backward compat)
  • CleanupResult includes both deprecated and deleted counts
  • Pinned memories still protected (existing filter)
  • Max 100 per cycle cap preserved
  • Dry-run mode still works (aging_preview)
  • Integration test: verify deprecated memory can be promoted back

Dependencies

Activity

  1. added this to the milestone on Aug 8, 2026
  2. added
    enhancement
    scope:core
    rust
    priority:critical
    epic:memory-lifecycle
    lifecycle
    safety
    on Aug 8, 2026
  3. modified the milestones: , v0.13.0 on Aug 8, 2026
  4. ajianaz commented on Aug 8, 2026

    @ajianaz
    CollaboratorAuthor

    Implemented in PR #938 (merged). Closing as completed.

  5. added a commit that references this issue on Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementepic:memory-lifecyclelifecyclepriority:criticalrustsafetyscope:core

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions