← Back to CRM system builders
See how it helps
Concurrent correctness properties
Tests whether concurrent operations preserve business invariants across controlled scheduling orders, with reproducible counterexamples when they fail.
concurrency-properties
Team members using this skill
When is it useful?
Use it when shared balances, stock or reservations must remain valid under simultaneous requests.
What does it help you do?
- Checks concurrent results against valid sequential histories.
- Generates controlled interleavings over a few shared resources.
- Records scheduling order to reproduce double-spend or locking failures.
Try asking this
Prove two concurrent withdrawals cannot spend the same available balance. Start two withdrawals against a balance sufficient for only one. Preserve the execution schedule and prove the final balance matches a valid sequential outcome.
Detailed documentation
Read the skill’s original instructions, examples and checks in their authored language.
Show less
Concurrency Properties
Use this skill when testing operations that may execute in parallel across requests, workers, or webhook deliveries (e.g., concurrent credit redemptions, stock reservations, seat assignments, unique slug claims, or idempotent retries).
Why Random Seeds Alone Do Not Reproduce Races
A PRNG seed only fixes the generated inputs; OS thread scheduling and network I/O timing remain non-deterministic unless the test either:
- Controls Interleaving Points: Uses deterministic schedulers (
fc.schedulerinfast-check, barrier hooks, or controlled async promise queues) to systematically permute the order in which pending async steps resolve, OR - Synchronizes Simultaneous Contention: Uses a barrier (
Promise.all/CountDownLatch/asyncio.gather) to fire $N$ conflicting operations against the same row/resource at the exact same instant and checks linearizability afterward.
Core Concurrency & Linearizability Invariants (Lamport)
- Linearizability Against Sequential Specification:
- When $N$ operations execute concurrently on the same entity (e.g., 5 parallel requests each trying to spend 40 credits from a 100-credit wallet), the final state and the set of
[succeeded, rejected]responses must match some valid sequential ordering of those operations:- Exactly $\lfloor 100 / 40 \rfloor = 2$ requests may succeed; the remaining $3$ must fail with insufficient funds; final balance must be $20$ (never $-100$ or $60$).
- When $N$ operations execute concurrently on the same entity (e.g., 5 parallel requests each trying to spend 40 credits from a 100-credit wallet), the final state and the set of
- Same-Key Concurrent Idempotency:
- Firing $N \ge 2$ parallel requests with the exact same
idempotency_keymust result in at most one side effect / state mutation; all callers must either receive the single committed result or a clean conflict/in-progress status—never duplicate charges or duplicate records.
- Firing $N \ge 2$ parallel requests with the exact same
- Conservation Under Contention (No Lost Updates or Write Skew):
- Concurrent deposits, withdrawals, transfers, or inventory reservations across shared accounts must preserve the exact sum of balances and never overwrite each other's updates.
- Deadlock & Orphan-Lock Freedom:
- Generated transfers between accounts $(A \to B)$ and $(B \to A)$ in parallel must complete or abort cleanly within a bounded timeout without deadlocking or leaving stuck reservation locks.
Designing Concurrent Property Tests
- Keep concurrency fan-out small and targeted ($2$ to $5$ parallel operations hitting $1$ or $2$ shared keys): bugs that occur under 50 threads almost always manifest with $2$ threads and $1–2$ shared resources, which shrinks and debugs far faster.
- Log the exact resolution order (
scheduler.report()or operation start/finish timestamps) whenever a counterexample occurs.
Checklist
- Are concurrent operations targeted at the same account, inventory item, or idempotency key to force real contention?
- Is the outcome verified to be linearizable (matching a valid sequential execution with exact balance/stock conservation)?
- Is async step ordering controlled or logged (e.g., via a deterministic promise scheduler or barrier) so race failures can be replayed?
- Are bidirectional operations ($A \to B$ and $B \to A$) tested for deadlock freedom and clean rollback?
Included files 1
SKILL.md
