soma.cell

Autoclave sterilization — a failed cycle can never release instruments

as sterile Surgical instruments are sterilized in an autoclave: saturated steam at 121–134 °C held long enough to kill spores, verified by a biological indicator. The deadly shortcut is releasing a load as "sterile" when the cycle aborted (a steam fault, a failed indicator) — every patient that tray touches is exposed to surgical-site infection, and outbreaks have been traced to exactly this. The standard is unforgiving: a failed cycle means the whole load is reprocessed, never released. Here a load runs loaded → running → (held params met) → indicator_pass → released. Any parameter fault or a failed biological indicator routes to the TERMINAL `failed` state — there is no edge from `failed` to `released`. A memory invariant also pins the sterilization hold temperature into the validated band, so a probe reading 80 °C cannot be charted as a passing cycle. `soma verify` proves released is unreachable from failed.

A Soma program from the medical part of the verified corpus: 159 lines, cells Autoclave, AutoclaveTests. It passes soma check with soma 3.2.4.

How it is built

The cell Autoclave declares 6 signals in its face: load_tray(tray: String) -> Map, run_cycle(tray: String, peak_c: Int) -> Map, indicator(tray: String, spores_killed: Bool) -> Map, release(tray: String) -> Map, tray_state(tray: String) -> String and demo() -> String; keeps 1 memory slot: peak_temp (Map<String, Int>, persistent and consistent) under the invariant peak_temp >= 0 && peak_temp <= 150. Its state machine load_sm starts in loaded and allows 6 transitions: loaded -> running, running -> params_met, params_met -> indicator_pass, indicator_pass -> released, running -> failed and params_met -> failed. failed and released are terminal. Handlers: load_tray (line 59), run_cycle (line 68), indicator (line 88), release (line 102), tray_state (line 110) and demo (line 112).

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

Generated from soma describe on this file.

The source

sterilization.cell

// ============================================================================
// AUTOCLAVE STERILIZATION — a failed cycle can never release instruments
// as sterile
// ============================================================================
//
// Surgical instruments are sterilized in an autoclave: saturated steam at
// 121–134 °C held long enough to kill spores, verified by a biological
// indicator. The deadly shortcut is releasing a load as "sterile" when the
// cycle aborted (a steam fault, a failed indicator) — every patient that
// tray touches is exposed to surgical-site infection, and outbreaks have
// been traced to exactly this. The standard is unforgiving: a failed cycle
// means the whole load is reprocessed, never released.
//
// Here a load runs loaded → running → (held params met) → indicator_pass →
// released. Any parameter fault or a failed biological indicator routes to
// the TERMINAL `failed` state — there is no edge from `failed` to
// `released`. A memory invariant also pins the sterilization hold
// temperature into the validated band, so a probe reading 80 °C cannot be
// charted as a passing cycle. `soma verify` proves released is unreachable
// from failed.
//
//   soma verify examples/corpus/medical/sterilization.cell
//   soma test   examples/corpus/medical/sterilization.cell
//   soma run    examples/corpus/medical/sterilization.cell demo
// ============================================================================

cell Autoclave {
    face {
        signal load_tray(tray: String) -> Map
        signal run_cycle(tray: String, peak_c: Int) -> Map
        signal indicator(tray: String, spores_killed: Bool) -> Map
        signal release(tray: String) -> Map
        signal tray_state(tray: String) -> String
        signal demo() -> String
    }

    memory {
        // Peak hold temperature recorded for the cycle, °C. The validated
        // steam-sterilization band tops out around 134; a probe value
        // outside [0,150] is a sensor fault and is rejected at the write.
        peak_temp: Map<String, Int> [persistent, consistent]
        invariant peak_temp >= 0 && peak_temp <= 150
    }

    // `released` is reachable ONLY through indicator_pass. `failed` is
    // TERMINAL — a faulted cycle or dead indicator ends the load for good;
    // it must be reprocessed under a new id. verify proves no failed ->
    // released path exists.
    state load_sm {
        initial: loaded
        loaded         -> running
        running        -> params_met        // 121–134 °C held long enough
        params_met     -> indicator_pass    // biological indicator killed spores
        indicator_pass -> released          // safe to use — terminal
        running        -> failed            // steam/temperature fault
        params_met     -> failed            // indicator failed
    }

    on load_tray(tray: String) {
        let r = try { transition(tray, "running") }
        if r.error != () { return map("ok", false, "reason", "{r.error}") }
        return map("ok", true, "state", get_status(tray))
    }

    // Run the hold phase. The peak temperature is recorded (a sensor fault
    // is rejected by the invariant). Below 121 °C the cycle fails
    // terminally; a valid hold advances to params_met.
    on run_cycle(tray: String, peak_c: Int) {
        let st = get_status(tray)
        if st != "running" {
            return map("ok", false, "reason", "tray is {st}, not running")
        }
        let w = try { peak_temp.set(tray, peak_c) }
        if w.error != () {
            return map("ok", false, "reason", "implausible probe: {w.error}")
        }
        if peak_c < 121 {
            transition(tray, "failed")
            return map("ok", false, "reason", "under-temperature {peak_c}°C — cycle FAILED",
                "state", get_status(tray))
        }
        transition(tray, "params_met")
        return map("ok", true, "peak", peak_c, "state", get_status(tray))
    }

    // The biological indicator is the final word. Spores not killed =>
    // terminal failure, never released.
    on indicator(tray: String, spores_killed: Bool) {
        let st = get_status(tray)
        if st != "params_met" {
            return map("ok", false, "reason", "no completed cycle to verify (state {st})")
        }
        if !spores_killed {
            transition(tray, "failed")
            return map("ok", false, "reason", "BIOLOGICAL INDICATOR FAILED — reprocess",
                "state", get_status(tray))
        }
        transition(tray, "indicator_pass")
        return map("ok", true, "state", get_status(tray))
    }

    on release(tray: String) {
        let r = try { transition(tray, "released") }
        if r.error != () {
            return map("ok", false, "reason", "cannot release: {r.error}")
        }
        return map("ok", true, "state", get_status(tray))
    }

    on tray_state(tray: String) { return get_status(tray) }

    on demo() {
        load_tray("tray-A")
        let cold = run_cycle("tray-A", 105)        // under-temp — FAILS terminally
        let blocked = release("tray-A")            // REFUSED — failed load
        // a clean load on a new id
        load_tray("tray-B")
        run_cycle("tray-B", 132)
        indicator("tray-B", true)
        let ok = release("tray-B")
        print("cold cycle:   {cold}")
        print("release fail: {blocked}")
        print("clean release: {ok}")
        return "demo done"
    }
}

