Token导航 LogoToken导航

Agent Skill · 研究检索

race-conditions(竞争条件)

race-conditions 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

race-conditions 是研究检索类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为需要联网;许可证为 MIT,第三方扫描已通过,按安装量在研究检索类的 73,675 个 Skill 里排第 46,227。

总安装 792周安装 33GitHub Stars 10下载 264核验 2026-05-01

安装说明

本站只整理中文说明,不托管安装包,也不代用户安装。
GitHub
许可证
MIT

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:race-conditions(竞争条件)
来源仓库:https://github.com/yanko-belov/code-craft
仓库路径:skills/race-conditions
安装命令:
npx skills add https://github.com/yanko-belov/code-craft --skill race-conditions
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。不同来源提供的安装方式可能略有差异;本站展示可直接复制的安装命令,安装前请核对来源页面。

skills.shnpx skills
npx skills add https://github.com/yanko-belov/code-craft --skill race-conditions

这个 Skill 是做什么的

研究检索类 Skill 主要解决「找资料、核对事实、把来源整理清楚」的问题,通常会让助手先检索再总结。

用于查找、检索和筛选相关信息,支持基于关键词或任务场景快速定位候选结果。适合在 Codex、Claude、Cursor、Gemini CLI 中需要线索匹配时使用。通过 GitHub 安装,使用 npx skills add 命令添加指定仓库的技能。

安装前需确认权限范围、维护状态,注意是否会触发联网、命令执行或文件读写操作。race-conditions 属于研究检索类 Skill,可作为该场景下的辅助能力补充。

来源仓库内路径:skills/race-conditions

上手步骤

4 步
  1. 1

    确认自己的宿主工具

    公开资料标注支持 Codex、Claude、Cursor、Gemini CLI;先确认自己用的是其中之一,再按对应工具的 Skills 目录放置。

  2. 2

    拿到安装命令

    可以直接复制的命令是 npx skills add https://github.com/yanko-belov/code-craft --skill race-conditions;命令里的占位符换成自己的路径或密钥再执行。

  3. 3

    安装后重启宿主

    命令执行完要完全退出宿主工具再打开,让新装的 Skill 被重新扫描到,否则列表里可能看不到。

  4. 4

    按最小权限试用

    它需要需要联网,先在测试目录或测试账号里跑,确认没问题再放到正式项目。

常见问题

6 条

race-conditions 怎么安装?

在终端执行 npx skills add https://github.com/yanko-belov/code-craft --skill race-conditions。装完完全退出宿主工具再打开,让它重新扫描本地 Skill。

race-conditions 支持哪些 AI 工具?

公开资料标注支持 Codex、Claude、Cursor、Gemini CLI。其他工具只要能读取本地 Skill 目录,一般也能手动放进去,但要自己确认触发方式是否一致。

race-conditions 需要什么权限?

权限级别是需要联网。该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

race-conditions 是免费的吗?

来源标注的许可证是 MIT。本站不代收任何费用,也不托管安装包;能否商用、要不要署名,以许可证原文为准。

race-conditions 用的人多吗?

公开数据是累计安装 792 次,近一周安装 33 次,下载 264 次,GitHub 10 星。这些数字来自第三方目录统计,只能当作热度参考,不代表质量或安全性。

race-conditions 安全吗?

第三方扫描结果为通过,但这只覆盖已知的静态检查项,不能替代自己读一遍源码和安装命令。

值得选的地方和要先想清楚的地方

值得选的地方

  • 同时适配 4 种工具,换客户端不用重新找替代品。
  • 3 个目录同时收录,说明这个 Skill 流传比较广。
  • 许可证明确为 MIT,商用和分发边界好判断。
  • 第三方扫描已通过,常见的高风险行为没有命中。

先想清楚的地方

  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

  • 已经在用 Codex,想直接扩展它能力的人。
  • 需要处理研究检索类任务、又不想每次都手写提示词的人。
  • 需要许可证清楚、并且有第三方扫描结果的团队项目。

不太适合

  • 需要厂商级技术支持和 SLA 的生产系统。

研究检索类 Skill 对比

6 个同类
Skill总安装GitHub 星权限许可证扫描
find-skills

寻找技能 · Codex、Claude

31,199,81316,486操作浏览器MIT有提醒
self-improving-agent

自我改进 Agent · OpenClaw

16,464,0023,396接触敏感数据MIT-0通过
soultrace

灵魂追踪 · Codex、Claude

7,588,94412需要联网未明确有提醒
self-improving

自我完善 · OpenClaw

6,829,2841,046需要联网MIT-0通过
microsoft-foundry

微软代工厂 · Codex、Claude

6,614,144764调用外部服务未明确有提醒
race-conditions

竞争条件 · 本页

79210需要联网MIT通过

按安装量取同分类前几名;数字来自第三方目录统计,只作热度参考,不代表质量结论。

SKILL.md 原文

Race Conditions

Overview

