ADR 0009 — Decisions Carry Reasons; 402 (Upsell) vs 403 (Forbidden); unlockedBy
Status: Accepted ★
Context
Section titled “Context”byo-oss and Schematic return { allowed, reason, balance, unlockedBy } so UIs can show an upsell
instead of an error. @12-apps/entitlements distinguishes 402 Payment Required (a paid plan would
allow it) from 403 Forbidden (no plan would, or an operator disabled it). Framework guards need to
pick a status code without re-deriving the reason.
Decision
Section titled “Decision”Every check/consume/reserve returns a CheckResult (see src/schema.ts):
allowed,reason(a closed union:included,within_limit,overage_allowed,limit_reached,not_in_plan,disabled_by_override,granted_by_override,subscription_inactive,unknown_feature,fallback), and for denialsdenial: "payment_required" | "forbidden".payment_requiredwhen some catalog plan or add-on (current versions) would allow the request — those plan keys are inunlockedBy, cheapest first.forbiddenotherwise (no plan includes it, disabled by override, unknown feature).- Usage fields:
limit(null= unlimited),used,remaining,overage,resetsAt, plusvaluefor value features andstale/bufferedprovenance flags. consumenever throws for a denial; it throws only for programmer errors (unknown feature whenstrict: true, negative amounts).ent.require(...)/consumeOrThrowthrowEntitlementDeniedErrorcarrying the result, which adapters’requireEntitlementguards turn into402/403JSON ({ error, reason, feature, unlockedBy, … }).
Consequences
Section titled “Consequences”- UIs render “Upgrade to Pro” from data, not from string matching.
- The reason union is part of the public API; adding a reason is a minor (0.x) change.