TL;DR
UCD-Training is a novel two-stage post-training framework that adapts Large Language Models (LLMs) to entirely new, unseen codebases using only their raw source code. By constructing a structured code graph, it synthesizes dependency-preserving pretraining data and reasoning-enriched fine-tuning data, boosting code generation performance by up to 26.1% over standard baselines and significantly outperforming Retrieval-Augmented Generation (RAG).
What Problem Does This Paper Address?
When developers work with newly released software frameworks, proprietary enterprise systems, or private repositories, LLMs frequently fail. Because these "unseen codebases" were absent from the models' pretraining corpora, the models suffer from high hallucination rates and generate invalid API compositions.
While inference-time techniques like Retrieval-Augmented Generation (RAG) can pull relevant code snippets into the prompt, they don't help the model fundamentally understand the underlying architecture or latent usage conventions of a complex codebase. On the other hand, traditional post-training data synthesis methods (like OSS-Instruct) rely on existing real-world usage examples from public repositories—a luxury that brand-new or private codebases simply do not have.
To bridge this gap, the authors tackle a tough question: How can we effectively teach an LLM to understand and utilize a completely unseen codebase when only its raw source code implementation is available?
Methods
The authors introduce UCD-Training (Unseen-Codebase-Domain Training), a framework that extracts structural knowledge directly from source code and injects it into LLMs via a two-stage training pipeline.
- Code Graph Construction: The framework first performs program analysis on the codebase to build a structured code graph. Code entities (files, classes, functions) become nodes, while their relationships (dependencies, calls, includes) become edges.
- Dependency-Preserving Continued Pretraining (CPT): To help the model memorize the codebase structure, the authors extract a file-level dependency graph. They use a Depth-First Search (DFS) traversal to concatenate file contents. This ensures that files with direct dependencies are placed adjacently within the training context window, preventing structural knowledge from being fragmented during truncation.
- Graph-Grounded Supervised Fine-Tuning (SFT): The framework synthesizes three complementary types of training data, all augmented with natural language reasoning traces:
- Single-hop relation data: Teaches basic structural connections (e.g., which class contains which method).
- Compositional API data: Generates multi-API exam-style questions (Q&A, fill-in-the-blank, and coding tasks) to teach how different APIs interact.
- Codebase utilization data: Converts internal test cases into functional code generation tasks by separating the implementation from the assertions.
To ensure data quality, a strict two-stage filtering pipeline uses rule-based syntactic checks and LLM-based semantic consistency checks to eliminate synthetic errors and hallucinations before training.
Datasets
Because existing code generation benchmarks focus almost entirely on public code, the authors introduced a new benchmark: UnseenCodeBench.
To guarantee the codebases were truly "unseen" by modern LLMs, they selected four real-world repositories created after March 2025 (past the knowledge cutoff of the evaluated models):
- C++:
sqlgen(database system),reaction(programming framework), andHexi(binary data stream processing). - Python:
LEANN(high-performance retrieval engine).
The evaluation tasks were generated with LLM assistance and rigorously double-checked by human engineers, consuming over 100 person-hours to ensure high quality.
Key Insights and Ideas
- DFS Beats Topological Sorting for CPT: Standard topological sorting can inadvertently separate closely dependent files when text is split into context windows. DFS traversal guarantees that directly related files stay close together, allowing the model to better capture cross-file dependencies.
- Test Cases as High-Quality Priors: Instead of randomly guessing how APIs might combine, UCD-Training leverages the codebase's internal test cases. Because these test cases were written by the original maintainers to validate concrete features, they naturally reflect realistic usage patterns and engineering constraints.
- Compositional API Data is King: In ablation studies, removing the compositional API reasoning data caused the most drastic performance drops (e.g., a 29.7% drop in
pass@1on the Python dataset). Learning how multiple APIs interact is the single most critical factor in mastering an unseen codebase.
Key Results
- Outperforming RAG: Models trained with UCD-Training significantly outperformed state-of-the-art models using RAG. A relatively small 8B model trained via UCD-Training achieved a 31.5% pass@1 score on UnseenCodeBench, beating Claude-Sonnet-4.5 with RAG by 10.1% absolute.
- Scaling Capabilities: Performance scaled favorably with model size. Moving from a Qwen 8B base to a 14B base improved
pass@1from 20.0% to 29.1% on thereactioncodebase. - Multi-Codebase Mastery: In a simulated enterprise scenario where a single model was trained on all four unseen codebases simultaneously, the unified model retained its capabilities well, achieving a 36.0% pass@1 and outperforming all non-UCD baselines by 4.7% to 23.6%.
Limitations and Future Work
While highly effective, the authors note a few limitations:
- Language Coverage: The current evaluation is restricted to C++ and Python. Future work will expand the framework to support a broader range of programming languages.
- Hyperparameter Optimization: Due to computational constraints, the authors could not exhaustively search for the absolute optimal training configurations (such as the perfect ratio of general-domain to domain-specific data). They plan to explore these optimal training configurations in future empirical studies.
Summary updated