When outcome depends on timing, you have a race. Races are bugs waiting to happen.

Race conditions occur when correctness depends on the relative timing of events. They're insidious because they work most of the time, fail randomly, and are nearly impossible to reproduce.

When to Use

  • Multiple async operations access shared state
  • Database read-then-write patterns
  • Concurrent API requests modify same resource
  • "Works in development, fails in production"
  • Intermittent bugs that can't be reproduced

The Iron Rule

NEVER read-then-write without atomicity guarantees.

No exceptions:

  • Not for "it's fast, timing won't matter"
  • Not for "only one user at a time"
  • Not for "we'll fix it if it breaks"
  • Not for "it works in testing"

If timing can affect outcome, you have a race condition.

Detection: The TOCTOU Pattern

Time-Of-Check to Time-Of-Use: checking something, then acting on it.

// ❌ VIOLATION: Classic race condition
async function withdrawMoney(accountId: string, amount: number): Promise<void> {
  // Time-of-check
  const account = await db.accounts.findById(accountId);
  if (account.balance >= amount) {
    // Time-of-use (gap where another transaction can happen!)
    await db.accounts.update(accountId, {
      balance: account.balance - amount  // Uses stale value!
    });
  }
}

// Two simultaneous $80 withdrawals from $100 account:
// T1: Reads balance = $100 ✓
// T2: Reads balance = $100 ✓  (race!)
// T1: balance >= 80? Yes. Update to $20
// T2: balance >= 80? Yes. Update to $20  (should have been denied!)
// Result: Two $80 withdrawals, final balance $20 (should be overdraft error)

Correct Patterns

1. Atomic Operations

// ✅ CORRECT: Atomic update with condition
async function withdrawMoney(accountId: string, amount: number): Promise<boolean> {
  const result = await db.accounts.updateOne(
    {
      _id: accountId,
      balance: { $gte: amount }  // Check AND update atomically
    },
    {
      $inc: { balance: -amount }
    }
  );

  if (result.modifiedCount === 0) {
    throw new InsufficientFundsError(accountId, amount);
  }

  return true;
}

2. Database Transactions

// ✅ CORRECT: Transaction with proper isolation
async function transferMoney(
  fromId: string,
  toId: string,
  amount: number
): Promise<void> {
  await db.transaction(async (tx) => {
    // Lock rows with FOR UPDATE
    const from = await tx.accounts
      .findById(fromId)
      .forUpdate();  // Locks row until commit

    const to = await tx.accounts
      .findById(toId)
      .forUpdate();

    if (from.balance < amount) {
      throw new InsufficientFundsError(fromId, amount);
    }

    await tx.accounts.update(fromId, { balance: from.balance - amount });
    await tx.accounts.update(toId, { balance: to.balance + amount });

    // Commit releases locks
  });
}

3. Optimistic Locking

// ✅ CORRECT: Optimistic locking with version
async function updateDocument(
  id: string,
  updates: Partial<Document>
): Promise<Document> {
  const maxRetries = 3;

  for (let attempt = 0; attempt < maxRetries; attempt++) {
    const doc = await db.documents.findById(id);

    const result = await db.documents.updateOne(
      {
        _id: id,
        version: doc.version  // Only update if version matches
      },
      {
        $set: updates,
        $inc: { version: 1 }  // Increment version
      }
    );

    if (result.modifiedCount > 0) {
      return { ...doc, ...updates, version: doc.version + 1 };
    }

    // Version mismatch - someone else updated, retry
    await sleep(Math.random() * 100);  // Jitter
  }

  throw new ConcurrentModificationError(id);
}

4. Distributed Locks

// ✅ CORRECT: Distributed lock for complex operations
async function processOrder(orderId: string): Promise<void> {
  const lockKey = `order:${orderId}:lock`;
  const lockTTL = 30000; // 30 seconds

  const lock = await redis.acquireLock(lockKey, lockTTL);
  if (!lock) {
    throw new OrderAlreadyProcessingError(orderId);
  }

  try {
    // Safe - only one process can be here for this order
    await doExpensiveOrderProcessing(orderId);
  } finally {
    await redis.releaseLock(lockKey, lock);
  }
}

5. Idempotency Keys

// ✅ CORRECT: Idempotency prevents duplicate processing
async function createPayment(
  idempotencyKey: string,
  data: PaymentData
): Promise<Payment> {
  // Check if already processed
  const existing = await db.payments.findByIdempotencyKey(idempotencyKey);
  if (existing) {
    return existing;  // Return previous result
  }

  // Try to claim the idempotency key atomically
  try {
    await db.idempotencyKeys.insert({
      key: idempotencyKey,
      status: 'processing',
      createdAt: new Date(),
    });
  } catch (error) {
    if (isDuplicateKeyError(error)) {
      // Another request claimed it - fetch and return
      const existing = await db.payments.findByIdempotencyKey(idempotencyKey);
      if (existing) return existing;
      throw new PaymentProcessingError('Payment in progress');
    }
    throw error;
  }

  // Safe to process - we own the idempotency key
  const payment = await processPayment(data);

  await db.idempotencyKeys.update(idempotencyKey, {
    status: 'completed',
    result: payment.id,
  });

  return payment;
}

