[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M79AAQW23BHDN0B5B7K8XTWS":3,"skill-same:01M79AAQW23BHDN0B5B7K8XTWS":44},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":14,"repositoryHtmlUrl":27,"repositoryHomepageUrl":6,"ownerHtmlUrl":28,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":29,"install":30,"resources":43},"01M79AAQW23BHDN0B5B7K8XTWS","idempotency-handling",null,"Idempotent API operations with idempotency keys, Redis caching, DB constraints. Use for payment systems, webhook retries, safe retries, or encountering duplicate processing, race conditions, key expiry errors.","Elogic360\u002Fsoftware-factory","Elogic360","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F156535519?v=4","01M74NH3F0RB13PWB7JZDE2V80","elogic360","01M74NH3FPC65082MDZVMFHDM3",0,"MIT","https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory\u002Fblob\u002Fmain\u002Fintegrations\u002Fclaude-skills-secondsky\u002Fplugins\u002Fidempotency-handling\u002Fskills\u002Fidempotency-handling\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: idempotency-handling\ndescription: Idempotent API operations with idempotency keys, Redis caching, DB constraints. Use for payment systems, webhook retries, safe retries, or encountering duplicate processing, race conditions, key expiry errors.\nlicense: MIT\n---\n\n# Idempotency Handling\n\nEnsure operations produce identical results regardless of execution count.\n\n## Idempotency Key Pattern\n\n```javascript\nconst redis = require('redis');\nconst client = redis.createClient();\n\nasync function idempotencyMiddleware(req, res, next) {\n  const key = req.headers['idempotency-key'];\n  if (!key) return next();\n\n  const cached = await client.get(`idempotency:${key}`);\n  if (cached) {\n    const { status, body } = JSON.parse(cached);\n    return res.status(status).json(body);\n  }\n\n  \u002F\u002F Store original send\n  const originalSend = res.json.bind(res);\n  res.json = async (body) => {\n    await client.setEx(\n      `idempotency:${key}`,\n      86400, \u002F\u002F 24 hours\n      JSON.stringify({ status: res.statusCode, body })\n    );\n    return originalSend(body);\n  };\n\n  next();\n}\n```\n\n## Database-Backed Idempotency\n\n```sql\nCREATE TABLE idempotency_keys (\n  key VARCHAR(255) PRIMARY KEY,\n  request_hash VARCHAR(64) NOT NULL,\n  response JSONB,\n  status VARCHAR(20) DEFAULT 'processing',\n  created_at TIMESTAMP DEFAULT NOW(),\n  expires_at TIMESTAMP DEFAULT NOW() + INTERVAL '24 hours'\n);\n\nCREATE INDEX idx_idempotency_expires ON idempotency_keys(expires_at);\n```\n\n```javascript\nasync function processPayment(idempotencyKey, payload) {\n  const requestHash = crypto.createHash('sha256')\n    .update(JSON.stringify(payload)).digest('hex');\n\n  \u002F\u002F Try to insert with 'processing' status - only one request will succeed\n  const insertResult = await db.query(\n    `INSERT INTO idempotency_keys (key, request_hash, status)\n     VALUES ($1, $2, 'processing')\n     ON CONFLICT (key) DO NOTHING\n     RETURNING *`,\n    [idempotencyKey, requestHash]\n  );\n\n  \u002F\u002F If we inserted the row (rowCount === 1), we're responsible for processing\n  if (insertResult.rowCount === 1) {\n    try {\n      \u002F\u002F Execute the payment\n      const result = await executePayment(payload);\n\n      \u002F\u002F Update to completed with response\n      await db.query(\n        'UPDATE idempotency_keys SET status = $1, response = $2 WHERE key = $3',\n        ['completed', JSON.stringify(result), idempotencyKey]\n      );\n\n      return result;\n    } catch (error) {\n      \u002F\u002F Mark as failed on error\n      await db.query(\n        'UPDATE idempotency_keys SET status = $1, response = $2 WHERE key = $3',\n        ['failed', JSON.stringify({ error: error.message }), idempotencyKey]\n      );\n      throw error;\n    }\n  }\n\n  \u002F\u002F Another request is\u002Fwas processing this key - check status\n  const existing = await db.query(\n    'SELECT * FROM idempotency_keys WHERE key = $1',\n    [idempotencyKey]\n  );\n\n  const row = existing.rows[0];\n  if (!row) {\n    throw new Error('Unexpected: idempotency key vanished');\n  }\n\n  \u002F\u002F Verify request hasn't changed\n  if (row.request_hash !== requestHash) {\n    throw new Error('Idempotency key reused with different request');\n  }\n\n  \u002F\u002F Check status\n  if (row.status === 'completed') {\n    return JSON.parse(row.response);\n  } else if (row.status === 'processing') {\n    throw new Error('Request already processing - retry later');\n  } else if (row.status === 'failed') {\n    const failedResponse = JSON.parse(row.response);\n    throw new Error(`Previous attempt failed: ${failedResponse.error}`);\n  }\n\n  throw new Error(`Unknown status: ${row.status}`);\n}\n```\n\n## When to Apply\n\n- Payment processing\n- Order creation\n- Webhook handling\n- Email sending\n- Any operation where duplicates cause issues\n\n## Best Practices\n\n- Require idempotency keys for mutations\n- Validate request body matches stored request\n- Set appropriate TTL (24 hours typical)\n- Use atomic database operations\n- Implement cleanup jobs to prevent table bloat\n\n### TTL Cleanup Strategy\n\nTo prevent unbounded table growth, implement periodic cleanup of expired keys:\n\n**Option 1: Scheduled Database Job (PostgreSQL)**\n```sql\n-- Run hourly via pg_cron or external scheduler\nDELETE FROM idempotency_keys\nWHERE expires_at \u003C NOW()\nLIMIT 1000; -- Batch delete to avoid long locks\n```\n\n**Option 2: Application Cleanup Job (Node.js)**\n```javascript\n\u002F\u002F Run via cron or job scheduler (e.g., node-cron, Bull)\nasync function cleanupExpiredKeys() {\n  try {\n    const result = await db.query(\n      'DELETE FROM idempotency_keys WHERE expires_at \u003C NOW()'\n    );\n    console.log(`Cleaned up ${result.rowCount} expired idempotency keys`);\n  } catch (error) {\n    console.error('Cleanup job failed:', error);\n  }\n}\n\n\u002F\u002F Schedule to run every hour\ncron.schedule('0 * * * *', cleanupExpiredKeys);\n```\n\n**Option 3: Application Cleanup Job (Python)**\n```python\nimport asyncio\nfrom datetime import datetime\n\nasync def cleanup_expired_keys():\n    \"\"\"Remove expired idempotency keys to prevent table bloat.\"\"\"\n    try:\n        result = await db.execute(\n            \"DELETE FROM idempotency_keys WHERE expires_at \u003C $1\",\n            datetime.now()\n        )\n        print(f\"Cleaned up {result} expired idempotency keys\")\n    except Exception as e:\n        print(f\"Cleanup job failed: {e}\")\n\n# Run with APScheduler, Celery, or similar\n# scheduler.add_job(cleanup_expired_keys, 'interval', hours=1)\n```\n\n**Cleanup Best Practices:**\n- Run cleanup during low-traffic periods to minimize lock contention\n- Use batched deletes (`LIMIT 1000`) for large tables\n- Monitor cleanup job execution and failures\n- Consider partitioning the table by created_at for easier cleanup\n- Set up alerts if table size grows unexpectedly\n","# Idempotency Handling\n\nEnsure operations produce identical results regardless of execution count.\n\n## Idempotency Key Pattern\n\n```javascript\nconst redis = require('redis');\nconst client = redis.createClient();\n\nasync function idempotencyMiddleware(req, res, next) {\n  const key = req.headers['idempotency-key'];\n  if (!key) return next();\n\n  const cached = await client.get(`idempotency:${key}`);\n  if (cached) {\n    const { status, body } = JSON.parse(cached);\n    return res.status(status).json(body);\n  }\n\n  \u002F\u002F Store original send\n  const originalSend = res.json.bind(res);\n  res.json = async (body) => {\n    await client.setEx(\n      `idempotency:${key}`,\n      86400, \u002F\u002F 24 hours\n      JSON.stringify({ status: res.statusCode, body })\n    );\n    return originalSend(body);\n  };\n\n  next();\n}\n```\n\n## Database-Backed Idempotency\n\n```sql\nCREATE TABLE idempotency_keys (\n  key VARCHAR(255) PRIMARY KEY,\n  request_hash VARCHAR(64) NOT NULL,\n  response JSONB,\n  status VARCHAR(20) DEFAULT 'processing',\n  created_at TIMESTAMP DEFAULT NOW(),\n  expires_at TIMESTAMP DEFAULT NOW() + INTERVAL '24 hours'\n);\n\nCREATE INDEX idx_idempotency_expires ON idempotency_keys(expires_at);\n```\n\n```javascript\nasync function processPayment(idempotencyKey, payload) {\n  const requestHash = crypto.createHash('sha256')\n    .update(JSON.stringify(payload)).digest('hex');\n\n  \u002F\u002F Try to insert with 'processing' status - only one request will succeed\n  const insertResult = await db.query(\n    `INSERT INTO idempotency_keys (key, request_hash, status)\n     VALUES ($1, $2, 'processing')\n     ON CONFLICT (key) DO NOTHING\n     RETURNING *`,\n    [idempotencyKey, requestHash]\n  );\n\n  \u002F\u002F If we inserted the row (rowCount === 1), we're responsible for processing\n  if (insertResult.rowCount === 1) {\n    try {\n      \u002F\u002F Execute the payment\n      const result = await executePayment(payload);\n\n      \u002F\u002F Update to completed with response\n      await db.query(\n        'UPDATE idempotency_keys SET status = $1, response = $2 WHERE key = $3',\n        ['completed', JSON.stringify(result), idempotencyKey]\n      );\n\n      return result;\n    } catch (error) {\n      \u002F\u002F Mark as failed on error\n      await db.query(\n        'UPDATE idempotency_keys SET status = $1, response = $2 WHERE key = $3',\n        ['failed', JSON.stringify({ error: error.message }), idempotencyKey]\n      );\n      throw error;\n    }\n  }\n\n  \u002F\u002F Another request is\u002Fwas processing this key - check status\n  const existing = await db.query(\n    'SELECT * FROM idempotency_keys WHERE key = $1',\n    [idempotencyKey]\n  );\n\n  const row = existing.rows[0];\n  if (!row) {\n    throw new Error('Unexpected: idempotency key vanished');\n  }\n\n  \u002F\u002F Verify request hasn't changed\n  if (row.request_hash !== requestHash) {\n    throw new Error('Idempotency key reused with different request');\n  }\n\n  \u002F\u002F Check status\n  if (row.status === 'completed') {\n    return JSON.parse(row.response);\n  } else if (row.status === 'processing') {\n    throw new Error('Request already processing - retry later');\n  } else if (row.status === 'failed') {\n    const failedResponse = JSON.parse(row.response);\n    throw new Error(`Previous attempt failed: ${failedResponse.error}`);\n  }\n\n  throw new Error(`Unknown status: ${row.status}`);\n}\n```\n\n## When to Apply\n\n- Payment processing\n- Order creation\n- Webhook handling\n- Email sending\n- Any operation where duplicates cause issues\n\n## Best Practices\n\n- Require idempotency keys for mutations\n- Validate request body matches stored request\n- Set appropriate TTL (24 hours typical)\n- Use atomic database operations\n- Implement cleanup jobs to prevent table bloat\n\n### TTL Cleanup Strategy\n\nTo prevent unbounded table growth, implement periodic cleanup of expired keys:\n\n**Option 1: Scheduled Database Job (PostgreSQL)**\n```sql\n-- Run hourly via pg_cron or external scheduler\nDELETE FROM idempotency_keys\nWHERE expires_at \u003C NOW()\nLIMIT 1000; -- Batch delete to avoid long locks\n```\n\n**Option 2: Application Cleanup Job (Node.js)**\n```javascript\n\u002F\u002F Run via cron or job scheduler (e.g., node-cron, Bull)\nasync function cleanupExpiredKeys() {\n  try {\n    const result = await db.query(\n      'DELETE FROM idempotency_keys WHERE expires_at \u003C NOW()'\n    );\n    console.log(`Cleaned up ${result.rowCount} expired idempotency keys`);\n  } catch (error) {\n    console.error('Cleanup job failed:', error);\n  }\n}\n\n\u002F\u002F Schedule to run every hour\ncron.schedule('0 * * * *', cleanupExpiredKeys);\n```\n\n**Option 3: Application Cleanup Job (Python)**\n```python\nimport asyncio\nfrom datetime import datetime\n\nasync def cleanup_expired_keys():\n    \"\"\"Remove expired idempotency keys to prevent table bloat.\"\"\"\n    try:\n        result = await db.execute(\n            \"DELETE FROM idempotency_keys WHERE expires_at \u003C $1\",\n            datetime.now()\n        )\n        print(f\"Cleaned up {result} expired idempotency keys\")\n    except Exception as e:\n        print(f\"Cleanup job failed: {e}\")\n\n# Run with APScheduler, Celery, or similar\n# scheduler.add_job(cleanup_expired_keys, 'interval', hours=1)\n```\n\n**Cleanup Best Practices:**\n- Run cleanup during low-traffic periods to minimize lock contention\n- Use batched deletes (`LIMIT 1000`) for large tables\n- Monitor cleanup job execution and failures\n- Consider partitioning the table by created_at for easier cleanup\n- Set up alerts if table size grows unexpectedly\n",{"name":5,"license":15,"description":7},"main","c475fc64e94e803b50d14a791dfee8853fbb2c5c","integrations\u002Fclaude-skills-secondsky\u002Fplugins\u002Fidempotency-handling\u002Fskills\u002Fidempotency-handling","https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory","https:\u002F\u002Fgithub.com\u002FElogic360","2026-11-08 22:21:22",{"source":8,"skillName":5,"commands":31,"prompt":41,"zipAvailable":42},[32,35,38],{"tool":33,"command":34},"npx","npx skills add Elogic360\u002Fsoftware-factory --skill idempotency-handling",{"tool":36,"command":37},"bunx","bunx skills add Elogic360\u002Fsoftware-factory --skill idempotency-handling",{"tool":39,"command":40},"pnpm","pnpm dlx skills add Elogic360\u002Fsoftware-factory --skill idempotency-handling","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory\u002Fblob\u002Fmain\u002Fintegrations\u002Fclaude-skills-secondsky\u002Fplugins\u002Fidempotency-handling\u002Fskills\u002Fidempotency-handling\u002FSKILL.md",true,[],[45,53,60,67,74,81],{"skillNo":46,"name":47,"nameZh":6,"description":48,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":49,"licenseFileUrl":6,"sourceHtmlUrl":50,"categories":51,"keywords":52,"publishedAt":19},"01M79G206MT3J6S0GY3C45P2KV","vss-summarize-video","Use to summarize a recorded video via the LVS summarization microservice (HITL-gated) with a VLM fallback. Not for report generation or live RTSP captioning.","Apache-2.0","https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fvss-summarize-video\u002FSKILL.md",[],[],{"skillNo":54,"name":55,"nameZh":6,"description":56,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":49,"licenseFileUrl":6,"sourceHtmlUrl":57,"categories":58,"keywords":59,"publishedAt":19},"01M79G1WN63PGRE8CKD47WEBQ5","vss-setup-video-analytics-api","Use to deploy the vss-video-analytics-api REST service standalone (config-source, data-log bind, Elasticsearch, optional Kafka). Not for full warehouse deploy.","https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fvss-setup-video-analytics-api\u002FSKILL.md",[],[],{"skillNo":61,"name":62,"nameZh":6,"description":63,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":49,"licenseFileUrl":6,"sourceHtmlUrl":64,"categories":65,"keywords":66,"publishedAt":19},"01M79G1S9F7VY3EF6H53PRP5AN","vss-setup-behavior-analytics","Use to deploy the vss-behavior-analytics service standalone (entrypoint, config-source, optional calibration). Not for the full warehouse deploy.","https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fvss-setup-behavior-analytics\u002FSKILL.md",[],[],{"skillNo":68,"name":69,"nameZh":6,"description":70,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":49,"licenseFileUrl":6,"sourceHtmlUrl":71,"categories":72,"keywords":73,"publishedAt":19},"01M79G1N1S1Y27PFZPYMNK1MTQ","vss-search-archive","Use this skill to run top-level VSS fusion search on archived video, or to ingest video files \u002F RTSP streams for search. Do NOT use for ad-hoc visual Q&A (use vss-ask-video), live captioning (use vss-deploy-dense-captioning), or video summarization and reports (use vss-summarize-video).","https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fvss-search-archive\u002FSKILL.md",[],[],{"skillNo":75,"name":76,"nameZh":6,"description":77,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":49,"licenseFileUrl":6,"sourceHtmlUrl":78,"categories":79,"keywords":80,"publishedAt":19},"01M79G1H6WN0Q6C0VCAXCZX6B7","vss-query-analytics","Use this skill when reading video-analytics metrics, incidents, alerts, and sensor data via the VA-MCP server (port 9901). Not for live VLM or incident-range narrative reports.","https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fvss-query-analytics\u002FSKILL.md",[],[],{"skillNo":82,"name":83,"nameZh":6,"description":84,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":49,"licenseFileUrl":6,"sourceHtmlUrl":85,"categories":86,"keywords":87,"publishedAt":19},"01M79G1DYPNXQS7QHZ0AAF5FX5","vss-manage-video-io-storage","Use to call the VIOS REST API (sensor list, timelines, clip extraction, snapshots, add\u002Fdelete sensors and streams). Not for VLM inference or search.","https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fvss-manage-video-io-storage\u002FSKILL.md",[],[]]