Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 115 additions & 1 deletion dag/gunbc/product/inventory.dag
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import std.minted_identity {
minted_id_eq,
minted_id_ordinal,
}
import product.placement_supply { PhysicalAssetIdentity, ProcurementReceiptIdentity }
import product.placement_supply { PhysicalAssetIdentity, ProcurementReceiptIdentity, physical_asset_identity_eq }

// INVENTORY-0: the generic product-layer authority for procurement lots and the append-only
// event ledger over them. It answers, for one lot of fungible stock: how much was acquired, what
Expand Down Expand Up @@ -512,6 +512,120 @@ fn departure_origin_position(origin: DepartureOrigin) -> StockPosition {
}
}

// WHICH LOT NAMED THIS PHYSICAL ASSET -- the narrowest generic projection over the event ledger, and
// it lives HERE because this module owns what an installation event says. A consumer that needs an
// asset's provenance must not re-read assets, origin or stock semantics for itself: that would be a
// second interpretation of one event shape, and the two would drift.
//
// THIS ANSWERS ABOUT ONE REQUESTED ASSET, NOT ABOUT THE WHOLE EVENT. The distinction is load-bearing
// and was nearly lost. QuantityInstalled deliberately permits fewer named assets than units
// installed -- it refuses only when there are MORE -- so `quantity: 2, assets: [spool_a]` records
// two installed units of which one is individually identified. That is a state this ledger means to
// represent. An earlier proposed rule made `identified count == quantity` a precondition for
// resolving ANY asset's lot, which would refuse spool_a's provenance because its SIBLING is
// anonymous: evidence unrelated to the requested subject, and an over-strict refusal is a defect in
// the same way a permissive one is. Whether the whole population is individuated is a DIFFERENT
// question, and a caller that needs it must ask it separately rather than reading it out of this.
//
// REPEATED EVIDENCE REFUSES RATHER THAN CORROBORATING. Two installation events naming the same asset
// -- even under one lot -- are not a stronger fact; they are an unadjudicated one, because these
// events carry no asset-grained removal or reinstallation history, so a legitimate reinstall and a
// double installation are indistinguishable here. Calling that corroboration would be the absorbing
// fallback: answering confidently where the model cannot discriminate. The trigger for admitting
// repeated same-lot occurrences is an asset-grained stock lifecycle.
type AssetSourceLotStanding
= AssetSourceLotUnobserved { asset: PhysicalAssetIdentity }
| AssetSourceLotResolved { asset: PhysicalAssetIdentity, lot: InventoryLotIdentity, event_ordinal: Nat }
| AssetSourceLotEvidenceDuplicate { asset: PhysicalAssetIdentity, occurrences: Nat }
| AssetSourceLotConflict { asset: PhysicalAssetIdentity, first_lot: InventoryLotIdentity, further_lots: List<InventoryLotIdentity> }

// One hit: the asset was named by an installation event, and where.
type AssetLotHit sole_constructor {
lot: InventoryLotIdentity
ordinal: Nat
}

type AssetLotScan sole_constructor {
hits: List<AssetLotHit>
next_ordinal: Nat
}

// The asset may appear more than once WITHIN one event's list, and that counts as more than one
// occurrence: a list naming the same asset twice is malformed evidence, not one sighting.
fn asset_hits_in_event(event: InventoryEvent, asset: PhysicalAssetIdentity, ordinal: Nat) -> List<AssetLotHit> {
match event {
QuantityInstalled { lot: l, quantity: _, origin: _, assets: a } =>
map(filter(a, x => physical_asset_identity_eq(a: x, b: asset)), _ => AssetLotHit { lot: l, ordinal: ordinal })
LotAcquired { lot: _ } => []
LotReceived { lot: _, quantity: _ } => []
QuantityQualified { lot: _, quantity: _ } => []
QuantityQuarantined { lot: _, quantity: _ } => []
QuantityReserved { lot: _, quantity: _, holder: _ } => []
ReservationReleased { lot: _, quantity: _, holder: _ } => []
QuantityRemoved { lot: _, quantity: _ } => []
QuantityFailed { lot: _, quantity: _, origin: _ } => []
QuantitySold { lot: _, quantity: _, origin: _ } => []
QuantityDisposed { lot: _, quantity: _, origin: _ } => []
}
}

