Shipmind Labs

A closed reason list matches by code and records its own sentence. An open list records the caller's words. Mix the two and two cancellations that mean the same thing end up telling two different stories in the history.

That distinction is a single branch in our open-source project order-lifecycle.

Each transition path carries a reasons tuple, normalized up front: one reason object, a bare code string, or an iterable of either, all collapsed into the same shape, with no reasons as the default. Everything downstream reads one type.

When a path declares no reasons, the vocabulary is open. Accept returns an empty string for nothing, and otherwise the reason's own sentence: its detail if it has one, or its code with underscores turned into spaces. Free text, recorded as given.

When a path declares reasons, the vocabulary is closed. The caller's code comes from the reason object or from the stripped string, then gets compared against each declared candidate in order. No match, or no reason at all, raises, and the error names the source state, the trigger, and the accepted codes, so the caller learns the vocabulary from the refusal instead of from the docs.

The part that matters for audit: on a match, accept returns the declared sentence, not the caller's. A reason whose code is DAMAGED but whose detail says something else is recorded with the wording DAMAGED declares. The caller picks the bucket, the system owns the phrasing.

Ordering carries the guarantee. The policy resolves the path, accepts the reason, and only then applies the transition. A refused reason does not reach the state machine, so there is no half-cancelled order to unwind, and the entry appended to the history quotes the path's sentence rather than a reconstruction of it.

Two helpers make the vocabulary legible: what an actor may use in a given state, and every declared reason across the whole timeline, once. The set of sentences a record can ever contain is enumerable before anything runs, which is the property compliance reviewers actually ask for, usually late.

That line is worth drawing somewhere explicit. Your status reasons either come from a closed list, or from whatever the operator typed into the box.

Was this useful?

Building something similar?

or email hello@shipmindlabs.com