Elamur Research⌕
☰
home / papers / 2026 / SpecAgent: A Speculative Retrieval and Forecasting Agent for Code Completion

SpecAgent: A Speculative Retrieval and Forecasting Agent for Code Completion

Paper · 2026 · George Ma, Anurag Koul, Qi Chen et al.

Summary

Repository-level code completion depends on project-specific knowledge such as private APIs and cross-file dependencies. Fetching that knowledge at inference time (BM25, dense embeddings) adds delay that hurts interactive in-IDE inline completion. In the authors' tests this delay reached 9 seconds. SpecAgent moves the work to repository indexing. An LLM agent with file-reading and bash tools explores the codebase in the background and prepares context blocks for every file. Some blocks are retrieved cross-file snippets. Others are speculative predictions of functions the developer is likely to write next. At completion time the code model simply receives these blocks, so no lookup is needed.

The authors also show that existing benchmarks suffer from future-context leakage: callers and tests elsewhere in the repository reveal the target function's signature and usage, which inflates scores. To avoid this, they build a leakage-free synthetic benchmark from REPOCOD. With Qwen3-8B and Qwen3-30B-A3B as completion models, SpecAgent beats the strongest baselines by 9–11 points pass@1 and adds no retrieval latency at inference.

Key points

  • Main gains: Qwen3-8B improves by about 10–11 points absolute (58% relative) and Qwen3-30B-A3B by about 9–10 points (48% relative). The baselines are BM25, dense retrieval (UniXcoder, CodeSage) and RepoMap. The cost is a one-time background indexing step of roughly 50 seconds. The agent runs on Claude 3.7 Sonnet.
  • Benchmark: REPOCOD was modified with a function-removal agent to simulate repository states at indexing time. An Oracle Agent with access to the ground truth provides an upper bound.
  • Evidence of leakage: Running SpecAgent in the leaky inference-time setting raises pass@1 from 27.86 to 30.92 (Qwen3-8B) and from 27.96 to 34.29 (Qwen3-30B-A3B). The authors consider these higher numbers unrealistic.
  • Ablations:
    • Both components are needed, and the Forecaster Agent alone beats the Retriever Agent alone.
    • Three prediction blocks work best (27.86 pass@1). With zero prediction blocks the score is 20.92, and with twelve it is 22.35.
    • Adding BM25 or UniXcoder contexts to SpecAgent's blocks lowers pass@1 to 25.10 and 25.31.
  • Setup and limits:
    • A maximum of 10K tokens applies separately to the left context, the right context and the cross-file context, and experiments ran on 8 A100 GPUs.
    • The benchmark is synthetic rather than drawn from real repository histories.
    • Indexing overhead may matter for very large or fast-changing repositories.
    • Only two models were tested.

Our summary of the paper, in our own words — not its text. The work belongs to its authors; read it at the links above.

 Institutions

 Fields, topics and concepts

Cite

Cite as George Ma, Anurag Koul, Qi Chen, Yawen Wu, Sachit Kuhar, Yu Yu, Aritra Sengupta, Varun Kumar and Murali Krishna Ramanathan. 2026. SpecAgent: A Speculative Retrieval and Forecasting Agent for Code Completion. Proceedings of the 64th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers).

The paper itself, not this page. BibTeX from the library's record of the work. DOI 10.18653/v1/2026.acl-long.786

@inproceedings{ma2026specagent,
  title = {{SpecAgent: A Speculative Retrieval and Forecasting Agent for Code Completion}},
  author = {George Ma, Anurag Koul, Qi Chen, Yawen Wu, Sachit Kuhar, Yu Yu, Aritra Sengupta, Varun Kumar and Murali Krishna Ramanathan},
  booktitle = {Proceedings of the 64th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers)},
  year = {2026},
  doi = {10.18653/v1/2026.acl-long.786},
  url = {https://doi.org/10.18653/v1/2026.acl-long.786}
}

References

