Coding & Debugging Prompts

Concurrency and Race Condition Investigator

Reconstruct intermittent concurrency failures using timelines, shared state, synchronization rules, and controlled reproduction experiments.

FreeClaudeChatGPT
Best for

Engineers diagnosing intermittent failures that appear only under parallel requests, threads, jobs, or message delivery.

Suitable LLM groups
FrontierReasoning
Download Prompt.md
Prompt
You are a concurrency specialist who diagnoses race conditions, deadlocks, lost updates, and ordering bugs in parallel systems.

Inputs:
1. Language, framework, and concurrency model: {{technology}}
2. Expected invariant and observed failure: {{failure}}
3. Relevant code and shared resources: {{code_and_state}}
4. Logs, traces, thread dumps, or event timelines: {{evidence}}
5. Load pattern and operational constraints: {{environment}}

Do the following:
1. State the invariant that should always hold, then reconstruct a possible interleaving that violates it using only evidence-supported assumptions.
2. Identify shared mutable state, synchronization boundaries, transaction scopes, message-delivery guarantees, lock ordering, and time-of-check/time-of-use gaps.
3. Rank candidate failure mechanisms and specify instrumentation or deterministic tests that can confirm or eliminate each one.
4. Propose the smallest correctness fix, then compare alternatives such as locking, atomic operations, optimistic concurrency, serialization, idempotency, and immutable state for safety, throughput, and complexity.
5. Produce a failing-test design, corrected code or pseudocode, invariant checks, load-test plan, and rollout safeguards. Warn explicitly when a local fix could create deadlock, starvation, or distributed consistency problems.

How to use

  1. Define the invariant before describing the suspected bug.
  2. Include timestamps, request IDs, and transaction boundaries.
  3. State whether concurrency spans processes or machines.
  4. Reproduce the issue with controlled scheduling when possible.

Example input

Technology: Java 21, Spring Boot, PostgreSQL, and two application replicas. Failure: occasionally two users reserve the final inventory unit, violating stock >= 0. Code: read stock, check stock > 0, decrement, then save in a transaction using the default isolation level. Evidence: two request traces read stock=1 within 12 ms and both return success. Load: 120 requests per second during product drops; adding a global application lock is not acceptable.

Example output

The timeline shows a lost-update race: both transactions read stock=1 before either commits. Because replicas do not share an application lock, local synchronization would not protect the invariant. The recommended fix is a conditional atomic update that decrements only where stock > 0 and verifies one affected row. Alternatives include row locking and an optimistic version column. The test uses a barrier to release concurrent transactions simultaneously and asserts one success, one sold-out response, and stock=0.

Customization tips

  • Include database isolation and message-delivery guarantees.
  • List all shared mutable resources.
  • Specify throughput and latency limits.
  • Test deadlock and starvation risks after the fix.

Tags

#race-condition#concurrency-debugging#deadlock-analysis#distributed-systems#thread-safety

FAQ

What is this prompt for?
It reconstructs and tests concurrency failures caused by unsafe ordering or access to shared state.
How should I customize it?
Include the invariant, concurrency model, transaction boundaries, code, synchronized resources, timelines, and load conditions.
Are there any limitations?
An inferred interleaving is not proof; reliable confirmation usually requires targeted instrumentation or deterministic stress tests.
How is it different from a basic prompt?
It models a concrete interleaving, checks synchronization boundaries, and evaluates fixes for correctness, throughput, deadlock, and distributed scope.
Free

Production Code-Path Reconstructor

Reconstruct the code path behind a production incident by correlating requests, releases, traces, logs, configuration, and side effects.

ClaudeChatGPT
#production-debugging#incident-analysis#distributed-tracing
Free

CI/CD Pipeline Failure Investigator

Diagnose failing or inconsistent build and deployment pipelines by comparing stages, environments, artifacts, permissions, and caches.

ClaudeChatGPT
#cicd-debugging#pipeline-failure#devops-troubleshooting
Free

Database Query Performance Investigator

Analyze a slow database query using execution evidence, data distribution, indexes, and workload constraints before recommending changes.

ClaudeChatGPT
#sql-performance#query-plan#database-indexing
Related skills coming soon — browse all skills.
Related articles coming soon — visit the Learn hub.