state-safety

Enforces atomic writes, locking, validation and backups for JSON state files.

9|1|Updated Feb 1, 2026
One-click install
npx skills add https://github.com/calcosmic/Aether --skill state-safety
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: state-safety
Source: https://github.com/calcosmic/Aether/tree/main/.aether/skills-codex/colony/state-safety
Command: npx skills add https://github.com/calcosmic/Aether --skill state-safety

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

State files used by the colony can become corrupted or lost during unexpected shutdowns or concurrent updates. This skill teaches safe handling of critical JSON state files to prevent data loss and ensure recoverability.

Core Features & Use Cases

  • Atomic writes for state mutations: write to a temporary file first, then rename to the target to prevent partial writes.
  • File locking and guarded mutations: acquire a lock before modifying COLONY_STATE.json, pheromones.json, constraints.json, or session.json to avoid race conditions.
  • Post-write validation and backups: validate the resulting JSON and restore from backups if validation fails.
  • Automatic backup strategy: maintain a single, valid backup per file to enable rollback after failures.
  • Read-time corruption checks: verify files exist, are non-empty, and parse correctly; fall back to backups when needed.
  • State files and critical fields awareness: track essential files and their required keys to maintain integrity.

Quick Start

Enable atomic writes and locking across state files and perform a backup after every successful write.

Frequently Asked Questions about state-safety

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent JSON file corruption during concurrent writes?

To prevent JSON file corruption during concurrent writes, use file locking to acquire exclusive access before modifying state files, ensuring multiple processes do not overwrite each other's changes and avoiding race conditions.

Why does my JSON state file get truncated after an unexpected shutdown?

JSON state files get truncated after unexpected shutdowns because standard writes save partial data. Atomic writes solve this by writing to a temporary file first, then renaming it to the target only after completion, preventing partial saves.

How can I validate JSON state and restore from backups automatically?

You can validate JSON state and restore from backups automatically by performing post-write validation immediately after saving. If the resulting JSON fails validation, the system restores the file from a single valid backup to ensure reliable recovery.

What is the best way to handle read-time corruption checks for state files?

The best way to handle read-time corruption checks for state files is to verify files exist, are non-empty, and parse correctly before reading. If these checks fail, fall back to backups to maintain state integrity and ensure recoverability.

Does atomic write file locking work across multiple processes?

Atomic write file locking works across multiple processes by acquiring a lock before modifying shared JSON state files like COLONY_STATE.json or session.json. This guarded mutation approach prevents race conditions and ensures safe concurrent access.