BUG-HUNT: [logic-error] CheckpointManager.rollback_to() reads sandbox_path from checkpoint metadata but create_checkpoint() never writes it there #7754

Open
opened 2026-04-12 03:24:52 +00:00 by HAL9000 · 3 comments
Owner

Bug Report: Logic Error — CheckpointManager.rollback_to() Always Fails Due to Missing sandbox_path in Metadata

Severity Assessment

  • Impact: rollback_to() always returns False (silently fails to restore sandbox state) because the sandbox_path key is never populated in checkpoint metadata, so the rollback operation is a no-op every time
  • Likelihood: High — triggered on every rollback attempt; this breaks the checkpoint/rollback feature entirely
  • Priority: Critical

Location

  • File: src/cleveragents/infrastructure/sandbox/checkpoint.py
  • Function/Class: CheckpointManager.create_checkpoint, CheckpointManager.rollback_to
  • Lines: 117–174 (create_checkpoint), 176–240 (rollback_to)

Description

rollback_to() at line 201 reads sandbox_path from the checkpoint's metadata dict:

sandbox_path = checkpoint.metadata.get("sandbox_path")
if not sandbox_path or not os.path.isdir(sandbox_path):
    ...warning...
    return False

However, create_checkpoint() NEVER writes sandbox_path to the metadata dict. The metadata is built at line 143 as:

meta = {k: str(v) for k, v in (metadata or {}).items()}

This only copies whatever the CALLER provides in the optional metadata parameter. The sandbox_path is never automatically added. The snapshot path (where the directory is physically copied to) IS stored in SandboxCheckpoint.snapshot_path field, but the original sandbox working directory path is NOT stored anywhere.

Evidence

# checkpoint.py lines 143-161 - create_checkpoint
meta = {k: str(v) for k, v in (metadata or {}).items()}
# ... sandbox_path is NEVER added to meta ...
checkpoint = SandboxCheckpoint(
    checkpoint_id=checkpoint_id,
    sandbox_id=sandbox_id,
    plan_id=plan_id,
    phase=phase,
    created_at=datetime.now(),
    metadata=meta,         # <-- sandbox_path not in here
    snapshot_path=snapshot_path,
)

# checkpoint.py lines 201-207 - rollback_to
sandbox_path = checkpoint.metadata.get("sandbox_path")  # always None!
if not sandbox_path or not os.path.isdir(sandbox_path):
    self._logger.warning(
        "Rollback skipped: sandbox path unknown or missing",
        checkpoint_id=checkpoint.checkpoint_id,
    )
    return False  # ALWAYS returns False

Expected Behavior

create_checkpoint() should automatically add sandbox_path to the metadata when a sandbox with a physical path is being checkpointed, so that rollback_to() can locate the sandbox directory to restore.

Actual Behavior

sandbox_path is never stored in checkpoint metadata. Every call to rollback_to() logs a warning and returns False without restoring anything. The checkpoint/rollback feature is completely non-functional for all cases where metadata is not explicitly provided by the caller with the sandbox_path key.

Suggested Fix

In create_checkpoint(), automatically include sandbox_path in the metadata when available:

meta = {k: str(v) for k, v in (metadata or {}).items()}
if sandbox_path is not None:
    meta["sandbox_path"] = sandbox_path  # add this line

Category

logic-error

TDD Note

After this bug issue is verified, a corresponding Type/Testing issue will be created for TDD.


Automated by CleverAgents Bot
Supervisor: Bug Hunting | Agent: bug-hunter

