You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(sessions): automatic retention policy and cleanup for session metadata on disk #971
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
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.
CLI cleanup command: Add zero sessions clean (or zero sessions prune --older-than <duration>) to allow users to trigger metadata sweeps manually.
Blob & checkpoint garbage collection: Prune unreferenced rewind blobs when sessions are removed.
Safety guards: Ensure active sessions (holding session.lock) and explicitly saved/named sessions are protected from automated pruning.
Approved as opt-in only. Session logs are the user's data and nothing should delete them by default.
Shape that would be accepted: an explicit zero sessions prune with a dry run that lists what would go and why, a config retention setting that is off unless the user sets it, and a hard rule that the session currently being resumed or forked is never a candidate. A background sweep that runs without being asked is not.
Back in the pool, and still valid on current main.
This came up in an audit of open issues whose only linked pull request had closed, which made them look covered to a query while nobody was actually working them. The earlier attempt closed without landing, so this is open for a fresh one.
I verified the problem still exists rather than assuming it, and the audit verdict was independently re-checked before I posted this. The label is already on, so a PR implementing it can merge on review.
Notes for whoever picks this up, from reading main at 99721c7. Two of them are traps the approved shape doesn't mention.
There is no lifetime lock.session.lock is taken by lockSession around each write and released straight after, so nothing holds it while a session is merely open in a TUI. Skipping sessions whose lock is busy only protects a write in flight, and zero sessions prune in one terminal can't see that another terminal has the session open. The protection has to be something real: a floor on the cutoff, so nothing touched in the last day is ever a candidate, or a lease that the TUI and exec hold for the session's lifetime. The floor is enough for a first version if it's stated in the help text.
Deleting a parent breaks its descendants' lineage.Store.Lineage walks ParentSessionID and returns "zero session not found" as soon as an ancestor is missing, so pruning a parent turns every fork or child below it into an error wherever lineage is shown. Either a session that is still the parent of a kept session is not a candidate, or Lineage and Tree stop at a missing ancestor instead of failing. The history itself is safe: Store.Fork copies the parent's events into the fork.
Checkpoint blobs live inside the session directory (<session>/checkpoints/blobs), so removing the directory removes them. There is no shared blob store to collect.
The rest of the approved shape stands: an explicit command, a dry run first, a retention setting that is off unless the user sets it, and nothing that runs on its own.
Activity
Vasanthdev2004 commentedon Sep 8, 2026
Approved as opt-in only. Session logs are the user's data and nothing should delete them by default.
Shape that would be accepted: an explicit
zero sessions prunewith a dry run that lists what would go and why, a config retention setting that is off unless the user sets it, and a hard rule that the session currently being resumed or forked is never a candidate. A background sweep that runs without being asked is not.Vasanthdev2004 commentedon Sep 12, 2026
Back in the pool, and still valid on current main.
This came up in an audit of open issues whose only linked pull request had closed, which made them look covered to a query while nobody was actually working them. The earlier attempt closed without landing, so this is open for a fresh one.
I verified the problem still exists rather than assuming it, and the audit verdict was independently re-checked before I posted this. The label is already on, so a PR implementing it can merge on review.
Vasanthdev2004 commentedon Sep 26, 2026
Notes for whoever picks this up, from reading
mainat 99721c7. Two of them are traps the approved shape doesn't mention.session.lockis taken bylockSessionaround each write and released straight after, so nothing holds it while a session is merely open in a TUI. Skipping sessions whose lock is busy only protects a write in flight, andzero sessions prunein one terminal can't see that another terminal has the session open. The protection has to be something real: a floor on the cutoff, so nothing touched in the last day is ever a candidate, or a lease that the TUI andexechold for the session's lifetime. The floor is enough for a first version if it's stated in the help text.Store.LineagewalksParentSessionIDand returns "zero session not found" as soon as an ancestor is missing, so pruning a parent turns every fork or child below it into an error wherever lineage is shown. Either a session that is still the parent of a kept session is not a candidate, orLineageandTreestop at a missing ancestor instead of failing. The history itself is safe:Store.Forkcopies the parent's events into the fork.<session>/checkpoints/blobs), so removing the directory removes them. There is no shared blob store to collect.The rest of the approved shape stands: an explicit command, a dry run first, a retention setting that is off unless the user sets it, and nothing that runs on its own.
feat(sessions): add zero sessions prune, which never removes a sessio…