Checkpoint

From masharratt/claude-flow-novice · View interactive version

Checkpoint is an AI agent skill from the GitHub repository masharratt/claude-flow-novice. Wave checkpoint mechanism provides crash recovery, orphan container detection, and automated resumption capabilities for CFN Docker orchestration. Enables orchestrators to survive process failures and

How to use this skill

Skill file

CFN Wave Checkpoint Skill

Overview

Wave checkpoint mechanism provides crash recovery, orphan container detection, and automated resumption capabilities for CFN Docker orchestration. Enables orchestrators to survive process failures and resume wave execution without losing work or leaving orphaned containers.

Architecture

Checkpoint Flow

execute_waves()
    ├── spawn_wave(task_id, wave_num)
    │   └── save_checkpoint(task_id, wave_num, container_ids, ...)
    ├── monitor_wave(task_id, wave_num)
    │   └── CRASH: Container/process dies
    └── RESUME: detect_checkpoint() → resume_wave() → cleanup_orphans()

Storage

Checkpoint Data Structure

{
  "task_id": "task-123",
  "wave_number": 1,
  "container_ids": ["id1", "id2", "id3"],
  "spawn_time": 1700000000,
  "expected_count": 3,
  "created_at": "2024-11-14T12:00:00Z",
  "status": "in_progress"
}

Components

1. save-checkpoint.sh

Saves execution state before or during wave spawning. Non-blocking: if Redis unavailable, continues execution.

Operations:

Usage:

# Save checkpoint before monitoring
./save-checkpoint.sh save task-123 1 "id1,id2,id3" 1700000000 3

# Check if checkpoint exists
./save-checkpoint.sh exists task-123 1

# Get checkpoint data
./save-checkpoint.sh get task-123 1

# Update status to completed
./save-checkpoint.sh update-status task-123 1 "completed"

Exit Codes:

2. resume-wave.sh

Detects checkpoints and resumes orphaned containers. Verifies containers still running, updates status.

Operations:

Usage:

# Resume all waves with checkpoints
./resume-wave.sh resume task-123

# Resume specific wave
./resume-wave.sh resume task-123 1

# Get list of resumable waves
./resume-wave.sh get-resumable task-123

# Verify container status for wave
./resume-wave.sh verify task-123 1

Exit Codes:

3. cleanup-orphans.sh

Removes orphaned containers while preserving logs for post-mortem analysis.

Operations:

Configuration:

Usage:

# Clean all orphaned containers for task
./cleanup-orphans.sh cleanup task-123

# Clean specific wave orphans
./cleanup-orphans.sh cleanup task-123 1

# List orphaned containers (no cleanup)
./cleanup-orphans.sh list task-123

# View cleanup summary
./cleanup-orphans.sh summary task-123

# Dry-run: preview cleanup
DRY_RUN=true ./cleanup-orphans.sh cleanup task-123

Exit Codes:

Integration with orchestrate.sh

Checkpoint Detection

Add to execute_waves() before spawning:

execute_waves() {
    local task_id="$1"
    local plan_file="$2"

    # Check for existing checkpoint
    if source "$HOME/.claude/skills/cfn-sprint-execution/lib/checkpoint/save-checkpoint.sh" && \
       checkpoint_exists "$task_id"; then
        log "Found checkpoint, resuming..."

        # Resume execution
        source "$HOME/.claude/skills/cfn-sprint-execution/lib/checkpoint/resume-wave.sh"
        resume_wave "$task_id"

        # Continue monitoring from checkpoint
    else
        # Normal execution path
        # ... spawn and monitor waves ...
    fi
}

Checkpoint Saving

Add after successful wave spawn:

# In spawn_wave completion
if $($HOME/.claude/skills/cfn-sprint-execution/lib/checkpoint/save-checkpoint.sh \
    save "$task_id" "$wave_num" "$container_ids" "$(date +%s)" "$batch_count"); then
    log_success "Checkpoint saved for recovery"
fi

Orphan Cleanup

Add to wave cleanup phase:

# After wave completion
$($HOME/.claude/skills/cfn-sprint-execution/lib/checkpoint/cleanup-orphans.sh \
    cleanup "$task_id" "$wave_num")

Recovery Scenarios

Scenario 1: Orchestrator Crash During Wave Spawn

  1. Orchestrator dies while spawning containers
  2. Some containers started, recorded in checkpoint
  3. On restart:

Scenario 2: Network Failure During Monitoring

  1. Network disconnects during wave monitoring
  2. Checkpoint persisted in Redis
  3. On recovery:

Scenario 3: Unplanned Process Termination

  1. Orchestrator killed (OOM, signal 9, etc.)
  2. Checkpoint in Redis, containers in Docker
  3. Recovery process:

Best Practices

Checkpoint Lifecycle

  1. Create: Save checkpoint immediately after successful spawn
  2. Update: Mark as "in_progress", then "monitoring"
  3. Complete: Mark as "completed" when wave finishes
  4. Clean: Archive logs, remove checkpoint from Redis

Log Preservation

Redis Configuration

Error Handling

# Non-fatal checkpoint errors
if ! save_checkpoint ...; then
    log_warning "Checkpoint save failed, continuing without recovery"
    # Execution continues
fi

# Fatal resume errors
if ! resume_wave ...; then
    log_error "Failed to resume from checkpoint"
    # Decide: retry, abort, or manual intervention
fi

Testing

Test suite validates:

  1. Checkpoint Creation
  1. Checkpoint Recovery
  1. Orphan Detection
  1. Edge Cases

Limitations

Future Enhancements

  1. Distributed Checkpointing
  1. Enhanced Analytics
  1. Automatic Remediation
  1. Checkpoint Versioning

Configuration Variables

# Redis connection
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=

# Checkpoint settings
CHECKPOINT_TTL=3600           # 1 hour
LOG_PRESERVE_DIR=.logs/wave-recovery

# Cleanup behavior
DRY_RUN=false                 # Preview mode
CLEANUP_PARALLEL=5            # Parallel cleanup workers

Related Skills

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.