ADR 0012: Canonical site_id on CapacityPlan and CapacityPlanPublished
Status
Accepted (2026-10-06).
Context
The fleet is gaining a network scope: several warehouses, each site able to
act as a transfer origin/destination. facility-layout owns the Site
aggregate and, since its SiteCapabilityChanged event, publishes each site's
site_code — the one canonical identifier of a site across contexts.
A CapacityPlan, however, is scoped only by warehouse_id + location.
warehouse_id is a free-text label (WH-1), and location is a planning
location (the ProcessCapacity lookup key, e.g. PATH-ZONE-A or a site code
when the labor consumer's building_id is used). Neither is a site
reference, and deriving one — by prefix-parsing location or assuming
warehouse_id names a site — would be exactly the kind of inference ADR 0002
banned for station composition ("neither derives anything it cannot derive
honestly").
Downstream, order-management already attributes consumed plans to a
configured PLANNED_CAPACITY_SITE_ID because the events carry no site; a
per-plan site id is the honest fix.
Decision
CapacityPlancarries a canonicalsite_id: a facility-layout Sitesite_code(the same identifierSiteCapabilityChangedpublishes). It is a STATED planning fact onPOST /capacity-plans(and thecreate_capacity_planMCP tool): REQUIRED, and never inferred fromwarehouse_idorlocation. A blank or absent one is rejected with 422missing-required-field(capacityplan.ErrRequiredField).- Persistence is additive: migration
0008addscapacity_plans.site_id TEXT NOT NULL DEFAULT ''. Existing rows keep''and read back as plans with an empty site id (the REST/MCP response exposessite_idadditively, empty for those plans). CapacityPlanPublished's v1 payload gainssite_idADDITIVELY. Thetype(com.warehouse.wes.warehouse-planning.capacityplan.CapacityPlanPublished),dataschema(urn:warehouse:warehouse-planning:events:CapacityPlanPublished:v1),source(/warehouse/warehouse-planning) and topic are UNCHANGED — an additive optional field is not a breaking payload change, so no.v2. The producer emitssite_idwithomitempty: a plan stored before migration0008publishes bytes byte-identical to the pre-site_id shape, and a legacy v1 payload withoutsite_idstill decodes (unknown-field tolerance). The analytics payload inherits the field the same waylocationdoes (it embeds the integration payload).- Only
CapacityPlanPublishedcarriessite_idon the wire. The other three events keep their exact shapes: consumers key network scope on the plan's publication;CapacityPlanCreatedis a DRAFT-lifecycle fact.
Consequences
- Producers and consumers can ship in any order: the field is additive on the wire and omitted-when-empty, so a mixed-version fleet is safe.
- A consumer reading an old plan's publication sees no
site_idand must treat the site as unknown — never derive it.order-management's configured-site fallback remains the answer for those plans. - Migration
0008is online-safe:ADD COLUMN ... NOT NULL DEFAULT ''takes a metadata-only lock on Postgres. - The REST/MCP request surface is a BREAKING additive change for clients
that create plans: they must now send
site_id. That is deliberate — a silently-defaulted site id would reintroduce the inference this ADR removes. The web console (web/src) ships in the same rollout window and is updated to require the field.
Alternatives considered
- Infer the site from
location's zone-id prefix (the ADR 0002 site-equals-first-dash-segment rule): rejected — that rule describes how facility zone ids are CODED, not a license to derive planning scope; a planning location is not always a zone-prefixed string. - Publish a
.v2dataschema: rejected — additive optional fields under an unchangeddataschemaare the fleet's established additive pattern (bottleneck_constrainton the analytics stream,demand_sourceon the REST response); a v2 would force coordinated consumer migration for no compatibility gain. - Key plans by site instead of warehouse: rejected — changes the aggregate's natural key and every consumer's read model for zero additional information over the additive column.