Metadata storage source of truth desync

From divinevideo/divine-mobile · View interactive version

Metadata storage source of truth desync is an AI agent skill from the GitHub repository divinevideo/divine-mobile. Fix content serving failures caused by metadata (KV store, database) being out of sync with actual storage (GCS, S3, filesystem). Use when: (1) Content exists in storage but API returns "processing" or "not ready", (2) Webhook callbacks that update metadata failed silently, (3) Backfill scripts gene

How to use this skill

Skill file

Metadata-Storage Source of Truth Desync

Problem

When a system has both metadata (KV store, database status field) and actual content

in object storage, the metadata can become stale. If the serving handler gates on

metadata status before checking storage, content that exists becomes inaccessible.

Common causes:

Context / Trigger Conditions

Solution

Pattern: Storage-First with Metadata Auto-Repair

Check storage (source of truth) BEFORE checking metadata status. If content exists,

serve it and fix metadata as a side effect.

// BAD: Metadata-first (blocks access when metadata is stale)
match metadata.transcode_status {
    Some(Complete) => { /* serve from storage */ }
    Some(Processing) => { return 202; }  // Blocks even if content exists!
    _ => { trigger_transcoding(); return 202; }
}

// GOOD: Storage-first with auto-repair
match download_from_storage(&path) {
    Ok(content) => {
        // Content exists — serve it and fix metadata if needed
        if metadata.transcode_status != Some(Complete) {
            eprintln!("[FIX] {} has content but status was {:?}", id, metadata.transcode_status);
            update_status(id, Complete);  // Auto-repair
        }
        serve(content)
    }
    Err(NotFound) => {
        // Content truly doesn't exist — now check metadata for status
        match metadata.transcode_status {
            Some(Processing) => return 202,
            _ => { trigger_processing(); return 202; }
        }
    }
}

Key Principles

  1. Storage is the source of truth — if the file exists, serve it regardless of metadata
  2. Auto-repair metadata — when you find a desync, fix it inline (best-effort, don't fail if update fails)
  3. Log desyncs — track how often metadata is wrong to find the root cause
  4. Don't block on metadata — metadata status should be advisory, not a gate

Apply to HEAD requests too

HEAD handlers often have the same bug. Apply the same storage-first pattern:

// HEAD: Check storage, not just metadata
match check_storage_exists(&path) {
    Ok(true) => {
        if metadata.status != Complete {
            update_status(id, Complete);
        }
        return 200;
    }
    Ok(false) | Err(_) => {
        // Fall back to metadata-based response
    }
}

Verification

  1. Request content that previously returned 202 — should now return 200 with content
  2. Check logs for "[FIX]" messages showing auto-repair in action
  3. After warming traffic, verify metadata has been corrected

Example

In Divine Blossom, the HLS handler checked transcode_status in KV before GCS:

Notes

on cache misses, and subsequent requests hit the cache

rather than relying solely on on-demand repair

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.