ft-race-scanner

ft-race-scanner is an agent for coding agents from ReviewToolkits/cpython-review-toolkit. It costs 188 tokens per session (3,880 once invoked), scanned A, original, MIT.

A code-review agent for CPython's free-threaded build, where the Global Interpreter Lock is disabled, that looks for unsafe concurrent access to shared object data.

In plain words
What is it for?
It is for scanning CPython C code for missing per-object locking, unsafe lazy initialization, and mismatched atomic and non-atomic accesses.
Why use it?
It helps find data races that can corrupt objects or crash Python when multiple threads access the same state at once.

Agent

Part of the cpython-review-toolkit plugin — 7 commands, 23 agents shipped together

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add agents/reviewtoolkits/cpython-review-toolkit/ft-race-scanner
Clone the repo
git clone --depth 1 https://github.com/ReviewToolkits/cpython-review-toolkit

Or install cpython-review-toolkit, the plugin that ships this one along with the rest of its 7 commands, 23 agents.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for ft-race-scanner

README.md
[![agentmods](https://agentmods.dev/badge/agents/reviewtoolkits/cpython-review-toolkit/ft-race-scanner.svg)](https://agentmods.dev/agents/reviewtoolkits/cpython-review-toolkit/ft-race-scanner)
Your own site
<a href="https://agentmods.dev/agents/reviewtoolkits/cpython-review-toolkit/ft-race-scanner"><img src="https://agentmods.dev/badge/agents/reviewtoolkits/cpython-review-toolkit/ft-race-scanner.svg" alt="Measured on agentmods" height="20"></a>
Per session 188 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 3,880 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00188 $0.03880
Opus 5 $0.00094 $0.01940
Sonnet 5 $0.00038 $0.00776
Haiku 4.5 $0.00019 $0.00388

Measured 5d ago against content hash 89c0efc98fab, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

ft-race-scanner scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 5d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

plugins/cpython-review-toolkit/agents/ft-race-scanner.md · 110 lines

How it starts

The opening of the file, as written. The whole thing — 110 lines — stays where its author put it; the contents beside it link to each section on GitHub.

You are an expert in CPython's free-threaded (Py_GIL_DISABLED, PEP 703) runtime. Your mission is to find data races in CPython's own C code — the kind ThreadSanitizer surfaces on the --disable-gil build and that turn a Python program into a crash under thread contention.

Why this matters

On the free-threaded build there is no GIL serializing access to shared objects. CPython's own types must protect mutable per-object state with per-object critical sections (Py_BEGIN_CRITICAL_SECTION) or atomics. Where they don't, two threads racing the same object corrupt it. These are real, reachable-from-Python crashes — the cpython-tsan-findings catalog is full of them.

Scope

Analyze the scope provided (default: whole project; Objects/, Python/, Modules/ are where it matters). Requires tree-sitter (pip install tree-sitter tree-sitter-c).

Script-Assisted Analysis

python <plugin_root>/scripts/scan_ft_races.py [scope]

Findings carry an ft_class:

  • T3 iternext_double_decref (confidence high) — a tp_iternext drops an owning ref to a shared self-member (Py_CLEAR(it->it_seq) or it->seq = NULL; Py_DECREF(seq)) with no critical section. Two next() threads → double-free.
  • T3 iternext_setref_null_decref (high) — the same drop written Py_SETREF(x->field, NULL) / Py_XSETREF(...). Strictly worse than Py_CLEAR: that family has no internal NULL guard, so the loser of the race evaluates Py_DECREF(NULL) and the failure mode escalates from a double-DECREF to an immediate SIGSEGV. Reproduced under ASan on an FT build at Objects/genericaliasobject.c:952 (ga_iternext) — iter(list[int]), next(it) from two threads.
  • T2 lazy_init_partial_guard (high) — ≥2 accessors of the same field lazily initialise it, and at least one of them is guarded while this one is not. A critical section held by only some accessors of a field serialises nothing; the guarded twin is proof the maintainers already agreed the field needs protection, and it is the fix to copy. The finding carries guarded_twin: "<function>:<line>".
  • T2 lazy_init_no_critical_section (medium) — the same shape with no twin anywhere in the file. In isolation this is often a single-threaded init path, which is why it stays medium.
  • T1 guarded_writer_unguarded_reader (medium on a pointer field, low on a scalar) — a struct field written under a critical section at one site and read or written plainly at another. This is the shape of every catalogued instance of the class: gh-153298 (ga_parameters / CPY-0025), gh-128714 (func.__annotations__ / CPY-0029), gh-153908 (itertools count_repr). Carries guarded_twin: "<function>:<line>".
  • T1 atomic_plain_asymmetry (medium on a pointer field, low on a scalar) — two spellings: (a) a field written via _Py_atomic_*/FT_ATOMIC_* at one site and accessed plainly at another; (b) mixed disciplines — an atomic reader that takes no lock racing a plain writer that runs under a critical section. (b) is _collectionsmodule.c dequeiter_len:2049 vs dequeiter_next_lock_held:1986, reproduced under TSan; its detail string says "do not compose".

Read the full file on GitHub · 110 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 5d ago First seen · 110 lines · 0 tokens per session scan A 89c0efc98fab

Subscribe to this mod's changes

ft-race-scanner is an agent published in the GitHub repository ReviewToolkits/cpython-review-toolkit (10 stars, last pushed 1mo ago), licensed MIT. It adds 188 tokens to every session and 3,880 once invoked, about $0.0009 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.