MARGIN: A Risk-Aware Agent for Robot Program Refinement
Authors: Hongbo Duan, Fan Du, Haipeng Luo, Bin Qian, Zichao Nie, Yilin Mi, Yaopeng Tian, Jiake Tian, Siyuan Liu, Yan Gao, Fangming Liu, Xueqian Wang
Organizations: Tsinghua University · Peng Cheng Laboratory · Southern University of Science and Technology · Institute of Automation, Chinese Academy of Science
Robot-programming agents improve executable control policies through repeated testing and repair, yet binary success saturates while execution risk persists across unseen scenes. We introduce MARGIN, a risk-aware agent that converts successful robot rollouts into actionable evidence for program refinement. Its near-miss margin measures the fraction of the execution budget remaining in the slowest successful development rollout. The agent uses this signal to prioritize fragile programs, guide targeted repairs, and select revisions that preserve development success while increasing execution headroom. An exact safe-racing rule accelerates success-based candidate evaluation. We evaluate MARGIN across LIBERO-Pro, LIBERO-90, and Robosuite. In our 80-task LIBERO-Pro reproduction, 78 programs attain perfect development success while accounting for substantial failures on unseen seeds. The near-miss margin predicts held-out failures with an AUC of 0.774, and low-margin programs exhibit 2.97 times higher failure risk. Across two independent evaluation rounds spanning 37 unique LIBERO-Pro tasks, MARGIN reduces executed control steps by 10.7% and 15.0%, with reductions of 18.0-20.0% on LIBERO-90 and Robosuite. Safe racing reduces fixed-sequence candidate-evaluation episodes by 53.5% while retaining identical selections, and paired execution probes improve acceptance decisions by identifying hidden regressions. Together, these results establish near-miss evidence as an effective basis for risk-aware, budget-efficient robot program refinement.
Figures & tables
Figure 2: MARGIN: risk-aware refinement within agentic robot debugging. (a) The debugging backbone combines task context, an LLM coding worker, development evaluation, and incumbent selection; each rollout yields a success indicator and execution length. (b) Before saturation, safe racing evaluates candidates under strict success-count improvement, rejecting a candidate when its upper bound U(k,n) cannot exceed S(P∗) . After S(P∗)=N , successful development rollouts provide the near-miss margin m(P∗) . The risk trigger allocates repair budget B ; a complete development sweep recomputes S(P′) and m(P′) , and the controller accepts only success-preserving, margin-improving audited revisions. Optional paired probes screen hidden regressions on separate diagnostic seeds. (c) An illustrative margin increase with unchanged development success.
Figure 3: MARGIN results across three benchmarks. Red, blue, and green indicate LIBERO-Pro, LIBERO-90, and Robosuite. (a) Task-level near-miss risk prediction with 95% bootstrap intervals. (b) Development evaluation cost relative to full candidate sweeps, with Safe Racing preserving candidate selections in fixed-sequence replay. (c) Paired original and refined execution steps on unseen initializations. (d) Fresh-seed failure rate across LIBERO-Pro margin bins; values above bars show task counts.
Object
Spatial
Goal
LIBERO-10
Mean (%)
Method
P
T
P
T
P
T
P
T
Avg.6 (Avg.8)
Policy
π0.5 [ 12 ]
17.0
1.0
20.0
1.0
38.0
0.0
–
–
12.8
Agent + policy
Pigey [ 13 ]
54.0
54.0
66.0
80.0
44.0
22.0
–
–
53.3
Harness VLA (Codex) [ 60 ]
91.0
94.0
69.0
81.0
66.0
75.0
49.0
52.0
79.3 (72.1)
Table 1: LIBERO-Pro success rates across eight task categories. P/T: position/task perturbations. Bold: best in each comparable column (ties included). The six-category mean is followed by the eight-category mean in parentheses when available. Only our ASPIRE reproduction is listed. MARGIN combines ASPIRE incumbents and accepted refinements over 80 tasks. Baseline scores are from the cited papers.
Figure 4: MARGIN refinement examples across three benchmarks. Real simulator frames illustrate paired execution outcomes on unseen initializations. Top: the original program at matched control steps and termination. Bottom: the MARGIN revision during execution and at termination. The variable t denotes the executed control step. (a) LIBERO-Pro mug placement. The revision completes placement with 200 fewer steps. (b) LIBERO-90 drawer closure and bowl placement. The revision completes the task with ample execution headroom. (c) Robosuite spill wiping. The revision completes the wipe in a shorter trajectory.
Table 5
Benchmark
Programs
AUC [95% CI]
Risk ratio
LIBERO-Pro
72
0.774 [0.63, 0.89]
2.97
LIBERO-90
90
0.697 [0.567, 0.811]
3.67
Robosuite
6
0.750 [0.200, 1.000]
–
Table 4: Near-miss risk prediction across benchmarks. Task-level failure prediction for dev-perfect programs, evaluated on unseen seeds.
Figure 5: Margin gains during agentic repair. Each curve traces the best eligible margin improvement within a refinement session as more development episodes are evaluated. The solid black curve summarizes the median across 74 repair sessions; the dashed line marks the acceptance threshold δ=0.02 .
Benchmark
Tasks
ASPIRE
Margin
Total
LIBERO-Pro
37
–
4.4
164
LIBERO-90
25
12.5
6.0
151
Robosuite
4
15.8
5.8
23
Total
66
–
5.1
338
Table 6: Agent cost by benchmark. USD per task for ASPIRE discovery and Margin refinement; total USD for refinement.
Offline selection
Dev ep.
Saved (%)
False rej.
Full-15
2,550
–
0
Stop-on-Perfect
1,395
45.3
0
Fixed-5 strict
1,290
49.4
20
Safe racing
1,186
53.5
0
Live agent (10 tasks)
Dev ep.
Held-out
LLM USD
Full-sweep agent
876
477/500
113.5
Table 7: Evaluation efficiency. Offline replay on 170 non-ablation candidates (fixed sequence); live 10-task agent experiment (different search trajectories).
Figure 6: Execution probes detect hidden regressions. The study covers 74 candidates and uses decisions frozen before evaluation on independent seeds. (a) Change in regression rate relative to accepting every MARGIN candidate, together with the evidence cost of each policy. (b) Regression and recovery rates alongside execution steps under each policy.
Policy
Probe ep.
VLM
Regr.
Recov.
A0: MARGIN
0
0
0.68
0.89
A1: alarm → probe
1,040
0
0.54
0.84
A1r: random probe
1,040
0
0.59
0.86
A1all: probe all
2,960
0
0.43
0.81
A2: VLM verdict
0
26
0.59
0.78
A3: VLM + probe
200
26
0.62
0.89
Table 8: Evidence-policy ablation. Round 2, 37 tasks and 74 candidate programs; final-seed regression and recovery rates (%).
Figure 7: Cross-benchmark repair gains. Per-task mean control steps for ASPIRE and MARGIN on independent LIBERO-90 and Robosuite seeds. Each point averages two repair runs; the dashed line denotes equal steps.