Code-as-policy agents often use execution feedback to retry failed programs. Additional sampling and task guidance can also improve success, leaving the contribution of failure-specific feedback unclear. We study this question in simulated robot manipulation. A fixed lookup selects feedback templates using failure labels and the API variant. A frozen code model generates a fresh program after each scene reset. On the same 252 initial failures, Qwen2.5-Coder-7B recovers 85.3% within five retries, compared with 68.3% for resampling with the same retry cap. The advantage persists under fixed total-token budgets. Feedback from other episodes and fixed task guidance yield similar recovery point estimates, with no detected benefit from matching the coarse failure label. In a separate study, a fixed guided prompt used from the first attempt achieves an observed overall success rate similar to that of template-based feedback. Template-based feedback also lowers recovery on a nut-insertion task requiring a rim grasp, consistent with an incompatible center-grasp instruction. Evaluations of robot self-repair should include resampling, mismatched feedback, and concise, task-compatible static guidance as baselines.
Figures & tables
Figure 1: Template-based feedback improves recovery over resampling. (a) Reset-and-retry loop and feedback methods. (b) Recovery on 252 initial failures, with similar outcomes for Compiled, Different-Label Feedback, and Fixed Task Template.
Detected failure
Guidance added to the retry prompt
Grasp did not secure the object
MUST: grasp at the object’s CENTRE: …, with the gripper empty
Object grasped but not lifted
MUST: … call lift(name, height=0.1) after the grasp
Unsupported function call
MUST: use ONLY the documented API functions … NEVER: import statements
Table 1: Failure labels select fixed retry guidance. Example instruction excerpts for the primitive API. Full templates are provided in Appendix D .
Figure 2: Guidance improves recovery under fixed token budgets. (a) An initial failure followed by a successful retry after reset. (b) Recovery under total-token budgets. (c) Paired recovery@5 comparisons show an advantage over resampling, with no detected advantage over different-label or fixed-template guidance.
Comparator
Question
Δ (pp; 95% CI)
Resample
benefit beyond another sample?
+17.1[+9.9,+24.2]
Different-Label Feedback
must the label match?
−0.8[−6.3,+4.8]
Fixed Task Template
dynamic versus fixed guidance?
−0.8[−6.7,+5.2]
Direct+Compiled
does editing improve recovery?
+63.9[+56.7,+70.6]
Table 2: Primary paired contrasts on 252 initial failures. Each entry is Compiled minus the comparator in recovery@5, with a 95% paired-bootstrap CI.
Figure 3: A fixed guided prompt improves initial success. (a) Initial and overall success on 700 fresh scenes. (b) Total model tokens per solved episode. Static-from-Start changes both the initial instruction and guidance.
Figure 4: Guidance benefits vary across tasks and models. Compiled–Resample recovery differences across evaluated settings. The diamond summarizes the seven eligible generalization settings.
Appendix figures & tables6 assets
Supplementary material from the paper’s appendix.
Appendix
Study
Model and evaluation set
Retry instruction
Main endpoint
Primary
Qwen2.5-Coder-7B; 252 held-out failures, lifting and stacking
Neutral
Recovery within five retries
Generalization
Qwen2.5-Coder-3B/7B; 354 failures across seven eligible settings, four tasks
Original
Recovery within five retries
Earlier end-to-end
Qwen2.5-Coder-7B; 700 fresh scenes, lifting and stacking
Original
Overall success within six executions
Static-from-Start
Qwen2.5-Coder-7B; 700 separate fresh scenes, lifting and stacking
Neutral
Overall success within six executions
Appendix
Table A1: Evaluation sets and endpoints. Comparisons pair conditions within each study. Original and neutral instructions are reproduced in Appendix B.4 .
Condition
Feedback supplied to program generation
Resample / Compiled
No feedback / accumulated templates for the observed labels.
Other-Episode Feedback
Accumulated feedback from a matched source episode.
Different-Label Feedback
Feedback from another failure, prioritizing a different label.
Permuted Labels
A fixed permutation replaces every observed label with a different label.
Cross-Task Feedback
A fixed assignment of source episodes from a different task.
Fixed Task Template
One fixed development-selected template per task, reused after failure.
Appendix
Table A2: Prompt inputs for each feedback and editing condition. Source-episode selection and prompt construction are specified below.
Figure A1: (a) Recovery with feedback and editing conditions in earlier evaluations. (b) A task-independent prompt improves recovery on stacking but reduces it on lifting.
Contrast
Δ (pp)
95% CI
p
Reflection Repair − Resample
−45.2
[−53.2,−36.9]
2.9×10−21
All-Template Union − Resample
−36.1
[−44.0,−27.8]
3.6×10−14
Compiled − Initial-Label Only
+0.4
[−4.0,+4.8]
1.0
Compiled − Permuted Labels
+1.6
[−3.6,+6.7]
1.0
Placebo − Resample
−29.8
[−37.7,−21.8]
3.7×10−11
Appendix
Table A3: Additional controls test feedback content and label matching. Comparisons using the original generation instruction on 252 held-out failures. p -values are Holm-adjusted within predefined groups of secondary comparisons.
Condition
Initial
Overall@6
Recovery@5
Tok/solved
Static-from-Start
36.9
92.4
88.0
2,087
Fixed Task Template
19.3
90.1
87.8
2,564
Compiled
19.3
89.6
87.1
2,578
Resample
19.3
73.1
66.7
3,623
Appendix
Table A4: Static-from-Start increases initial success and reduces tokens per solved episode. Results on 700 fresh scenes with neutral retry instructions. Success and recovery are percentages; recovery uses different initial-failure subsets.
Figure A2: Recovery differences between Compiled and Resample across model-specific studies. Each point compares Compiled with Resample within a separately evaluated model and task set.
Self-repair - returning a failed program to the model together with its test output and asking for a correction - is a standard component of code agents, and is almost always evaluated against a baseline that does not retry at all. We argue that this comparison confounds the value of the feedback with the value of the extra attempt. Using a placebo-controlled design on MBPP+ at three model scales (1.5B, 3B, 7B), we compare four matched-budget retry conditions: blind resampling, a content-free failure notice, genuine execution feedback, and feedback augmented with verbal self-reflection. Blind resampling is the strongest condition below 7B, and remains statistically tied with the best condition at 7B, while consuming 2.5-5.5x fewer tokens; conditioning on the model's own failed attempt costs 6.1 points at 1.5B (p=0.006), and the informational content of execution feedback adds nothing measurable over the placebo. We attribute this to anchoring: when shown its previous attempt, a model reproduces a near-identical program in 33-68% of retries, against 2-14% under blind resampling. Two further experiments delimit the effect. Retrieved solutions to other tasks change nothing (bounded to +/-3.5 points), which localizes the harm to self-conditioning rather than context length; and reflection, the only condition that measurably weakens the anchor, remains dominated on cost. Replication rules out two competing explanations: the penalty is unchanged at full precision, and it reproduces on an independent model family. Across six configurations spanning two families and two precisions, its magnitude is predicted by baseline quality alone (r=0.96) - the cost of anchoring is the cost of committing to a bad first attempt.
Self-improving agents use failure feedback to revise their code or instructions, but gains after selection do not establish target-specific repair or generalization. We measure directedness by comparing repair of a randomly selected target failure with repair of the parent's other failures. Across 145 eligible modifications in public Darwin Gödel Machine logs, we find no detectable target-specific advantage. Controlled instruction-revision experiments with small open models show that relevant feedback can improve target repair. In a second study with a pre-specified analysis plan, target feedback raised repair by 20 percentage points for Qwen3-4B relative to matched same-category feedback; the 7-point increase for Phi-4-mini was not significant. Target repair did not reliably imply held-out improvement. Held-out gains were concentrated in settings with identifiable, repairable failure mechanisms, including planted errors and natural tool-interface failures. Benefits of edit localization and regression screening varied across settings, while eight-step revision loops and GEPA ended at similar mean held-out accuracy. Evaluations should report target repair, transfer to related failures, and held-out net change separately.
Rejection sampling fine-tuning (RFT) is widely used to train code agents by generating trajectories on verifiable software engineering tasks, retaining those that pass the tests, and fine-tuning on the successful rollouts. However, even strong code agents repeatedly fail on a substantial fraction of such tasks, and standard RFT simply discards these failures. The discarded samples are precisely the hardest and most informative ones, drawn from verifiable instances that are costly to curate. Stronger base models may reduce the number of failures, but the remaining hard cases still define the frontier for further improvement. We propose FailForge, an agentic framework that converts failed rollouts into training signal. For each failed instance, an agent diagnoses the failure from error feedback and execution traces, distills the diagnosis into a concise and actionable skill, and injects the skill into the agent context for a guided second attempt. Trajectories that succeed under skill guidance are folded back into the RFT corpus. Crucially, the skill is removed at training time, so the model internalizes the recovered behavior rather than relying on external hints at inference. FailForge recovers over 26% of previously failed instances at marginal additional cost, and training Qwen3.5-4B on the augmented corpus improves the SWE-bench Verified resolve rate by 6.6 points over a strong RFT baseline, with gains concentrated on the hardest problems.
Dongyi Lv, Fushun E, Aichen Cai +8
Xi’an Jiaotong University · Joy Future Academy, JD