Repository navigation
Conversation
The dry-run branches only counted every checkpoint at the location, ignoring --keep and --older-than, so the preview did not match what the command actually deletes. Reuse the real prune logic with a dry_run flag that skips deletion (and the commit for SQLite), and report the computed count. Fixes crewAIInc#9697
Strix Security ReviewTo fix before merging (1)
PR summary: Makes the `crewai checkpoint prune --dry-run` preview reuse the real prune logic (with a `dry_run` flag that skips deletion and the SQLite commit) and report the computed count instead of the total checkpoint count. Review summaryThe change is a small refactor of the checkpoint prune helpers so that One issue was confirmed on the SQLite path: Ruled out (2)
Fixed the findings? re-run the review, or tag Review 1 on this PR · Reviewed by Strix |
| if not dry_run: | ||
| conn.commit() |
There was a problem hiding this comment.
🔵 LOW: Prune dry run still commits its DELETEs through the connection context manager
TL;DR: crewai checkpoint prune --dry-run really deletes rows from the SQLite checkpoint store, including checkpoints from other branches and flows. It runs the same DELETE statements as a real prune and relies on the missing conn.commit() to keep them uncommitted, but with sqlite3.connect(...) commits the open transaction when the block exits, so the preview persists. Rolling back when dry_run is set keeps the preview read-only.
Cause, impact and fix
Cause: _prune_sqlite executes the _DELETE_OLDER_THAN and _DELETE_KEEP_N statements unconditionally and guards only the explicit conn.commit(). The with sqlite3.connect(db_path) as conn block commits any pending transaction on normal exit, so withholding the commit call does not stop the deletes from being written.
Impact: An operator running --dry-run to preview a cleanup permanently loses the oldest checkpoints in that store, not only the rows they meant to drop, and is told those rows only "would" be pruned. The DELETEs carry no branch or flow predicate, so the loss spans every branch sharing the default ./.checkpoints.db.
Fix: Make the dry-run path explicitly non-destructive: roll back the transaction when dry_run is true and commit only otherwise, or count the matching rows with SELECT COUNT(*) and skip the DELETEs entirely. Add a test that runs a dry run against a populated store and asserts the row count is unchanged.
🔵 `crewai checkpoint prune --dry-run` still deletes SQLite checkpoints: `with sqlite3.connect(...)` commits on exit
🔵 crewai checkpoint prune --dry-run still deletes SQLite checkpoints: with sqlite3.connect(...) commits on exit
Severity: LOW
TL;DR: _prune_sqlite in lib/cli/src/crewai_cli/checkpoint_cli.py only skips conn.commit() for --dry-run, but the with sqlite3.connect(...) block commits the pending DELETEs on exit, so the "preview" deletes them.
Impact: Anyone running crewai checkpoint prune --keep N --dry-run to preview a cleanup silently loses the oldest N checkpoints in that store - including rows belonging to other branches and flows - and is told only how many "would" be removed.
Root cause:
- The PR implements dry-run by withholding the explicit
conn.commit(), assuming that no commit call means no write, but Python's connection context manager commits any open transaction when thewithblock exits normally. with sqlite3.connect(db_path) as conntherefore persists theDELETEstatements executed at lines 705 and 709 even whendry_runis true; reproduced with the same code shape: 10 rows, dry run reported 7 deleted and 3 rows remained.- The statements carry no branch predicate, so the preview-time deletion spans every branch and crew sharing the default
./.checkpoints.db, not just the rows the operator intended to prune.
Prompt to fix with AI
This is a security vulnerability found during a code review.
Vulnerability: `crewai checkpoint prune --dry-run` still deletes SQLite checkpoints: `with sqlite3.connect(...)` commits on exit
Severity: LOW
CWE: CWE-693
**TL;DR:** `_prune_sqlite` in `lib/cli/src/crewai_cli/checkpoint_cli.py` only skips `conn.commit()` for `--dry-run`, but the `with sqlite3.connect(...)` block commits the pending DELETEs on exit, so the "preview" deletes them.
**Impact:** Anyone running `crewai checkpoint prune --keep N --dry-run` to preview a cleanup silently loses the oldest N checkpoints in that store - including rows belonging to other branches and flows - and is told only how many "would" be removed.
**Root cause:**
- The PR implements dry-run by withholding the explicit `conn.commit()`, assuming that no commit call means no write, but Python's connection context manager commits any open transaction when the `with` block exits normally.
- `with sqlite3.connect(db_path) as conn` therefore persists the `DELETE` statements executed at lines 705 and 709 even when `dry_run` is true; reproduced with the same code shape: 10 rows, dry run reported 7 deleted and 3 rows remained.
- The statements carry no branch predicate, so the preview-time deletion spans every branch and crew sharing the default `./.checkpoints.db`, not just the rows the operator intended to prune.
Location: lib/cli/src/crewai_cli/checkpoint_cli.py:712-713
Context: dry-run branch that leaves the transaction open for the context manager to commit
```
// Before:
if not dry_run:
conn.commit()
// After:
if dry_run:
conn.rollback()
else:
conn.commit()
```
Location: lib/cli/src/crewai_cli/checkpoint_cli.py:700-700
Context: connection context manager that commits the pending DELETEs on exit
```
with sqlite3.connect(db_path) as conn:
```
How to fix:
Make the non-destructive path explicitly non-destructive: when `dry_run` is true, roll the transaction back (or count the matching rows with `SELECT COUNT(*)` instead of executing the DELETEs) rather than relying on the absence of an explicit commit. Add a regression test that runs a dry run against a populated SQLite store and asserts the row count is unchanged.
Please fix this vulnerability. If you propose a fix, make it concise and minimal.React 👍 / 👎 to tune Strix for this repo. A repo collaborator (or the PR author) can resolve this thread to dismiss these findings.
Fixes #9697.
The dry-run branches only counted every checkpoint at the location, ignoring --keep and --older-than, so the preview did not match what the command actually deletes.
Reuses the real prune logic with a dry_run flag that skips deletion (and the SQLite commit), and reports the computed count with a 'Would prune' message.