Example

Worked example / Organization

Moving cart, checkout, and support onto one allocation function

A cart preview, checkout, and a support replacement all need the same answer: how many units can this order claim? The first implementation works, but two workflows carry private copies of a policy that already has a name.

01 / Application requirement

Calculate allocations consistently at each customer touchpoint.

CartPreview whether the request can proceed in full.
CheckoutAccept the order only when nothing is backordered.
SupportPromise replacement units and name a partial backorder.

02 / The maintenance problem

The policy exists, but only checkout calls it.

Featured WebMCP request: api_abstraction_map({ sources: [{ fileName: "before.bosatsu", source: "…complete source…" }] })

Recorded engine result · before

Two workflows route around the policy block.

Compiled dependency mapArrows point from a definition to what it uses. On a narrow screen, scroll the map sideways.

Loading recorded evidence…

Select a definition to read its direct dependencies.

Exact request, response, and complete source

Request


        

Response


        

Complete program


      

03 / The repair

Make each channel depend on the allocation plan.

Focused source diff
 def cart_preview(sku: String, stock: Stock, requested: Int) -> CartPreview:
-  allocation = Allocation(
-    nonnegative(requested),
-    min_int(nonnegative(requested), sellable_units(stock)),
-    nonnegative(requested).sub(min_int(nonnegative(requested), sellable_units(stock))),
-    sellable_units(stock).sub(min_int(nonnegative(requested), sellable_units(stock))),
-  )
+  allocation = allocation_plan(stock, requested)
   CartPreview(sku, allocation, is_complete(allocation))

 def support_replacement(case_id: String, stock: Stock, requested: Int) -> SupportReplacement:
-  allocation = Allocation(
-    nonnegative(requested),
-    min_int(nonnegative(requested), sellable_units(stock)),
-    nonnegative(requested).sub(min_int(nonnegative(requested), sellable_units(stock))),
-    sellable_units(stock).sub(min_int(nonnegative(requested), sellable_units(stock))),
-  )
+  allocation = allocation_plan(stock, requested)

Recorded engine result · after

The three entry points meet at one policy.

Compiled dependency mapThe same request shape, run against the repaired source. On a narrow screen, scroll the map sideways.

Loading recorded evidence…

Select a definition to read its direct dependencies.

Exact request, response, and complete source

Request


        

Response


        

Complete repaired program


      
Read the repaired organization request and response

      

    

04 / Behavior check

Exercise ordinary orders and inventory boundaries.

The recorder executed cart, checkout, and support in both complete programs over a named scenario set.

Recorded allocation result for every workflow in both versions
ScenarioStock snapshotRequestAllocationComparison

Exact run requests, responses, and all scenario records

Representative partial-allocation run · before


      

Representative partial-allocation run · after


      

Complete bounded scenario record


    

These executions pin the chosen cases. They do not quantify over every Bosatsu Int, and the organization lens does not claim behavioral equivalence.

05 / Run and change it

Use the same source and browser engine.

Code & run Inspect both complete order-allocation programs

Recording identity

Loading recording identity…

Desktop verification capture · Phone verification capture

Ask your agent about anything here; it has the detail.

Where this fits

What this is about: Lenses and Diagrams