TL;DR
How do you make a coding agent smarter without touching a single weight in its neural network? SpecForge teaches agents to iteratively rewrite their own natural-language documentation based on unit test failures—and uses a clever tree search to stop them from accidentally breaking working code while fixing bugs elsewhere. The result is crisp, reusable codebase knowledge that helps agents translate repositories into new languages and build new features better than human-written requirement docs.
What Problem Does This Paper Address?
Autonomous coding agents are only as good as their understanding of the codebase they inhabit. While we usually write documentation for human eyes, agents need behavioral specifications: precise, actionable natural-language descriptions of inputs, outputs, and edge cases.
Because these specifications are just text, an agent can theoretically improve itself in a loop: read the specs (without seeing the original source code), try to reconstruct the code, run unit tests, and rewrite the specs wherever tests fail. This is recursive self-improvement in context space—no expensive fine-tuning required.
There is just one catch: software isn't a bag of independent functions. When an agent edits the specification for Function A, it often breaks Function B. The authors call this output coupling, and it happens in two ways:
- Dependency coupling: If Function A calls Function B, trying to fix A's spec while B is still broken gives the agent misleading error signals.
- Generation coupling: Because the LLM reads the entire bundle of specifications at once to generate code, tweaking one description shifts the prompt context and subtly alters how completely unrelated functions get generated.
Left unchecked, iterative refinement turns into a frustrating game of whack-a-mole, oscillating endlessly instead of converging on a working codebase.
Methods
Instead of marching down a single, fragile chain of edits, SpecForge frames specification writing as a multi-frontier tree search, where each node is a complete bundle of specifications for the codebase.
Every iteration of the search answers three questions:
- Where to search (Pareto-Guided State Selection): Rather than scoring specification bundles with a single average pass rate, SpecForge keeps an archive of Pareto-optimal states—bundles that aren't strictly worse than any other across all functions. One state might nail the low-level math utilities while another nails the high-level API logic. Keeping both alive prevents premature commitment to a dead-end trajectory.
- What to refine (Dependency-Constrained Entity Selection): Using the program's call graph, SpecForge locks functions until all of their callees pass 100% of their tests (enforcing a strict bottom-up order). Among unlocked candidates, a discounted Upper Confidence Bound (D-UCB) bandit algorithm allocates compute to functions showing the highest "gap-closing rate"—separating genuinely fixable functions from stubborn ones.
- How to refine (Error-Diversified Expansion): Dumping 20 failing unit tests into an LLM prompt often dilutes the diagnostic signal with cascading or redundant errors. SpecForge instead samples different subsets of failing tests to generate multiple candidate rewrites in parallel, hedging its bets so at least one branch gets a clean, noiseless clue.
Datasets
Because SpecForge keeps model weights frozen, there is no training dataset—optimization happens per codebase using execution-verified unit tests automatically generated from the reference code (with developer-written ground-truth tests held out strictly for final evaluation).
- DevEval+: A revised Python benchmark of 20 modules, 247 functions/classes, and 760 tests (averaging a call-graph depth of 4.2), built by expanding DevEval with complex GitHub repos in finance, biology, and signal processing.
- DevEval+-Java: A newly constructed 16-module JUnit 5 mirror of DevEval+ (208 entities, 680 tests) for testing Python-to-Java translation.
- SWE-Dev: 27 feature-implementation tasks across 10 open-source Python packages, testing whether specs help implement brand-new functionality.
Key Insights and Ideas
- Readable docs make terrible specs: Static documentation tools written for humans (like RepoAgent) actually hurt cross-language code translation compared to just handing the LLM raw source code (33.5% vs. 39.7% solve rate). Human-friendly prose leaves ambiguities that code generators interpret all too literally.
- Less error context can be more: Mixing noisy or cascading test failures with informative ones actively corrupts an LLM's diagnostic reasoning. Subsampling errors across tree branches reliably unlocks better fixes.
- Self-improved specs beat human PRDs: On SWE-Dev, giving an agent SpecForge's optimized specifications of the existing codebase helped it build new features better than giving it the benchmark's official Product Requirements Documents (PRDs). The loop distills genuinely reusable architectural knowledge rather than overfitting to tests.
Key Results
- Code Reconstruction (DevEval+): SpecForge outperforms static docs, monolithic prompt optimizers (MIPROv2, GEPA, ACE), commercial agents (Cursor, Claude Code), and prior spec-search baselines across all five tested LLMs. It hits a 94.9% entity solve rate with Claude-4.5-Sonnet (90.9% on GPT-4o), beating the strongest baseline (DocSearch) by 5.7 percentage points on average.
- Ablations: Removing reverse-topological ordering causes the steepest drop (-18.6% solve rate), followed by removing the D-UCB bandit (-10.4%), error diversity (-9.5%), and the Pareto archive (-5.2%).
- Downstream Transfer: In Python-to-Java translation, SpecForge specs boost GPT-4o's solve rate from 39.7% (source-only) to 65.7%, and reach 76.2% when combined with the Python source. On SWE-Dev new-feature tasks, SpecForge achieves 74.5% Pass@1 on easy and 51.7% on hard tasks, beating the reference PRDs by +18.8 and +7.1 points.
Limitations and Future Work
The main text of the paper does not include a dedicated limitations section. However, a few scope boundaries are apparent from the setup: SpecForge relies on having an existing reference implementation from which passing unit tests can be automatically generated and executed to ground the search loop, and its cross-language evaluation excludes modules tied to libraries without direct target-language equivalents.
Summary updated