soma.cell

Proof of delivery — no signature, no "delivered"

Last-mile drivers paid per stop, racing a routing app's countdown, have a known shortcut: scan "delivered" from the van and toss the parcel — or never deliver it at all. Carrier audits call these "phantom deliveries"; for high-value freight (pharma, electronics) the missing proof-of-delivery turns straight into chargebacks and theft claims that the shipper, not the courier, eats. The fix is sequencing made structural: `delivered` is reachable ONLY from `pod_captured`, and capturing a POD requires being physically at the stop (`at_door`). A driver still in `en_route` has no transition — not a forbidden one, a NONEXISTENT one — that marks the box delivered. `delivered` and `returned_undeliverable` are terminal; verify proves it.

A Soma program from the logistics part of the verified corpus: 105 lines, cells LastMile, NoPhantomDeliveries. It passes soma check with soma 3.2.4.

How it is built

The cell LastMile declares 7 signals in its face: depart_depot(stop: String) -> Map, arrive_at_door(stop: String) -> Map, capture_pod(stop: String, signer: String) -> Map, confirm_delivered(stop: String) -> Map, return_undeliverable(stop: String) -> Map, stop_state(stop: String) -> String and pod_signer(stop: String) -> String; keeps 1 memory slot: signers (Map<String, String>, persistent and consistent). Its state machine delivery starts in assigned and allows 6 transitions: assigned -> en_route, en_route -> at_door, at_door -> pod_captured, pod_captured -> delivered, at_door -> en_route and en_route -> returned_undeliverable. delivered and returned_undeliverable are terminal. Handlers: depart_depot (line 44), arrive_at_door (line 45), capture_pod (line 47), confirm_delivered (line 55), return_undeliverable (line 61), move_stop (line 63), stop_state (line 69) and pod_signer (line 70).

The file also holds 1 test cell (NoPhantomDeliveries) with 18 assertions, run by soma test.

Generated from soma describe on this file.

The source

proof_of_delivery.cell

// ============================================================================
// PROOF OF DELIVERY — no signature, no "delivered"
// ============================================================================
//
// Last-mile drivers paid per stop, racing a routing app's countdown, have
// a known shortcut: scan "delivered" from the van and toss the parcel —
// or never deliver it at all. Carrier audits call these "phantom
// deliveries"; for high-value freight (pharma, electronics) the missing
// proof-of-delivery turns straight into chargebacks and theft claims that
// the shipper, not the courier, eats.
//
// The fix is sequencing made structural: `delivered` is reachable ONLY
// from `pod_captured`, and capturing a POD requires being physically at
// the stop (`at_door`). A driver still in `en_route` has no transition —
// not a forbidden one, a NONEXISTENT one — that marks the box delivered.
// `delivered` and `returned_undeliverable` are terminal; verify proves it.
// ============================================================================

cell LastMile {
    face {
        signal depart_depot(stop: String) -> Map
        signal arrive_at_door(stop: String) -> Map
        signal capture_pod(stop: String, signer: String) -> Map
        signal confirm_delivered(stop: String) -> Map
        signal return_undeliverable(stop: String) -> Map
        signal stop_state(stop: String) -> String
        signal pod_signer(stop: String) -> String
    }

    memory {
        signers: Map<String, String> [persistent, consistent]
    }

    state delivery {
        initial: assigned
        assigned     -> en_route
        en_route     -> at_door
        at_door      -> pod_captured
        pod_captured -> delivered
        at_door      -> en_route                  // nobody home, keep routing
        en_route     -> returned_undeliverable
    }

    on depart_depot(stop: String) { return move_stop(stop, "en_route") }
    on arrive_at_door(stop: String) { return move_stop(stop, "at_door") }

    on capture_pod(stop: String, signer: String) {
        if len(signer) == 0 { return map("ok", false, "reason", "signature required") }
        let r = try { transition(stop, "pod_captured") }
        if r.error != () { return map("ok", false, "reason", "{r.error}") }
        signers.set(stop, signer)
        return map("ok", true, "stop", stop, "signed_by", signer)
    }

    on confirm_delivered(stop: String) {
        let r = try { transition(stop, "delivered") }
        if r.error != () { return map("ok", false, "reason", "no POD on file: {r.error}") }
        return map("ok", true, "stop", stop, "state", "delivered")
    }

    on return_undeliverable(stop: String) { return move_stop(stop, "returned_undeliverable") }

    on move_stop(stop: String, to: String) {
        let r = try { transition(stop, to) }
        if r.error != () { return map("ok", false, "reason", "{r.error}") }
        return map("ok", true, "stop", stop, "state", to)
    }

    on stop_state(stop: String) { return get_status(stop) }
    on pod_signer(stop: String) { return signers.get(stop) ?? "" }
}

