fuyu12345/terminalgen-skills/distributed-lock-redlock-medium
Claude Code and agent skill by fuyu12345/terminalgen-skills
- community
Checking that the SKILL.md file is still in the repository.
Implement and validate a Redlock-style distributed lock simulator with majority consensus, expiry, and safe release semantics. Use when a lock simulator allows multiple clients to acquire the same lock or scenario files encode expected lock outcomes.
Install
npx vskill@latest install fuyu12345/terminalgen-skills/distributed-lock-redlock-mediumSKILL.md
The same SKILL.md was published earlier as fuyu12345/terminalgen-skills/distributed-lock-redlock-medium.
Fixing Redlock Simulator with Scenario-Driven Validation
When to Use
- Fixing a broken distributed lock simulator (especially Redlock-style quorum logic).
- Diagnosing mutual exclusion bugs where multiple clients can acquire the same lock.
- Handling scenario datasets with sequential
acquire/releaseactions and delays. - Producing both corrected code and a required
results.jsonsummary artifact.
Minimal Reliable Workflow
- Inspect implementation and scenario schema first.
Read the existing simulator and confirm scenario structure before coding. In these runs, clients was a JSON-encoded string, not a native list.
- Normalize scenario input parsing.
Accept both:
clientsas JSON string →json.loads(...)clientsas list → use directly
- Implement per-node lock semantics with expiry cleanup.
For each storage node:
- Purge expired lock entries before reads/writes.
- Allow acquisition only if lock absent after purge.
- Release only if
client_idmatches owner.
- Implement distributed acquire with quorum + rollback.
- Compute
quorum = (num_nodes // 2) + 1. - Attempt set across all nodes.
- Succeed only if acquired on quorum.
- If quorum not reached, release partial writes (rollback).
- Implement release across all nodes.
- Attempt owner-checked release on every node.
- Return success based on consistent policy (recommended: client held quorum before release).
- Simulate delays via virtual time, not `sleep`, when replaying scenarios.
Increment a current_time accumulator by each step delay and pass now=current_time into lock operations. This avoids slow/flaky runtime and still validates timeout behavior.
- Evaluate each scenario step-by-step against `should_succeed`.
Track mismatch details for debugging; aggregate into:
tests_passedtests_failedsuccess(tests_failed == 0)
- Write exact required output structure to `results.json`.
Keep only required summary fields unless task explicitly requests extras.
Common Pitfalls
- Treating `clients` as a list when it is a JSON string.
Seen in all runs’ dataset inspection; parsing is required.
- Using real `time.sleep` for delays.
One run stalled due to cumulative delay; virtual time was more reliable.
- Forgetting newline in terminal command batches.
Produced concatenated commands/warnings in one run; always terminate keystrokes with \n.
- Incorrect quorum threshold.
Buggy baseline used required_nodes = 1; must require majority.
- No rollback on failed acquire.
Leaves partial lock state and breaks subsequent actions.
- Partial release (subset of nodes only).
Baseline released only first two nodes; must release across all nodes.
- Wrong expiry computation.
Baseline used expiry_time = now; must be now + timeout.
Verification Strategy
- Structural checks
fixed_simulator.pyexists, non-empty, valid Python.results.jsonexists, valid JSON, exact required fields/types.
- Behavioral checks against scenario file
- Parse all scenarios successfully.
- Replay actions in order with cumulative time.
- Assert each operation matches
should_succeed.
- Targeted assertions derived from observed bug classes
- Second client fails while first lock is unexpired.
- New client succeeds after timeout expiry.
- Release by non-owner fails.
- Re-acquire by same client without release fails (if non-reentrant contract is expected).
- Competing clients never both succeed for same active lock window.
- Final consistency check
- Ensure
tests_failed == 0andsuccess == true. - Ensure
tests_passedequals number of scenarios executed.
References to Load On Demand
- Redlock quorum rule: majority of independent nodes required.
- Deterministic simulation technique: inject
nowinto time-dependent methods. - Terminal automation hygiene: newline-terminated commands, short polling waits instead of long blocking sleeps.
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckinggenerated_skills/distributed_lock_redlock_medium/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/fuyu12345/terminalgen-skills/distributed-lock-redlock-medium)