Skip to content

feat: Server auto-aging thread → auto-lifecycle cycle replacement #934

Closed

Description

@ajianaz

Overview

Server saat ini punya background thread yang memanggil aging_cleanup() (hard delete) setiap N hours. Ganti dengan auto_lifecycle_cycle() yang menggunakan dynamic soft-delete.

Current Behavior (crates/uteke-server/src/main.rs:312-365)

// Auto-aging background thread
std::thread::spawn(move || {
    let interval = Duration::from_secs(aging_hours * 60 * 60);
    loop {
        std::thread::sleep(interval);
        match aging_uteke.lock() {
            Ok(u) => {
                match u.aging_cleanup(age_days, max_access, None) {
                    Ok(result) => { /* logs deleted count */ }
                }
            }
        }
    }
});

Target Behavior

// Auto-lifecycle background thread (replaces auto-aging)
let lifecycle_config = config.lifecycle.clone();
let lifecycle_enabled = lifecycle_config.auto_aging_enabled;
let interval_hours = lifecycle_config.auto_aging_interval_hours.max(1);

if lifecycle_enabled {
    info!("Auto-lifecycle: enabled (every {interval_hours}h, cap={:.1}%)",
          lifecycle_config.max_deprecate_percent);
    std::thread::spawn(move || {
        let interval = Duration::from_secs(interval_hours * 60 * 60);
        loop {
            std::thread::sleep(interval);
            if SHUTDOWN.load(Ordering::SeqCst) { break; }
            match lifecycle_uteke.lock() {
                Ok(u) => {
                    u.set_lifecycle_config(lifecycle_config.clone());
                    match u.auto_lifecycle_cycle(false) {
                        Ok(report) => {
                            if report.deprecated > 0 || report.pruned > 0 {
                                info!(
                                    "Auto-lifecycle: deprecated={}, pruned={}, total={}",
                                    report.deprecated, report.pruned, report.total_memories
                                );
                            }
                        }
                        Err(e) => warn!("Auto-lifecycle failed: {e}"),
                    }
                }
                Err(_) => debug!("Auto-lifecycle: lock busy, skipping cycle"),
            }
        }
    });
}

Migration Notes

  • [maintenance] auto_aging_enabled → [lifecycle] auto_aging_enabled
  • [maintenance] auto_aging_interval_hours → [lifecycle] auto_aging_interval_hours
  • [aging] max_age_days → [lifecycle] min_age_days
  • [aging] max_access_count → [lifecycle] max_access_count
  • [maintenance] auto_dream_* → stays in [maintenance] (dream config separate)
  • Backward compat: parse old config sections, fall back to lifecycle config

Files Changed

File Change
crates/uteke-server/src/main.rs Replace auto-aging thread with lifecycle thread
crates/uteke-cli/src/config.rs Add backward-compat merge: old [aging]/[maintenance] → [lifecycle]

Acceptance Criteria

  • Server starts lifecycle thread instead of aging thread
  • Thread respects auto_aging_interval_hours (default 168 = weekly)
  • Thread calls auto_lifecycle_cycle(false) (not dry-run)
  • Logs show deprecated/pruned counts with total memory context
  • SHUTDOWN flag respected (clean exit)
  • Lock-busy handled gracefully (skip, not crash)
  • Old config sections still work (backward compat)
  • Startup log clearly shows lifecycle config summary

Dependencies

Activity

  1. added this to the milestone on Aug 8, 2026
  2. added
    enhancement
    rust
    scope:server
    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:mediumrustsafetyscope:server

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions