code-audit-fanout
When to use
USE for any code review request where correctness matters more than
speed. Especially:
- ML training loops, loss functions, custom layers
- Signal-processing pipelines (FFT, filters, modulation)
- 5G PHY simulators (channel models, MIMO precoding, decoders)
- Any function touching complex-valued tensors, dB scales, or
hardware-determinism primitives
- Diffs > 50 lines before merge
SKIP for trivial edits (typo fix, rename, formatting).
The 5 specialist agents
Each spawned in parallel in ONE assistant message. Each has a
narrow scope, a required source list, and a citation contract.
Specialist 1 — static-analyzer
Scope: Read-only static analysis.
Tools: Read, Grep, Glob, Bash
Checks:
ruff check --select ALL output
mypy --strict output (if config present, else mypy)
pyright if available
- Function-level cyclomatic complexity > 10
- Bare
except:, except Exception:, swallowed errors
- Mutable default args
- Print statements left in code (vs logging)
Citation requirement: every flagged rule must reference the
exact ruff / mypy / pyright rule ID and link to the rule docs.
Specialist 2 — library-api-auditor
Scope: Verify every imported API call against official docs.
Tools: Read, Grep, WebFetch, WebSearch
Required sources (in order of precedence):
- Extract every imported symbol and every
X.Y.Z(...) call.
- For each, WebFetch the official doc page.
- Check: function exists? signature matches? deprecated? known
gotchas in the docs (the "Note" / "Warning" boxes)?
- Flag mismatches with: file:line — call — expected signature
per docs URL — quoted doc passage.
Citation requirement: every finding cites the exact doc URL
- section anchor + a verbatim quote.
HARD RULE: if a fetch fails or the page doesn't mention the
symbol, mark UNVERIFIED. Do NOT guess.
Specialist 3 — standards-spec-auditor
Scope: For wireless / signal-processing code only. Verify the
code's constants and procedures against published standards.
Tools: Read, WebFetch, WebSearch
Required sources:
- 3GPP TS portal — https://www.3gpp.org/specifications-technologies
- ETSI standards — https://www.etsi.org/standards
- IEEE Xplore (citation only — no full-text fetch unless user
provides access)
- IETF RFCs — https://www.rfc-editor.org/
- ITU-R recommendations — https://www.itu.int/rec/R-REC/en
Checks:
- Numerology constants (subcarrier spacing 15/30/60/120/240/480 kHz)
- Resource grid dimensions (PRB = 12 subcarriers, slot = 14 symbols)
- LDPC base graph selection thresholds (TS 38.212)
- Modulation mapping tables (TS 38.211 §5.1)
- Channel-model parameters (TR 38.901 tables)
- TBS / MCS index tables (TS 38.214)
Citation requirement: every numeric constant or procedure
verified must cite TS/TR number + clause + table + quoted line.
HARD RULE: if the user's code is not wireless, this specialist
returns "NOT APPLICABLE" and does not invent issues.
Specialist 4 — reproducibility-auditor
Scope: Ensure the code will produce the same result on a
second run.
Tools: Read, Grep, WebFetch
Required sources:
- https://docs.pytorch.org/docs/stable/notes/randomness.html
- https://docs.jax.dev/en/latest/jep/263-prng.html
- https://numpy.org/doc/stable/reference/random/index.html
Checks (cite the relevant doc section for each):
- All seeds set:
random.seed, np.random.seed,
torch.manual_seed, torch.cuda.manual_seed_all
- Env vars:
PYTHONHASHSEED, CUBLAS_WORKSPACE_CONFIG=:4096:8
torch.use_deterministic_algorithms(True) present
torch.backends.cudnn.deterministic = True and benchmark = False
- DataLoader:
worker_init_fn + generator=torch.Generator() set
- JAX: explicit
PRNGKey threading; no global jax.random calls
- Non-deterministic ops used without acknowledgment:
scatter_add_,
index_add_, bincount, embedding-bag backward, CTC loss,
pooling backwards
- Resumed-from-checkpoint code: re-seeds AND saves RNG state
Citation requirement: each finding cites the exact PyTorch /
JAX / NumPy doc URL + the warning passage that justifies the rule.
Specialist 5 — numerical-correctness-auditor
Scope: Catch silent numerical bugs.
Tools: Read, Grep, WebFetch
Required sources:
- https://numpy.org/doc/stable/reference/generated/numpy.fft.fft.html
- https://docs.pytorch.org/docs/stable/generated/torch.fft.fft.html
- https://nvlabs.github.io/sionna/ (for complex-tensor conventions)
- Any user-supplied papers/notes the code claims to implement
Checks:
- Complex dtypes preserved end-to-end (no silent cast to real)
- FFT normalization explicit (
norm="ortho" vs "backward" vs
"forward")
- dB ↔ linear conversions named (
lin2db, db2lin); no bare
10*log10 or 10**(x/10)
- Sample-rate / FFT-size consistency across the pipeline
- Tensor-shape order matches the library convention
(Sionna: [batch, rx, tx, subcarrier, symbol])
- In-place ops on autograd tensors (breaks backward)
- Mixed precision: explicit autocast scope, gradient scaler used
- Numerical-stability tricks: log-sum-exp, log1p, expm1 where
appropriate
Citation requirement: every claim about a library behavior
cites the docs URL + quoted passage. Claims about the user's own
math must cite the user-supplied paper / equation number.
Aggregator agent
After all 5 specialists return, ONE final aggregator agent
(general-purpose) merges results.
Aggregator system prompt:
You are merging 5 specialist code-audit reports. Do NOT add new
findings. Do NOT remove any cited finding. Your job:
1. Group findings by file:line — show all specialists who flagged
the same line together.
2. Deduplicate identical findings (same line, same root cause).
3. Rank by severity:
- CRITICAL — code will not run, or returns silently wrong values
- HIGH — reproducibility broken, results not trustworthy
- MEDIUM — style / maintainability / minor numerical risk
- LOW — cosmetic
4. Emit final report in this exact structure:
## Summary
- N findings total (X critical, Y high, Z medium, W low)
- K verified vs U unverified
- File coverage: list of files reviewed
## Findings
For each finding:
### [SEVERITY] file:line — short title
- **Specialist:** name
- **Problem:** 1-2 sentences
- **Source:** URL + verbatim quoted passage
- **Fix:** minimal diff or code snippet
## UNVERIFIED claims (skipped)
- List anything a specialist could not source
## What was NOT checked
- Be explicit about gaps (e.g. "no integration tests run",
"GPU-specific behavior not reproduced on this machine")
NEVER invent a finding. NEVER paraphrase a source quote — quote
verbatim. If a specialist had zero findings, say so explicitly.
Orchestrator prompt template (paste-and-go)
I want a 5-way parallel audit of the following code.
CODE TO AUDIT:
<paste file path OR ```python ... ``` block>
CONTEXT (optional — fill if relevant):
- This code implements: <one-line description>
- Reference paper / spec: <citation or URL if any>
- Known constraints: <e.g. must run deterministic on A100>
SPAWN 5 SPECIALISTS IN PARALLEL IN ONE MESSAGE:
1. static-analyzer
2. library-api-auditor
3. standards-spec-auditor (or "NOT APPLICABLE" if not wireless)
4. reproducibility-auditor
5. numerical-correctness-auditor
Each must follow the citation contract from the code-audit-fanout
skill: every finding cites a URL + verbatim quoted passage. No
claim without a source. UNVERIFIED items must be marked, not
hidden.
After all 5 return, spawn the aggregator agent to merge. Show me
the merged report ONLY — do not show raw specialist outputs.
Files in this skill folder
SKILL.md — this file. Self-contained — all 5 specialist prompts, the
aggregator prompt, the orchestrator template, and the citation contract are
inline above. No companion files required to run.
Citation contract (the only rule that matters)
Every finding MUST include:
- URL to the official documentation page or spec.
- Verbatim quote from that page — not a paraphrase.
- Anchor (section / clause / table number) within the page.
Example of a valid finding:
HIGH — train.py:42 — torch.use_deterministic_algorithms not called
Specialist: reproducibility-auditor
Problem: Code seeds RNGs but does not enable deterministic
algorithms. CUBLAS, cuDNN convolutions, and atomicAdd float ops
will produce different bit patterns across runs.
Source: https://docs.pytorch.org/docs/stable/notes/randomness.html
§"Avoiding nondeterministic algorithms"
Quote: "torch.use_deterministic_algorithms() lets you configure
PyTorch to use deterministic algorithms instead of nondeterministic
ones where available, and to throw an error if an operation is
known to be nondeterministic (and without a deterministic alternative)."
Fix:
import torch
torch.use_deterministic_algorithms(True, warn_only=False)
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
Example of what is NOT allowed:
❌ "I think this might cause issues with reproducibility."
❌ "PyTorch docs say something about determinism."
❌ "This API was deprecated recently."
❌ Any finding without URL + verbatim quote + anchor.
Failure modes + fixes
| Failure |
Cause |
Fix |
| Specialist invents an API that doesn't exist |
Skipped WebFetch verification |
Re-run with explicit "no claim without quoted source" rule |
| Specialist quotes outdated docs |
Library version mismatch |
Tell orchestrator the exact library version installed |
| Aggregator drops findings |
Over-aggressive dedup |
Use "preserve unique URLs even if same line" rule |
| All 5 specialists fire sequentially |
Spawned in separate messages |
Re-issue as a single message with 5 Agent calls |
| 3GPP fetch blocked / requires login |
3GPP portal session needed |
Specialist marks UNVERIFIED + suggests user downloads PDF |
| Specialist times out |
Code too long |
Chunk by function. Run audit per-function in a secondary fanout. |
Anti-patterns
- ❌ Specialist paraphrases instead of quoting docs verbatim
- ❌ Findings without a URL — silent hallucination risk
- ❌ Standards-spec-auditor invents 3GPP clause numbers — must cite real TS
- ❌ Aggregator adds its own opinions
- ❌ Running fewer than 5 specialists to "save tokens" — defeats the cross-check
- ❌ Sequential dispatch — one message, five Agent calls
Cost model
- Wall clock: ~max(specialist) instead of sum — typically 60-120s
- API tokens: 5× a solo review's tokens + aggregator merge
- Worth it when: code touches production / publication / shared lab repos
- Skip when: throwaway notebook exploration
1---2name: code-audit-fanout3description: Five-way parallel code audit. User pastes a Python file / function / diff → orchestrator fans out 5 specialist sub-agents in ONE message, each reviewing a DIFFERENT axis (static analysis, library API correctness, standards/spec compliance, reproducibility, numerical correctness). Every finding MUST cite an exact URL + a quoted passage from the official documentation. Aggregator agent merges, dedupes, ranks by severity. Code returns reviewed 4-5 times before the user touches it. Trigger when user says: "audit this code", "review this diff", "debug this", "check my function", "find bugs", "/audit-code", "/code-audit-fanout", "fanout audit", or pastes a code block and asks for review. Auto-trigger heuristic: user pastes >20 lines of Python and asks for "review", "audit", "debug", "check", or "bug". HARD RULE: zero claims without a source. Every issue cites a URL to the official docs / paper / spec, plus the exact quoted passage. No hallucinated APIs, function signatures, or behaviors. If a specialist cannot veri4---56# code-audit-fanout78## When to use9USE for any code review request where correctness matters more than10speed. Especially:11- ML training loops, loss functions, custom layers12- Signal-processing pipelines (FFT, filters, modulation)13- 5G PHY simulators (channel models, MIMO precoding, decoders)14- Any function touching complex-valued tensors, dB scales, or15 hardware-determinism primitives16- Diffs > 50 lines before merge1718SKIP for trivial edits (typo fix, rename, formatting).1920## The 5 specialist agents2122Each spawned in parallel in ONE assistant message. Each has a23narrow scope, a required source list, and a citation contract.2425### Specialist 1 — static-analyzer26**Scope:** Read-only static analysis.27**Tools:** Read, Grep, Glob, Bash28**Checks:**29- `ruff check --select ALL` output30- `mypy --strict` output (if config present, else `mypy`)31- `pyright` if available32- Function-level cyclomatic complexity > 1033- Bare `except:`, `except Exception:`, swallowed errors34- Mutable default args35- Print statements left in code (vs logging)36**Citation requirement:** every flagged rule must reference the37exact ruff / mypy / pyright rule ID and link to the rule docs.3839### Specialist 2 — library-api-auditor40**Scope:** Verify every imported API call against official docs.41**Tools:** Read, Grep, WebFetch, WebSearch42**Required sources (in order of precedence):**43- PyTorch — https://docs.pytorch.org/docs/stable/44- NumPy — https://numpy.org/doc/stable/reference/45- SciPy — https://docs.scipy.org/doc/scipy/46- JAX — https://docs.jax.dev/en/latest/47- Sionna — https://nvlabs.github.io/sionna/48- HuggingFace — https://huggingface.co/docs/49- pandas — https://pandas.pydata.org/docs/50**Procedure:**511. Extract every imported symbol and every `X.Y.Z(...)` call.522. For each, WebFetch the official doc page.533. Check: function exists? signature matches? deprecated? known54 gotchas in the docs (the "Note" / "Warning" boxes)?554. Flag mismatches with: file:line — call — expected signature56 per docs URL — quoted doc passage.57**Citation requirement:** every finding cites the exact doc URL58+ section anchor + a verbatim quote.59**HARD RULE:** if a fetch fails or the page doesn't mention the60symbol, mark UNVERIFIED. Do NOT guess.6162### Specialist 3 — standards-spec-auditor63**Scope:** For wireless / signal-processing code only. Verify the64code's constants and procedures against published standards.65**Tools:** Read, WebFetch, WebSearch66**Required sources:**67- 3GPP TS portal — https://www.3gpp.org/specifications-technologies68- ETSI standards — https://www.etsi.org/standards69- IEEE Xplore (citation only — no full-text fetch unless user70 provides access)71- IETF RFCs — https://www.rfc-editor.org/72- ITU-R recommendations — https://www.itu.int/rec/R-REC/en73**Checks:**74- Numerology constants (subcarrier spacing 15/30/60/120/240/480 kHz)75- Resource grid dimensions (PRB = 12 subcarriers, slot = 14 symbols)76- LDPC base graph selection thresholds (TS 38.212)77- Modulation mapping tables (TS 38.211 §5.1)78- Channel-model parameters (TR 38.901 tables)79- TBS / MCS index tables (TS 38.214)80**Citation requirement:** every numeric constant or procedure81verified must cite TS/TR number + clause + table + quoted line.82**HARD RULE:** if the user's code is not wireless, this specialist83returns "NOT APPLICABLE" and does not invent issues.8485### Specialist 4 — reproducibility-auditor86**Scope:** Ensure the code will produce the same result on a87second run.88**Tools:** Read, Grep, WebFetch89**Required sources:**90- https://docs.pytorch.org/docs/stable/notes/randomness.html91- https://docs.jax.dev/en/latest/jep/263-prng.html92- https://numpy.org/doc/stable/reference/random/index.html93**Checks (cite the relevant doc section for each):**94- All seeds set: `random.seed`, `np.random.seed`,95 `torch.manual_seed`, `torch.cuda.manual_seed_all`96- Env vars: `PYTHONHASHSEED`, `CUBLAS_WORKSPACE_CONFIG=:4096:8`97- `torch.use_deterministic_algorithms(True)` present98- `torch.backends.cudnn.deterministic = True` and `benchmark = False`99- DataLoader: `worker_init_fn` + `generator=torch.Generator()` set100- JAX: explicit `PRNGKey` threading; no global `jax.random` calls101- Non-deterministic ops used without acknowledgment: `scatter_add_`,102 `index_add_`, `bincount`, embedding-bag backward, CTC loss,103 pooling backwards104- Resumed-from-checkpoint code: re-seeds AND saves RNG state105**Citation requirement:** each finding cites the exact PyTorch /106JAX / NumPy doc URL + the warning passage that justifies the rule.107108### Specialist 5 — numerical-correctness-auditor109**Scope:** Catch silent numerical bugs.110**Tools:** Read, Grep, WebFetch111**Required sources:**112- https://numpy.org/doc/stable/reference/generated/numpy.fft.fft.html113- https://docs.pytorch.org/docs/stable/generated/torch.fft.fft.html114- https://nvlabs.github.io/sionna/ (for complex-tensor conventions)115- Any user-supplied papers/notes the code claims to implement116**Checks:**117- Complex dtypes preserved end-to-end (no silent cast to real)118- FFT normalization explicit (`norm="ortho"` vs `"backward"` vs119 `"forward"`)120- dB ↔ linear conversions named (`lin2db`, `db2lin`); no bare121 `10*log10` or `10**(x/10)`122- Sample-rate / FFT-size consistency across the pipeline123- Tensor-shape order matches the library convention124 (Sionna: [batch, rx, tx, subcarrier, symbol])125- In-place ops on autograd tensors (breaks backward)126- Mixed precision: explicit autocast scope, gradient scaler used127- Numerical-stability tricks: log-sum-exp, log1p, expm1 where128 appropriate129**Citation requirement:** every claim about a library behavior130cites the docs URL + quoted passage. Claims about the user's own131math must cite the user-supplied paper / equation number.132133## Aggregator agent134135After all 5 specialists return, ONE final aggregator agent136(general-purpose) merges results.137138**Aggregator system prompt:**139```140You are merging 5 specialist code-audit reports. Do NOT add new141findings. Do NOT remove any cited finding. Your job:1421431. Group findings by file:line — show all specialists who flagged144 the same line together.1452. Deduplicate identical findings (same line, same root cause).1463. Rank by severity:147 - CRITICAL — code will not run, or returns silently wrong values148 - HIGH — reproducibility broken, results not trustworthy149 - MEDIUM — style / maintainability / minor numerical risk150 - LOW — cosmetic1514. Emit final report in this exact structure:152153 ## Summary154 - N findings total (X critical, Y high, Z medium, W low)155 - K verified vs U unverified156 - File coverage: list of files reviewed157158 ## Findings159 For each finding:160 ### [SEVERITY] file:line — short title161 - **Specialist:** name162 - **Problem:** 1-2 sentences163 - **Source:** URL + verbatim quoted passage164 - **Fix:** minimal diff or code snippet165166 ## UNVERIFIED claims (skipped)167 - List anything a specialist could not source168169 ## What was NOT checked170 - Be explicit about gaps (e.g. "no integration tests run",171 "GPU-specific behavior not reproduced on this machine")172173NEVER invent a finding. NEVER paraphrase a source quote — quote174verbatim. If a specialist had zero findings, say so explicitly.175```176177## Orchestrator prompt template (paste-and-go)178179```180I want a 5-way parallel audit of the following code.181182CODE TO AUDIT:183<paste file path OR ```python ... ``` block>184185CONTEXT (optional — fill if relevant):186- This code implements: <one-line description>187- Reference paper / spec: <citation or URL if any>188- Known constraints: <e.g. must run deterministic on A100>189190SPAWN 5 SPECIALISTS IN PARALLEL IN ONE MESSAGE:1911. static-analyzer1922. library-api-auditor1933. standards-spec-auditor (or "NOT APPLICABLE" if not wireless)1944. reproducibility-auditor1955. numerical-correctness-auditor196197Each must follow the citation contract from the code-audit-fanout198skill: every finding cites a URL + verbatim quoted passage. No199claim without a source. UNVERIFIED items must be marked, not200hidden.201202After all 5 return, spawn the aggregator agent to merge. Show me203the merged report ONLY — do not show raw specialist outputs.204```205206## Files in this skill folder207208- `SKILL.md` — this file. **Self-contained** — all 5 specialist prompts, the209 aggregator prompt, the orchestrator template, and the citation contract are210 inline above. No companion files required to run.211212## Citation contract (the only rule that matters)213214Every finding MUST include:2151. **URL** to the official documentation page or spec.2162. **Verbatim quote** from that page — not a paraphrase.2173. **Anchor** (section / clause / table number) within the page.218219Example of a valid finding:220```221HIGH — train.py:42 — torch.use_deterministic_algorithms not called222Specialist: reproducibility-auditor223Problem: Code seeds RNGs but does not enable deterministic224algorithms. CUBLAS, cuDNN convolutions, and atomicAdd float ops225will produce different bit patterns across runs.226Source: https://docs.pytorch.org/docs/stable/notes/randomness.html227 §"Avoiding nondeterministic algorithms"228Quote: "torch.use_deterministic_algorithms() lets you configure229PyTorch to use deterministic algorithms instead of nondeterministic230ones where available, and to throw an error if an operation is231known to be nondeterministic (and without a deterministic alternative)."232Fix:233 import torch234 torch.use_deterministic_algorithms(True, warn_only=False)235 torch.backends.cudnn.deterministic = True236 torch.backends.cudnn.benchmark = False237```238239Example of what is NOT allowed:240```241❌ "I think this might cause issues with reproducibility."242❌ "PyTorch docs say something about determinism."243❌ "This API was deprecated recently."244❌ Any finding without URL + verbatim quote + anchor.245```246247## Failure modes + fixes248249| Failure | Cause | Fix |250|---|---|---|251| Specialist invents an API that doesn't exist | Skipped WebFetch verification | Re-run with explicit "no claim without quoted source" rule |252| Specialist quotes outdated docs | Library version mismatch | Tell orchestrator the exact library version installed |253| Aggregator drops findings | Over-aggressive dedup | Use "preserve unique URLs even if same line" rule |254| All 5 specialists fire sequentially | Spawned in separate messages | Re-issue as a single message with 5 Agent calls |255| 3GPP fetch blocked / requires login | 3GPP portal session needed | Specialist marks UNVERIFIED + suggests user downloads PDF |256| Specialist times out | Code too long | Chunk by function. Run audit per-function in a secondary fanout. |257258## Anti-patterns259260- ❌ Specialist paraphrases instead of quoting docs verbatim261- ❌ Findings without a URL — silent hallucination risk262- ❌ Standards-spec-auditor invents 3GPP clause numbers — must cite real TS263- ❌ Aggregator adds its own opinions264- ❌ Running fewer than 5 specialists to "save tokens" — defeats the cross-check265- ❌ Sequential dispatch — one message, five Agent calls266267## Cost model268269- Wall clock: ~max(specialist) instead of sum — typically 60-120s270- API tokens: 5× a solo review's tokens + aggregator merge271- Worth it when: code touches production / publication / shared lab repos272- Skip when: throwaway notebook exploration