Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Heuristic:AMAP ML SkillClaw Backup Rollback Safety

From Leeroopedia
Knowledge Sources
Domains Debugging, Cloud_Storage
Last Updated 2026-10-22 00:00 GMT

Overview

Backup-and-rollback safety pattern for skill pull operations that copies the existing skills directory before mirroring, and restores from backup if the mirror download or write fails.

Description

When `SkillHub.pull_skills` runs in mirror mode (default), it first copies the entire local skills directory to a timestamped backup under `.skillclaw_backups/`. It then downloads remote skills into a staging directory. Only after all downloads succeed does it atomically replace the live skills directory with the staged content. If any step fails, the backup is restored. Only the 3 most recent backups are kept (pruned by `_prune_backups`). An empty or failed remote manifest is treated as a no-op to prevent accidental data loss — the pull returns `downloaded=0, deleted=0` without touching local skills.

Usage

Use this heuristic when pulling shared skills from cloud storage. It prevents catastrophic data loss if a pull fails midway or if the remote manifest is empty/corrupted. Applied automatically by `SkillHub.pull_skills` in mirror mode.

The Insight (Rule of Thumb)

  • Action: Copy local skills to `.skillclaw_backups/{dir}_{timestamp}/` before mirroring; stage downloads in a temp dir; swap only on full success; restore backup on failure.
  • Value: Keep 3 backups max. Empty manifest = no-op (never wipe local on empty remote).
  • Trade-off: Extra disk I/O (copy + stage + swap) doubles storage temporarily, but guarantees zero data loss on pull failure.
  • Compatibility: Works with all storage backends (local, S3, OSS). Incremental mode (mirror=False) skips backup since it never deletes.

Reasoning

Mirroring replaces the entire local skill directory with the remote snapshot. Without a backup, a network glitch or corrupted manifest would wipe all local skills. The staging-then-swap approach ensures the live directory is only modified when all downloads succeed. The empty-manifest no-op prevents a scenario where a misconfigured or temporarily-empty remote storage causes all local skills to be deleted. Keeping only 3 backups bounds disk usage while providing rollback history.

Code Evidence

Backup creation from `skillclaw/skill_hub.py:700-722`:

parent_dir = os.path.dirname(os.path.abspath(skills_dir))
base_name = os.path.basename(os.path.abspath(skills_dir))
stamp = datetime.now(timezone.utc).strftime("%Y%m%dT%H%M%S%fZ")
backup_root = os.path.join(parent_dir, ".skillclaw_backups")
backup_dir = os.path.join(backup_root, f"{base_name}_{stamp}")
staging_dir = os.path.join(parent_dir, f".skillclaw_pull_stage_{base_name}_{stamp}")

try:
    shutil.copytree(skills_dir, backup_dir, symlinks=True)
except Exception as e:
    logger.warning("[SkillHub] backup before pull failed: %s", e)
    shutil.rmtree(backup_dir, ignore_errors=True)
    self._prune_backups(backup_root, f"{base_name}_", keep=3)
    return _result(downloaded=0, skipped=0, deleted=0, ...)

Empty manifest no-op from `skillclaw/skill_hub.py:629-645`:

if not manifest:
    if include_set:
        logger.info("[SkillHub] none of the requested remote skills matched the manifest: %s", ...)
    else:
        logger.warning("[SkillHub] remote manifest empty; skip mirror pull (downloaded=0 skipped=0 deleted=0)")
    return _result(downloaded=0, skipped=0, deleted=0, total_remote=0,
                   restored_from_backup=False, backup_dir="")

Backup pruning from `skillclaw/skill_hub.py:537-550`:

@staticmethod
def _prune_backups(backup_root: str, prefix: str, keep: int = 3) -> None:
    names = sorted(n for n in os.listdir(backup_root) if n.startswith(prefix))
    to_delete = names[:-keep] if keep > 0 else names
    for name in to_delete:
        path = os.path.join(backup_root, name)
        shutil.rmtree(path, ignore_errors=True)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment