Cost-Aware Python Code Repair via Budget-Threshold LLM Optimization
Abstract
Repeated test feedback can increase token consumption during large language model (LLM) code repair, particularly for difficult tasks. This study examines whether fixed feedback compression and observable progress signals can control this overhead without changing model parameters. The cost_aware strategy combines feedback filtering, budget-threshold and no-progress stopping, reset prompts, and a final rewrite opportunity. Five strategies were evaluated on 30 QuixBugs-derived Python tasks over three independent API runs. Public tests guided repair, whereas hidden tests were reserved for final evaluation. cost_aware fully passed 27 tasks in every run, averaging 90.0%, and consumed 47.5% fewer tokens than full_loop. Maximum per-task usage dropped substantially from 29,498 to 4,185 tokens, demonstrating effective tail suppression; while conservative multiplicity-adjusted inference reflects the limited sample size (N=30), the observed effect sizes highlight substantial practical utility. A single exploratory DeepSeek run showed a smaller reduction in the same direction. These observations warrant further evaluation of transparent invocation control, with conclusions limited to the tested tasks, models, and sampling conditions.
References
- Gazzola, L., Micucci, D., & Mariani, L. (2019). Automatic software repair: A survey.IEEE Transactions on Software Engineering, 45(1), 34-67. DOI: 10.1109/TSE.2017.2755013.
- Nguyen, H. D. T., Qi, D., Roychoudhury, A., et al. (2013). SemFix: Program repair via semantic analysis. InProceedings of the 35th International Conference on Software Engineering(pp. 772-781). IEEE. DOI: 10.1109/ICSE.2013.6606623.
- Martinez, M., Durieux, T., Sommerard, R., et al. (2017). Automatic repair of real bugs in Java: A large-scale experiment on the Defects4J dataset.Empirical Software Engineering, 22(4), 1936-1964. DOI: 10.1007/s10664-016-9470-4.
- Lu, S., Guo, D., Ren, S., et al. (2021). CodeXGLUE: A machine learning benchmark dataset for code understanding and generation. arXiv:2102.04664.
- Bouzenia, I., Devanbu, P., & Pradel, M. (2025). RepairAgent: An autonomous, LLM-based agent for program repair. InProceedings of the 47th IEEE/ACM International Conference on Software Engineering(pp. 2188-2200). IEEE. DOI: 10.1109/ICSE55347.2025.00157.
- Shinn, N., Cassano, F., Gopinath, A., et al. (2023). Reflexion: Language agents with verbal reinforcement learning.Advances in Neural Information Processing Systems, 36, 8634–8652. DOI: 10.52202/075280-0377.
- Yang, J., Jimenez, C. E., Wettig, A., et al. (2024). SWE-agent: Agent-computer interfaces enable automated software engineering.Advances in Neural Information Processing Systems, 37. DOI: 10.52202/079017-1601.
- Jia, H., Barr, E. T., MechtAev, S. (2026). Compressing code context for LLM-based issue resolution. arXiv:2603.28119.
- Yang, B., Tian, H., Ren, J., et al. (2025). MORepair: Teaching LLMs to repair code via multi-objective fine-tuning.ACM Transactions on Software Engineering and Methodology. DOI: 10.1145/3735129.
- Solat, F., & Lee, J. (2025). Optimizing client participation in communication-constrained federated LLM adaptation with LoRA.Sensors (Basel, Switzerland), 25(21), 6538. DOI: 10.3390/s25216538.
- Yin, Y., Zhang, F., Wu, Z., et al. (2024). PILL: Plug into LLM with adapter expert and attention gate.Applied Soft Computing, 165(000). DOI: 10.1016/j.asoc.2024.112115.
- Xu, J., Xu, Z., Jiang, Z., et al. (2026). Labeling-free RAG-enhanced LLM for intelligent fault diagnosis via reinforcement learning.Advanced Engineering Informatics, 69(pa), 103864. DOI: 10.1016/j.aei.2025.103864.
- Lin, D., Koppel, J., Chen, A., et al. (2017). QuixBugs: A multi-lingual program repair benchmark set based on the Quixey challenge.Proceedings of the 2017 ACM SIGPLAN International Conference on Systems, Programming, Languages, and Applications: Software for Humanity, 55–56. DOI: 10.1145/3135932.3135941.
- Widyasari, R., Sim, S. Q., Lok, C., et al. (2020). BugsInPy: A database of existing bugs in Python programs to enable controlled testing and debugging studies.Proceedings of the 28th ACM Joint Meeting on European Software Engineering Conference and Symposium on the Foundations of Software Engineering, 1556–1560. DOI: 10.1145/3368089.3417943.