In this article
Choose commit timing before promising rollback behavior, and design compensation for external effects that transaction state cannot undo automatically.
Locate when a child result becomes committed
A workflow prepares an analysis, writes an external annotation and later fails while building its report. Whether a nested result is already committed matters during recovery. Prefect’s transaction source distinguishes EAGER, LAZY and OFF commit modes. A nested transaction can inherit its parent’s mode. Read the effective mode at each boundary rather than assuming every nested block waits for the final report.
Follow the parent responsibility in LAZY mode
For a child leaving normally without an eager commit, the parent takes responsibility for the child transaction. An outermost LAZY transaction commits when its context exits normally. This makes the surrounding scope meaningful: moving a task into or out of that scope can change when its staged record becomes committed. The transaction reference separates staging from final commit, so a staged value should not yet be described as the completed storage outcome.
Account for already committed children
EAGER commits on normal context exit before handing control back to a parent. The implementation’s rollback returns without undoing a transaction already marked committed. A later parent failure therefore does not imply that every earlier child result disappears. OFF also has a specific exit behavior: if no parent took responsibility and no explicit commit occurred, the outer exit rolls back. Treat these choices as lifecycle rules, not interchangeable labels for the same behavior.
Write compensation for remote effects
The task interface offers commit and rollback hooks. A hook can implement an application-specific compensating action, such as removing a provisional annotation identified by the original write receipt. Prefect cannot infer the inverse of an arbitrary remote operation from a Python context boundary. Compensation can itself fail; preserve enough information to reconcile the remote object rather than claiming that a local rollback restores every external system atomically.
Explain partial outcomes to the next run
A useful recovery record identifies committed results, staged work and external effects requiring reconciliation. Task contracts establish which artifact constitutes completion; tool observations show which operations actually happened. With those distinctions, a failed report can be resumed deliberately. The next run can reuse suitable committed analysis while addressing a provisional annotation instead of assuming that the word rollback guarantees a completely untouched world.
Earn rental income from GPUs
Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.