Skip to content

Commit 2cec58e

Browse files
committed
fix: require threshold or purge_all for mimir_prune (#202)
- Add purge_all bool to PruneParams (models.rs) - Validate in handle_prune: error if no min_decay/older_than_days/purge_all - Prevents footgun where prune(category=X) silently archives nothing
1 parent 80de650 commit 2cec58e

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

src/models.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,9 @@ pub struct PruneParams {
466466
pub limit: usize,
467467
#[serde(default)]
468468
pub dry_run: bool,
469+
/// Explicitly archive everything in the category (no threshold required).
470+
#[serde(default)]
471+
pub purge_all: bool,
469472
}
470473

471474
fn default_prune_limit() -> usize {

src/tools.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,15 @@ pub fn handle_embed(db: &Database, args: Value) -> Result<String, String> {
936936
pub fn handle_prune(db: &Database, args: Value) -> Result<String, String> {
937937
let params: PruneParams =
938938
serde_json::from_value(args).map_err(|e| format!("Invalid prune arguments: {}", e))?;
939+
940+
// #202: require a threshold or explicit purge_all — category alone is a footgun
941+
if !params.purge_all && params.min_decay.is_none() && params.older_than_days.is_none() {
942+
return Err(
943+
"prune requires min_decay, older_than_days, or purge_all=true to archive the whole category"
944+
.to_string(),
945+
);
946+
}
947+
939948
match db.prune(&params) {
940949
Ok(report) => {
941950
serde_json::to_string(&report).map_err(|e| format!("Serialization failed: {}", e))

0 commit comments

Comments
 (0)