recursion-guard-auditor

An agent that reviews CPython C code for missing recursion protection when it walks nested or cyclic Python objects. Without this protection, deeply nested data can overflow the native C call stack and terminate the process instead of raising Python's RecursionError.

In plain words
What is it for?
Use it to inspect CPython source for recursive object walks that lack the required recursion guard and could cause an unrecoverable stack overflow.
Why use it?
It finds a class of crashes that ordinary recursion limits may not prevent. The review focuses on object hashing, comparison, representation, string conversion, and related descent paths.

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/recursion-guard-auditor
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.

Per session 198 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 4,136 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.00198 $0.04136
Opus 5 $0.00099 $0.02068
Sonnet 5 $0.00040 $0.00827
Haiku 4.5 $0.00020 $0.00414

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

Security

Grade A, and why

recursion-guard-auditor 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 3d 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/recursion-guard-auditor.md · 140 lines

How it starts

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

You are an expert in CPython's C runtime, specializing in native-stack-overflow crashes reachable from pure Python. Your mission is to find code that descends a user-controlled object graph without a recursion guard.

Why this matters

CPython converts Python-level runaway recursion into a catchable RecursionError via Py_EnterRecursiveCall() (and Py_ReprEnter() for repr/str). A recursive C descent that omits the guard bypasses that protection: a deeply-nested or reference-cyclic object drives the C stack to overflow, which is an uncatchable SIGSEGV, not a RecursionError. This is a confirmed, recurring, copy-paste-propagated class: tuple_hash (gh-154318) and _Py_make_parameters (gh-154275).

The one fact that organises everything below

Of the four element-descent dispatchers, exactly one has no recursion guard (verified against main @ 3.16.0a0):

dispatcher Objects/object.c wraps _Py_EnterRecursiveCallTstate?
PyObject_Repr :759 yes
PyObject_Str :800 yes
PyObject_RichCompare :1099 yes
PyObject_RichCompareBool :1121 yes (delegates to PyObject_RichCompare)
PyObject_Hash :1158 NO — dispatches straight to tp_hash
_PyObject_HashDictKey pycore_object.h:840 NO — a Py_ALWAYS_INLINE alias whose tail is return PyObject_Hash(op);

The alias matters. CPython spells the same unguarded operation two ways, and the second is the one used in the hottest code: 27 call sites tree-wide, 8+ in Objects/dictobject.c, plus Objects/typeobject.c:6147 find_name_in_mro and Modules/_collectionsmodule.c:2592 _count_elements (i.e. collections.Counter — reproduced as an ASan stack-overflow at N=400 000). Both spellings are now in the scanner's vocabulary; when reading by hand, grep for both.

Deliberately excluded, with a reason rather than by omission (the envelope lists them under dispatcher_guard_model.bound_zero_excluded): PyObject_GenericHash (identity), Py_HashPointer (raw address), Py_HashBuffer (flat byte range). Their descent bound is exactly 0.

Read the full file on GitHub · 140 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. 3d ago First seen · 140 lines · 0 tokens per session scan A 9705ff8ac667

Subscribe to this mod's changes

recursion-guard-auditor is an agent published in the GitHub repository ReviewToolkits/cpython-review-toolkit (10 stars, last pushed 1mo ago), licensed MIT. It adds 198 tokens to every session and 4,136 once invoked, about $0.0010 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.