agentleFS
bordenetbordenet/superpowers-plus/skills/engineering/state-consistency-investigator/skill.md

state-consistency-investigator

Skill8 starsChanged 6 months agoMITView on GitHub

Specialized investigator for diagnosing state consistency failures: replication lag, cache staleness, event ordering issues, cross-service data divergence, and eventual consistency bugs. Dispatched by debug-conductor.

The file

We split this skill into the rules it gives an agent

6 rules. About 0 are common, 6 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈6

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Check historical lag: is it steady or spiking?

    line 69
  2. Distinctive:

    Check if lag explains the observed inconsistency window

    line 73
  3. Distinctive:

    Verify events were published in correct order

    line 78
  4. Distinctive:

    Verify events were consumed in correct order

    line 79
  5. Distinctive:

    Check cache TTL vs. invalidation timing

    line 87
  6. Distinctive:

    Check cache hit rate: sudden drops may indicate invalidation storms

    line 91

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
skill.md

State Consistency Investigator

Role: Diagnose state consistency failures across services: stale reads, replication lag, event ordering, cache-vs-source divergence. Dispatched by: debug-conductor — never invoked directly by user. Evidence type: StateEvidence (see skills/_shared/evidence-schema.md)

When to Use

Dispatched by debug-conductor when the incident involves data inconsistency — stale reads, replication lag, cache staleness, event reordering, or cross-service state divergence.

Investigation Protocol

Step 1: Identify the Consistency Boundary

  1. Which data entities are affected? (user profiles, order records, account settings)
  2. Which services read this data? (source of truth vs. replicas vs. caches)
  3. What consistency model is expected? (strong, eventual, read-after-write)
  4. What propagation paths exist? (DB replication, event bus, cache invalidation, API sync)

Step 2: Cross-Source Comparison

For each affected entity:

  1. Query the source of truth (primary DB) — what's the current value?
  2. Query each consumer (replica DB, cache, downstream service) — what do they see?
  3. Record discrepancies with timestamps:
{
  "inconsistencies": [
    {
      "entity": "customer:C-1001:phone",
      "sourceA": "primary-db",
      "sourceB": "replica-db",
      "valueA": "+1-555-0199",
      "valueB": "+1-555-0100"
    }
  ]
}

Step 3: Replication Lag Assessment

  1. Measure current replication lag (primary → replica)
  2. Check historical lag: is it steady or spiking?
  3. Compare lag SLA vs. actual:
    • Average within SLA but P99 outside? (intermittent issue)
    • Lag correlated with load patterns? (peak hours)
  4. Check if lag explains the observed inconsistency window

Step 4: Event Ordering Audit

  1. Inspect the event/message bus for the affected entity
  2. Verify events were published in correct order
  3. Verify events were consumed in correct order
  4. Check for:
    • Duplicate events (at-least-once delivery)
    • Lost events (check consumer acknowledgment)
    • Reordered events (partition key mismatch, consumer parallelism)

Step 5: Cache Behavior Analysis

  1. Check cache TTL vs. invalidation timing
  2. Trace the invalidation flow: event received → cache key deleted → next read
  3. Identify: does the cache-miss read go to source of truth or replica?
    • Critical pattern: Cache invalidation works, but re-fill reads stale replica → re-caches stale data
  4. Check cache hit rate: sudden drops may indicate invalidation storms

Step 6: Produce Evidence

{
  "inconsistencies": [ /* cross-source comparison results */ ],
  "replicationLag": { "primaryToReplica": 4500, "measured": "ISO-8601" },
  "eventOrdering": [
    { "expected": ["update", "invalidate", "read"], "actual": ["update", "read", "invalidate"], "divergencePoint": 1 }
  ],
  "staleReads": [
    { "query": "SELECT phone FROM profiles WHERE id=C-1001", "staleValue": "+1-555-0100", "currentValue": "+1-555-0199", "lagMs": 4500 }
  ]
}

Stop Conditions

  • Inconsistency source identified (replication lag, cache re-fill, event ordering)
  • 3 cross-source comparison checks completed
  • Token budget exhausted
  • Wall-clock limit (5 minutes)

Escalation Conditions

  • Multiple unrelated inconsistencies with no common cause (may indicate data corruption)
  • Replication lag within SLA but inconsistency persists (not a lag issue — something else)
  • Event bus shows correct delivery but consumer state is wrong (consumer bug)

Common Patterns This Investigator Detects

PatternEvidence Shape
Stale replica readPrimary has new value, replica has old; lag > consistency window
Cache re-fill from replicaCache invalidated correctly, but refill reads stale replica
Event reorderingEvents consumed in different order than published
Invalidation raceRead arrives between invalidation and re-fill → cache miss → stale read
Dual-write inconsistencyTwo services write same entity independently; values diverge
Eventual consistency window violationConsumer reads during propagation delay

Failure Modes

ModeSymptomRecovery
Timing sensitivityBug only appears under specific timingTest with artificial delays
Stale readReading from replica during lagRead from primary for verification
Event orderingAssuming ordered deliveryCheck for out-of-order events explicitly

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.