ROS 2 managed nodes have an ErrorProcessing transition state for failures that occur while lifecycle user code runs. A successful onError callback does not return the node to Active or prove that the robot function resumed. The managed-node design sends the node to Unconfigured and expects onError to have cleared all state from the previous lifecycle state. If full cleanup is impossible, the node proceeds to Finalized for inspection and destruction.

This is a different contract from retrying the failed operation. It is a cleanup boundary that lets a supervisor decide whether to configure and activate a fresh operating instance or destroy and recreate the node.

How errors enter the transition

The lifecycle design defines four primary states: Unconfigured, Inactive, Active, and Finalized. User code runs in intermediate transition states such as Configuring, Activating, Deactivating, CleaningUp, ShuttingDown, and ErrorProcessing. A callback error return, another method failure, or an uncaught exception can lead to ErrorProcessing.

The entry path matters because resources differ by source state. A failure during configuration may leave partially created publishers, subscriptions, buffers, parameters, or hardware handles. A failure during activation may happen after an active-only resource was acquired. An error from Active can occur while the node owns both configured resources and resources introduced during activation.

The ErrorProcessing callback needs enough local bookkeeping to unwind partial work safely. Relying only on the last primary-state label can be insufficient when a transition failed halfway through. Each acquired resource should have an explicit ownership flag or RAII-style lifetime so cleanup can be repeated without double close, double free, or reuse of an invalid handle.

What onError success means

The design states that successful onError processing transitions to Unconfigured. Unconfigured is expected to contain no stored state. If the error began in Active, onError must provide the cleanup effects of both deactivation and cleanup before returning success.

That requirement is stronger than logging an error and returning a success code. Active-only hardware access should be relinquished, managed output stopped, configured resources released, and application state brought back to the equivalent of a newly created but unconfigured node. Any resource intentionally retained must still fit the node's declared lifecycle contract.

The supervisor should record the origin state, failed transition or callback, exception or return code, onError outcome, and observed end state. A green onError result means the cleanup callback reported that reset succeeded. It does not mean the original task completed, the sensor recovered, the actuator is physically safe, or the node is ready to process data.

When cleanup cannot complete

If the error handler cannot fully clear previous state, it must fail and the lifecycle moves to Finalized. Finalized exists so the failed node can remain visible for debugging and introspection immediately before destruction. The only lifecycle transition from Finalized is destruction.

A supervisor should not loop configure or activate against Finalized. Its policy may capture diagnostics, stop dependent components, destroy the node, and create a replacement. Automatic respawn is a supervisory choice; the lifecycle state alone does not prescribe how many attempts are safe or whether a device should be power-cycled.

Failure cleanup must be bounded. An error handler that waits indefinitely for an unavailable device prevents the supervisor from reaching a known end state. Use timeouts for external cleanup and record which resources could not be released. If a physical mechanism needs a separate safe-state procedure, implement and validate that procedure independently of the software lifecycle callback.

Design idempotent cleanup

Make each cleanup step safe when earlier steps already ran. An activation callback might acquire an exclusive device lease and then fail before enabling a publisher. Error cleanup should release the lease only if owned and deactivate the publisher only if activated. The same guards let a later shutdown or destructor operate without assuming a perfect history.

Order cleanup from dependent resources to their foundations. Stop work producers before destroying their queues. Prevent new callbacks before releasing shared state. Join or quiesce worker threads before deallocating buffers they can access. Release hardware access after commands and I/O have stopped. These are application design rules; the generic lifecycle state machine does not inspect them.

Keep the cause record separate from cleanup progress. If cleanup overwrites the original exception, an operator sees only a secondary close failure. Preserve the primary fault, every cleanup attempt, the final ownership inventory, and the transition result.

Supervisor recovery is a new sequence

After successful onError, the node is Unconfigured. Recovery requires a configure request, verification that configuration reached Inactive, an activate request, and verification that activation reached Active. A supervisor may also require application evidence such as a fresh sensor frame, a valid calibration revision, or a completed self-check before declaring the function ready.

Use a recovery generation number. Increment it whenever the node returns from ErrorProcessing or is recreated. Stamp diagnostics and application output with the generation so consumers do not combine pre-fault state with post-recovery measurements. Clear or invalidate any higher-level leases and work orders that were tied to the failed generation.

Dependencies need their own policy. If localization enters ErrorProcessing, navigation can deactivate and wait rather than repeatedly sending work. If a camera driver is Finalized, an inspection component should report a missing dependency instead of treating its own Active state as complete readiness.

Test every source path

Inject failures after each acquisition in onConfigure and onActivate. Confirm that ErrorProcessing runs, all resources acquired so far are released once, and a successful handler lands in Unconfigured. Verify that no managed publisher continues producing data and no functional service remains usable after reset.

Create an Active-state fault with both configured and active-only resources present. The onError path should perform the effects of deactivation and cleanup. Then configure and activate again, checking for duplicate subscriptions, leaked threads, stale handles, or repeated callbacks.

Force one cleanup operation to fail. Confirm that the node reaches Finalized, remains introspectable long enough to capture evidence, and cannot be reactivated. Destroy and recreate it according to the supervisor policy, while keeping the failed instance and replacement identities distinct.

Finally, interrupt the supervisor during recovery. Restart it and reconcile the node's observed state before issuing another transition. A request log saying configure was sent is weaker than a current state observation and transition result.

Report precise outcomes

Useful status text says: error originated in Active; onError released the active device lease and configured resources; cleanup succeeded; node is now Unconfigured; reconfiguration has not begun. Another precise outcome says: cleanup could not stop worker thread W; onError failed; node is Finalized and awaiting destruction.

Calling either case recovered hides the lifecycle boundary. ErrorProcessing success proves the node reported a return to an unconfigured baseline. Functional recovery begins afterward through a new supervised configure-and-activate sequence plus whatever application evidence the robot function requires.