Skip to content

feat(sessions): automatic retention policy and cleanup for session metadata on disk #971

Description

@euxaristia

Summary

Zero currently persists session metadata and event logs to disk (~/.local/share/zero/sessions/ on Unix, %LOCALAPPDATA%\zero\sessions\ on Windows), but never prunes or deletes old session directories. Over extended usage, session logs and checkpoint blobs accumulate indefinitely without an automatic retention policy or CLI cleanup mechanism.

Motivation

While in-memory prompt compaction (internal/agent/compaction.go) and tool body pruning (internal/agent/prune.go) manage context token pressure, on-disk storage grows monotonically:

  • Every session generates a separate directory containing metadata.json, events.jsonl, and optional checkpoint blobs.
  • internal/sessions/store.go provides listing and appending, but no cleanup lifecycle or deletion API.
  • Users currently have to manually inspect and delete old session directories.

Proposed Solution

  1. Configurable retention policy: Introduce configuration settings in config.json (e.g. sessions.retention_days or sessions.max_count) to automatically prune stale, non-bookmarked session directories.
  2. CLI cleanup command: Add zero sessions clean (or zero sessions prune --older-than <duration>) to allow users to trigger metadata sweeps manually.
  3. Blob & checkpoint garbage collection: Prune unreferenced rewind blobs when sessions are removed.
  4. Safety guards: Ensure active sessions (holding session.lock) and explicitly saved/named sessions are protected from automated pruning.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions