reliability-and-state-integrity

Implements transactions, idempotency, execution guards, and expiry handling for server-side stateful operations.

Updated Dec 24, 2025
One-click install
npx skills add https://github.com/JoyJoin-Tech-Limited/JoyJoin_app_v0.1 --skill reliability-and-state-integrity-joyjoin-tech-limited
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: reliability-and-state-integrity
Source: https://github.com/JoyJoin-Tech-Limited/JoyJoin_app_v0.1/tree/main/.github/skills/reliability-and-state-integrity
Command: npx skills add https://github.com/JoyJoin-Tech-Limited/JoyJoin_app_v0.1 --skill reliability-and-state-integrity-joyjoin-tech-limited

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Multi-step server operations like payments, pool matching, and session creation can silently corrupt data when retries, crashes, or duplicate webhooks occur. This Skill provides patterns to keep critical writes atomic, make retried operations idempotent, and keep side effects out of transactions. ## Core Features & Use Cases - Atomic Transactions: Wrap critical multi-table writes in db.transaction() and move notifications, AI calls, and analytics outside the commit boundary. - Idempotency & Re-entry: Use existence checks and unique constraints so retried payments, pool joins, and session creations return existing results instead of duplicating work. - Execution Guards & Expiry: Acquire and release concurrency guards in finally blocks, and enforce expiry with server-side timestamps on every read. - Use Case: When a WeChat Pay webhook fires twice, add an existence check for the confirmed payment inside a transaction so the duplicate delivery returns 200 without re-running charge logic. ## Quick Start Ask the assistant to review your payment or session flow and make it idempotent with a transaction boundary and side effects after commit.

Frequently Asked Questions about reliability-and-state-integrity

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I make a payment webhook idempotent?▼

Add an existence check for the confirmed payment record inside a database transaction before processing. If the payment is already confirmed, return 200 without re-running charge logic, so duplicate webhook deliveries are safely ignored.

How do I wrap multi-table writes in a database transaction?▼

Use db.transaction with an async callback containing all critical inserts and updates, so any failure rolls back the entire write. Keep notifications, AI calls, and analytics outside the transaction body so side effects only run after commit.

Why do duplicate rows appear after a client retry?▼

The operation is not idempotent. Add a UNIQUE constraint on the natural key, such as userId plus poolId, and check for an existing record before inserting within the transaction so retries return the original result.

What happens if an execution guard gets stuck after a crash?▼

A guard left at isRunning true blocks future runs. Always release the guard in a finally block and add a timeout-based stale guard reset so crash recovery can clear it automatically.

Should expiry be checked on read or by a background sweep?▼

Check expiry on every read using a server-side Date.now comparison against the expiry timestamp. A sweep is only cleanup; read-time enforcement prevents users from seeing expired state as valid when the sweep is delayed.

When should side effects like notifications run relative to a transaction?▼

Side effects must run after the transaction commits, never inside it. Commit the critical write first, then send notifications or AI enrichment, and treat failed side effects as best-effort so they never roll back committed data.