sync-state-invariants

Enforces invariants for session synchronization, event reducers, optimistic updates, and cache lifecycle.

9.5k|1.0k|Updated Sep 11, 2025
One-click install
npx skills add https://github.com/openchamber/openchamber --skill sync-state-invariants
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sync-state-invariants
Source: https://github.com/openchamber/openchamber/tree/main/.agents/skills/sync-state-invariants
Command: npx skills add https://github.com/openchamber/openchamber --skill sync-state-invariants

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

State synchronization bugs in session-driven UIs are subtle and destructive: fetch failures masquerade as empty data, stale snapshots wipe newer mutations, and cache eviction loops cause endless request churn. This Skill provides a rigorous set of invariants and verification rules so changes to sync, bootstrap, reconnect, and optimistic-update logic do not corrupt or lose state.

Core Features & Use Cases

  • Source-of-truth classification: Distinguishes live directory stores, global session caches, persisted history, and optimistic shadow state, assigning each state a single owner with explicit lifecycle.
  • Failure-vs-empty discipline: Requires loaders to distinguish fetch failure from successful empty results, preventing destructive replacement of prior state after errors.
  • Reducer, polling, and optimistic-update rules: Covers event reducer transitions, bootstrap/reconnect retry semantics, mutation revision capture, and shadow-state reconciliation.
  • Cache lifecycle safety: Prevents evict/recreate render loops by requiring protection guarantees before eviction and deferred, coalesced eviction scans.
  • Use Case: When modifying a session store that merges polling snapshots with in-flight user mutations, apply the mutation-revision protocol so responses started before a delete cannot resurrect the deleted session.

Quick Start

Ask the AI to review your changes to session synchronization or optimistic update logic against the sync-state-invariants rules before committing.

Frequently Asked Questions about sync-state-invariants

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

FAQPage Schema
How do I prevent fetch failures from clearing existing state?

Distinguish failure from successful empty data by throwing when an outer block can preserve prior state, or returning null exclusively for fetch failure. Never convert an SDK or API error into an empty array or object, and verify callers skip destructive replacement after failure.

How do I reconcile optimistic updates with server state?

Insert optimistic data into both the visible store and a separate shadow tracker using client-generated IDs the server echoes back. Reconcile deterministically on authoritative fetches or events, and remove optimistic entries from both stores on failure.

Why does my cache cause an endless request loop?

Eviction running on the acquisition path disposes entries that are actively mounting, triggering refetches that repeat forever. Protect entries before eviction can observe them, treat capacity as a soft target, and coalesce eviction into one deferred pass instead of scanning per acquisition.

When can I infer deletion from snapshot differences?

Only after establishing a complete authoritative baseline from the same runtime and scope. Never infer disappearance from the first snapshot, startup-empty state, or partial loads, and key comparisons by stable entity identity rather than directory or grouping.

How do I handle mutations during an in-flight authoritative load?

Capture a mutation revision when the load starts, then at commit time preserve or overlay entity mutations newer than that revision. Record removals as mutations even for absent entities so a stale response cannot resurrect them.