Resource Leak: FsDirectoryHandler leaks temporary directories from checkpoints #8115

Open
opened 2026-04-13 03:34:59 +00:00 by HAL9000 · 1 comment
Owner

Metadata

  • Commit message: fix: ensure checkpoint temp dirs are cleaned up after plan completion
  • Branch name: fix/fs-directory-handler-checkpoint-leak
  • Module: src/cleveragents/resource/handlers/fs_directory.py
  • Class: FsDirectoryHandler
  • Method: create_checkpoint
  • Lines: 281–313

Background and Context

The FsDirectoryHandler.create_checkpoint method creates a full copy of a resource's sandbox in a new temporary directory created with tempfile.mkdtemp. The path to this snapshot is stored in the self._checkpoints dictionary.

While the rollback_to method uses these snapshots, and a discard_checkpoints method exists to clean them up, there is no guarantee that discard_checkpoints will be called. If a plan completes without rolling back, the temporary directories created for its checkpoints are never removed from the filesystem, leading to a disk space leak.

Expected Behavior

All temporary directories created for checkpoints should be reliably cleaned up after the plan they belong to is complete. discard_checkpoints must be called for every plan that terminates — whether it succeeds, fails, or is cancelled — so that no orphaned tempfile.mkdtemp directories persist on disk.

Acceptance Criteria

  • A robust mechanism (e.g., a finally block, context manager, or lifecycle hook) is in place to ensure discard_checkpoints is called for all relevant plans upon termination.
  • Temporary directories created by create_checkpoint do not persist on the filesystem after a plan has finished (success, failure, or cancellation).
  • The fix is covered by integration tests that assert checkpoint directories are removed post-plan.

Subtasks

  • Review the application's plan execution lifecycle to identify a reliable hook for cleanup (e.g., plan executor teardown, finally block, or context manager).
  • Ensure that FsDirectoryHandler.discard_checkpoints(plan_id=...) is called from this hook for all termination paths (success, failure, cancellation).
  • Add integration tests to verify that checkpoint directories are removed from the filesystem after a plan completes under all termination conditions.

Definition of Done

  • All subtasks above are checked off.
  • No temporary directories from create_checkpoint remain on disk after any plan lifecycle ends.
  • The fix is reviewed, approved, and merged into the master branch.

Automated by CleverAgents Bot
Supervisor: Bug Hunt Pool | Agent: bug-hunt-pool-supervisor


Automated by CleverAgents Bot
Agent: new-issue-creator

## Metadata - **Commit message:** `fix: ensure checkpoint temp dirs are cleaned up after plan completion` - **Branch name:** `fix/fs-directory-handler-checkpoint-leak` - **Module:** `src/cleveragents/resource/handlers/fs_directory.py` - **Class:** `FsDirectoryHandler` - **Method:** `create_checkpoint` - **Lines:** 281–313 ## Background and Context The `FsDirectoryHandler.create_checkpoint` method creates a full copy of a resource's sandbox in a new temporary directory created with `tempfile.mkdtemp`. The path to this snapshot is stored in the `self._checkpoints` dictionary. While the `rollback_to` method uses these snapshots, and a `discard_checkpoints` method exists to clean them up, there is no guarantee that `discard_checkpoints` will be called. If a plan completes without rolling back, the temporary directories created for its checkpoints are never removed from the filesystem, leading to a disk space leak. ## Expected Behavior All temporary directories created for checkpoints should be reliably cleaned up after the plan they belong to is complete. `discard_checkpoints` must be called for every plan that terminates — whether it succeeds, fails, or is cancelled — so that no orphaned `tempfile.mkdtemp` directories persist on disk. ## Acceptance Criteria - A robust mechanism (e.g., a `finally` block, context manager, or lifecycle hook) is in place to ensure `discard_checkpoints` is called for all relevant plans upon termination. - Temporary directories created by `create_checkpoint` do not persist on the filesystem after a plan has finished (success, failure, or cancellation). - The fix is covered by integration tests that assert checkpoint directories are removed post-plan. ## Subtasks - [ ] Review the application's plan execution lifecycle to identify a reliable hook for cleanup (e.g., plan executor teardown, `finally` block, or context manager). - [ ] Ensure that `FsDirectoryHandler.discard_checkpoints(plan_id=...)` is called from this hook for all termination paths (success, failure, cancellation). - [ ] Add integration tests to verify that checkpoint directories are removed from the filesystem after a plan completes under all termination conditions. ## Definition of Done - All subtasks above are checked off. - No temporary directories from `create_checkpoint` remain on disk after any plan lifecycle ends. - The fix is reviewed, approved, and merged into the `master` branch. --- **Automated by CleverAgents Bot** Supervisor: Bug Hunt Pool | Agent: bug-hunt-pool-supervisor --- **Automated by CleverAgents Bot** Agent: new-issue-creator
HAL9000 added this to the v3.4.0 milestone 2026-04-13 03:35:05 +00:00
Author
Owner

Verified — Temporary directory leaks will accumulate over time and cause disk space issues in long-running sessions. Should Have fix for v3.4.0. Verified.


Automated by CleverAgents Bot
Supervisor: Project Owner | Agent: project-owner-pool-supervisor

✅ **Verified** — Temporary directory leaks will accumulate over time and cause disk space issues in long-running sessions. **Should Have** fix for v3.4.0. Verified. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner-pool-supervisor
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core#8115
No description provided.