fn scan_asset_lot_hits(events: List<InventoryEvent>, asset: PhysicalAssetIdentity) -> AssetLotScan {
fold(events, init: AssetLotScan { hits: [], next_ordinal: 0 }, f: fn(acc, e) {
AssetLotScan {
hits: concat(acc.hits, asset_hits_in_event(event: e, asset: asset, ordinal: acc.next_ordinal)),
next_ordinal: acc.next_ordinal + 1
}
})
}

fn distinct_hit_lots(hits: List<AssetLotHit>) -> List<InventoryLotIdentity> {
fold(hits, init: [], f: fn(acc, h) {
let already = fold(acc, init: false, f: fn(seen, l) { seen || minted_id_eq(left: l, right: h.lot) })
if already { acc } else { concat(acc, [h.lot]) }
})
}

// The first lot names the conflict and the rest are carried beside it, built in ONE pass rather than
// by a head-and-tail pair: `.first()` yields an option, so a head/tail split would introduce an
// absent-arm that cannot occur here (the caller has already established more than one lot) and would
// have to be discharged with a fabricated default.
fn conflict_over_lots(asset: PhysicalAssetIdentity, lots: List<InventoryLotIdentity>) -> AssetSourceLotStanding {
fold(lots, init: AssetSourceLotUnobserved { asset: asset }, f: fn(acc, l) {
match acc {
AssetSourceLotUnobserved { asset: _ } =>
AssetSourceLotConflict { asset: asset, first_lot: l, further_lots: [] }
AssetSourceLotConflict { asset: _, first_lot: fl, further_lots: fr } =>
AssetSourceLotConflict { asset: asset, first_lot: fl, further_lots: concat(fr, [l]) }
AssetSourceLotResolved { asset: _, lot: _, event_ordinal: _ } => acc
AssetSourceLotEvidenceDuplicate { asset: _, occurrences: _ } => acc
}
})
}

// CONFLICT OUTRANKS DUPLICATE, because two lots is the more specific and more actionable statement:
// reporting "seen twice" for an asset claimed by two different lots would discard the fact a reader
// most needs. Duplicate is what remains when the repetition is within ONE lot.
fn asset_source_lot_standing(events: List<InventoryEvent>, asset: PhysicalAssetIdentity) -> AssetSourceLotStanding {
let scan = scan_asset_lot_hits(events: events, asset: asset)
let lots = distinct_hit_lots(hits: scan.hits)
let n = count(scan.hits)
if n == 0 {
AssetSourceLotUnobserved { asset: asset }
} else {
if count(lots) > 1 {
conflict_over_lots(asset: asset, lots: lots)
} else {
if n > 1 {
AssetSourceLotEvidenceDuplicate { asset: asset, occurrences: n }
} else {
fold(scan.hits, init: AssetSourceLotUnobserved { asset: asset }, f: fn(_, h) {
AssetSourceLotResolved { asset: asset, lot: h.lot, event_ordinal: h.ordinal }
})
}
}
}
}

type InventoryEvent
= LotAcquired { lot: InventoryLotIdentity }
| LotReceived { lot: InventoryLotIdentity, quantity: Nat }
Expand Down
11 changes: 11 additions & 0 deletions dag/gunbc/product/placement_supply.dag
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ fn host_identity_eq(a: HostIdentity, b: HostIdentity) -> Bool {
a as String == b as String
}

// The same comparison for physical assets, and it lives here for the same reason the one above does:
// product.placement_supply owns PhysicalAssetIdentity, so consumers that need to ask whether two
// asset identities are the same asset should not each re-derive it. It was re-derived once already
// -- product.printed_chassis.manufacturing_manifest defined a private copy -- which was tolerable
// only while that module was the sole consumer, and stopped being tolerable as soon as
// product.inventory needed the same question answered, because inventory is a generic authority and
// importing a specific product's helper to get it would invert the layering.
fn physical_asset_identity_eq(a: PhysicalAssetIdentity, b: PhysicalAssetIdentity) -> Bool {
a as String == b as String
}

