ADR 0002: Aggregate, invariants and assumptions
Status
Accepted (2026-10-25).
Context
The design source is warehouse-docs storefront/model/model.yaml, context checkout,
with the FINAL decisions of the storefront campaign applied on top (they override the
model where they differ): H1 DECLINED -> EXPIRED, H2 authAttempt and the key
<sessionId>:auth:<attempt>, H3 ErrOfferNotQuotable (422, no state change), H4 the
policy ResolveStuckAuthorizations, H5 voidOwed and the policy RetryOwedVoids, H6 the
ordered timeline (alert 20 h < give up and void 22 h < customer-payments backstop 24 h),
H7 the analytics events CheckoutSessionExpired and CheckoutPlacementInDoubt, H9
StoredPlacement; and contracts-delta S1 (lines numbered 1..n, a quote group that cannot
be formed from the cart is a contract bug), S2 (the binding number is the PriceQuote;
confirming after quoteExpiresAt is 422 price-quote-expired) and S3 (pre-check, then
void and REQUOTE_REQUIRED). This ADR records the aggregate as built and every
assumption (A1, A2, ...) taken where the model and the decisions are silent. Each is
also reported as a model_gap.
Decision
Aggregate
- CheckoutSession (
internal/domain/checkoutsession, rootsessionId):cartIdandcartVersion,shopperId,shipToAddressId(references, never PII), numbered lines{lineNo, catalogItemId, quantity}, groups{groupNo, offerId, tier, lineNos, amountMinor},priceQuoteId,currency,totalMinor,quoteExpiresAt,authorizationId,orderId,requotedOffers,failureCode,authAttempt,voidOwed, the StoredPlacement{requestBody, requestHash, placingSince},version.- States OPEN, AUTHORIZING, DECLINED, PLACING, REQUOTE_REQUIRED, COMPLETED, EXPIRED, FAILED with exactly the model's transitions plus DECLINED -> EXPIRED (H1).
- COMPLETED, EXPIRED, FAILED and REQUOTE_REQUIRED are closed (
ErrSessionClosed). - PLACING is the semantic lock: no new attempt while the outcome is unknown
(
ErrPlacementInDoubt).
- Errors and problem types:
ErrCartNotCheckoutReady409,ErrSessionClosed409,ErrAuthorizationMismatch409,ErrPlacementInDoubt409,ErrVoidPending409 (A4),ErrPriceQuoteExpired422 (A6),ErrOfferNotQuotable422,ErrContractViolation502 (A8), plus the sharednot-found,illegal-transition,concurrent-updateandvalidation-failed.
Assumptions
- A1
authAttemptstarts at 0 and grows on each DECLINED -> AUTHORIZING, so the keys are<sessionId>:auth:0,:auth:1, ... The pack OpenAPI text<sessionId>:authis superseded by H2. - A2 The PSP token is kept on the session ONLY while it is AUTHORIZING (needed to re-call Authorize with the same key, H4) and cleared when the state is left. It is a token, never a card number, and never leaves the service in an event or a response.
- A3 When the Authorize outcome is unknown (transport error, 5xx, 409) the confirm route answers 202 with the session still AUTHORIZING (the pack lists 202 for PLACING only); the BFF polls and ResolveStuckAuthorizations settles it after 2 minutes.
- A4 An authorized amount or currency that is not the quote's puts the session back
to DECLINED (reason
authorization-mismatch, event CheckoutDeclined) with the void owed (H5) and answers 409authorization-mismatch. No AUTHORIZING -> FAILED transition is invented. A new confirm is refused with 409void-pending(ErrVoidPending) until the void succeeded, because customer-payments allows one active authorization per session. - A5 The void is always recorded as owed in the same change as the decision (REQUOTE _REQUIRED or FAILED), attempted right away and cleared on success; a failed void is retried every minute. The pack text "only after the void succeeded" is therefore read as "the void is guaranteed, not yet done". The give-up at 22 h follows the same path.
- A6
price-quote-expiredis 422 (contracts-delta S2); the pack OpenAPI said 409. - A7 The allocation of a group is its item totals plus its delivery charge plus a pro-rata share of the tax (floor, remainder to the first group), so the allocations sum to the quote total exactly; a quote that does not add up is a contract bug.
- A8 A sibling answer that cannot form a session (groups that do not cover the lines,
a quote that does not price a line) is
ErrContractViolation: 502upstream-contract-violationand an alert. FAILED exists only after PLACING, so no session is created. - A9 GetCart, GetDeliveryOffer and IssuePriceQuote run before the aggregate checks the
offers; a quote issued before an
offer-not-quotableanswer simply expires. - A10 CheckoutPlacementInDoubt is raised on the first unknown outcome only.
- A11 The resolver backs off 30 s, doubling to 15 min. The 20 h alert fires once
(
alertedAt); at 22 h one last replay is tried and, if still unknown, the session fails with codeplacement-unresolvedand the void. - A12 Several sessions may exist for one cart; a cart closes on CheckoutCompleted.
- A13 The network's
deliverBydate-times become ISO dates (the UTC date) inrequotedOffers. - A14 A cart is ready only when its own readiness holds AND its state is OPEN.
- A15 An unknown offer (404) is reported as not quotable, not as an error.
- A16 The placement purge drops only the stored request, 24 h after a closed state; the session row stays.
- A17 Timestamps are truncated to the microsecond (Postgres) in the domain.