# Cleanup can be an idempotent postcondition

Principle `cleanup-can-be-an-idempotent-postcondition`. Already-absent state can be success when absence is the operation’s intended result.

Also searched as: idempotent postcondition, define errors out of existence.

A useful API can make a routine absent-state condition ordinary. The service owns the postcondition instead of requiring every caller to catch and ignore it.

> Rather than throwing an error when unset is asked to delete an unknown variable, it should have simply returned without doing anything.

Source: [Q16](/bibliography#q16); [B10](/bibliography#b10-a-philosophy-of-software-design).

## Failure it prevents

Cleanup accumulates special cases and fails on harmless repeated execution.

## Our Effect 4.0.5 reading

Typed failures do not require exporting avoidable errors. Put the domain meaning in the service contract; Effect supplies execution, not the postcondition.

Source: `packages/effect/src/Effect.ts`, `packages/effect/src/Context.ts`.

## How to check

Run cleanup twice. Require the same intended result, while preserving meaningful permission or storage failures. This is our proposed verification, not a quoted procedure.

Continue with [Retry needs idempotent effects](/principles/retry-needs-idempotency), [Failures keep their meaning](/principles/failures-keep-their-meaning).

Connect this to [the existing rat-stack guidance](https://ratstack.sh/lore/error-model).

Use [the durability skill](/skills/durability) for the full review. Return to [the durability index](/principles/durability).

## Skills
- [Durability starts with a recovery record](/principles/durability)

## Sources
- Ousterhout, John. *A Philosophy of Software Design*. 2018. [Link](https://web.stanford.edu/~ouster/cgi-bin/book.php). ([b10-a-philosophy-of-software-design](/bibliography#b10-a-philosophy-of-software-design))

## References
- [Effect contributors. Effect 4.0.5. Effect.ts](https://github.com/Effect-TS/effect/blob/7f524e25cfb49a71ac39b0f44278d08d40dda5de/packages/effect/src/Effect.ts). Pinned source for our Effect mapping, not a claim from the book.
- [Effect contributors. Effect 4.0.5. Context.ts](https://github.com/Effect-TS/effect/blob/7f524e25cfb49a71ac39b0f44278d08d40dda5de/packages/effect/src/Context.ts). Pinned source for our Effect mapping, not a claim from the book.
