Get the FREE Ultimate OpenClaw Setup Guide →

ln-628-concurrency-auditor

npx machina-cli add skill levnikolaevich/claude-code-skills/ln-628-concurrency-auditor --openclaw
Files (1)
SKILL.md
7.0 KB

Paths: File paths (shared/, references/, ../ln-*) are relative to skills repo root. If not found at CWD, locate this SKILL.md directory and go up one level for repo root.

Concurrency Auditor (L3 Worker)

Specialized worker auditing concurrency and async patterns.

Purpose & Scope

  • Worker in ln-620 coordinator pipeline
  • Audit concurrency (Category 11: High Priority)
  • Check race conditions, async/await, thread safety
  • Calculate compliance score (X/10)

Inputs (from Coordinator)

Receives contextStore with tech stack, language, codebase root, output_dir.

Workflow

  1. Parse context + output_dir
  2. Check concurrency patterns
  3. Collect findings
  4. Calculate score
  5. Write Report: Build full markdown report in memory per shared/templates/audit_worker_report_template.md, write to {output_dir}/628-concurrency.md in single Write call
  6. Return Summary: Return minimal summary to coordinator

Audit Rules

1. Race Conditions

What: Shared state modified without synchronization

Detection Patterns:

LanguagePatternGrep
PythonGlobal modified in asyncglobal\s+\w+ inside async def
TypeScriptModule-level let in async^let\s+\w+ at file scope + async function modifies it
GoMap access without mutexmap\[.*\].*= without sync.Mutex in same file
AllShared cachecache\[.*\]\s*= or cache\.set without lock

Severity:

  • CRITICAL: Race in payment/auth (payment, balance, auth, token in variable name)
  • HIGH: Race in user-facing feature
  • MEDIUM: Race in background job

Recommendation: Use locks, atomic operations, message queues

Effort: M-L

2. Missing Async/Await

What: Callback hell or unhandled promises

Detection Patterns:

