.gemini/skills/offline-sync-strategies/SKILL.md
Advanced conflict resolution and data consistency patterns for offline-first architecture
npx skillsauth add captjay98/gemini-livestockai Offline Sync StrategiesInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
LivestockAI's "Action Era" requires robust handling of data conflicts beyond simple "last-write-wins".
A user offline might:
tmp_123)tmp_123)tmp_123)If the sync order is wrong, or if Batch A creation fails on the server, the subsequent records will be orphaned or invalid.
Always generate UUIDs on the client using crypto.randomUUID(). Do not rely on server-side ID generation for primary entities.
// ✅ Correct
const batchId = crypto.randomUUID()
const batch = { id: batchId, ...data }
await db.batches.add(batch) // IndexedDB
await syncQueue.add({ type: 'CREATE_BATCH', payload: batch })
// ❌ Wrong (Server ID dependency)
const response = await api.createBatch(data)
const batchId = response.id // Fails if offline
The Sync Queue must process operations serially per entity.
interface SyncOperation {
id: string
entityId: string // Partition key for ordering
type: 'CREATE' | 'UPDATE' | 'DELETE'
payload: any
occurredAt: number
}
Rule: If CREATE fails, all subsequent UPDATE operations for that entityId must be effectively paused or moved to a "Dead Letter Queue" for manual intervention.
Used for: Settings, Profile updates. User A changes Name. User B changes Email. Both succeed.
Used for: Sensor readings, Status updates. The latest timestamp prevails.
Used for: Feed Logs, Mortality Records, Sales. These are "facts" that occurred. They don't update state; they append events. Even if two users log feed at the same time, both logs are valid.
Never hard delete entities on the client. Mark as deletedAt: timestamp.
Server syncs the deletion.
Other clients receive "tombstone" updates.
When automated resolution is impossible (e.g. User A sets Price=500, User B sets Price=600 for the same sale):
offline-first - The mechanism (IndexedDB/TanStack Query)batch-centric-design - The UI context for these operationsdata-ai
Input validation patterns with Zod in LivestockAI server functions
testing
Unit testing patterns with Vitest in LivestockAI
tools
Server → Service → Repository pattern for feature organization
data-ai
Server-side rendering and server functions with TanStack Start in LivestockAI