44 references, 9 of them with a card of ours. ↗ leads to the work, «find» searches for one we have no id for yet.

  1. Natural Languages. In Findings of the Association for Computational Linguistics: EMNLP 2020, pages 1536–1547. find
  2. Aider. 2023. Repository map. Blog post. find
  3. Anthropic. 2025. Claude 3.7 Sonnet and Claude Code. Blog post. find
  4. Jacob Austin, Augustus Odena, Maxwell Nye, Maarten Bosma, Henryk Michalewski, David Dohan, Ellen Jiang, Carrie Cai, Michael Terry, Quoc Le, and 1 others. 2021. Program Synthesis with Large Language Models. arXiv preprint arXiv:2108.07732.
  5. Max Brunsfeld, Patrick Thomson, Andrew Hlynskyi, Josh Vera, Phil Turnbull, Timothy Clem, Douglas Creager, Andrew Helwer, Rob Rix, Hendrik van Antwerpen, Michael Davis, Ika, Tuan-Anh Nguyen, Stafford Brunk, Niranjan Hasabnis, bfredl, Mingkai Dong, Vladimir Panteleev, ikrima, and 10 others. 2019. Tree… find
  6. Mark Chen, Jerry Tworek, Heewoo Jun, Qiming Yuan, Henrique Ponde De Oliveira Pinto, Jared Kaplan, Harri Edwards, Yuri Burda, Nicholas Joseph, Greg Brockman, and 1 others. 2021. Evaluating Large Language Models Trained on Code. arXiv preprint arXiv:2107.03374.
  7. Xinyun Chen, Maxwell Lin, Nathanael Schärli, and Denny Zhou. 2023. Teaching Large Language Models to Self-Debug. In The Twelfth International Conference on Learning Representations. find
  8. Ken Deng, Jiaheng Liu, He Zhu, Congnan Liu, Jingxin Li, Jiakai Wang, Peng Zhao, Chenchen Zhang, Yanan Wu, Xueqiao Yin, and 1 others. 2024. R2C2-Coder: Enhancing and Benchmarking Real-world Repository-level Code Completion Abilities of Code Large Language Models. In CoRR. find
  9. Yinlin Deng, Chunqiu Steven Xia, Haoran Peng, Chenyuan Yang, and Lingming Zhang. 2023. Large Language Models Are Zero-Shot Fuzzers: Fuzzing Deep-Learning Libraries via Large Language Models. In Proceedings of the 32nd ACM SIGSOFT International Symposium on Software Testing and Analysis, pages 423–43… find
  10. Akash Dhruv and Anshu Dubey. 2025. Leveraging large language models for code translation and software development in scientific computing. In Proceedings of the Platform for Advanced Scientific Computing Conference, pages 1–9. find
  11. Yangruibo Ding, Zijian Wang, Wasi Ahmad, Hantian Ding, Ming Tan, Nihal Jain, Murali Krishna Ramanathan, Ramesh Nallapati, Parminder Bhatia, Dan Roth, and 1 others. 2023. CrossCodeEval: A Diverse and Multilingual Benchmark for Cross-File Code Completion. In Advances in Neural Information Processing S… find
  12. Zhangyin Feng, Daya Guo, Duyu Tang, Nan Duan, Xiaocheng Feng, Ming Gong, Linjun Shou, Bing Qin, Ting Liu, Daxin Jiang, and 1 others. 2020. Code-BERT: A Pre-Trained Model for Programming and Wenchao Gu, Zongyi Lyu, Yanlin Wang, Hongyu Zhang, Cuiyun Gao, and Michael R Lyu. 2025a. SPENCER: Self-Adaptiv… — [arXiv:2508.00546](https://arxiv.org/abs/2508.00546) find
  13. Wenchao Gu, Ensheng Shi, Yanlin Wang, Lun Du, Shi Han, Hongyu Zhang, Dongmei Zhang, and Michael R Lyu. 2025b. SECRET: Towards Scalable and Efficient Code Retrieval via Segmented Deep Hashing. In Proceedings of the IEEE/ACM 47th International Conference on Software Engineering, pages 2303–2315. IEEE. find
  14. Wenchao Gu, Yanlin Wang, Lun Du, Hongyu Zhang, Shi Han, Dongmei Zhang, and Michael Lyu. 2022. Accelerating Code Search with Deep Hashing and Code Classification. In Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics, pages 2534–2544. find
  15. Daya Guo, Shuai Lu, Nan Duan, Yanlin Wang, Ming Zhou, and Jian Yin. 2022. UniXcoder: Unified Cross-Modal Pre-training for Code Representation. In Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics, pages 7212– 7225.
  16. Priyanshu Gupta, Avishree Khare, Yasharth Bajpai, Saikat Chakraborty, Sumit Gulwani, Aditya Kanade, Arjun Radhakrishna, Gustavo Soares, and Ashish Tiwari. 2023. Grace: Language Models Meet Code Edits. In Proceedings of the 31st ACM Joint European Software Engineering Conference and Symposium on the… find
  17. Siming Huang, Tianhao Cheng, Jason Klein Liu, Jiaran Hao, Liuyihan Song, Yang Xu, J Yang, Jiaheng Liu, Chenchen Zhang, Linzheng Chai, and 1 others. 2024. OpenCoder: The Open Cookbook for Top-Tier Code Large Language Models. In CoRR.
  18. GitHub Inc. 2024. GitHub Copilot: Your AI Pair Programmer. Accessed: 2024-10-06. find
  19. Maliheh Izadi, Jonathan Katzy, Tim Van Dam, Marc Otten, Razvan Mihai Popescu, and Arie Van Deursen. 2024. Language Models for Code Completion: A Practical Evaluation. In Proceedings of the IEEE/ACM 46th International Conference on Software Engineering, pages 1–13. find
  20. Carlos Jimenez, John Yang, Alexander Wettig, Shunyu Yao, Kexin Pei, Ofir Press, and Karthik R Narasimhan. 2024. SWE-bench: Can Language Models Resolve Real-world Github Issues? In The Twelfth International Conference on Learning Representations.
  21. Denis Kocetkov, Raymond Li, Chenghao Mou, Yacine Jernite, Margaret Mitchell, Carlos Muñoz Ferrandis, Sean Hughes, Thomas Wolf, Dzmitry Bahdanau, Leandro Von Werra, and 1 others. 2023. The Stack: 3 TB of permissively licensed source code. In Transactions on Machine Learning Research. find
  22. Cursor Team. 2024. Cursor. Accessed: 2024-10-06. find
  23. Patrick Lewis, Ethan Perez, Aleksandra Piktus, Fabio Petroni, Vladimir Karpukhin, Naman Goyal, Heinrich Küttler, Mike Lewis, Wen-tau Yih, Tim Rocktäschel, and 1 others. 2020. Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks. In Advances in Neural Information Processing Systems, volum…
  24. Yue Wang, Weishi Wang, Shafiq Joty, and Steven CH Hoi. 2021. CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generation. In Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing, pages 8696–8708. find
  25. Ming Liang, Xiaoheng Xie, Gehao Zhang, Xunjin Zheng, Peng Di, Wei Jiang, Hongwei Chen, Chengpeng Wang, and Gang Fan. 2024. REPOFUSE: Repository-Level Code Completion with Fused Dual Context. In CoRR. find
  26. Shanchao Liang, Spandan Garg, and Roshanak Zilouchian Moghaddam. 2025a. The SWE-Bench Illusion: When State-of-the-Art LLMs Remember Instead of Reason. arXiv preprint arXiv:2506.12286. find
  27. Shanchao Liang, Yiran Hu, Nan Jiang, and Lin Tan. 2025b. Can Language Models Replace Programmers? REPOCOD Says ‘Not Yet’. In Proceedings of the 63rd Annual Meeting of the Association for Computational Linguistics. find
  28. Tianyang Liu, Canwen Xu, and Julian McAuley. 2024. RepoBench: Benchmarking Repository-Level Code Auto-Completion Systems. In The Twelfth International Conference on Learning Representations. find
  29. Anton Lozhkov, Raymond Li, Loubna Ben Allal, Federico Cassano, Joel Lamy-Poirier, Nouamane Tazi, Ao Tang, Dmytro Pykhtar, Jiawei Liu, Yuxiang Wei, and 1 others. 2024. StarCoder 2 and The Stack v2: The Next Generation. arXiv preprint arXiv:2402.19173. find
  30. Siru Ouyang, Wenhao Yu, Kaixin Ma, Zilin Xiao, Zhihan Zhang, Mengzhao Jia, Jiawei Han, Hongming Zhang, and Dong Yu. 2025. RepoGraph: Enhancing AI Software Engineering with Repository-level Code Graph. In The Thirteenth International Conference on Learning Representations. find
  31. Debalina Ghosh Paul, Hong Zhu, and Ian Bayley. 2024. Benchmarks and Metrics for Evaluations of Code Generation: A Critical Review. In 2024 IEEE International Conference on Artificial Intelligence Testing (AITest), pages 87–94. IEEE. find
  32. Stephen Robertson, Hugo Zaragoza, and 1 others. 2009. The Probabilistic Relevance Framework: BM25 and Beyond. Foundations and Trends® in Information Retrieval, 3(4):333–389. find
  33. ByteDance Seed, Yuyu Zhang, Jing Su, Yifan Sun, Chenguang Xi, Xia Xiao, Shen Zheng, Anxiang Zhang, Kaibo Liu, Daoguang Zan, and 1 others. 2025. Seed-Coder: Let the Code Model Curate Data for Itself. arXiv preprint arXiv:2506.03524.
  34. Qwen Team. 2025. Qwen3-Coder: Agentic Coding in the World. Blog post. find
  35. Zora Zhiruo Wang, Akari Asai, Frank F Xu, Yiqing Xie, Graham Neubig, Daniel Fried, and 1 others. 2025. CodeRAG-Bench: Can Retrieval Augment Code Generation? In Findings of the Association for Computational Linguistics: NAACL 2025, pages 3199–3214. find
  36. Michael L. Waskom. 2021. seaborn: statistical data visualization. Journal of Open Source Software, 6(60):3021. find
  37. Amazon Web Services. 2024. Amazon Q Developer: AI-Powered Coding Assistant. Accessed: 2024-10-06. find
  38. Di Wu, Wasi Uddin Ahmad, Dejiao Zhang, Murali Krishna Ramanathan, and Xiaofei Ma. 2024. Repoformer: Selective Retrieval for Repository-Level Code Completion. In Proceedings of the 41st International Conference on Machine Learning, pages 53270–53290. find
  39. An Yang, Anfeng Li, Baosong Yang, Beichen Zhang, Binyuan Hui, Bo Zheng, Bowen Yu, Chang Gao, Chengen Huang, Chenxu Lv, and 1 others. 2025. Qwen3 Technical Report. arXiv preprint arXiv:2505.09388.
  40. Dejiao Zhang, Wasi Uddin Ahmad, Ming Tan, Hantian Ding, Ramesh Nallapati, Dan Roth, Xiaofei Ma, and Bing Xiang. 2024. Code Representation Learning at Scale. In The Twelfth International Conference on Learning Representations. find
  41. Fengji Zhang, Bei Chen, Yue Zhang, Jacky Keung, Jin Liu, Daoguang Zan, Yi Mao, Jian-Guang Lou, and Weizhu Chen. 2023. RepoCoder: Repository-Level Code Completion Through Iterative Retrieval and Generation. In Proceedings of the 2023 Conference on Empirical Methods in Natural Language Processing, pag… find
  42. Lei Zhang, Yunshui Li, Jiaming Li, Xiaobo Xia, Jiaxi Yang, Run Luo, Minzheng Wang, Longze Chen, Junhao Liu, Qiang Qu, and 1 others. 2025. Hierarchical Context Pruning: Optimizing Real-World Code Completion with Repository-Level Pretrained Code LLMs. In Proceedings of the AAAI Conference on Artificia… find
  43. Dewu Zheng, Yanlin Wang, Ensheng Shi, Ruikai Zhang, Yuchi Ma, Hongyu Zhang, and Zibin Zheng. 2025. HumanEvo: An Evolution-Aware Benchmark for More Realistic Evaluation of Repository-Level Code Generation. In 2025 IEEE/ACM 47th International Conference on Software Engineering, pages 1372– 1384. IEEE. find
  44. Terry Yue Zhuo, Vu Minh Chien, Jenny Chim, Han Hu, Wenhao Yu, Ratnadira Widyasari, Imam Nur Bani Yusuf, Haolan Zhan, Junda He, Indraneil Paul, and 1 others. 2025. BigCodeBench: Benchmarking Code Generation with Diverse Function Calls and Complex Instructions. In The Thirteenth International Conferen…

Updated

↑ back to top

This page in Markdown → https://md.research.elamur.ai/free/en/papers/ma-2026-specagent-speculative-retrieval-forecasting-agent/