Skip to content

Make checkpoint prune --dry-run match the real prune - #9777

Open
Wooohaaa wants to merge 1 commit into
crewAIInc:mainfrom
Wooohaaa:fix/checkpoint-dry-run
Open

Wooohaaa wants to merge 1 commit into
crewAIInc:mainfrom
Wooohaaa:fix/checkpoint-dry-run

Conversation

@Wooohaaa

Copy link
Copy Markdown

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.

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

strix-security Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Strix Security Review

To 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 summary

The change is a small refactor of the checkpoint prune helpers so that --dry-run reuses the real prune logic instead of a separate count-only branch. Review focused on whether the new dry_run flag actually prevents mutation on both the JSON and SQLite paths, whether the reported preview count can diverge from what a real prune deletes, and whether the prune path is reachable from anything other than the local operator.

One issue was confirmed on the SQLite path: _prune_sqlite runs the real DELETE statements and only skips the explicit conn.commit(), but a sqlite3.connect(...) used as a context manager commits the open transaction in __exit__, so --dry-run persists the deletions while printing "Would prune". This is filed as crewai checkpoint prune --dry-run still deletes SQLite checkpoints. The JSON path is correct — it returns the computed count before any os.remove — and no network, server or multi-tenant caller of the prune command exists, so the blast radius stays with the operator's own store.

Ruled out (2)
  • Do the unscoped DELETE statements in `_prune_sqlite` let pruning for one crew or branch destroy checkpoints belonging to other branches?
    The DELETE statements and their lack of a branch filter are pre-existing and untouched by this PR, the only caller is the local `crewai checkpoint prune` command with no server, API or MCP path, and the only party affected is the operator who already has write access to the same store.
  • Can a checkpoint file supplied by a third party make the resume path build an LLM client pointed at an attacker host and leak the operator's API key?
    The resume/info/diff restore flow is entirely pre-existing code that this PR neither edits nor reaches; the diff is confined to the prune helpers, which only glob and remove JSON files and run two parameterized DELETEs, never parsing a checkpoint payload or constructing a provider.

Fixed the findings? re-run the review, or tag @strix-security in a PR comment to run a fresh review.

Review 1 on this PR · efa6853 · requested Nov 25 08:34 UTC when the PR was opened


Reviewed by Strix
Re-run review · Configure security review settings · Try a deeper review with @strix-security /deep

@strix-security strix-security Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strix flagged a new security finding below. See the pinned summary comment for the full PR status.

Comment on lines +712 to +713
if not dry_run:
conn.commit()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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 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.
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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] checkpoint prune --dry-run ignores --keep and --older-than

1 participant