// SPATIAL-0: physical placement and RF reachability — the product-layer authority for WHERE assets
// sit, whether they share a rack, and whether a wireless bootstrap step is admissible. Logical
// packet reach (extdeps.network.reach) and logical topology zones
Expand Down
9 changes: 3 additions & 6 deletions dag/gunbc/product/printed_chassis/manufacturing_manifest.dag
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import std.decl_ref { DeclarationRef, WholeDeclaration }
import product.placement_supply {
PhysicalAsset,
PhysicalAssetIdentity,
physical_asset_identity_eq,
}

// THE MANIFEST BINDS A PRINTED THING TO THE PROCESS THAT PRODUCED IT, and it exists because the
Expand Down Expand Up @@ -55,11 +56,7 @@ type PrinterAssetAdmission
= PrinterAssetAdmitted { binding: AdmittedPrinterAsset }
| PrinterAssetAbsent { requested: PhysicalAssetIdentity }
| PrinterAssetDuplicate { requested: PhysicalAssetIdentity, matches: Int }
| PrinterCatalogMismatch { requested: PhysicalAssetIdentity, expected_module: NonEmptyStr, found_module: NonEmptyStr }

fn physical_asset_identity_eq(a: PhysicalAssetIdentity, b: PhysicalAssetIdentity) -> Bool {
a as String == b as String
}
| PrinterCatalogModuleMismatch { requested: PhysicalAssetIdentity, expected_module: NonEmptyStr, found_module: NonEmptyStr }

