Robots that run programs written by a language model, such as Python scripts that call perception and motion functions, have one familiar failure mode. When a script breaks partway through a task, current systems stop the robot, ask the model to debug the script, and resume only after the fix is ready. Examples of such breaks include an exception, a missed grasp, or a container that turns out to be locked. In a static scene, stopping costs only time. In a scene where objects or people move, the world the fix was written for no longer exists when the fix arrives. We propose to let a fast, simple safety behavior keep the robot moving while a slower language-model loop debugs the failed code in the background and then swaps the repaired function into the running program. The central technical idea is to test each candidate fix against a forecast of the state the robot will be in when the swap happens, not against the snapshot taken when the failure occurred. A final check at swap time decides whether the fix is still valid.
The opportunity comes from two literatures that have not been joined. Robot controllers that split a slow reasoner from a fast actor already show that the robot must not wait for the reasoner, and that the actor needs to be told how stale the reasoner's output is. Separately, systems that refine code by executing it already show that tests and error messages make generated code far more reliable. Every code-refinement system in our file runs before execution or between episodes. Every reasoner–actor split in our file passes neural features rather than programs. Nobody has asked what goes wrong when debugging a program takes three seconds and the world moves during those three seconds.
Core Claim
Asynchronous repair of executing code policies is only useful if the repair is anchored to where the world will be at swap time. Our main claim is that a refinement loop which runs its tests in a simulator copy advanced to the predicted swap state, followed by a swap-time admission check on the real state, will recover from mid-task failures in dynamic scenes more often than three alternatives. The first is stopping to debug. The second is asynchronous repair tested against the failure-time snapshot. The third is regenerating the program from scratch. We further claim that the advantage over snapshot-anchored repair should grow roughly with the product of scene speed and refinement latency, because that product sets how far the real state drifts from the state the fix was tested against. The advantage should vanish when the scene is static. This dependence is the experiment that tells us whether the mechanism, and not merely the concurrency, is doing the work.
Where This Sits
Three code-as-policy lines supply the code representation and the refinement machinery, and all three refine before or between executions.
Code as Policies has a language model write Python programs that call perception and control functions. It runs them open-loop with no repair. We keep its program representation but add live repair.
NESYRO verifies generated code with an SMT solver (an automatic logic checker) and a PDDL planner, and runs safe probing scripts when confidence is low. It reduces irreversible actions from 53 to 7 and improves RLBench success by 46.2% over Code as Policies. It does all of this while the robot is stationary. We reuse its idea of explicit preconditions as the content of our swap-time check. We drop the assumption that the robot may wait.
LearnAct refines a library of Python action functions from failures across episodes, reaching 72.2% on AlfWorld. Its observation that the model prefers editing code over writing notes 90% of the time supports making function-level patches, rather than prose advice, our unit of repair. Its learning is episodic and turn-based.
RobotGPT, Code-as-Symbolic-Planner and Code-BT all use multi-round checking loops, but entirely before motion. RobotGPT's authors themselves call for closed-loop LLM interaction after open-loop real-world placement errors.
Asynchronous reasoner–actor work motivates the setting and supplies the staleness idea.
HiRT runs a large vision-language model in the background and a light policy at about 10 Hz. It raises success on moving targets from 48% to 75%. This is our main evidence that blocking on slow reasoning fails in dynamic scenes.
TIC-VLA passes elapsed latency and ego-motion offset from the reasoner to the actor. Removing the offset drops success from 47% to 41%. This is the closest precedent for our forecast anchoring. TIC-VLA, however, corrects a neural feature at consumption time, whereas we must correct a test procedure at refinement time, because a program that passed its tests on a stale state can be confidently wrong.
Bridging the Resource Gap drops action chunks that would have run during inference lag, raising cup stacking from 68% to 88%. It is a simpler cousin of the swap-time check, discarding outdated output rather than validating it.
The constraining evidence comes from refinement itself. SlopCodeBench shows that repeated refinement erodes previously working code. Yan et al. report that compiler-driven refinement plateaus after a few rounds. Both push us toward small, function-scoped patches with rollback, and toward a hard per-failure iteration budget, rather than open-ended repository-level loops like MAGIS, which takes minutes per issue.
Research Program
The system has three concurrent parts.
The executing program. This is a Code-as-Policies-style script decomposed into named functions such as approach, grasp and place. Each function must declare preconditions as executable assertions. These are checks on the observed state, for example that the target is within reach or the gripper is empty.
The holding behavior. When a function raises an exception or fails a postcondition, control passes to one of a few hand-written safe primitives: hold pose, track the target at a standoff distance, or retreat from the nearest moving obstacle. The reasoner selects the primitive in a single fast call. These primitives are deliberately simple, so that their future trajectory can be predicted.
The background repair loop. This loop forks the simulator from the current estimated state. It then advances the fork to a predicted swap time $t + \hat{T}$. During that advance, the robot follows the chosen holding primitive, and other moving objects are extrapolated at constant velocity from their observed tracks. No privileged future simulator state is used. Here $\hat{T}$ is a running estimate of how long one repair takes. The loop runs the familiar generate–execute–debug cycle on the failed function only, testing each candidate against the forecast state, with a budget of at most four iterations.
When a candidate passes, the swap-time check runs on the actual current state. It evaluates the patch's preconditions and a short rollout in a fresh fork.
- If the check succeeds, the function is swapped in and the program resumes from that function.
- If it fails, the loop re-forecasts from the new state and warm-starts from the last candidate.
- If the patch later causes a regression in a previously working function, the system rolls back to the last stable version.
We will build this on RLBench, using its simulator for forking. The conceptual work is a measurement of staleness: the fraction of patches that pass their tests yet fail at swap time. We will measure staleness as a function of scene speed and repair latency, and compare it with what the anchoring removes.
Baselines
The naive reference point is Code as Policies with no repair: the program fails and the episode ends. It sets the floor and shows how often mid-task failures occur at all under our perturbations.
The strongest existing method is NESYRO-style synchronous repair (NESYRO). The robot halts at failure, the same language model repairs the same function with the same precondition checks and iteration budget, and execution resumes. NESYRO's reported figures are a 46.2% RLBench success gain over Code as Policies and 53 to 7 irreversible actions on hardware. Those numbers are for its static pre-execution setting. We found no reported result on Lacuna for any method on mid-execution dynamic perturbations of RLBench, so we will rerun this baseline ourselves. We will give it the same model, token budget and simulator test budget as our method. We would claim to beat it only if we show higher success and fewer irreversible actions at nonzero scene speeds, while matching it within noise in static scenes.
The key ablation is snapshot-anchored asynchronous repair. It is identical to our system, including the holding primitives and the concurrency, but tests patches against the failure-time state and swaps without the admission check. It isolates the forecast anchoring and swap check from the mere benefit of not stopping. A second ablation keeps forecasting but removes the swap-time check, to separate the two pieces.
A further baseline is asynchronous regeneration. The background model rewrites the whole program from the current state instead of iteratively patching one function, with the same compute.
Why not just…?
Why not just stop the robot and repair, as NESYRO does? In static scenes this is probably the right answer, and we expect it to tie or win there. Our sweep includes zero-speed conditions so that this outcome is visible rather than hidden. The evidence that halting fails in dynamic scenes comes from neural controllers: HiRT's 48% versus 75% on moving targets, and the jitter-induced 68% in Bridging the Resource Gap. Whether the same holds for code repair is exactly what the speed sweep measures.
Why not just repair asynchronously on the snapshot and swap when ready? This is the most serious threat, because it captures most of the engineering with none of the forecasting. If staleness turns out to be rare, for instance because repairs usually finish in under a second, this baseline will match ours. We would then report that anchoring is unnecessary at current model speeds. The prediction that separates the two is that the gap should scale with speed times latency. We test this directly by sweeping both, artificially lengthening latency with a delay.
Why not pre-generate a library of contingency functions offline and just select one at runtime? This follows LearnAct's episodic library learning or RobotGPT's offline refinement. When failures resemble training failures, such a library is fast and may beat any online repair. We will build this library with the same model on a held-out set of perturbation types. We will then evaluate both seen and unseen perturbation types. Our method only needs to win on the unseen ones for the claim to stand, and we will report where the library wins.
Why not stream latent features like HiRT or TIC-VLA instead of code? Code-as-Symbolic-Planner's 24.1% gain from symbolic programs and LearnAct's preference for code edits suggest that programs carry structure that latents do not. However, this proposal does not test that question. We hold the representation fixed as code and study only how to repair it live.
Proposed Experiments
The main testbed is a set of RLBench manipulation tasks with mid-execution perturbations injected at random times:
- the target object begins sliding at a controlled speed from 0 to 3 cm/s, bracketing HiRT's 1 cm/s condition;
- a drawer becomes locked, echoing NESYRO's probe scenarios;
- a perception function returns a wrong pose;
- an obstacle enters the arm's path.
We will sweep scene speed and injected repair latency on a grid. The metrics are:
- task success;
- irreversible actions, using NESYRO's definition;
- time the robot spends stalled;
- time from failure to successful resume;
- the staleness rate, meaning patches that passed their tests but failed at swap time or on resume.
A secondary check repeats the conditions on BEHAVIOR-1K tasks using Code-BT's program format, to test whether the effect holds for longer-horizon household programs. If time permits, we will run a small set of Franka trials restricted to the slowest speeds.
Three outcomes would be decisive.
- Snapshot-anchored repair should show a staleness rate that rises with speed times latency, while our forecast-anchored variant stays flat. If both are flat, the anchoring idea is wrong or unnecessary.
- Synchronous repair should cross over with our method as speed rises: tied or better when static, worse when dynamic. If there is no crossover, asynchrony itself is not buying anything in code-policy settings.
- Our method should beat the offline contingency library on unseen perturbation types. If it does not, live repair is not worth its cost.
References
- Code as Policies: Language Model Programs for Embodied Control
- Towards Reliable Code-as-Policies: A Neuro-Symbolic Framework for Embodied Task Planning
- Empowering Large Language Model Agents through Action Learning
- RobotGPT: Robot Manipulation Learning From ChatGPT
- Code-as-Symbolic-Planner: Foundation Model-Based Robot Planning via Symbolic Code Generation
- Code-BT: A Code-Driven Approach to Behavior Tree Generation for Robot Tasks Planning with Large Language Models
- HiRT: Enhancing Robotic Control with Hierarchical Robot Transformers
- TIC-VLA: A Think-in-Control Vision-Language-Action Model for Robot Navigation in Dynamic Environments
- Bridging the Resource Gap: Deploying Advanced Imitation Learning Models Onto Affordable Embedded Platforms
- SlopCodeBench: Measuring Code Erosion Under Iterative Specification Refinement
- CodeTransOcean: A Comprehensive Multilingual Benchmark for Code Translation
- MAGIS: LLM-Based Multi-Agent Framework for GitHub Issue Resolution