# Cleanup can be an idempotent postcondition

> For agents: start with the [agent guide](https://ratstack.sh/llms.txt). Every page is Markdown by default; add `Accept: text/html` for HTML.

Free workshop: [Build Agent Loops That Never Stop Shipping](/tokenmaxx#interested).

A useful API can make a routine absent-state condition ordinary. The [service](/lore/services-capture-dependencies) 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](/lore/durability-bibliography#q16); [B10](/lore/durability-bibliography#b10-a-philosophy-of-software-design).

## Failure it prevents

Cleanup accumulates special cases and fails on harmless repeated execution.

## Our Effect 4.0.0 reading

Typed failures do not require exporting avoidable errors. Put the domain meaning in the service [contract](/systems/capabilities); [Effect](/lore/effect-basics) supplies execution. The domain defines 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 check is our proposal. The books do not prescribe it.

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

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

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

## Sources

1. [Ousterhout, John. A Philosophy of Software Design. 2018.](https://web.stanford.edu/~ouster/cgi-bin/book.php)
   John Ousterhout. §4.4 Deep Modules; §10.2 Too Many Exceptions; §10.3 Define Errors Out of Existence; §10.6 Mask Exceptions; §10.7 Exception Aggregation; §10.8 Just Crash?; §10.10 Taking It Too Far. Accessed 2026-10-23.

2. [Effect contributors. Effect 4.0.0. Effect.ts](https://github.com/Effect-TS/effect/blob/67ba4e46a11ccda0b6761578bfd22c04ae00167d/packages/effect/src/Effect.ts)
   Effect-TS. Pinned source for our Effect mapping, not a claim from the book. Accessed 2026-10-23.

3. [Effect contributors. Effect 4.0.0. Context.ts](https://github.com/Effect-TS/effect/blob/67ba4e46a11ccda0b6761578bfd22c04ae00167d/packages/effect/src/Context.ts)
   Effect-TS. Pinned source for our Effect mapping, not a claim from the book. Accessed 2026-10-23.

## Lore on this page

- [Handle expected failures without hiding defects](/lore/error-model)

## Linked from

- Agent guide → An Effect stack so pure (aspirational) Kit Langton will blush. → [Read page](https://ratstack.sh/llms.txt)

- Change log → What changed in the files served here, newest first. → [Read page](https://ratstack.sh/log)

- durability → Keep a rat-stack app standing when a provider, pool, or dependency slows down or a worker dies. Use at any I/O boundary, connection pool, provider call, shared waiter, fan-out, flag, gate, or work that can outlive a request, or when asked "what happens when this is slow", "add a timeout", "make this durable", or "what survives a crash". → [Read page](https://ratstack.sh/skills/durability)

- Durability bibliography → Books, checked short quotations, source limits, and Effect mapping provenance. → [Read page](https://ratstack.sh/lore/durability-bibliography)

- Durability starts with a recovery record → A reading order for storage, replay, worker ownership, overload, and recovery tests. → [Read page](https://ratstack.sh/lore/durability)

- Failures keep their meaning → Expected refusals, infrastructure faults, and defects need different policies. → [Read page](https://ratstack.sh/lore/failures-keep-their-meaning)

- Full agent guide → An Effect stack so pure (aspirational) Kit Langton will blush. → [Read page](https://ratstack.sh/llms-full.txt)

- Rat Stack lore | rat-stack → Short, source-grounded notes on the ideas and decisions behind rat-stack. → [Read page](https://ratstack.sh/lore)

- Retry needs idempotent effects → Repeating an operation must preserve its intended observable result. → [Read page](https://ratstack.sh/lore/retry-needs-idempotency)

- Source change history (log.md) → The generated change log as Markdown. → [Read page](https://ratstack.sh/log.md)