Common Race Condition Patterns

PatternProblemSolution
Check-then-actState changes between check and actAtomic check-and-act
Read-modify-writeValue changes after readAtomic update or lock
Lazy initializationMultiple threads initializeDouble-checked locking or atomic init
Counter incrementLost updatesAtomic increment
First-one-winsMultiple claim "first"Atomic claim with unique constraint

Language-Specific Patterns

JavaScript/Node.js

// ❌ VIOLATION: Shared state in closure
let requestCount = 0;
async function handleRequest() {
  requestCount++;  // Race! Read-modify-write is NOT atomic
  // ...
}

// ✅ CORRECT: Atomic counter
import { createClient } from 'redis';
const redis = createClient();

async function handleRequest() {
  const count = await redis.incr('request_count');  // Atomic
  // ...
}

Python

# ❌ VIOLATION: Check-then-act
def get_or_create(key: str, factory: Callable) -> Any:
    if key not in cache:  # Check
        cache[key] = factory()  # Act - race!
    return cache[key]

# ✅ CORRECT: Atomic with lock
from threading import Lock
lock = Lock()

def get_or_create(key: str, factory: Callable) -> Any:
    with lock:
        if key not in cache:
            cache[key] = factory()
        return cache[key]

Pressure Resistance Protocol

1. "It's Fast, Timing Won't Matter"

Pressure: "The operation takes microseconds"

Response: Production load creates overlap. Under load, "fast" operations overlap frequently. Race conditions scale with traffic.

Action: Use atomic operations. Speed doesn't prevent races.

2. "Only One User at a Time"

Pressure: "Low traffic, won't have concurrent requests"

Response: Users double-click. Tabs refresh. Bots hammer. Mobile retries on timeout. "Low traffic" has bursts.

Action: Design for concurrency even if you don't expect it.

3. "We'll Fix It If It Breaks"

Pressure: "Ship now, fix later"

Response: Race conditions are nearly impossible to reproduce. You'll spend weeks debugging "random" failures.

Action: Build it correctly now. Cheaper than debugging later.

4. "It Works in Testing"

Pressure: "All tests pass"

Response: Tests run sequentially. Production runs concurrently. Race conditions hide in serial execution.

Action: Write concurrent tests. Load test. Assume races exist.

Red Flags - STOP and Reconsider

If you notice ANY of these patterns, you likely have a race:

  • if (condition) {update based on condition}
  • read(); compute(); write(computed);
  • check availability; book;
  • get count; increment; save count;
  • Global or shared mutable state
  • "Works most of the time"
  • "Can't reproduce in development"
  • Timeouts that "fix" intermittent bugs

All of these mean: Add atomicity guarantees.

Testing for Race Conditions

// Concurrent test to expose races
describe('withdraw', () => {
  it('handles concurrent withdrawals correctly', async () => {
    await db.accounts.create({ id: 'test', balance: 100 });

    // Simulate 10 concurrent $20 withdrawals
    const withdrawals = Array(10).fill(null).map(() =>
      withdrawMoney('test', 20).catch(() => 'failed')
    );

    const results = await Promise.all(withdrawals);
    const successful = results.filter(r => r !== 'failed').length;

    // Only 5 should succeed (5 × $20 = $100)
    expect(successful).toBe(5);

    const account = await db.accounts.findById('test');
    expect(account.balance).toBe(0);
  });
});

Common Rationalizations (All Invalid)

ExcuseReality
"It's fast enough"Fast operations still overlap under load.
"Low traffic"Retries, double-clicks, bots create concurrency.
"Works in dev"Dev is serial. Prod is parallel.
"Fix when it breaks"Race bugs are unfindable. Fix now.
"Just add a sleep"Sleeps don't fix races, just hide them.
"Users won't do that"Users do everything you don't expect.

Quick Reference

ScenarioSolution
Balance check before updateAtomic conditional update
Increment counterAtomic increment (Redis INCR, SQL += 1)
Complex multi-step operationDatabase transaction with locks
Cross-service operationDistributed lock
Duplicate request preventionIdempotency key
Version conflictsOptimistic locking

The Bottom Line

If correctness depends on timing, you have a bug.

Read-then-write is a race. Check-then-act is a race. Any gap between observing state and acting on it is a race. Use atomic operations, transactions, locks, or idempotency keys. Never assume "it's fast enough" or "traffic is low."

平台分布

Codex

29.59%
按下载量换算78

Claude Code

23.67%
按下载量换算62

windsurf

15.81%
按下载量换算42

Antigravity

11.44%
按下载量换算30

trae

8.24%
按下载量换算22

OpenCode

3.5%
按下载量换算9

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。

继续浏览同类 Skills