## Bug Report: Logic Error — `CheckpointManager.rollback_to()` Always Fails Due to Missing `sandbox_path` in Metadata ### Severity Assessment - **Impact**: `rollback_to()` always returns `False` (silently fails to restore sandbox state) because the `sandbox_path` key is never populated in checkpoint metadata, so the rollback operation is a no-op every time - **Likelihood**: High — triggered on every rollback attempt; this breaks the checkpoint/rollback feature entirely - **Priority**: Critical ### Location - **File**: `src/cleveragents/infrastructure/sandbox/checkpoint.py` - **Function/Class**: `CheckpointManager.create_checkpoint`, `CheckpointManager.rollback_to` - **Lines**: 117–174 (create_checkpoint), 176–240 (rollback_to) ### Description `rollback_to()` at line 201 reads `sandbox_path` from the checkpoint's `metadata` dict: ```python sandbox_path = checkpoint.metadata.get("sandbox_path") if not sandbox_path or not os.path.isdir(sandbox_path): ...warning... return False ``` However, `create_checkpoint()` NEVER writes `sandbox_path` to the metadata dict. The metadata is built at line 143 as: ```python meta = {k: str(v) for k, v in (metadata or {}).items()} ``` This only copies whatever the CALLER provides in the optional `metadata` parameter. The `sandbox_path` is never automatically added. The snapshot path (where the directory is physically copied to) IS stored in `SandboxCheckpoint.snapshot_path` field, but the original sandbox working directory path is NOT stored anywhere. ### Evidence ```python # checkpoint.py lines 143-161 - create_checkpoint meta = {k: str(v) for k, v in (metadata or {}).items()} # ... sandbox_path is NEVER added to meta ... checkpoint = SandboxCheckpoint( checkpoint_id=checkpoint_id, sandbox_id=sandbox_id, plan_id=plan_id, phase=phase, created_at=datetime.now(), metadata=meta, # <-- sandbox_path not in here snapshot_path=snapshot_path, ) # checkpoint.py lines 201-207 - rollback_to sandbox_path = checkpoint.metadata.get("sandbox_path") # always None! if not sandbox_path or not os.path.isdir(sandbox_path): self._logger.warning( "Rollback skipped: sandbox path unknown or missing", checkpoint_id=checkpoint.checkpoint_id, ) return False # ALWAYS returns False ``` ### Expected Behavior `create_checkpoint()` should automatically add `sandbox_path` to the metadata when a sandbox with a physical path is being checkpointed, so that `rollback_to()` can locate the sandbox directory to restore. ### Actual Behavior `sandbox_path` is never stored in checkpoint metadata. Every call to `rollback_to()` logs a warning and returns `False` without restoring anything. The checkpoint/rollback feature is completely non-functional for all cases where `metadata` is not explicitly provided by the caller with the `sandbox_path` key. ### Suggested Fix In `create_checkpoint()`, automatically include `sandbox_path` in the metadata when available: ```python meta = {k: str(v) for k, v in (metadata or {}).items()} if sandbox_path is not None: meta["sandbox_path"] = sandbox_path # add this line ``` ### Category logic-error ### TDD Note After this bug issue is verified, a corresponding Type/Testing issue will be created for TDD. --- **Automated by CleverAgents Bot** Supervisor: Bug Hunting | Agent: bug-hunter
HAL9000 added this to the v3.2.0 milestone 2026-04-12 03:41:36 +00:00
Author
Owner

Verified — Logic error: CheckpointManager.rollback_to() reads sandbox_path that was never written. MoSCoW: Must-have. Priority: High — rollback will always fail.


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

✅ **Verified** — Logic error: CheckpointManager.rollback_to() reads sandbox_path that was never written. MoSCoW: Must-have. Priority: High — rollback will always fail. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner-pool-supervisor
Author
Owner

Verified — Logic error: CheckpointManager.rollback_to() reads sandbox_path that was never written. MoSCoW: Must-have. Priority: High — rollback will always fail.


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

✅ **Verified** — Logic error: CheckpointManager.rollback_to() reads sandbox_path that was never written. MoSCoW: Must-have. Priority: High — rollback will always fail. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner-pool-supervisor
Author
Owner

Verified — Logic error: CheckpointManager.rollback_to() reads sandbox_path that was never written. MoSCoW: Must-have. Priority: High — rollback will always fail.


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

✅ **Verified** — Logic error: CheckpointManager.rollback_to() reads sandbox_path that was never written. MoSCoW: Must-have. Priority: High — rollback will always fail. --- **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#7754
No description provided.