IssueGrepExample
Callback hell\.then\(.*\.then\(.*\.then\(.then().then().then()
Fire-and-forgetasync.*\(\) not preceded by awaitsaveToDb() without await
Missing awaitreturn\s+new\s+Promise in async functionShould just return await or return value
Dangling promise\.catch\(\s*\)Empty catch swallows errors

Severity:

  • HIGH: Fire-and-forget async (can cause data loss)
  • MEDIUM: Callback hell (hard to maintain)
  • LOW: Mixed Promise styles

Recommendation: Convert to async/await, always await or handle promises

Effort: M

3. Resource Contention

What: Multiple processes competing for same resource

Detection Patterns:

IssueGrepExample
File lock missingopen\(.*["']w["']\) without flock or lockfileConcurrent file writes
Connection exhaustioncreate_engine\(.*pool_size check if pool_size < 5DB pool too small
Concurrent writeswriteFile or fs\.write without lock checkFile corruption risk

Severity:

  • HIGH: File corruption risk, DB exhaustion
  • MEDIUM: Performance degradation

Recommendation: Use connection pooling, file locking, asyncio.Lock

Effort: M

4. Thread Safety Violations

What: Shared mutable state without synchronization

Detection Patterns:

LanguageSafe PatternUnsafe Pattern
Gosync.Mutex with mapmap[...] without Mutex in same struct
RustArc<Mutex<T>>Rc<RefCell<T>> in multi-threaded context
Javasynchronized or ConcurrentHashMapHashMap shared between threads
Pythonthreading.LockGlobal dict modified in threads

Grep patterns:

  • Go unsafe: type.*struct\s*{[^}]*map\[ without sync.Mutex in same struct
  • Python unsafe: global\s+\w+ in function + threading.Thread in same file

Severity: HIGH (data corruption possible)

Recommendation: Use thread-safe primitives

Effort: M

5. Deadlock Potential

What: Lock acquisition in inconsistent order

Detection Patterns:

IssueGrepExample
Nested lockswith\s+\w+_lock:.*with\s+\w+_lock: (multiline)Lock A then Lock B
Lock in loopfor.*:.*\.acquire\(\)Lock acquired repeatedly without release
Lock + external call.acquire\(\) followed by await or requests.Holding lock during I/O

Severity: HIGH (deadlock freezes application)

Recommendation: Consistent lock ordering, timeout locks (asyncio.wait_for)

Effort: L

6. Blocking I/O in Event Loop (Python asyncio)

What: Synchronous blocking calls inside async functions

Detection Patterns:

Blocking CallGrep in async defReplacement
time.sleeptime\.sleep inside async defawait asyncio.sleep
requests.requests\.(get|post) inside async defhttpx or aiohttp
open() fileopen\( inside async defaiofiles.open

Severity:

  • HIGH: Blocks entire event loop
  • MEDIUM: Minor blocking (<100ms)

Recommendation: Use async alternatives

Effort: S-M

Scoring Algorithm

MANDATORY READ: Load shared/references/audit_scoring.md for unified scoring formula.

Output Format

MANDATORY READ: Load shared/templates/audit_worker_report_template.md for file format.

Write report to {output_dir}/628-concurrency.md with category: "Concurrency" and checks: race_conditions, missing_await, resource_contention, thread_safety, deadlock_potential, blocking_io.

Return summary to coordinator:

Report written: docs/project/.audit/ln-620/{YYYY-MM-DD}/628-concurrency.md
Score: X.X/10 | Issues: N (C:N H:N M:N L:N)

Reference Files

  • Worker report template: shared/templates/audit_worker_report_template.md
  • Audit scoring formula: shared/references/audit_scoring.md
  • Audit output schema: shared/references/audit_output_schema.md

Critical Rules

  • Do not auto-fix: Report only, concurrency fixes require careful human review
  • Language-aware detection: Use language-specific patterns (Go sync.Mutex, Python asyncio.Lock, Java synchronized)
  • Effort realism: S = <1h, M = 1-4h, L = >4h
  • Critical path escalation: Race conditions in payment/auth = CRITICAL, regardless of other factors
  • Exclusions: Skip test files, skip single-threaded CLI tools, skip generated code

Definition of Done

  • contextStore parsed (language, concurrency model, output_dir)
  • All 6 checks completed (race conditions, missing await, resource contention, thread safety, deadlock potential, blocking I/O)
  • Findings collected with severity, location, effort, recommendation
  • Score calculated per shared/references/audit_scoring.md
  • Report written to {output_dir}/628-concurrency.md (atomic single Write call)
  • Summary returned to coordinator

Version: 3.0.0 Last Updated: 2025-12-23

Source

git clone https://github.com/levnikolaevich/claude-code-skills/blob/master/ln-628-concurrency-auditor/SKILL.mdView on GitHub

Overview

Concurrency Auditor (L3) analyzes code for race conditions, missing async/await usage, resource contention, and deadlock risks. It collects findings with severity, location, and recommended fixes, then writes a Markdown report to the designated output directory.

How This Skill Works

The auditor receives context from the coordinator, scans code against language-specific detection patterns (race conditions, missing async/await, resource contention, thread safety), and aggregates findings. It then computes a compliance score and writes a single Markdown report to {output_dir}/628-concurrency.md, returning a concise summary to the coordinator.

When to Use It

  • Auditing a codebase for race conditions in worker pipelines.
  • Validating proper async/await usage in async-heavy modules.
  • Identifying resource contention like file locks or DB pool exhaustion.
  • Checking thread safety in shared mutable state across goroutines/threads.
  • Generating a formal audit report for stakeholders.

Quick Start

  1. Step 1: Provide contextStore and target output_dir from the coordinator to the worker.
  2. Step 2: Run the concurrency auditor to collect findings and compute the score.
  3. Step 3: Review {output_dir}/628-concurrency.md and apply fixes; re-run to verify.

Best Practices

  • Apply strict synchronization around shared state using mutexes, atomic ops, or message queues.
  • Ensure all asynchronous operations are awaited or properly handled; avoid fire-and-forget without checks.
  • Use resource pools and file locking to prevent contention and data corruption.
  • Adopt language-appropriate thread-safety primitives (e.g., Mutex, Arc<Mutex<T>>, synchronized blocks).
  • Validate findings with tests and generate the in-memory report before writing to disk.

Example Use Cases

  • Python: global variable modified inside an async def leading to race on a shared cache.
  • TypeScript: module-level let mutated by an async function without proper synchronization.
  • Go: map access without a mutex inside the same struct, causing data races.
  • JavaScript/Node: fire-and-forget call (e.g., saveToDb()) without awaiting, risking ordering issues.
  • JavaScript/Promises: dangling promise with an empty .catch() swallowing errors.

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers