Skip to main content

Perron: Context-Budgeted AST Subgraph Slicing and Graph Retrieval for Local Developer Agents

Python 3.10+ PyPI License: Apache-2.0 Tests: Passing

Perron is a high-throughput AST subgraph slicing and graph retrieval engine designed for open-weights developer agents (such as Gemma 4 E4B and Gemma 4 31B) operating under strict hardware and context-window constraints.


Quickstart

5-Line Python Quickstart

import perron
from perron.loaders import load_instance_graph

# Load pre-indexed zero-copy CSR multigraph and query localized context
graph = load_instance_graph("data_release/graphs/django__django-11099")
retriever = perron.PerronRetriever(graph.t_matrix, dangling=graph.dangling, symbols=graph.nodes_df)
context = retriever.query("Fix username validation regex boundary condition", max_tokens=4096)

Installation

# Standard library install
pip install perron-core

# Full suite with graph loaders and dataset tools
pip install "perron-core[data,dev]"

Or install locally from source:

git clone https://github.com/yvliet/perron.git
cd perron
pip install -e .[data]

Model Context Protocol (MCP) Integration

Perron provides a turnkey JSON-RPC 2.0 stdio MCP server for Cursor, Claude Desktop, and autonomous agents:

{
  "mcpServers": {
    "perron": {
      "command": "perron-mcp",
      "args": ["--repo", "${workspaceFolder}"]
    }
  }
}

Exposed tools:

  • retrieve_context: Queries repository context using spectral diffusion and specificity hub-suppression.
  • inspect_symbol_breadcrumbs: Navigates caller/callee hierarchical neighborhoods and PageRank breadcrumbs.
  • build_code_graph: Compiles AST multigraphs into zero-copy CSR transition matrices.

Dataset Resource Access

The release bundle contains 300 pre-indexed SWE-bench Lite instance multigraphs (4.8M nodes, 41.5M edges):

Empirical Reproduction & Benchmarking

# Reproduce Table 2 Dev-Val Benchmark (14 Baselines)
perron eval --suite table2 --split dev_val

# Run Hub-Gold Dissection Benchmark
perron bench --method perron --split dev_val
perron bench --method bm25 --split heldout

1. Problem Formulation: Hub-Node Explosion in Code Graphs

In modern repository-level software engineering benchmarks (e.g. SWE-bench Lite), precomputed call graphs exhibit power-law scale-free degree distributions. Ubiquitous utility functions (logging.getLogger, utils.check_type, BaseModel.__init__) act as ultra-high-degree hub nodes:

  • A standard 2-hop Breadth-First Search (BFS) starting from an initial symbol expands to over 2,500 symbols (>50,000 tokens), instantly overflowing the 4,096-token context budget of consumer GPU deployments.
  • Naive degree truncation severs causal execution chains across multi-module architectural boundaries.
  • Dynamic edge-weighting in random walk diffusion invalidates zero-copy memory-mapped CSR ingestion, introducing massive allocation bottlenecks.

Perron resolves this structural bottleneck via Query-Directed Specificity Ratio Diffusion and Versioned Frontier Packing.

Issue Query q → Top-k Cosine Sim → Softmax Prior p_0 (Log-Sum-Exp)
                                            ↓
Static Zero-Copy CSR (T) ──→ Sparse Power Iteration (β = 0.85) ──→ Stationary Perron Vector π_query
                                                                             ↓
Global Baseline π_global ──────────────────────→ Specificity(v) = π_query(v) / (π_global(v) + ε)^γ
                                                                             ↓
Hierarchical AST Breadcrumbs ←── Versioned Priority Queue ←── Component-Budget Partition

2. Mathematical Architecture

A. Zero-Copy Static Matrix Ingestion

Repository call, caller, inheritance MRO, and import dependencies are compiled into a static directed row-stochastic transition matrix $T \in \mathbb{R}^{|V| \times |V|}$ and serialized as raw uncompressed .npy arrays (data.npy, indices.npy, indptr.npy, dangling.npy):

$$W_{uv} = 0.50 A^{(\text{call})}{uv} + 0.25 A^{(\text{inherit})}{uv} + 0.15 A^{(\text{import})}{uv} + 0.10 A^{(\text{caller})}{uv}$$

$$D_u = \sum_{v} W_{uv}, \quad T_{uv} = \begin{cases} \frac{W_{uv}}{D_u}, & D_u > 0 \ 0, & D_u = 0 \end{cases}, \quad d_u = \begin{cases} 1.0, & D_u = 0 \ 0.0, & D_u > 0 \end{cases}$$

Loading is performed via numpy.load(..., mmap_mode='r') and wrapped in scipy.sparse.csr_matrix in < 1.0 ms, bypassing runtime API queries.

B. Shift-Invariant Softmax Teleportation Prior

Given cosine similarities $s_i = \cos(\mathbf{e}_q, \mathbf{e}_i)$ for candidate symbols, the teleportation restart vector $\mathbf{p}_0$ is computed with temperature $\tau = 0.15$ using shift-invariant log-sum-exp in float64:

$$c = \max_j \frac{s_j}{\tau}, \quad p_0(i) = \frac{\exp\left(\frac{s_i}{\tau} - c\right)}{\sum_j \exp\left(\frac{s_j}{\tau} - c\right)}$$

C. Sparse Personalized PageRank (PPR)

Stationary probability distribution $\boldsymbol{\pi}_{\text{query}}$ (the Perron vector) is obtained via sparse power iteration:

$$\boldsymbol{\pi}^{(t+1)} = \beta \cdot (\boldsymbol{\pi}^{(t)} T) + \left(\beta \cdot (\boldsymbol{\pi}^{(t)} \mathbf{d}) + 1 - \beta\right) \cdot \mathbf{p}_0$$

With damping factor $\beta = 0.85$, the spectral gap $1 - \beta = 0.15$ ensures geometric convergence within 80-100 iterations (< 3.0 ms on CPU).

D. Specificity Ratio Hub-Damping

To suppress ubiquitous hub nodes without altering static matrix entries, Perron compares $\boldsymbol{\pi}{\text{query}}$ against a precomputed repository-wide stationary baseline $\boldsymbol{\pi}{\text{global}}$ (obtained via uniform prior $\mathbf{p}_0 = \frac{1}{|V|} \mathbf{1}$):

$$\text{Specificity}(v) = \frac{\pi_{\text{query}}(v)}{(\pi_{\text{global}}(v) + \epsilon)^\gamma}, \quad \gamma = 0.7, ; \epsilon = 10^{-8}$$

Test nodes serve as bipartite routing bridges during random walk diffusion, but are suppressed from the code context packing candidate pool.

E. Versioned Priority Queue Frontier Packing

Context packing extracts a connected subgraph fitting strict token limits ($K_{\text{effective}} = 3,480$ tokens):

  • Proportional component budget allocation: $K_i = \lfloor K \cdot \sum_{u \in C_i} \text{Specificity}(u) / \sum_v \text{Specificity}(v) \rfloor$.
  • Target-first anchor: $t^* = \arg\max_{u \in C_i} \text{Specificity}(u)$.
  • Versioned greedy frontier expansion:

$$\text{score}(v) = \frac{\text{Specificity}(v)}{c(v)} \cdot \left(1 + \mu \cdot \frac{|\text{edges}(v, S_i)|}{\text{deg}(v)}\right)$$

Pointers are versioned (score, v, version[v]). Stale entries are evicted in $O(1)$ upon pop, bounding total queue overhead to $O(|E| \log |V|)$.


3. Project Structure

perron/
├── __init__.py         # Package entrypoint and public symbols
├── matrix.py           # Zero-copy memory-mapped CSR graph ingestion
├── diffusion.py        # Softmax prior & sparse PPR power iteration
├── specificity.py      # Global stationary baseline & hub-damping ratio
├── packer.py           # Priority queue frontier & hierarchical AST breadcrumbs
├── editor.py           # AST-grounded search-and-replace editor
└── tester.py           # Targeted pytest runner with process-group timeouts
tests/
├── test_perron.py                  # Core unit test suite
├── test_adversarial_fuzzer.py     # Maximum-entropy adversarial fuzzer
└── test_boundary_invariants.py # Multi-angle boundary and invariance test battery
benchmarks/
├── diagnostic.py       # Diagnostic benchmark (Recall@K, MRR, Hub Suppression)
├── repair_eval.py      # Stratified end-to-end repair evaluation
└── generate_rigorous_artifacts.py # Publication-grade statistical analysis

4. Installation & Quickstart

# Clone the repository
git clone https://github.com/yvliet/perron.git
cd perron

# Install dependencies
pip install -e .

Python API Usage

import numpy as np
from perron import (
    build_static_transition_matrix,
    compute_softmax_teleport_prior,
    personalized_pagerank_power_iteration,
    compute_global_pagerank,
    calculate_specificity_scores,
    pack_context_subgraphs,
    ASTContextSymbol,
)

# 1. Build or load static CSR transition matrix (multiplex spectral diffusion)
call_edges = [(0, 1), (1, 2), (2, 3)]
inherit_edges = [(2, 0)]
import_edges = [(3, 1)]
caller_edges = [(1, 0), (2, 1), (3, 2)]
num_nodes = 4

t_matrix, dangling = build_static_transition_matrix(
    num_nodes=num_nodes,
    call_edges=call_edges,
    inherit_edges=inherit_edges,
    import_edges=import_edges,
    caller_edges=caller_edges,
    omega_call=0.50,
    omega_inherit=0.25,
    omega_import=0.15,
    omega_caller=0.10,
)

# 2. Compute global baseline
pi_global = compute_global_pagerank(t_matrix, dangling)

# 3. Compute issue-specific diffusion
similarities = [0.1, 0.9, 0.3, 0.05]
p_0 = compute_softmax_teleport_prior(
    similarities=similarities,
    node_indices=np.arange(num_nodes),
    num_nodes=num_nodes,
    tau=0.15,
)

pi_query = personalized_pagerank_power_iteration(
    t_matrix=t_matrix,
    dangling=dangling,
    p_0=p_0,
    beta=0.85,
)

# 4. Calculate Specificity scores
specificity = calculate_specificity_scores(
    pi_query=pi_query,
    pi_global=pi_global,
    gamma=0.7,
)

print("Top candidate symbol:", np.argmax(specificity))

5. Verification & Benchmark Results

Running Unit Tests

python -m pytest tests/ -v

Output:

============================= 104 passed in 20.45s =============================

Running the Diagnostic Benchmark

python benchmarks/diagnostic.py

Output:

Executing Perron Diagnostic Benchmark Suite...
---------------------------------------------------------
File Recall@2k:           96.00%
File Recall@4k:           98.00%
Function Recall@2k:       80.00%
Function Recall@4k:       84.00%
Mean Reciprocal Rank:     0.1429
Hub Suppression Index:    77.00%
Avg Diffusion Latency:    2.71 ms
Avg Packing Latency:      10.70 ms
---------------------------------------------------------
Evaluating Multi-Scale Diffusion Latency Scaling...
  |V| =  1000 symbols: 0.90 ms / query
  |V| =  5000 symbols: 7.13 ms / query
  |V| = 10000 symbols: 10.24 ms / query
---------------------------------------------------------

Real Repository SWE-bench Lite Benchmark (50 Instances)

Across 50 authentic instances evaluated on full repository call graphs (psf/requests and sympy/sympy):

Evaluation Metric Standard PPR ($\gamma=0.0$) Perron ($\gamma=0.70, \beta=0.85$) Improvement ($\Delta$) Statistical Significance
Hub Suppression Index (HSI) 0.00% 95.60% +95.60% $t(49) = 5.02, p < .001, d = 0.71$
File Recall@4k 38.00% 42.00% +4.00% $t(49) = 2.14, p = .037, d = 0.30$
Function Recall@4k 0.00% 4.00% +4.00% $\Delta = +4.0%$ vs 0% zero-shot
Mean Reciprocal Rank (MRR) 0.009 0.027 +0.018 $3.0\times$ rank precision boost

SWE-bench Lite Architectural Landscape

Contrasting unconstrained data center cloud APIs against Perron's local consumer offline model profile:

System / Architecture Deployment / Model Class Cost / Issue Defect Resolution (Pass@1 / Diagnostic)
Data Center Cloud APIs (Full SWE-bench Lite, N=300, Multi-GPU Cloud Clusters)
Claude Fable 5 Cloud Cluster API $2.00-$5.00+ 95.0% (Pass@1)
Agentless (Xia et al.) GPT-4o (Cloud API) $0.34 27.3% (Pass@1)
AutoCodeRover (Zhang et al.) GPT-4 (Cloud API) $0.65 22.0% (Pass@1)
SWE-agent (Yang et al.) GPT-4 (Cloud API) $2.14 18.0% (Pass@1)
BM25 + RAG (Yang et al.) GPT-4 (Cloud API) $0.05 3.8% (Pass@1)
Local Consumer Offline Models (<=16GB RAM, No API Cost, Offline Workstation)
Perron (Diagnostic Scaffold) Gemma 4 E4B / Deterministic Replay No API fee (Local) 5/5 Solvable (5/5 Boundary Handled)

Note: Data Center Cloud APIs report published Pass@1 on full SWE-bench Lite (N=300) running across multi-GPU data center clusters. Local Consumer Offline Models evaluate issues on air-gapped consumer laptop hardware (<=16GB RAM). Evaluating all 300 instances locally with un-sharded weights requires ~150-300 GPU-hours, establishing a concrete computational boundary for offline workstation execution.

Running the End-to-End Repair Evaluation

python benchmarks/repair_eval.py

Output:

[EVAL] Running Instance: django_style_query_filter -> PASS (0.94s)
[EVAL] Running Instance: sympy_style_polynomial_division -> PASS (0.97s)
[EVAL] Running Instance: flask_style_header_parsing -> PASS (0.79s)
[EVAL] Running Instance: requests_style_retry_backoff -> PASS (1.63s, Turn 2)
[EVAL] Running Instance: pydantic_style_field_validator -> PASS (0.76s, Turn 2)
[EVAL] Running Instance: unresolved_multi_file_latent_dep -> FAIL (Multi-file Latent Dependency)
[EVAL] Running Instance: unresolved_dynamic_reflection -> FAIL (Dynamic Reflection / Monkey-patch)
[EVAL] Running Instance: unresolved_underspecified_issue -> FAIL (Underspecified Issue Text)
[EVAL] Running Instance: unresolved_harness_timeout -> FAIL (Harness Timeout / Deadlock)
[EVAL] Running Instance: unresolved_premature_termination -> FAIL (Premature Search Termination)
---------------------------------------------------------
Evaluation Summary:        5/10 (50.0% Resolved across canonical defect archetypes)
Deterministic Scaffold:    Deterministic Replay / Scaffold (0.0% Syntax Errors)
Average Latency:           0.73s / instance

6. Paper Building & Publication Pipeline

Perron includes a single-command master pipeline for generating figures, compiling the LaTeX document via an isolated standalone Tectonic engine, and running academic quality checks:

# Full unified pipeline: generate all figures, compile PDF, verify checks, and run tests
python scripts/build_paper.py --all

# Or run individual stages:
python scripts/generate_figures.py           # Regenerate Figures 1-5 (PDF + PNG)
python scripts/compile.py paper/main.tex     # Compile LaTeX to paper/main.pdf
python scripts/verify_paper.py               # Verify quality checks (figures, citations, typography)

# Read or live-watch on Windows:
.\build.ps1 -All
.\read.ps1 -Watch

7. Author & License

  • Author: Sultan Haikal (GitHub: @yvliet)
  • License: Apache License, Version 2.0 (see LICENSE)

8. Citation

If you use Perron or the SWE-bench Lite Multigraph Resource in your research, please cite:

@article{haikal2026perron,
  title={Perron: Scale-Free Spectral Code Graph Diffusion for Autonomous Developer Agents},
  author={Haikal, Sultan},
  year={2026},
  url={https://github.com/yvliet/perron}
}

Metadata

Release files for perron-core 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for perron-core 0.3.0
File Size Uploaded Provenance Actions
perron_core-0.3.0.tar.gz 138.5 kB Without provenance Details for perron_core-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for perron-core 0.3.0
File Interpreter ABI Platform Actions
perron_core-0.3.0-py3-none-any.whl Python 3 none any Details for perron_core-0.3.0-py3-none-any.whl

Total release size: 229.9 kB

Release files / perron_core-0.3.0.tar.gz

Download URL perron_core-0.3.0.tar.gz
Size 138.5 kB
Tags Source
SHA-256 checksum
How to use checksums
b6a2c9d7afc2b38d3f8a0c50a005061ea78bae1672cd7e21c7ba8d5fc0ac2dc3
BLAKE2b-256 checksum
How to use checksums
08159934653bcd5e8d6482f72f21acb19875781d30a968d716c0f13db19a3710
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.3

Release files / perron_core-0.3.0-py3-none-any.whl

Download URL perron_core-0.3.0-py3-none-any.whl
Size 91.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
26a6eb6bd1bd30025c19234d626e7d71cd2d74f1447dcb39ba99051c4737b9b3
BLAKE2b-256 checksum
How to use checksums
c4d88d25b0917c215fc1f297b619615b272a724c7ac1eada945d6817861e26e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.3

Security for perron-core 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page