// THE SCAN CARRIES THE MATCHES RATHER THAN A COUNT PLUS A VALUE, because a count and a separately
// held candidate can disagree. Holding the matched rows is what lets the duplicate arm report how
Expand Down Expand Up @@ -126,7 +123,7 @@ fn admit_printer_asset(inventory: List<PhysicalAsset>, requested: PhysicalAssetI
if catalog_matches {
PrinterAssetAdmitted { binding: AdmittedPrinterAsset { asset: a } }
} else {
PrinterCatalogMismatch {
PrinterCatalogModuleMismatch {
requested: requested,
expected_module: a1_mini_catalog_module,
found_module: a.catalog.module_path,
Expand Down
138 changes: 138 additions & 0 deletions dag/test/claim/inventory_asset_source_lot_witness_test.dag
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
module test.claim.inventory_asset_source_lot_witness_test

import product.inventory {
AssetSourceLotStanding,
AssetSourceLotUnobserved,
AssetSourceLotResolved,
AssetSourceLotEvidenceDuplicate,
AssetSourceLotConflict,
asset_source_lot_standing,
InventoryEvent,
InventoryLotIdentity,
QuantityInstalled,
InstallFromAvailable,
inventory_lot_allocator_initial,
mint_inventory_lot_identity,
}
import product.placement_supply { PhysicalAssetIdentity }
import std.types { Bool, List, NonEmptyStr, String }
import std.nat { Nat }
import std.minted_identity { minted_id_eq }
import v2.std.live_tree { LiveTreeDisposition, SubstrateInputsOnly }

data live_tree_disposition: LiveTreeDisposition = SubstrateInputsOnly

// THE DISCRIMINATOR POPULATION FOR asset_source_lot_standing, and the first two rows are the reason
// this file exists rather than a single happy-path check. QuantityInstalled deliberately permits
// fewer named assets than units installed, so an implementation that required
// `identified count == quantity` before resolving ANY asset's provenance would still satisfy every
// obvious test while refusing a named asset because its SIBLING is anonymous. Row 1 is exactly that
// case and it must RESOLVE; row 2 is the same question where the population happens to be fully
// individuated. The pair is what states that full-population individuation is not a prerequisite for
// one asset's lot, and that the two properties are separate questions.

fn lot_a() -> InventoryLotIdentity {
mint_inventory_lot_identity(alloc: inventory_lot_allocator_initial()).id
}

fn lot_b() -> InventoryLotIdentity {
let first = mint_inventory_lot_identity(alloc: inventory_lot_allocator_initial())
mint_inventory_lot_identity(alloc: first.alloc).id
}

fn requested() -> PhysicalAssetIdentity {
"spool-a" as PhysicalAssetIdentity
}

fn other() -> PhysicalAssetIdentity {
"spool-b" as PhysicalAssetIdentity
}

fn install(lot: InventoryLotIdentity, quantity: Nat, assets: List<PhysicalAssetIdentity>) -> InventoryEvent {
QuantityInstalled { lot: lot, quantity: quantity, origin: InstallFromAvailable, assets: assets }
}

fn resolves_to_lot(events: List<InventoryEvent>, lot: InventoryLotIdentity) -> Bool {
match asset_source_lot_standing(events: events, asset: requested()) {
AssetSourceLotResolved { asset: a, lot: l, event_ordinal: _ } =>
a as String == "spool-a" && minted_id_eq(left: l, right: lot)
AssetSourceLotUnobserved { asset: _ } => false
AssetSourceLotEvidenceDuplicate { asset: _, occurrences: _ } => false
AssetSourceLotConflict { asset: _, first_lot: _, further_lots: _ } => false
}
}

// ROW 1 -- the load-bearing one. Two units installed, only the requested asset named. Its provenance
// is unambiguous and must resolve; the anonymous sibling is evidence about a different subject.
test fn w_a_named_asset_resolves_even_when_its_sibling_is_anonymous() -> Bool {
resolves_to_lot(events: [install(lot: lot_a(), quantity: 2, assets: [requested()])], lot: lot_a())
}

// ROW 2 -- the same question with the population fully individuated. Pairing it with row 1 is what
// proves the two properties were not fused.
test fn w_a_named_asset_resolves_when_the_population_is_fully_individuated() -> Bool {
resolves_to_lot(events: [install(lot: lot_a(), quantity: 2, assets: [requested(), other()])], lot: lot_a())
}

// ROW 3 -- the same asset named twice in one event list is malformed evidence, not one sighting.
test fn w_an_asset_named_twice_in_one_event_refuses_as_duplicate() -> Bool {
match asset_source_lot_standing(
events: [install(lot: lot_a(), quantity: 2, assets: [requested(), requested()])],
asset: requested()
) {
AssetSourceLotEvidenceDuplicate { asset: _, occurrences: n } => n == 2
AssetSourceLotResolved { asset: _, lot: _, event_ordinal: _ } => false
AssetSourceLotUnobserved { asset: _ } => false
AssetSourceLotConflict { asset: _, first_lot: _, further_lots: _ } => false
}
}

// ROW 4 -- two lots claim the asset. Conflict outranks duplicate because naming both lots is the
// more actionable statement; reporting only "seen twice" would discard what a reader needs.
test fn w_an_asset_claimed_by_two_lots_refuses_naming_both() -> Bool {
match asset_source_lot_standing(
events: [
install(lot: lot_a(), quantity: 1, assets: [requested()]),
install(lot: lot_b(), quantity: 1, assets: [requested()]),
],
asset: requested()
) {
AssetSourceLotConflict { asset: _, first_lot: f, further_lots: r } =>
minted_id_eq(left: f, right: lot_a()) && count(r) == 1
AssetSourceLotEvidenceDuplicate { asset: _, occurrences: _ } => false
AssetSourceLotResolved { asset: _, lot: _, event_ordinal: _ } => false
AssetSourceLotUnobserved { asset: _ } => false
}
}

// ROW 5 -- an installation that names only a DIFFERENT asset says nothing about this one. Absent is
// not the same as resolved-to-nothing, and it must not borrow the sibling's lot.
test fn w_an_unnamed_asset_is_unobserved_not_resolved() -> Bool {
match asset_source_lot_standing(
events: [install(lot: lot_a(), quantity: 2, assets: [other()])],
asset: requested()
) {
AssetSourceLotUnobserved { asset: a } => a as String == "spool-a"
AssetSourceLotResolved { asset: _, lot: _, event_ordinal: _ } => false
AssetSourceLotEvidenceDuplicate { asset: _, occurrences: _ } => false
AssetSourceLotConflict { asset: _, first_lot: _, further_lots: _ } => false
}
}

// ROW 6 -- the day-one positive control: one event per spool, quantity 1, singleton asset list. At
// this shape exact attribution and full individuation coincide, which is precisely why the rows
// above exist rather than this one standing alone.
test fn w_the_day_one_singleton_event_resolves() -> Bool {
resolves_to_lot(events: [install(lot: lot_a(), quantity: 1, assets: [requested()])], lot: lot_a())
}

// The empty ledger observes nothing. Without it every arm above could be satisfied by a function
// that answered Unobserved only because it never iterated.
test fn w_an_empty_ledger_observes_nothing() -> Bool {
match asset_source_lot_standing(events: [], asset: requested()) {
AssetSourceLotUnobserved { asset: a } => a as String == "spool-a"
AssetSourceLotResolved { asset: _, lot: _, event_ordinal: _ } => false
AssetSourceLotEvidenceDuplicate { asset: _, occurrences: _ } => false
AssetSourceLotConflict { asset: _, first_lot: _, further_lots: _ } => false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,20 @@ data live_tree_disposition: LiveTreeDisposition = ReadsLiveTree
// on the reasoning that declaration_ref_resolves needs an expensive decl_facts index resolved
// against a pool. That claim was FALSE, and the required floor proved it by refusing: its
// declarations phase resolves every cited module path in the corpus and failed this PR with
// CITED-MODULE-ABSENT when a sibling fixture cited a module nobody declares. So a DeclarationRef
// here is a gated citation, the strongest of the three forms this program considered, and it needs
// no local witness. What was nearly recorded instead was a fabricated gap -- an admission of missing
// evidence for a check that was already running -- which would have understated the rung exactly as
// inflating it would overstate it.
// CITED-MODULE-ABSENT when a sibling fixture cited a module nobody declares. What was nearly recorded
// instead was a fabricated gap -- an admission of missing evidence for a check that was already
// running -- which understates a rung exactly as inflation overstates it.
//
// THE GATE HOLDS AT MODULE-PATH GRAIN, AND NO FURTHER. That red proves the cited module_path is
// resolved. It does NOT establish that the decl_name resolves, that the field exists, or that the
// named declaration is a catalog row -- no mutation here tested any of those, and claiming the whole
// DeclarationRef has been adjudicated would promote the evidence past what it measured. This is why
// the manifest compares module_path alone and its refusal arm carries expected_module/found_module:
// the admission asserts that the asset's catalog module identifies the A1 mini product AUTHORITY,
// not that it names an exact catalog row, because extdeps.printing.bambu_lab_a1_mini exposes product
// facts such as a1_mini_build_envelope and no separately named catalog record for one to point at.
// The trigger for the stronger claim is authoring that catalog declaration; until it exists, the
// weaker sentence is the true one.

data forged_source: String = "module probe_manifest_forged_admitted\nimport product.printed_chassis.manufacturing_manifest { AdmittedPrinterAsset }\nimport product.placement_supply { PhysicalAsset, PhysicalAssetIdentity }\nimport std.decl_ref { DeclarationRef, WholeDeclaration }\nfn forged() -> AdmittedPrinterAsset {\n AdmittedPrinterAsset {\n asset: PhysicalAsset {\n identity: \"forged\" as PhysicalAssetIdentity,\n catalog: DeclarationRef { module_path: \"extdeps.printing.bambu_lab_a1_mini\", decl_name: \"a1_mini_build_envelope\", field: WholeDeclaration },\n physical_serial: Absent,\n procurement: Absent,\n },\n }\n}\n"

Expand Down
Loading
Loading