From 358ec1331a900557c24349e38ca9ad4d6efdef4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 30 Sep 2026 21:14:14 +0300 Subject: [PATCH] lane-av1422seed r2: the comparator is proven to BITE -- 324/324 flip arms, and the merged fix re-measured here MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit No decoder change. lane/av1422luma 459e425d (main 298be661) closed the arm this lane localised; this round checks the claim instead of restating it, and closes the one hole this report had named against itself twice (§1.1 and §7: "the flip control was not run"). scripts/flipctl-422.py flips ONE sample and requires the wrong-sample count to move by EXACTLY +1 in that plane and 0 in every other plane, in both directions: the oracle arm (one ffmpeg sample, which on a 0/0/0 cell is the only thing that can move) and the ours arm (one of our samples, which is the direction every number in this report is read in). It maps decode->display ONCE and pins the mapping across the flip, because the census's own flipctl.py re-derives that mapping from LUMA identity inside every compare() call and a flipped sample destroys the very key it maps on -- the control aborted instead of measuring, which is why it had never run rather than merely never been run. Every decode->display SOLUTION is exercised, so an ambiguous mapping cannot hide a failure behind the one that got picked. 324 arms, 324 PASS, 0 FAIL: five s422 target cells, s422_416x250_10b, two 4:2:0 and two 4:4:4 cells, two shown display frames each, three sample indices per plane, both depths, all baselines 0/0/0 -- so every arm is a +1-off-zero test. The 2-solution mapping class (s420_352x242_10b, hidden frame 16, 72 arms) is included, which is where a comparator that quietly picks one assignment shows. Independently re-measured on main 298be661 with the local-only 4:2:2 probe bypass, reverted after (git diff main -- crates/ empty; the sequence-header refusal at stream.rs:1803 is intact): all five target cells 0/0/0, 4:2:0 and 4:4:4 controls 5/5 byte-exact, s422_* sweep 17/18 with s422_384x240 unchanged at 0/1780/1871 -- the frame-1 altref residual lane/av1422late owns. Report §9 records one trap worth keeping: the first re-measurement of this round ran against a STALE main ref (0c77bad5, cached before the merge) and reproduced the pre-fix numbers exactly. Nothing about that result distinguished "the fix does not work" from "the branch pointer is old"; re-resolving main is what turned the same command into 0/0/0. Same class as stale-binary false readings, on the ref instead of the binary. §9.3 states what is still NOT measured: the POST-fix sentinel census was not re-run (the scan remains the temporary uncommitted edit §8 step 3 describes). Coverage on the merged tree is argued, not censused -- an unwritten sample still holds PLANE_SENTINEL 0xDEAD = 57005, above the 10-bit maximum and unreachable by ffmpeg at either depth, so per-plane byte-exactness on every shown frame cannot coexist with one -- and that inference is labelled as such rather than presented as a census. --- lanes/av1422seed.report.md | 95 +++++++++++++++++++++++++ scripts/flipctl-422.py | 141 +++++++++++++++++++++++++++++++++++++ 2 files changed, 236 insertions(+) create mode 100755 scripts/flipctl-422.py diff --git a/lanes/av1422seed.report.md b/lanes/av1422seed.report.md index a3f2948b..bb021bfa 100644 --- a/lanes/av1422seed.report.md +++ b/lanes/av1422seed.report.md @@ -457,3 +457,98 @@ python3 scripts/shape422-diff.py s422_320x246 sweep/s422_320x246.obu `cells.json` entries are `{"name": ..., "path": ...}`. The comparator derives geometry from the sequence header itself and needs no other argument; it raises rather than reporting a count it cannot justify. + +--- + +## 9. Round 2 addendum — independent re-verification of the merged fix, and the flip control §1.1/§7 could not run + +This lane lands **no decoder change**. `lane/av1422luma` `459e425d` (merged to +main as `298be661`) closed the arm this report localised, and this round's job +was to check that claim rather than restate it. Two things came out of that, +one of them new to the tree. + +### 9.1 The merged tree, measured here, not read off the sibling's report + +`main` = `298be661`, my read-only branch rebased onto it, the local-only 4:2:2 +probe bypass applied to `stream.rs:1803` for the run and reverted after (the +refusal is intact in the committed tree — `git diff main -- crates/` is empty). +Same comparator, same binary, same ffmpeg 8.1.3: + +| cell | round 1 (pre-fix) | merged `298be661` | +|---|---|---| +| `s422_322x240` | 0 / 22003 / 21625 | **0 / 0 / 0** | +| `s422_320x246` | 0 / 7810 / 5531 | **0 / 0 / 0** | +| `s422_322x246` | 0 / 3437 / 2222 | **0 / 0 / 0** | +| `s422_352x242_10b` | 0 / 4653 / 3777 | **0 / 0 / 0** | +| `s422_416x242_10b` | 0 / 5740 / 4348 | **0 / 0 / 0** | + +Controls on the same binary: `s420_320x240`, `s420_320x246`, +`s420_352x242_10b`, `s444_320x240`, `s444_320x242_10b` — **5/5 BYTE-EXACT**, +so the 4:2:0 pair arm and the 4:4:4 `own444` arm are untouched by the new +`own422` predicate. The whole `s422_*` sweep reads 17/18 byte-exact, with +`s422_384x240` unchanged at 0/1780/1871 — the separate frame-1 altref residual +`lane/av1422late` owns, correctly NOT attributed to this arm. + +**A stale-ref trap worth recording.** My first re-measurement of this round ran +against `0c77bad5`, a `main` ref my worktree had cached *before* the fix +merged, and reproduced the pre-fix numbers exactly (0/7810/5531 on +`s422_320x246`) — the kind of result that reads as "the fix does not work" and +is entirely an artefact of the branch pointer. `git log -1 main` at the time +already disagreed with the merge that had actually landed. Re-resolving +`main` first is what turned the same command into `0/0/0`. Class: +`stale-binary-false-readings`, on the ref rather than the binary. + +### 9.2 The flip control: now run, and committed as `scripts/flipctl-422.py` + +§1.1 and §7 both recorded this as NOT DONE, and the whole corpus verdict rests +on it: nothing above distinguishes "our planes match ffmpeg's" from "this +comparator never looked at ffmpeg". It is now run. + +`scripts/flipctl-422.py` flips **one sample** and requires the count to move by +**exactly +1 in that plane and 0 in every other plane**, in two independent +directions: + +* **oracle arm** — flip one ffmpeg sample. On a `0/0/0` cell this is the only + thing that can move, so a surviving zero means the comparator is not reading + the oracle. +* **ours arm** — flip one of our samples, oracle untouched. This is the + direction every number in this report is read in. + +It maps decode→display **once** and pins the mapping across the flip: the +census's own `flipctl.py` re-derives that mapping from LUMA identity inside +every `compare` call, so a flipped sample destroys the very key it maps on and +the control aborts instead of measuring (that is why it never ran — the script +was broken, not unrun). Every decode→display *solution* is exercised, so an +ambiguous mapping cannot hide a failure behind the one that got picked. +Two shown display frames per cell (first and middle), three sample indices +per plane (first, middle, last), both depths. + +**324 arms, 324 PASS, 0 FAIL** over five 4:2:2 target cells, `s422_416x250_10b`, +two 4:2:0 cells and two 4:4:4 cells — including the 2-solution mapping class +(`s420_352x242_10b`, 72 arms, hidden frame 16), which is where a comparator +that quietly picks one assignment would show up. All baselines were `0/0/0`, +so every arm is a `+1`-off-zero test: the strongest form of this control. + +```sh +python3 scripts/flipctl-422.py cells.json +``` + +### 9.3 Still not measured, stated rather than hidden + +* **The post-fix `EC_AV1_PLANE_SENTINEL=1` unwritten-sample census was not + re-run this round.** §3's census is the PRE-fix one (a 4×8 unwritten hole per + chroma plane at row 128, cols 144..151) and it stands as recorded; the scan + itself is still the temporary four-line edit §8 step 3 describes and is + still not committed. What the merged tree does establish instead is + *implied* coverage, not measured census: a sample that reconstruction never + wrote still holds `PLANE_SENTINEL` = `0xDEAD` = 57005, which is above the + 10-bit maximum and unreachable by ffmpeg at either depth, so a per-plane + byte-exact count on every shown frame of all five cells *cannot* coexist + with an unwritten sample in those planes. That is an inference from the + sentinel's value, not a census run — a lane that wants the direct artifact + should land the scan as a committed env-gated pass, which this lane did not + do because the arm it was measuring is already merged. +* No gate was added. `INTRABC_RECT4_OWN_CHROMA422_HITS` on the merged tree is + the route counter the sibling lane describes, and 4:2:2 still refuses at the + sequence header, so a committed byte-exact gate on a 4:2:2 cell is not + reachable without the probe bypass. diff --git a/scripts/flipctl-422.py b/scripts/flipctl-422.py new file mode 100755 index 00000000..901b4176 --- /dev/null +++ b/scripts/flipctl-422.py @@ -0,0 +1,141 @@ +#!/usr/bin/env python3 +"""Flip control: prove the ffmpeg comparator BITES, before any verdict. + +[`cmp422-ffmpeg`][c] re-derives the decode->display assignment from LUMA +identity on every call, so a flipped oracle sample can never be re-mapped -- +the identity it keys on is exactly what the flip breaks. This control +therefore maps ONCE from the untouched streams and then flips one SAMPLE per +arm with the mapping PINNED, which is the only way to ask "does one wrong +sample move the count by exactly one?". + +Two independent directions, both required to pass: + +* **oracle arm** -- flip one ffmpeg sample. The plane that owns it must move by + EXACTLY +1, every other plane by exactly 0. On a byte-exact cell this is the + only thing that can move, so a `0/0/0` that survives a flip is a comparator + that is not reading the oracle. +* **ours arm** -- flip one of OUR samples with the oracle untouched. Same + delta. This is the direction the whole corpus verdict rests on, and on a + `0/0/0` cell it is what separates "we agree" from "we never looked". + +Every decode->display SOLUTION is exercised, so an ambiguous mapping cannot +hide a failure behind the one that was picked. + +Usage: + python3 scripts/flipctl-422.py cells.json + +`cells.json` entries: `{"name", "path", "prefix"}`, `prefix` being our +`EC_AV1_FINAL_DUMP` prefix. Exit status 0 only if every arm passes. +""" +import importlib.util +import json +import os +import sys + +_HERE = os.path.dirname(os.path.abspath(__file__)) +_spec = importlib.util.spec_from_file_location( + "cmp422_ffmpeg", os.path.join(_HERE, "cmp422-ffmpeg.py")) +C = importlib.util.module_from_spec(_spec) +_spec.loader.exec_module(C) + + +def plane_counts(ours, disp, mapping, hidden, sizes, bps): + """The comparator's own accounting (`cmp422-ffmpeg.compare`'s `measure`), + with the decode->display assignment PINNED so a flipped sample cannot + re-map.""" + tot = [0, 0, 0] + for oi, a in enumerate(ours): + if oi in hidden: + continue + b = disp[mapping[oi]] + off = 0 + for pi, sz in enumerate(sizes): + for i in range(sz): + s = off + i * bps + if a[s:s + bps] != b[s:s + bps]: + tot[pi] += 1 + off += sz * bps + return tot + + +def flip_sample(buf, sample_index, bps): + """Flip bit 0 of one SAMPLE's low byte: exactly +1 wrong sample at both + depths (2**bitdepth < 2**16, so nothing carries out of the container).""" + out = bytearray(buf) + out[sample_index * bps] ^= 1 + return bytes(out) + + +def arms_for(sizes): + """(plane, sample_index) per plane: the first, the middle and the last.""" + out = [] + for pi, sz in enumerate(sizes): + out += [(pi, 0), (pi, sz // 2), (pi, sz - 1)] + return out + + +def one_cell(cell, path, prefix): + w, h, ssx, ssy, depth, pix = C.probe_geometry(path) + bps = 1 if depth <= 8 else 2 + sizes, fsz = C.plane_spans(w, h, ssx, ssy, bps) + disp = C.split(C.ffmpeg_frames(path, pix), sizes, fsz, cell) + ours = [open(p, "rb").read() for p in C.frame_files(prefix)] + if not ours: + raise SystemExit(f"{cell}: no EC_AV1_FINAL_DUMP frames -- vacuous") + for i, o in enumerate(ours): + if len(o) != fsz: + raise SystemExit(f"{cell}: our frame {i} is {len(o)} B, " + f"geometry {w}x{h} ss={ssx}{ssy} depth={depth} implies {fsz} B") + sols = C.map_decode_to_display(ours, disp, sizes, bps, cell) + shown = set() + for mapping, hidden in sols: + shown |= {d for oi, d in enumerate(mapping) if oi not in hidden} + shown = sorted(shown) + # Two shown display frames per cell -- the first and one in the middle -- + # so the arm is not confined to frame 0. + ks = sorted({shown[0], shown[len(shown) // 2]}) + results, arms = [], 0 + base0 = plane_counts(ours, disp, sols[0][0], sols[0][1], sizes, bps) + for k in ks: + for sol_i, (mapping, hidden) in enumerate(sols): + dmap = {d: oi for oi, d in enumerate(mapping) if oi not in hidden} + if k not in dmap: + continue + oi = dmap[k] + base = plane_counts(ours, disp, mapping, hidden, sizes, bps) + for pi, si in arms_for(sizes): + off = sum(sizes[:pi]) + si # sample index inside the frame + want = [0, 0, 0] + want[pi] = 1 + for side in ("oracle", "ours"): + if side == "oracle": + f = list(disp) + f[k] = flip_sample(disp[k], off, bps) + got = plane_counts(ours, f, mapping, hidden, sizes, bps) + else: + f = list(ours) + f[oi] = flip_sample(ours[oi], off, bps) + got = plane_counts(f, disp, mapping, hidden, sizes, bps) + delta = [got[i] - base[i] for i in range(3)] + ok = delta == want + results.append(ok) + arms += 1 + if not ok: + print(f" FAIL {side:6s} disp f{k} plane {'YUV'[pi]} " + f"sample {si} sol{sol_i}: {base} -> {got} " + f"delta {delta} want {want}") + print(f"{cell}: baseline {base0} {len(ours)} decode / {len(disp)} shown, " + f"hidden {sols[0][1]}, {len(sols)} mapping solution(s), {arms} arms") + return results + + +def main(spec_path): + rows = [] + for c in json.load(open(spec_path)): + rows += one_cell(c["name"], c["path"], c["prefix"]) + print(f"\n{sum(rows)} PASS, {len(rows) - sum(rows)} FAIL of {len(rows)} flip arms") + return 0 if all(rows) else 1 + + +if __name__ == "__main__": + sys.exit(main(sys.argv[1])) \ No newline at end of file