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
- 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.
- 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.
- Do all compensations have to be in reverse order?
Compensation requires reasoning about dependencies, beyond simply reversing a stack of actions.
Foundation · Understand the concepts
Derive ownership and invariants
Objectives of this level: Map known, unknown and irreversible effects to different recovery paths.
Visual guide · 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.
Compensation is another business operation
Reserve inventory, charge money and ship goods live behind different authorities. If shipping fails, rolling back the agent's database does not reverse the charge. Compensation introduces new business effects subject to current rules; it is not time travel.
Derive the decision in order: any unknown original effect → reconcile first; known shipment → manual review under this fixture; otherwise refund a known charge before releasing the reservation. This ordering protects against releasing inventory while a charge or shipment is still unresolved. A planned refund is not a refund receipt.
The published function deliberately uses a narrow policy: one unknown freezes all automatic compensation. Some applications safely compensate independent branches, but that needs a different dependency contract. Preserve the original operation key and receipt when explaining every planned action.
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
Derive ownership and invariants
Compensation is another business operation
Reserve inventory, charge money and ship goods live behind different authorities. If shipping fails, rolling back the agent's database does not reverse the charge. Compensation introduces new business effects subject to current rules; it is not time travel.
Derive the decision in order: any unknown original effect → reconcile first; known shipment → manual review under this fixture; otherwise refund a known charge before releasing the reservation. This ordering protects against releasing inventory while a charge or shipment is still unresolved. A planned refund is not a refund receipt.
The published function deliberately uses a narrow policy: one unknown freezes all automatic compensation. Some applications safely compensate independent branches, but that needs a different dependency contract. Preserve the original operation key and receipt when explaining every planned action.
Acceptance task for this level
For the three inputs, write each output/error by hand and identify the source of trusted facts; explain which expected fields encode business rather than transport success.
Reading this browser’s record…
Hide the answer and check your understanding
Why not compensate an unknown charge immediately?
Expand reference derivation
Its outcome is not established. Query/reconcile the original operation before deciding whether a refund is needed.
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.