cell test NoPhantomDeliveries {
    rules {
        // THE VAN SCAN: driver marks delivered while still en_route.
        // Neither delivered nor pod_captured is reachable from there.
        assert depart_depot("S-9").ok == true
        assert confirm_delivered("S-9").ok == false
        assert_fails transition("S-9", "delivered")
        assert_fails transition("S-9", "pod_captured")

        // the honest path: at the door, signature, delivered
        assert arrive_at_door("S-9").ok == true
        assert capture_pod("S-9", "M. Okafor").ok == true
        assert confirm_delivered("S-9").ok == true
        assert pod_signer("S-9") == "M. Okafor"

        // delivered is forever — no un-delivering, no re-routing
        assert_fails transition("S-9", "en_route")
        assert_fails transition("S-9", "at_door")

        // at the door but nobody signs: no delivered without POD
        assert depart_depot("S-10").ok == true
        assert arrive_at_door("S-10").ok == true
        assert capture_pod("S-10", "").ok == false
        assert confirm_delivered("S-10").ok == false
        assert_fails transition("S-10", "delivered")

        // legal retreat, and the undeliverable terminal
        assert depart_depot("S-10x").ok == true
        assert return_undeliverable("S-10x").ok == true
        assert_fails transition("S-10x", "en_route")
    }
}

What the toolchain says

Run on a fresh copy of the program at build time; the outputs are pasted unedited.

$ soma check proof_of_delivery.cell
✓ All checks passed.
$ soma test proof_of_delivery.cell
test NoPhantomDeliveries ...
  ✓ assert depart_depot("S-9").ok == true
  ✓ assert confirm_delivered("S-9").ok == false
  ✓ assert_fails transition("S-9", "delivered") — raised invalid transition: en_route → delivered. Current state: 'en_route'. Valid targets: [at_door, returned_undeliverable]
  ✓ assert_fails transition("S-9", "pod_captured") — raised invalid transition: en_route → pod_captured. Current state: 'en_route'. Valid targets: [at_door, returned_undeliverable]
  ✓ assert arrive_at_door("S-9").ok == true
  ✓ assert capture_pod("S-9", "M. Okafor").ok == true
  ✓ assert confirm_delivered("S-9").ok == true
  ✓ assert pod_signer("S-9") == "M. Okafor"
  ✓ assert_fails transition("S-9", "en_route") — raised invalid transition: delivered → en_route. Current state: 'delivered'. Valid targets: []
  ✓ assert_fails transition("S-9", "at_door") — raised invalid transition: delivered → at_door. Current state: 'delivered'. Valid targets: []
  ✓ assert depart_depot("S-10").ok == true
  ✓ assert arrive_at_door("S-10").ok == true
  ✓ assert capture_pod("S-10", "").ok == false
  ✓ assert confirm_delivered("S-10").ok == false
  ✓ assert_fails transition("S-10", "delivered") — raised invalid transition: at_door → delivered. Current state: 'at_door'. Valid targets: [pod_captured, en_route]
  ✓ assert depart_depot("S-10x").ok == true
  ✓ assert return_undeliverable("S-10x").ok == true
  ✓ assert_fails transition("S-10x", "en_route") — raised invalid transition: returned_undeliverable → en_route. Current state: 'returned_undeliverable'. Valid targets: []

18 tests: 18 passed, 0 failed
$ soma verify proof_of_delivery.cell
Verifying proof_of_delivery.cell...

State machine 'delivery': 6 states, initial 'assigned'
  States: [assigned, at_door, delivered, en_route, pod_captured, returned_undeliverable]

  ✓ 6 states, 6 transitions
  ✓ all states reachable from 'assigned'
  ✓ terminal states: [delivered, returned_undeliverable]
  ✓ no deadlocks
  ✓ liveness: every state can eventually reach a terminal state
  ⚠ dynamic transition targets: handler `move_stop` uses a dynamic (computed) transition target — the state these handlers move to is computed at run time (from input or an LLM answer), so the machine's safety is checked at run time for them, not proven
  ✓ termination: all 8 handlers structurally terminate
  ⚠ refinement (partial — dynamic targets fall back to runtime check): handler `move_stop` calls transition() with a computed target — which edge it takes is checked at run time (invalid_transition), not proven; write the target as a literal state to have it verified
  ✓ refinement (partial — dynamic targets fall back to runtime check): handler `capture_pod` ⟶ {pod_captured}
  ✓ refinement (partial — dynamic targets fall back to runtime check): handler `confirm_delivered` ⟶ {delivered}
  ✓ refinement (partial — dynamic targets fall back to runtime check): handler `move_stop` ⟶ <dynamic>
  · transition sources: `capture_pod`, `confirm_delivered` call transition(id, target) without declaring the source — the runtime refuses a move the graph forbids, but the proof does not see where the handler starts; `transition(id, from, to)` names the edge (checked by `soma check`, refused at run time from any other state)

9 passed, 2 warnings, 0 failures

  Temporal properties for 'delivery':
  ✓ deadlock_free — no deadlocks in any reachable state
Temporal: 1 passed, 0 failed
VERIFY OK

Builtins used

get_status, len, map, transition

Source file: /corpus/logistics/proof_of_delivery.cell · examples/corpus/logistics/proof_of_delivery.cell