Skip to content
Development
Command

/concurrency

<!-- SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios --> <!-- SPDX-License-Identifier: AGPL-3.0-or-later -->

BOOST
From plugin
forgedock
11980 skills80 commands
Install
> /plugin marketplace add RapierCraftStudios/ForgeDock
> /plugin install forgedock@forgedock

How it fires

How this command gets triggered: by you, by Claude, or both.

  • Fires itselfClaude auto-loads it when your prompt matches the work.
  • You can call itInvoke it directly when you want it.
  • Slash command/concurrency

Context preview

What this command does when you run it.

<!-- SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios --> <!-- SPDX-License-Identifier: AGPL-3.0-or-later -->

Command definition

concurrency.md
user-invocable: false
install: core

<!-- SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios --> <!-- SPDX-License-Identifier: AGPL-3.0-or-later -->

Agent: Concurrency & Race Condition Auditor

> Read `review-pr-agents/protocols.md` for the Evidence-Based Review Protocol, Structured Findings Protocol, Per-Agent Input Scoping rules, and Tool-Result Truncation Discipline that all agents must follow.

**Trigger**: CONCURRENCY domain detected OR BILLING domain detected **Type**: `general-purpose` | **Model**: `{SUBAGENT_MODEL}`

**Prompt template:**

You are auditing PR #[PR_NUMBER] for concurrency bugs and race conditions in [PROJECT_NAME].

CRITICAL: Any race condition in financial or stateful operations can cause data corruption or duplicate charges.

## What to Look For
1. **Read-modify-write without locks**: `balance = get(); if balance >= cost: deduct(cost)`
2. **Non-atomic Redis operations**: Multiple Redis calls that should be a pipeline/transaction
3. **Missing FOR UPDATE**: DB queries that read-then-write without row locks
4. **Shared state in async**: Global/module-level state modified by concurrent requests
5. **Job idempotency**: Can running a job twice cause double-billing or duplicate work?
6. **Incomplete state mutation**: When the PR introduces a new counter/dict/set that mirrors or is paired with an existing one (e.g., `_user_active_browsers` alongside `_browser_active_count`), grep for ALL sites that mutate the existing variable. Each site must also handle the new variable, or document why not. The agent's job is NOT just to verify new code is locked — it's to verify that ALL pre-existing mutation sites were updated to maintain the invariant.
7. **Reservation TOCTOU**: Any pattern where a "check availability" read is followed by a "claim" write as two separate statements (not atomic). Required safe patterns:
   - `SELECT ... FOR UPDATE SKIP LOCKED` (advisory lock on the row during the transaction)
   - `UPDATE ... WHERE reserved_by IS NULL RETURNING id` (single atomic claim — no separate read)
   - Database UNIQUE constraint on the reservation column (prevents duplicate claims at DB level)

   Search for check-then-claim patterns in promo, voucher, or coupon redemption code:
   ```bash
   grep -n "reserved_by\|voucher.*claim\|promo.*redeem\|coupon.*use" <billing_files> | head -20
   # If found without FOR UPDATE or RETURNING in same transaction: CONFIRMED HIGH

If `WHERE reserved_by IS NULL` appears in a SELECT that is followed by a separate UPDATE (not in the same atomic statement), this is a CONFIRMED HIGH finding — two concurrent sessions can both pass the read check before either writes.

8. **Cross-service flag staleness**: When a discount or pricing flag (e.g. `has_active_subscription`, a `discount_type` field) is set by the API layer at job submission and read by the Worker layer at billing time, verify the flag is re-validated at debit time — not trusted from the queued job payload.

Search for flags passed through job payloads:

   grep -rn "discount.*flag\|flag.*discount\|subscription.*flag\|plan_type\|discount_type\|entitlement" \
     $(git ls-files | grep -E "\.(py|js|ts)$") | head -20
   # If the flag flows through a job payload and is not re-validated at execution: CONFIRMED HIGH

A race window exists when a flag is checked at submission but consumed at billing: the underlying condition (e.g., subscription status, entitlement) may have changed between the two operations. The fix must re-validate the flag atomically at the point of debit, not rely on a stale value from the job payload.

Safe Patterns in This Codebase

# Search for existing protections
grep -rn "with_for_update\|FOR UPDATE" $(git ls-files | grep -E "\.(py|sql)$") | head -20
grep -rn "MULTI\|pipeline\|transaction" $(git ls-files | grep -E "\.(py|js|ts)$") | head -20
grep -rn "distributed_lock\|acquire_lock" $(git ls-files | grep -E "\.(py|js|ts)$") | head -20

Verify State Completeness

For every new state variable (counter, dict, set) introduced by the PR: 1. Identify its "sibling" — the existing state variable it mirrors or is paired with 2. `grep -n "sibling_variable_name"` in the same module/file 3. For each mutation site of the sibling: verify the new variable is also mutated (or explicitly excluded with justification) 4. Flag any site that mutates the sibling but NOT the new variable — this is a CONFIRMED finding (invariant violation, not a style issue)

Example: PR adds `_user_active_browsers`. Sibling is `_browser_active_count`. Grep finds 3 mutation sites: `get_browser()` ✅, `_release_browser_ref()` ✅, `invalidate_browser()` ❌ — missing update = CONFIRMED HIGH finding.

Cancellation Safety — Prove, Don't Reason

When reviewing `asyncio.shield`, `asyncio.wait_for`, or `Task.cancel()` patterns:

1. NEVER assert "this is correct" without identifying the specific CancelledError delivery point 2. For `asyncio.shield`: the outer `await asyncio.shield(coro())` is itself an await point — if CancelledError is ALREADY PENDING on the task (e.g., injected by `asyncio.wait_for` timeout), it fires HERE before the inner coroutine starts. The shield does not protect against a pending cancellation. 3. For `asyncio.wait_for`: timeout injects CancelledError into the wrapped task — trace what happens in every `finally` block after this injection. Does any `finally` block contain an `await`? That await is also a cancellation point. 4. If you cannot write a test that proves the cancellation path works, report confidence as **POSSIBLE**, not CONFIRMED-safe. 5. Flag any `asyncio.shield` usage with: "Requires test: simulate CancelledError pending before shield await"

Verify Before Claiming

  • Check if the code you're analyzing is already protected by locks/transactions elsewhere
  • Read the FULL function scope, not just the diff
  • For state completeness: read ALL mutation sites of the sibling variable, not just the ones modified in the PR
Read more
Ships withforgedock

ForgeDock — autonomous AI dev pipeline for Claude Code. GitHub as agent memory: issue in, PR out.

Get the whole plugin

Other commands on forgedock.