/harness-claude:resilience-idempotencyfrom harness-claude
Implements idempotency for API endpoints and message consumers using Idempotency-Key headers, Redis-backed response caching, and locking to prevent duplicate processing.
Claude never picks this skill on its own
Its frontmatter has no description. Without a description, Claude Code leaves it out of the list Claude chooses from. Typing /harness-claude:resilience-idempotency still runs it.
What the skill costs in Claude's context, stage by stage
No description Claude Code can read, so Claude's list leaves it out: only you can start it.
SKILL.md joins the conversation and stays.
Ensure safe retries by making operations produce the same result regardless of how many times they execute
Idempotency-Key header on non-idempotent endpoints (POST, PATCH). The client generates a unique key per logical operation.// middleware/idempotency.ts
interface StoredResponse {
statusCode: number;
body: unknown;
headers: Record<string, string>;
createdAt: number;
}
export class IdempotencyStore {
constructor(
private redis: Redis,
private ttlSeconds: number = 86400 // 24 hours
) {}
async check(key: string): Promise<StoredResponse | null> {
const data = await this.redis.get(`idem:${key}`);
return data ? JSON.parse(data) : null;
}
async lock(key: string): Promise<boolean> {
// Set NX — only succeeds if key does not exist
const result = await this.redis.set(`idem:lock:${key}`, '1', 'EX', 60, 'NX');
return result === 'OK';
}
async store(key: string, response: StoredResponse): Promise<void> {
await this.redis.setex(`idem:${key}`, this.ttlSeconds, JSON.stringify(response));
await this.redis.del(`idem:lock:${key}`);
}
async unlock(key: string): Promise<void> {
await this.redis.del(`idem:lock:${key}`);
}
}
// Express middleware
export function idempotencyMiddleware(store: IdempotencyStore) {
return async (req: Request, res: Response, next: NextFunction) => {
const key = req.headers['idempotency-key'] as string;
if (!key) return next(); // No key = no idempotency protection
// Check for cached response
const cached = await store.check(key);
if (cached) {
Object.entries(cached.headers).forEach(([k, v]) => res.setHeader(k, v));
return res.status(cached.statusCode).json(cached.body);
}
// Acquire lock to prevent concurrent processing
const locked = await store.lock(key);
if (!locked) {
return res.status(409).json({ error: 'Request is being processed' });
}
// Intercept the response to store it
const originalJson = res.json.bind(res);
res.json = (body: unknown) => {
store.store(key, {
statusCode: res.statusCode,
body,
headers: { 'content-type': 'application/json' },
createdAt: Date.now(),
});
return originalJson(body);
};
next();
};
}
// Client-side usage
const idempotencyKey = crypto.randomUUID();
const response = await fetch('/api/payments', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Idempotency-Key': idempotencyKey,
},
body: JSON.stringify({ amount: 1000, currency: 'usd' }),
});
// Safe to retry with the same key — will get the same response
Naturally idempotent operations: GET, PUT, DELETE are idempotent by HTTP semantics. PUT /users/123 { name: "Alice" } always produces the same result. POST is not naturally idempotent — creating a resource twice creates two resources.
Database-level idempotency: Use unique constraints and upserts:
-- Instead of INSERT (which fails on duplicate)
INSERT INTO orders (idempotency_key, user_id, amount)
VALUES ($1, $2, $3)
ON CONFLICT (idempotency_key) DO NOTHING
RETURNING *;
Message deduplication:
async function processMessage(message: QueueMessage): Promise<void> {
const messageId = message.id;
const processed = await redis.set(`msg:${messageId}`, '1', 'EX', 3600, 'NX');
if (!processed) {
console.log(`Duplicate message ${messageId}, skipping`);
return;
}
await handleMessage(message.body);
}
Key generation strategies:
Edge cases:
https://stripe.com/docs/api/idempotent_requests
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub intense-visions/harness-engineering --plugin harness-claudeRead when SKILL.md points to them.
793 skills in this plugin
/a11y-aria-patternsARIA Patterns> Apply ARIA roles, states, and properties correctly to enhance assistive technology support for custom widgets/a11y-color-contrastColor Contrast and Color Independence> Ensure sufficient color contrast ratios and never use color as the sole means of conveying information/a11y-form-patternsAccessible Form Patterns> Build accessible forms with proper labeling, grouped controls, inline validation, and clear error communicationOther plugins' skills for the same job