Skip to content
Agent Field Notes
Course contentsExpand a topic to choose a lesson.

SYSTEMATIC LEARNING / FOUR-LEVEL COURSE

Committed effects and conditional compensation in sagas

Examine cross-service transactions, compensation conditions, irreversible actions, and human intervention.

Learning objectives: Compensation is another business action that may charge, fail, or be irreversible, not erase history. First confirm the positive results, and then decide whether to compensate according to the terms, dependencies and authorization. The compensation itself must also be recoverable.

Content checked: 2026-10-30 · Each level has independent explanations, tasks and inspections

Choose a starting point based on your familiarity with this topic. Current level: Debugging · Diagnose failures. After completing the task, continue to the next level. Reading and self-checks alone do not establish mastery.

On this level

Review the prerequisites

Suitable for: Backend developers learning Agent applications.

Committed effects and conditional compensation in sagas
Compensation is another business action that may charge, fail, or be irreversible, not erase history. First confirm the positive results, and then decide whether to compensate according to the terms, dependencies and authorization. The compensation itself must also be recoverable.

How does the mechanism work?

Step-by-step explanation
  1. If I cancel a hotel, I will be deducted. Will the original approval cover it?

    Move from deciding whether to compensate to checking the compensation action's own authorization and economic conditions.

  2. What should I do if the compensation request also times out?

    Compensation also has a window where the remote action succeeds but remains unconfirmed locally, in addition to unknown forward-action outcomes.

  3. Do all compensations have to be in reverse order?

    Compensation requires reasoning about dependencies, beyond simply reversing a stack of actions.

Debugging · Diagnose failures

Trace counterexamples and failure windows

Objectives of this level: Repair forward-order and unknown-write compensation on fixed facts.

Visual guide · Compensation starts from facts

Compensation starts from facts

The planner emits commands only. Unknown effects freeze compensation; completed shipment requires review. Compensation needs its own authority and receipt. Select the figure to open it at full size.

Diagnose a second failure during recovery

Consider reserve succeeded, charge unknown and ship failed. Refunding immediately assumes a charge occurred; declaring complete assumes it did not. Query the charge service by the original key. A not-found result is conclusive only under that service's visibility and retention contract; a transient lookup failure remains unknown.

Next window: the compensating refund commits, but its response is lost. Retrying with a fresh compensation key may refund twice. A production executor needs a stable compensation identity, original-effect binding and independent compensation receipt. The local planner's compensated list is a fixture for already recorded facts, not a transactional executor.

Finally inject charge-refund succeeded while reservation-release fails. Preserve partial compensation rather than resetting all steps to failed. The public contract rejects compensated keys outside succeeded reserve/charge operations. Never “fix” this by inserting a ship key or deleting the original ledger entry.

Continue the same implementation

Use the complete function contract and reproduction commands in the implementation layer. Public cases remain in cases/agent-saga-compensation.json inside the existing extended-agent-practice-v1.zip. These are local fixtures, not remote-model or production-load measurements.

code example

Trace counterexamples and failure windows

Diagnose a second failure during recovery

Consider reserve succeeded, charge unknown and ship failed. Refunding immediately assumes a charge occurred; declaring complete assumes it did not. Query the charge service by the original key. A not-found result is conclusive only under that service's visibility and retention contract; a transient lookup failure remains unknown.

Next window: the compensating refund commits, but its response is lost. Retrying with a fresh compensation key may refund twice. A production executor needs a stable compensation identity, original-effect binding and independent compensation receipt. The local planner's compensated list is a fixture for already recorded facts, not a transactional executor.

Finally inject charge-refund succeeded while reservation-release fails. Preserve partial compensation rather than resetting all steps to failed. The public contract rejects compensated keys outside succeeded reserve/charge operations. Never “fix” this by inserting a ship key or deleting the original ledger entry.

Acceptance task for this level

Use the faulty function below in the learner module, grade the same inputs to a before report, then write your own repair/diff and rerun. Do not edit cases or expected values. The defect is given: this is public repair, not unseen independent diagnosis.

Acceptance self-checks

Reading this browser’s record…

Hide the answer and check your understanding

Why must charge precede reserve in this repair?

Further explanations and practice

When encountering unfamiliar principles, first read the implementation, continuous questioning and migration cases, and then independently explain the premise and boundaries. Answers and notes are saved to the original account record.

All linked explanations and exercises (1 )

Sources and verification scope

The principles are based on public information; the numbers, cases and tasks are the teaching design of this website. Offline experiments verify the range noted on this page, and the learning effect still needs to be judged through independent tasks and feedback.