﻿# Prefect nested commit modes define rollback reach

Prefect nested transactions can defer commit to a parent or commit eagerly; rollback hooks need explicit compensation for effects already performed outside result storage.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/guide-prefect-nested-commit-rollback/
Language: en

## 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](https://raw.githubusercontent.com/PrefectHQ/prefect/main/src/prefect/transactions.py) 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](https://reference.prefect.io/prefect/transactions/) 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](https://reference.prefect.io/prefect/tasks/) 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](/journal/learn-codex-task-contract/) establish which artifact constitutes completion; [tool observations](/journal/learn-codex-tool-observation/) 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.
