- Home
- Skills
- Agents & Orchestration
- Repair Distributed Semaphore Permit Leaks
More screenshots
Works with the AI Agents you already use
Repair Distributed Semaphore Permit Leaks
Diagnose and repair distributed semaphore permits, ownership, crash recovery, fairness, and bounded concurrency.
$1
Repair Distributed Semaphore Permit Leaks
Example session with this skill installed
Repair Distributed Semaphore Permit Leaks targets production and repository defects around diagnose and repair distributed semaphore permits, ownership, crash recovery, fairness, and bounded concurrency.. It examines permit acquisition identity, owner token and generation binding, release idempotency, TTL/lease renewal semantics, worker crash and abandoned permits, double release and over-release prevention, fairness and configured concurrency caps, reconciliation metrics and recovery, then establishes one explicit repair contract and focused deterministic validation.
The skill works from repository access or partial evidence such as snippets, logs, configuration, traces, and architecture notes. It preserves existing product/security policy, avoids invented execution claims, and keeps production systems, real credentials, and deployment outside the validation path.
- Read your context and instructions
- Compiled the repair distributed semaphore
I have analyzed the provided Lua script for your Redis semaphore implementation. The leak occurs because the permit acquisition is not bound to a unique owner ID, and the recovery logic fails to account for heartbeat expiration before the release call.
Distributed Semaphore Repair Plan
| Component | Current Behavior | Identified Defect | Required Invariant |
|---|---|---|---|
| Acquisition | Increments a global counter | No caller identity stored; cannot verify ownership. | Permit[i] must map to OwnerToken. |
| Recovery | Relies on 30s Key TTL | TTL expires but counter isn't decremented on timeout. | Expired(TTL) => Decrement(Counter). |
| Release | Simple DECR command | Double-release by late worker drains counter below zero. | Release must be idempotent per OwnerToken. |
Implementation Pattern (Atomic Lua)
-- Proposed Fix: Hash-based semaphore with heartbeat
local semaphore_key = KEYS[1]
local owner_id = ARGV[1]
local limit = tonumber(ARGV[2])
local ttl_ms = tonumber(ARGV[3])
-- Check if already owned
if redis.call('HEXISTS', semaphore_key, owner_id) == 1 then
redis.call('PEXPIRE', semaphore_key, ttl_ms)
return 1
end
-- Check capacity
if redis.call('HLEN', semaphore_key) >= limit then
return 0
end
-- Acquire with identity
redis.call('HSET', semaphore_key, owner_id, ARGV[4]) -- ARGV[4] is timestamp
redis.call('PEXPIRE', semaphore_key, ttl_ms)
return 1
Next steps
- Implement a background cleanup job to
HDELfields wheretimestamp + ttl < now. - Add a unique
request_idto your client release calls to ensure idempotency. - Deploy the provided Lua script to replace the existing
INCR/DECRlogic.
Connects securely to your tools. The creator never sees your data.
About this skill
The problem
Distributed semaphores often fail silently when workers crash or networks partition, leading to permit leaks that permanently exhaust concurrency limits. Debugging these race conditions in production environments like Redis, Etcd, or Postgres is notoriously difficult without a formal state invariant.
What it does
- Analyzes permit acquisition identity and owner token binding to detect orphaned locks.
- Evaluates TTL/lease renewal semantics against worker crash scenarios to prevent deadlocks.
- Identifies release idempotency failures that cause double-releases or over-release bugs.
- Generates deterministic test plans using fake clocks and barriers to reproduce race conditions without flaky sleeps.
- Proposes bounded repairs that restore canonical state invariants while preserving existing retry and security policies.
Frameworks & tools
Works with distributed stores like Redis (Redlock), Etcd, PostgreSQL (advisory locks), and DynamoDB. Compatible with Go, Node.js, Python, and Java concurrency primitives.
Why this beats prompting it yourself
Generic LLMs often struggle to maintain state consistency across distributed systems, frequently suggesting unsafe "quick fixes" that introduce new race conditions. This skill enforces a rigorous repair method that reconstructs ownership boundaries and defines strict invariants before writing a single line of code.
Use cases
- Recovering from permit exhaustion in a Redis-backed task queue after worker OOM events.
- Implementing idempotent release logic to prevent permit inflation during network retries.
- Adding observability and reconciliation metrics to legacy distributed locking systems.
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Agents & Orchestration.
Requires logs, architecture notes, or repository access to provide exact diagnosis. Does not perform live production data migrations.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before buying a skill.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Money-back guarantee
Doesn't do what its page promises? You get your money back.
Trust & safety
Security scan
Security scan passed 2 months ago