arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2606.27733cs.SE
收藏

BashCoder-R1: 面向鲁棒且可解释的Bash代码生成——鲁棒感知组相对策略优化

BashCoder-R1: Towards Robust and Explainable Bash Code Generation with Robustness-Aware Group Relative Policy Optimization

University of Chinese Academy of Sciences(中国科学院大学);Institute of Software, Chinese Academy of Sciences(中国科学院软件研究所)

Lei Yu, Peng Wang, Jia Xu, Jingyuan Zhang, Xin Wang, Jiajia Ma, Li Yang, Changzhi Deng, Zenghua Wang, Fengjun Zhang

AI总结:

提出BashCoder-R1框架,结合持续预训练、长思维链监督微调和鲁棒感知组相对策略优化,在BashBench基准上实现高语法通过率、低鲁棒警告率和功能完整率,显著超越DeepSeek-V3.2。

摘要:

Bash脚本是系统管理和DevOps自动化的基石,代码质量直接影响系统稳定性和安全性。在使用大型语言模型(LLMs)自动生成Bash脚本时,会出现两个相互关联的失败:不可审计的“黑箱”推理和生成代码中的关键鲁棒性漏洞。为解决这两个问题,我们提出了BashCoder-R1,一个用于鲁棒且可解释的Bash脚本生成的新颖框架。我们的流程结合了:(1)持续预训练(CPT),使模型专门化于Bash范式;(2)在专家验证的推理与代码样本上进行长思维链监督微调(L-CoT SFT),以模拟主动的风险感知思维;(3)鲁棒感知组相对策略优化(R-GRPO),一个强化学习阶段,优化语法正确性、鲁棒性(通过shellcheck)和格式正确性的加权奖励。我们在BashBench(一个包含952个真实世界任务的新基准,其中773个单行任务,179个多行任务)上进行评估。BashCoder-R1在单行/多行任务上实现了SyntaxPass(100.00%/94.97%)、RobustWarnRate(4.01%/16.47%)、RobustPass(95.99%/79.33%)、FuncRate(93.01%/93.85%)和FullRate(90.04%/73.18%),在FullRate上分别比最强基线DeepSeek-V3.2(推理)高出37.82%和20.18%。在功能性、鲁棒性和清晰度上的人工评估进一步证实BashCoder-R1获得了最高质量评级。

英文摘要:

Bash scripts are critical for system administration, DevOps, and CI/CD, where code quality affects stability and security. However, LLM-generated scripts often lack reasoning and contain robustness flaws such as mishandled edge cases and unchecked failures. This is particularly critical in production environments where even minor errors can lead to service disruptions. We propose BashCoder-R1, a framework that jointly addresses both issues by treating explainability as a design goal. The pipeline has three stages. Continual Pre-training adapts to Bash syntax. Long Chain-of-Thought Supervised Fine-Tuning on expert-validated samples teaches risk-averse reasoning before code generation. Robustness-Aware Group Relative Policy Optimization optimizes a weighted reward for syntax correctness, robustness (verified by shellcheck), and format adherence. This staged design ensures that the model progressively acquires syntax knowledge, reasoning capability, and robust decision-making. On our BashBench benchmark (952 real-world tasks, 773 single-line and 179 multi-line), BashCoder-R1 achieves SyntaxPass of 100.00/94.97, RobustWarnRate of 4.01/16.47, RobustPass of 95.99/79.33, FuncRate of 93.01/93.85, and FullRate of 90.04/73.18 for single-line and multi-line tasks, respectively. These are relative FullRate improvements of 37.82 and 20.18 percent over the strongest baseline, DeepSeek-V3.2 (Reasoning). Human evaluation confirms its reasoning chains are highest in quality.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