cell test AutoclaveTests {
    rules {
        // clean cycle reaches released
        assert load_tray("a").ok == true
        assert run_cycle("a", 134).ok == true
        assert indicator("a", true).ok == true
        assert release("a").ok == true
        assert tray_state("a") == "released"

        // released is terminal — no re-running a released load
        assert_fails transition("a", "running")

        // an under-temperature cycle fails terminally and blocks release
        assert load_tray("b").ok == true
        assert run_cycle("b", 100).ok == false
        assert tray_state("b") == "failed"
        assert_fails transition("b", "released")
        assert_fails transition("b", "params_met")
        assert release("b").ok == false

        // a failed biological indicator also blocks release forever
        assert load_tray("c").ok == true
        assert run_cycle("c", 130).ok == true
        assert indicator("c", false).ok == false
        assert tray_state("c") == "failed"
        assert_fails transition("c", "released")

        // a probe sensor fault is rejected at the slot
        assert_fails peak_temp.set("a", 999)
    }
}

What the toolchain says

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

$ soma check sterilization.cell
✓ All checks passed.
$ soma test sterilization.cell
test AutoclaveTests ...
  ✓ assert load_tray("a").ok == true
  ✓ assert run_cycle("a", 134).ok == true
  ✓ assert indicator("a", true).ok == true
  ✓ assert release("a").ok == true
  ✓ assert tray_state("a") == "released"
  ✓ assert_fails transition("a", "running") — raised invalid transition: released → running. Current state: 'released'. Valid targets: []
  ✓ assert load_tray("b").ok == true
  ✓ assert run_cycle("b", 100).ok == false
  ✓ assert tray_state("b") == "failed"
  ✓ assert_fails transition("b", "released") — raised invalid transition: failed → released. Current state: 'failed'. Valid targets: []
  ✓ assert_fails transition("b", "params_met") — raised invalid transition: failed → params_met. Current state: 'failed'. Valid targets: []
  ✓ assert release("b").ok == false
  ✓ assert load_tray("c").ok == true
  ✓ assert run_cycle("c", 130).ok == true
  ✓ assert indicator("c", false).ok == false
  ✓ assert tray_state("c") == "failed"
  ✓ assert_fails transition("c", "released") — raised invalid transition: failed → released. Current state: 'failed'. Valid targets: []
  ✓ assert_fails peak_temp.set("a", 999) — raised memory invariant violated on 'peak_temp': peak_temp >= 0 && peak_temp <= 150 — rejected write of 999 (key "a"); the slot is unchanged

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

State machine 'load_sm': 6 states, initial 'loaded'
  States: [failed, indicator_pass, loaded, params_met, released, running]

  ✓ 6 states, 6 transitions
  ✓ all states reachable from 'loaded'
  ✓ terminal states: [released, failed]
  ✓ no deadlocks
  ✓ liveness: every state can eventually reach a terminal state
  ✓ think-isolated: CTL safety properties hold regardless of LLM output (4 handlers, 6 literal transitions, 0 dynamic)
  ✓ termination: all 6 handlers structurally terminate
  ✓ refinement: handler `load_tray` ⟶ {running}
  ✓ refinement: handler `run_cycle` ⟶ {running → failed [if peak_c < 121], running → params_met}
  ✓ refinement: handler `indicator` ⟶ {params_met → failed [if !spores_killed], params_met → indicator_pass}
  ✓ refinement: handler `release` ⟶ {released}
  · transition sources: `load_tray`, `release` 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)

Autoclave/invariants:

  ⚠ invariant peak_temp >= 0 && peak_temp <= 150 — runtime-checked (computed values): run_cycle → peak_temp because `peak_c` is a parameter (narrow it: `require peak_c >= 0 && peak_c <= 150 else …`)

11 passed, 1 warnings, 0 failures

  Temporal properties for 'load_sm':
  ✓ deadlock_free — no deadlocks in any reachable state
Temporal: 1 passed, 0 failed
VERIFY OK
$ soma run sterilization.cell demo
cold cycle:   {"ok": false, "reason": "under-temperature 105°C — cycle FAILED", "state": "failed"}
release fail: {"ok": false, "reason": "cannot release: invalid transition: failed → released. Current state: 'failed'. Valid targets: []"}
clean release: {"ok": true, "state": "released"}
demo done

Builtins used

get_status, map, print, transition

Source file: /corpus/medical/sterilization.cell · examples/corpus/medical/sterilization.cell