agentstatedeveloper_core/gc.rs
1//! ASD's garbage-collection retention policy, shared by `asd gc` and
2//! `asd-serve`'s sweep preview so the two can never disagree about what a sweep
3//! keeps.
4//!
5//! ASD's answer differs from AgentStateGraph's `RetentionPolicy::default()` in
6//! one place, `checkpoint_every`. That default keeps every hundredth commit's
7//! state as a sparse checkpoint, which suits a store whose history is its
8//! product. ASD's is not: nearly all of it is derived index state, rebuilt from
9//! source at the git revision a milestone records. At one pin per hundred
10//! commits a busy store (a million commits is not unusual — every `asd index`
11//! commits) would keep thousands of full snapshots, and a sweep would reclaim
12//! almost nothing.
13
14use agentstategraph::RetentionPolicy;
15
16/// Commits whose state a sweep keeps in full, newest first.
17pub const GC_KEEP_RECENT: usize = 100;
18
19/// Sparse checkpoints among older commits: none. See the module docs.
20pub const GC_CHECKPOINT_EVERY: usize = 0;
21
22/// The retention policy an ASD sweep runs under.
23///
24/// Milestones are always kept, but since AgentStateGraph v1.2.2 a milestone
25/// pins state only when its checkpoint asked to. Pins distilled before then are
26/// cleared explicitly, with `asd gc --unpin-legacy`, never by a policy switch —
27/// a switch would also drop the pins someone deliberately asked for.
28pub fn gc_policy(keep_recent: usize, checkpoint_every: usize) -> RetentionPolicy {
29 RetentionPolicy {
30 keep_recent,
31 checkpoint_every,
32 keep_milestones: true,
33 }
34}