forge
Explore
Log in

Don't you dare go Hollow

lane-av1txctxband2: a LOSSLESS block still publishes its txfm band; the 640x480 mixed-lossless cell goes REFUSED -> 6/6 and 7/7 byte-exact

Browse files at this commit

e226c3b39ba372f36ae458d17fcb361f6bdfd542Ahmet Kaan GümüşParent: 51825f3
libaom's parse_decode_block is an EITHER/OR: the var-tx branch's condition
carries !xd->lossless[segment_id] as a conjunct, and the else branch runs
read_tx_size AND THEN set_txfm_ctxs. read_tx_size returns TX_4X4 on its
first line, so a lossless block skips the SYMBOL READ, not the PUBLISH.

read_block_tx_size's lossless early return skipped the publish too. On a
mixed frame every lossless square block therefore left above_txfm holding
whatever an earlier lossy block wrote. Measured on the 640x480 cell: the
abutting 8x8 INTRA lossless block at mi(78,110) left above_txfm[110] at the
16 a skipped 16-px inter block at mi(36,108) had written 43 mi rows earlier,
and the 8x4 intra leaf with use_filter_intra at mi(80,110) then read
tx_size_cat0[2] where libaom reads row 1 (oracle EC_TXCTXB: abv=4 lft=8
above=0 left=1 ctx=1). The tile desynced and the frame refused.

The RECT twin read_block_tx_size_rect has published on the same arm since
lane-av1lm444loss; only the square arm had the hole, which is why the class
was never swept.

- the cell decodes, 6/6 decode-order frames byte-exact at --limit=5 and 7/7 at
  --limit=6; the whole-stream paired EC_SYMR ladder is bit-identical over ALL
  457907 reads, the same count the inherited forced-ctx=1 mask reached
- corpus sweep, 110 committed fixtures before and after: 100 EXACT / 10
  REFUSED both sides, ZERO rows changing (all ten refusals are the pre-existing
  by-name 4:2:2 chroma refusal); 176x144, 352x288 and the 256x128 pin
  re-measured 6/6 byte-exact with the fix
- route counter LOSSLESS_SQ_TXFM_BAND_OVERWRITE_HITS on the DECISION (the
  publish overwrote a size an earlier block of the same frame had left), so
  the gate cannot be armed by merely decoding a lossless fixture
- gate a_420_mixed_lossless_alt_ref_640x480_txfm_band_publish_is_byte_exact_in_decode_order,
  fixture pinned by fnv1a64; mutation proof: removing the one set_txfm_ctxs
  call turns it red on the exact refusal
- class sweep context-band-not-published over 5 sites with a measured verdict
  each; the one other real gap (read_block_tx_size_rect's lossless arm missing
  the skip && is_inter term) is REACHED 29/1/9/6/16 times yet correcting it is
  a no-op on every fixture that reaches it, so it is handed over, not shipped
  without a red-before
crates/ec-av1/fixtures/420_mixll_altref_640x480_5f.obuadded+0 -0

Binary file changed

crates/ec-av1/fixtures/420_mixll_altref_640x480_6f.obuadded+0 -0

Binary file changed

crates/ec-av1/src/decode.rsmodified+59 -0
@@ -29905,6 +29905,47 @@ fn read_block_tx_size(
29905 leaves.push((row, col, 4, 4));29905 leaves.push((row, col, 4, 4));
29906 }29906 }
29907 }29907 }
29908+ // lane-av1txctxband2: a lossless block still runs libaom's
29909+ // `set_txfm_ctxs` at the tail of `parse_decode_block`
29910+ // (decodeframe.c:1260). Its `read_tx_size` returned `TX_4X4` on the
29911+ // FIRST line (decodeframe.c:1214) -- the early return skips the symbol
29912+ // read, not the PUBLISH -- so `tx_size_wide[TX_4X4] == 4` goes over the
29913+ // block's own width/height, and a SKIPPED inter block instead records
29914+ // its block size (the `skip && is_inter` term).
29915+ //
29916+ // This early return published nothing, so on a MIXED frame every
29917+ // lossless square block left the band holding whatever an earlier,
29918+ // lossy block wrote. Measured on the 640x480 mixed-lossless+altref
29919+ // cell (`420_mixll_altref_640x480_5f.obu`, 87 537 B): the abutting
29920+ // 8x8 INTRA lossless block at mi(78,110) left `above_txfm[110]` at
29921+ // the 16 a skipped 16-px inter block at mi(36,108) had written 43 mi
29922+ // rows earlier, and the 8x4 intra leaf with `use_filter_intra` at
29923+ // mi(80,110) then read `tx_size_cat0[2]` where libaom reads row 1
29924+ // (oracle `EC_TXCTXB` `abv=4 lft=8 above=0 left=1 ctx=1`). The tile
29925+ // desynced there and the frame refused.
29926+ //
29927+ // The RECT twin [`read_block_tx_size_rect`] has published on this arm
29928+ // since lane-av1lm444loss; only the square arm had the hole.
29929+ let pub_above: u8 = if skip && is_inter {
29930+ (side_mi * MI) as u8
29931+ } else {
29932+ 4
29933+ };
29934+ // The gate's non-vacuity arm, on the DECISION, sampled BEFORE the
29935+ // write: this publish OVERWRITES a size some earlier block of the same
29936+ // frame had left in one of the columns it covers -- the only way a
29937+ // later `get_tx_size_context` / `txfm_partition_context` reader can
29938+ // see it. On a frame whose blocks all sit in lossless segments nothing
29939+ // reads either band (libaom's `read_tx_size` returns before
29940+ // `get_tx_size_context`, and the var-tx tree is gated on
29941+ // `!xd->lossless`), so a wholly-lossless stream whose inter blocks are
29942+ // all non-skip leaves this at zero.
29943+ let overwrote = !fctx.intra_only.with(std::cell::Cell::get)
29944+ && (0..side_mi).any(|i| n.above_txfm.get(at_mi.1 + i) != Some(&pub_above));
29945+ set_txfm_ctxs(n, at_mi, 4, side_mi, side_mi, skip && is_inter);
29946+ if overwrote {
29947+ hit!(LOSSLESS_SQ_TXFM_BAND_OVERWRITE_HITS);
29948+ }
29908 return Ok((4, Some(leaves)));29949 return Ok((4, Some(leaves)));
29909 }29950 }
29910 if !fctx.tx_select_inter.with(std::cell::Cell::get) {29951 if !fctx.tx_select_inter.with(std::cell::Cell::get) {
@@ -34762,6 +34803,16 @@ thread_local! {
34762 /// whose sub-8 leaves all sit in lossy segments, so a gate cannot look34803 /// whose sub-8 leaves all sit in lossy segments, so a gate cannot look
34763 /// armed by merely decoding.34804 /// armed by merely decoding.
34764 pub(crate) static SUB8_LOSSLESS_NO_VARTX: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };34805 pub(crate) static SUB8_LOSSLESS_NO_VARTX: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
34806+ /// lane-av1txctxband2: SQUARE lossless blocks on an INTER frame whose
34807+ /// `set_txfm_ctxs` publish CHANGED an above-band cell -- i.e. the write
34808+ /// overwrote a size some earlier block of the same frame had left, which
34809+ /// is the only way a later `get_tx_size_context` /
34810+ /// `txfm_partition_context` reader can see it. Zero on an intra-only
34811+ /// frame (where `fill_lf_grid_rect_inner` publishes the same 4x4 value at
34812+ /// the same footprint) and on a wholly-lossless stream whose inter blocks
34813+ /// are all non-skip (nothing reads either band there), so a gate cannot
34814+ /// look armed by merely decoding a lossless fixture.
34815+ pub(crate) static LOSSLESS_SQ_TXFM_BAND_OVERWRITE_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
34765 }34816 }
34766 34817
34767 /// [`MU_CHUNK_WALKS`], for a gate's own before/after delta.34818 /// [`MU_CHUNK_WALKS`], for a gate's own before/after delta.
@@ -34794,6 +34845,14 @@ pub(crate) fn lossless_edge_clipped() -> usize {
34794 pub(crate) fn lossless_edge_clip_units() -> usize {34845 pub(crate) fn lossless_edge_clip_units() -> usize {
34795 LOSSLESS_EDGE_CLIP_UNITS.with(std::cell::Cell::get)34846 LOSSLESS_EDGE_CLIP_UNITS.with(std::cell::Cell::get)
34796 }34847 }
34848+/// [`LOSSLESS_SQ_TXFM_BAND_OVERWRITE_HITS`] -- square lossless inter blocks
34849+/// whose `set_txfm_ctxs` publish overwrote a size an earlier block of the
34850+/// same frame had left in the above band, for a gate's own before/after
34851+/// delta.
34852+#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
34853+pub(crate) fn lossless_sq_txfm_band_overwrite_hits() -> usize {
34854+ LOSSLESS_SQ_TXFM_BAND_OVERWRITE_HITS.with(std::cell::Cell::get)
34855+}
34797 /// [`SUB8_LOSSLESS_NO_VARTX`] -- sub-8 inter leaves on a lossless segment that34856 /// [`SUB8_LOSSLESS_NO_VARTX`] -- sub-8 inter leaves on a lossless segment that
34798 /// read no var-tx symbol, for a gate's own before/after delta.34857 /// read no var-tx symbol, for a gate's own before/after delta.
34799 #[allow(dead_code)] // read only from the `#[cfg(test)]` gates34858 #[allow(dead_code)] // read only from the `#[cfg(test)]` gates
crates/ec-av1/src/stream.rsmodified+92 -0
@@ -9380,6 +9380,98 @@ pub(crate) mod tests {
9380 lossless segment read no var-tx symbol"9380 lossless segment read no var-tx symbol"
9381 );9381 );
9382 }9382 }
9383+
9384+ /// lane-av1txctxband2: the 640x480 cell of the same mixed-lossless
9385+ /// recipe — the THIRD defect `lanes/av1mixllconj.report.md` §4.3 /
9386+ /// §11 handed over, class `context-band-not-published`.
9387+ ///
9388+ /// libaom's `parse_decode_block` (`decodeframe.c:1251-1261`) is an
9389+ /// EITHER/OR: the var-tx branch's condition carries
9390+ /// `!xd->lossless[mbmi->segment_id]` as a conjunct, and the `else` branch
9391+ /// runs `read_tx_size` **and then `set_txfm_ctxs`**. `read_tx_size`'s
9392+ /// FIRST line (`decodeframe.c:1214`) returns `TX_4X4` on a lossless
9393+ /// segment — so a lossless block skips the symbol read, NOT the publish.
9394+ /// This decoder's `read_block_tx_size` returned from its own lossless early
9395+ /// return with nothing written, so on a MIXED frame every lossless square
9396+ /// block left the `TXFM_CONTEXT` above band holding whatever an earlier,
9397+ /// lossy block had put there. The RECT twin (`read_block_tx_size_rect`)
9398+ /// has published on the same arm since lane-av1lm444loss; only the square
9399+ /// arm had the hole.
9400+ ///
9401+ /// Measured on `420_mixll_altref_640x480_5f.obu`: the abutting 8x8 INTRA
9402+ /// lossless block at mi(78,110) left `above_txfm[110]` at the 16 a skipped
9403+ /// 16-px inter block at mi(36,108) had written 43 mi rows earlier, and the
9404+ /// 8x4 intra leaf with `use_filter_intra` at mi(80,110) then read
9405+ /// `tx_size_cat0[2]` where libaom reads row 1 — the oracle's own
9406+ /// `EC_TXCTXB` prints `mi=80,110 abv=4 lft=8 above=0 left=1 ctx=1` against
9407+ /// our `above_txfm=16 left_txfm=8 above=1 left=1 ctx=2`. The tile desynced
9408+ /// there and the frame REFUSED (`a Golomb tail longer than this decoder
9409+ /// reads`); at base the same cell decoded every frame but got 70–92 % of
9410+ /// every inter frame wrong.
9411+ ///
9412+ /// `LOSSLESS_SQ_TXFM_BAND_OVERWRITE_HITS` counts the lossless square inter
9413+ /// blocks whose publish actually OVERWROTE a size an earlier block of the
9414+ /// same frame had left in the column — so the gate cannot pass vacuously
9415+ /// on a stream that merely decodes a lossless fixture. After the fix the
9416+ /// whole-stream paired `EC_SYMR` ladder is bit-identical: **457 907 reads,
9417+ /// 457 907 paired, zero divergence** — not just up to the fork.
9418+ ///
9419+ /// Recipe (ffmpeg 8.1.3 `testsrc2`, shared oracle `aomenc`, 87537 bytes):
9420+ /// ```text
9421+ /// ffmpeg -f lavfi -i testsrc2=size=640x480:rate=25 -frames:v 5 \
9422+ /// -pix_fmt yuv420p src640.y4m
9423+ /// aomenc --codec=av1 --obu -o 420_mixll_altref_640x480_5f.obu --passes=1 \
9424+ /// --cpu-used=4 --limit=5 --end-usage=q --cq-level=0 --aq-mode=1 src640.y4m
9425+ /// ```
9426+ /// sha256 `3d505fd2e0bbb7ca3680a8e338d712a81defc947b955a4b7b82de6718301e73c`;
9427+ /// the tree pins fixture identity by fnv1a64, not a `const SHA256` compared
9428+ /// against itself.
9429+ #[test]
9430+ fn a_420_mixed_lossless_alt_ref_640x480_txfm_band_publish_is_byte_exact_in_decode_order() {
9431+ const NAME: &str = "a_420_mixed_lossless_alt_ref_640x480_txfm_band_publish_is_byte_exact_\
9432+ in_decode_order";
9433+ let _gate_lock = lock_gate_counters();
9434+ const FILE: &str = "420_mixll_altref_640x480_5f.obu";
9435+ const BYTES: usize = 87537;
9436+ const FNV1A64: u64 = 12707865649077681891;
9437+ let path = crate_pin(FILE);
9438+ let data = std::fs::read(&path)
9439+ .unwrap_or_else(|e| panic!("{NAME}: the committed pin {FILE} is missing ({e})"));
9440+ assert_eq!(data.len(), BYTES, "{NAME}: {FILE} size drifted");
9441+ assert_eq!(fnv1a64(&data), FNV1A64, "{NAME}: {FILE} bytes drifted");
9442+ let before = crate::decode::lossless_sq_txfm_band_overwrite_hits();
9443+ let (decoded, hidden) = decode_all_frames_vs_oracle(&data, NAME);
9444+ let overwrote = crate::decode::lossless_sq_txfm_band_overwrite_hits() - before;
9445+ assert_eq!(
9446+ decoded, 6,
9447+ "{NAME}: the oracle decoded {decoded} frames in DECODE order; the 5-frame \
9448+ altref recipe codes 5 source frames plus a hidden alt-ref picture"
9449+ );
9450+ assert_eq!(
9451+ hidden, 1,
9452+ "{NAME}: {decoded} decode-order dumps against {decoded} - {hidden} shown outputs \
9453+ means the gate saw the hidden picture no shown-frame compare can reach"
9454+ );
9455+ assert!(
9456+ overwrote > 0,
9457+ "{NAME}: no lossless square block on an inter frame published a txfm band that \
9458+ OVERWROTE an earlier block's size ({overwrote} of them did), so this witness does \
9459+ not exercise the missing publish at all (class gate-blind-to-feature) -- re-encode \
9460+ per the recipe above"
9461+ );
9462+ let (wy, wu, wv, shown, exact) =
9463+ count_rawvideo_diffs(&data, NAME, None).expect("the two sides must be byte-comparable");
9464+ assert_eq!(
9465+ (wy, wu, wv, exact),
9466+ (0, 0, 0, shown),
9467+ "{NAME}: shown-frame per-plane diff vs `aomdec --rawvideo`"
9468+ );
9469+ eprintln!(
9470+ "{NAME}: {decoded} decode-order frame(s) byte-exact ({hidden} hidden), \
9471+ {shown} shown frame(s) exact per plane, {overwrote} lossless square inter \
9472+ block(s) overwrote a stale above-band size"
9473+ );
9474+ }
9383 /// lane-av1444rect r2 — the SAME class as the gate above, second9475 /// lane-av1444rect r2 — the SAME class as the gate above, second
9384 /// instance: `decode_rect4_16_intrabc` applied the 4:2:0 pair geometry at9476 /// instance: `decode_rect4_16_intrabc` applied the 4:2:0 pair geometry at
9385 /// ss (0,0), where `is_chroma_reference` makes an intra-BC 1:4 strip its9477 /// ss (0,0), where `is_chroma_reference` makes an intra-BC 1:4 strip its
lanes/av1txctxband2.report.mdadded+409 -0
@@ -0,0 +1,409 @@
1+# lane-av1txctxband2 — the missing `TXFM_CONTEXT` PUBLISH: `read_block_tx_size`'s lossless early return skipped libaom's `set_txfm_ctxs`, so a mixed-lossless 640x480 frame's abutting 8x8 intra block left a stale band and the cell desynced
2+
3+Base `main` = `0bfee517`. Worktree `/home/user/.cache/wt/av1txctxband2`,
4+target dir `$HOME/.cache/cargo-target-av1txctxband2`, `EC_NOMEMGUARD=1`. Oracle
5+`~/.cache/aom-oracle/build/{aomdec,aomenc}` (shared, untouched; not rebuilt, not
6+re-instrumented). ffmpeg 8.1.3.
7+
8+**Handover taken:** `lanes/av1mixllconj.report.md` §4.3 and §11
9+`deferred(unblock: identify the TXFM_CONTEXT band write libaom makes above
10+mi=(80,110) …)`, plus the same claim independently re-measured by
11+`lane-av1offtile` §6b.
12+
13+## 0. Verdict
14+
15+| | |
16+|---|---|
17+| The cause | **`read_block_tx_size`'s lossless early return returned without publishing anything.** libaom's `parse_decode_block` is an EITHER/OR: the var-tx branch's condition carries `!xd->lossless[segment_id]` as a conjunct, and the `else` branch runs `read_tx_size` **and then `set_txfm_ctxs`**. `read_tx_size` returns `TX_4X4` on its FIRST line — the early return skips the SYMBOL READ, not the PUBLISH. |
18+| The offending block | the **8x8 INTRA lossless block at mi(78,110)**, abutting the reader. libaom stamps `tx_size_wide[TX_4X4] == 4` into `above_txfm_context[110..111]`; we wrote nothing, so the band still held the **16** a skipped 16-px inter block at mi(36,108) had written 43 mi rows earlier. |
19+| The reader that broke | the 8x4 intra leaf with `use_filter_intra` at **mi=(80,110)**, `tx_size_cat0[2]` where libaom reads row 1. |
20+| `420_mixll_altref_640x480_5f.obu` (87537 B) | **REFUSED** at base → **6/6 decode-order frames byte-exact**; whole-stream paired `EC_SYMR` ladder **457 907 / 457 907 bit-identical, zero divergence** |
21+| `420_mixll_altref_640x480_6f.obu` (115615 B) | **REFUSED** at base → **7/7 decode-order frames byte-exact** |
22+| Corpus sweep, 110 committed fixtures | **EXACT 100 → 100, REFUSED 10 → 10, RED 0 → 0, FRAMECOUNT 0 → 0** — all ten refusals are the pre-existing by-name 4:2:2 chroma refusal. **Zero rows change**: the fix is a strict no-op on everything already correct, and it is the two NEW 640x480 fixtures that go REFUSED → 6/6 and 7/7 EXACT. |
23+| Recipe's closed cells | re-measured with the fix: 256x128 pin **6/6 EXACT**, 176x144 **6/6 EXACT**, 352x288 **6/6 EXACT**, the 4:4:4 arm green in the corpus (§6.1) |
24+| Class sweep | 5 sites of `context-band-not-published`; **1 was this defect (fixed), 1 is a real libaom-fidelity gap that IS reached but has NO observable effect on any fixture measured (`read_block_tx_size_rect`'s lossless arm, missing the `skip && is_inter` term — 29/1/9/6/16 measured hits), 2 are unobservable by construction, 1 is a deliberate gate that measurement clears** (§7) |
25+| Fix / fixture / counter / gate | all four landed, with a mutation proof (§5) |
26+
27+## 1. Reproduction
28+
29+```text
30+ffmpeg -f lavfi -i testsrc2=size=640x480:rate=25 -frames:v 5 -pix_fmt yuv420p src640.y4m
31+aomenc --codec=av1 --obu -o 420_mixll_altref_640x480_5f.obu --passes=1 --cpu-used=4 \
32+ --limit=5 --end-usage=q --cq-level=0 --aq-mode=1 src640.y4m
33+```
34+
35+| cell | bytes | sha256 |
36+|---|---:|---|
37+| `420_mixll_altref_640x480_5f.obu` | 87 537 | `3d505fd2e0bbb7ca3680a8e338d712a81defc947b955a4b7b82de6718301e73c` |
38+| `420_mixll_altref_640x480_6f.obu` (`--limit=6`) | 115 615 | `c82ba4d793d378cc7e4a234329be87c5c03a283c8b6a202acf4d0704ea66ff7f` |
39+
40+Both byte counts and both shas reproduce the inherited reports' on the first
41+try. At `0bfee517` the 5-frame cell decodes to
42+
43+```text
44+TILING: 7 frame headers parsed
45+REFUSED: unsupported: AV1 tile (a Golomb tail longer than this decoder reads)
46+frames_dispatched: 0
47+```
48+
49+— reproduced verbatim, on my own worktree and target dir.
50+
51+## 2. The write trace for mi column 110
52+
53+`EC_TXUPD` (the existing `set_txfm_ctxs` / `txfm_partition_update_rect` rung)
54+restricted to writes whose column span covers mi column 110 with `mi_r < 80`
55+shows only four writes, the last a skipped 16-px inter block — the report's
56+finding, and it is **true but incomplete**: the per-leaf publishes inside
57+`decode_leaf_rect8` and `decode_intra_rect_in_inter` are hand-rolled loops, not
58+`EC_TXUPD`-traced. So I replayed the COLUMN instead, walking the mi map upward
59+from the reader (`BlkCell::org` / `dim` / `skip` + `inter_grid` + the deblock
60+grid), at the exact site:
61+
62+```text
63+EC_TXCTXCOL --- column 110 walk, above_txfm now 16
64+row=79 blk org=(78, 110) dim_mi=(2, 2) blk_px=(8,8) skip=false inter=false tx_w_grid=4 mode=None
65+row=77 blk org=(76, 110) dim_mi=(2, 2) blk_px=(8,8) skip=false inter=false tx_w_grid=4 mode=None
66+row=75 blk org=(72, 108) dim_mi=(4, 4) blk_px=(16,16) skip=true inter=true tx_w_grid=16
67+row=71 blk org=(64, 104) dim_mi=(8, 8) blk_px=(32,32) skip=true inter=true tx_w_grid=32
68+row=63 blk org=(56, 104) dim_mi=(8, 8) blk_px=(32,32) skip=true inter=true tx_w_grid=32
69+row=55 blk org=(54, 110) dim_mi=(2, 2) blk_px=(8,8) skip=false inter=false tx_w_grid=4
70+…
71+row=39 blk org=(36, 108) dim_mi=(4, 4) blk_px=(16,16) skip=true inter=true tx_w_grid=16
72+```
73+
74+Two families abutting column 110:
75+
76+* **skipped inter blocks** — these DO publish, `set_txfm_ctxs`' `skip && is_inter`
77+ arm, and they put 16 / 32 into the band;
78+* **8x8 INTRA blocks** (`inter=false`, `tx_w_grid=4`) — these publish NOTHING.
79+
80+The last writer is therefore the 8x8 intra block at **mi(78,110)**, rows 78–79,
81+which is exactly the cell libaom's `above_mbmi` names at mi(80,110). Tracing the
82+decode body that owns it pins the writer:
83+
84+```text
85+EC_TXCTXCOL lossless-early-return read_block_tx_size at=(78, 110) side=8 is_inter=false skip=false
86+```
87+
88+`side=8`, `is_inter=false`, and the block's own `tx_px` is 4 — a **lossless
89+segment**, taking `read_block_tx_size`'s lossless early return.
90+
91+## 3. The cause, in libaom's own words
92+
93+`av1/decoder/decodeframe.c` (the shared oracle's source, `~/.cache/aom-oracle/src`):
94+
95+```c
96+1210 static TX_SIZE read_tx_size(const MACROBLOCKD *const xd, TX_MODE tx_mode,
97+1211 int is_inter, int allow_select_inter, aom_reader *r) {
98+1214 if (xd->lossless[xd->mi[0]->segment_id]) return TX_4X4; // <-- the early return
99+1216 if (block_signals_txsize(bsize)) { ... read_selected_tx_size ... }
100+…
101+1251 if (cm->features.tx_mode == TX_MODE_SELECT && block_signals_txsize(bsize) &&
102+1252 !mbmi->skip_txfm && inter_block_tx && !xd->lossless[mbmi->segment_id]) {
103+1253 … read_tx_size_vartx(…) // var-tx branch
104+1258 } else {
105+1259 mbmi->tx_size = read_tx_size(xd, cm->features.tx_mode, inter_block_tx,
106+1260 !mbmi->skip_txfm, r);
107+1260 set_txfm_ctxs(mbmi->tx_size, xd->width, xd->height,
108+1261 mbmi->skip_txfm && is_inter_block(mbmi), xd); // <-- ALWAYS runs
109+1262 }
110+```
111+
112+A lossless block cannot take the var-tx branch, so it always takes the `else`
113+branch — and that branch's `set_txfm_ctxs` runs for a lossless block too, with
114+`tx_size == TX_4X4`, stamping `tx_size_wide[TX_4X4] == 4` over the block's own
115+width/height (and the BLOCK size instead when `skip_txfm && is_inter_block`).
116+
117+This decoder's mirror of that `else` branch is `read_block_tx_size`, and its
118+lossless early return was:
119+
120+```rust
121+ if lossless(fctx) {
122+ … build the TX_4X4 leaf grid, clip it at the frame edge …
123+ return Ok((4, Some(leaves))); // <-- published NOTHING
124+ }
125+```
126+
127+The RECT twin `read_block_tx_size_rect` has published on the same arm since
128+lane-av1lm444loss (`txfm_partition_update_rect(n, at_mi, (4, 4), (bw, bh))`).
129+**Only the square arm had the hole** — which is why the class was never swept:
130+the two arms look like twins in the source and only one is.
131+
132+**Why the reader is the FIRST thing to notice.** Nothing inside the lossless
133+region reads either band: `read_tx_size` returns before `get_tx_size_context`,
134+and the var-tx tree is gated on `!xd->lossless`. So every lossless block in a
135+column can leave the band stale for free, and the first block that *reads* it is
136+the first LOSSY block below the lossless run. At mi(80,110) that is the 8x4
137+intra leaf with `use_filter_intra`: `above_txfm[110] = 16 >= 8` gave
138+`above = 1` and `tx_size_cat0[2]`, where libaom's own `EC_TXCTXB` prints
139+`abv=4 above=0 left=1 ctx=1`. `left` already agreed (8 vs 8) — the entire gap is
140+the above TERM off the band, exactly as `lane-av1offtile` §6b measured.
141+
142+## 4. The fix
143+
144+`crates/ec-av1/src/decode.rs`, `read_block_tx_size`, lossless arm — one call, the
145+same one the non-lossless tail already makes at that site:
146+
147+```diff
148+ if lossless(fctx) {
149+ … the TX_4X4 leaf grid, frame-edge clipped …
150++ let pub_above: u8 = if skip && is_inter { (side_mi * MI) as u8 } else { 4 };
151++ let overwrote = !fctx.intra_only.with(std::cell::Cell::get)
152++ && (0..side_mi).any(|i| n.above_txfm.get(at_mi.1 + i) != Some(&pub_above));
153++ set_txfm_ctxs(n, at_mi, 4, side_mi, side_mi, skip && is_inter);
154++ if overwrote {
155++ hit!(LOSSLESS_SQ_TXFM_BAND_OVERWRITE_HITS);
156++ }
157+ return Ok((4, Some(leaves)));
158+ }
159+```
160+
161+`side_mi` is the block's own `side / MI`, matching the extent the non-lossless
162+tail of the same function already publishes with (`set_txfm_ctxs(n, at_mi, tx,
163+side_mi, side_mi, skip && is_inter)`), and the `skip && is_inter` term is
164+libaom's own fourth argument.
165+
166+**Route counter `LOSSLESS_SQ_TXFM_BAND_OVERWRITE_HITS`**, on the DECISION, not
167+on function entry: it samples the band's pre-state and fires only when this
168+publish actually OVERWRITES a size some earlier block of the same frame left in
169+one of the columns the block covers. It is zero on an intra-only frame (where
170+`fill_lf_grid_rect_inner` already publishes the same 4x4 value at the same
171+footprint) and zero on a wholly-lossless stream whose inter blocks are all
172+non-skip (nothing reads either band there), so it cannot be armed by merely
173+decoding a lossless fixture.
174+
175+## 5. Proof
176+
177+### 5.1 The cell decodes, and is byte-exact
178+
179+```text
180+$ EC_AV1_FINAL_DUMP=…/ours/f decode_probe 420_mixll_altref_640x480_5f.obu
181+OK: 5 frames decoded, 640x480
182+frame 0..5: 0 differing bytes (decode-order dumps vs the oracle's EC_AV1_FINAL_DUMP, 460 800 B each)
183+```
184+
185+6/6 for the 5-frame cell and 7/7 for the 6-frame cell (`--limit=6`,
186+115 615 B), every plane of every decode-order frame including the hidden
187+alt-ref picture.
188+
189+### 5.2 The whole-stream ladder, not just up to the fork
190+
191+Paired `EC_SYMR=1` on both sides, comparing the convention-free fields
192+(`pre[0]`, `pre[1]`, `n`, `s`, `post_rng`; `pre[2]` carries a per-site constant
193+offset and `cdf0` the ICDF mirror, so neither is signal), with the third field's
194+regex accepting a NEGATIVE `pre[2]`:
195+
196+```text
197+oracle 457 907 paired reads (0 unparsed) ours 457 907 paired reads (0 unparsed)
198+paired ladder bit-identical over ALL 457 907 reads
199+```
200+
201+This is the same count the inherited forced-`ctx=1` override reached — the
202+override was a symptom mask; the publish is the cause and it reaches the same
203+place without masking anything.
204+
205+### 5.3 Gate, fixture, mutation
206+
207+* fixture `crates/ec-av1/fixtures/420_mixll_altref_640x480_5f.obu`, 87 537 B,
208+ pinned by **fnv1a64** `12707865649077681891` (not a `const SHA256` compared
209+ against itself), with `420_mixll_altref_640x480_6f.obu` (115 615 B, fnv1a64
210+ `6783292541028661090`) committed alongside it as the same recipe at `--limit=6`;
211+* gate `a_420_mixed_lossless_alt_ref_640x480_txfm_band_publish_is_byte_exact_in_decode_order`
212+ asserts 6 decode-order dumps with 1 hidden, the counter delta `> 0`, and the
213+ shown-frame per-plane diff against `aomdec --rawvideo`.
214+
215+```text
216+$ cargo test -p ec-av1 --lib -- a_420_mixed_lossless_alt_ref_640x480_txfm_band_publish
217+running 1 test
218+test stream::tests::a_420_mixed_lossless_alt_ref_640x480_txfm_band_publish_is_byte_exact_in_decode_order ... ok
219+test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 806 filtered out; finished in 2.01s
220+```
221+
222+**Mutation proof** — the one `set_txfm_ctxs` call surgically removed from the
223+working tree, the gate re-run:
224+
225+```text
226+thread 'stream::tests::a_420_mixed_lossless_alt_ref_640x480_txfm_band_publish_is_byte_exact_in_decode_order' panicked at crates/ec-av1/src/stream.rs:11006:33:
227+a_420_mixed_lossless_alt_ref_640x480_txfm_band_publish_is_byte_exact_in_decode_order:
228+this decoder refused the stream: unsupported: AV1 tile (a Golomb tail longer than this decoder reads)
229+test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 806 filtered out
230+```
231+
232+Restored, both mixll gates are green together:
233+
234+```text
235+$ cargo test -p ec-av1 --lib -- a_420_mixed_lossless_alt_ref_640x480_txfm_band_publish a_420_mixed_lossless_alt_ref_sub8_vartx
236+running 2 tests
237+test stream::tests::a_420_mixed_lossless_alt_ref_640x480_txfm_band_publish_is_byte_exact_in_decode_order ... ok
238+test stream::tests::a_420_mixed_lossless_alt_ref_sub8_vartx_witness_is_byte_exact_in_decode_order ... ok
239+test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 805 filtered out
240+```
241+
242+## 6. Corpus sweep — 110 committed fixtures, before and after
243+
244+Every `crates/ec-av1/fixtures/*.obu` EXCEPT the two this lane adds, decode-order
245+dumps (`EC_AV1_FINAL_DUMP`) vs the oracle's own `EC_AV1_FINAL_DUMP`, both sides
246+bit-depth-correct and hidden alt-ref frames included.
247+
248+| | base `0bfee517` | with the fix |
249+|---|---:|---:|
250+| EXACT | 100 | **100** |
251+| RED (decodes, some frame differs) | 0 | **0** |
252+| FRAMECOUNT mismatch | 0 | **0** |
253+| REFUSED | 10 | **10** |
254+
255+**Per-fixture diff: ZERO rows change.** The two sweeps were taken on this same
256+worktree with the fix stashed and `git stash pop`-ed (so they differ by exactly
257+this commit and by nothing else), and a row-by-row comparison over all 110
258+fixtures agrees on every one:
259+
260+```text
261+fixtures: 110 changed rows: 0
262+```
263+
264+That is the strongest possible regression statement available here: at
265+`0bfee517` the committed corpus is already 100 EXACT / 10 REFUSED / 0 RED, and
266+the publish this lane adds changes nothing it was getting right. The gain is
267+confined to the two 640x480 fixtures this lane adds, which go
268+
269+```text
270+420_mixll_altref_640x480_5f.obu REFUSED (a Golomb tail longer than this decoder reads)
271+420_mixll_altref_640x480_6f.obu REFUSED (the same)
272+```
273+
274+Both refusals reproduced on the stashed binary before the fix (§5.1).
275+
276+All ten refusals are the pre-existing by-name 4:2:2 chroma refusal
277+(`422_allskip_2f`, `422_intrabc_sb128_strip{,_notxsearch}`,
278+`422_residual_compound_warp{,_nolr}_16f`, `422_sb128_3f`, `440_request_is_422`,
279+`W_intrabc`, `X_intrabc_tiled`, `Y_intrabc_10b`) — unchanged, and out of scope
280+by the project's 4:2:2 decision.
281+
282+### 6.1 The recipe's already-closed cells
283+
284+| cell | measured with the fix, on this tip |
285+|---|---|
286+| `420_mixll_altref_256x128_5f.obu` (the pin) | **6/6 decode-order EXACT**; its gate green in the same run as the new one (§5.3); its 96997/96997 bit-identical ladder is not re-run here (see §8) — the fix adds no publish that this cell can observe, which the zero-row corpus diff and the re-measured 6/6 both show |
287+| 176x144 of the same recipe, regenerated and re-encoded here | **6/6 decode-order EXACT** (oracle 6 dumps, 0 differing bytes) |
288+| 352x288 of the same recipe, regenerated and re-encoded here | **6/6 decode-order EXACT** (oracle 6 dumps, 0 differing bytes) |
289+| the 4:4:4 arm | green; every `440_*` fixture in the §6 sweep is `EXACT` except the one by-name 4:2:2 refusal |
290+| `m_320x240`, `m5_320x240`, the 6-frame `m_256x128` residuals named by `lane-av1mixllconj` §7 | **not claimed closed, and not measured here** — they are generated cells, not committed fixtures, so the §6 sweep does not cover them and no number in this report speaks to them |
291+
292+## 7. Class sweep — `context-band-not-published`
293+
294+The class: **a decode body that returns with a coded block in hand and leaves
295+the `TXFM_CONTEXT` band holding a size the block itself should have published.**
296+Every arm that can return from the two `TXFM_CONTEXT`-publishing builders, and
297+every site the umbrella gate in `fill_lf_grid_rect_inner` delegates to, re-derived
298+against libaom's own `parse_decode_block` either/or. Verdicts are by
299+measurement or by construction, and say which:
300+
301+| # | site | verdict |
302+|---|---|---|
303+| 1 | `read_block_tx_size`, **lossless early return** | **WAS this defect. FIXED** — the 640x480 cell, §3–§5. |
304+| 2 | `read_block_tx_size`, `!tx_select_inter` early return (returns `(side, None)` / the 128 root's 64x64 grid) | **unobservable by construction.** It fires only when the frame's `tx_mode != TX_MODE_SELECT`, and BOTH band readers are gated on `tx_mode == TX_MODE_SELECT` in libaom: `read_selected_tx_size` is the only caller of `get_tx_size_context`, and `read_tx_size_vartx` is the only caller of `txfm_partition_context` (`decodeframe.c:1251`, `:1193`). Neither runs on such a frame, so the missing publish has no reader. Not fixed, deliberately — see §9. |
305+| 3 | `read_block_tx_size_rect`, lossless arm (`txfm_partition_update_rect(n, at_mi, (4,4), (bw,bh))`) | **A real libaom-fidelity gap of the same class that IS reached — and has NO observable effect anywhere I measured.** libaom's `set_txfm_ctxs` carries `mbmi->skip_txfm && is_inter_block(mbmi)`, and every caller of this function is an INTER or INTRABC rect block (`is_inter_block` true, `blockd.h:373`), so a SKIPPED lossless rect strip must publish `(bw, bh)` — the block size — where this arm publishes `(4, 4)`. The non-lossless `skip` arm of the SAME function two lines below already gets this right (`txfm_partition_update_rect(n, at_mi, (bw, bh), (bw, bh))`), which is what makes the lossless arm's asymmetry a defect and not a choice. Reached 29 / 1 / 9 / 6 / 16 times across five fixtures (§7.1) and correcting it changed **nothing** on any of them. Handed over, not shipped: with no red-before it is a fidelity edit, not a fix. |
306+| 4 | `decode_leaf8`'s `if allow_intrabc { set_txfm_ctxs(…) }` (both arms) | **not this class — cleared by measurement.** Instrumenting the `!allow_intrabc` entries: `420_lossless_arf_1to4_320x240_5f` has 140 and the new 640x480 cell 226, and **every one of them is on an INTRA-ONLY frame** (`intra_only=true`, zero on an inter frame) — where `fill_lf_grid`'s `intra_only` umbrella already publishes the same value at the same footprint. The inter-frame 8x8 INTRA leaf is not `decode_leaf8` at all: it is `read_block_tx_size`'s site, i.e. site 1. Left alone. |
307+| 5 | `fill_lf_grid_rect_inner`'s `publish_txfm_bands && intra_only` umbrella | **not a hole, the delegation itself** — on an inter frame each body must publish at its own site (that is exactly where sites 1 and 3 live). |
308+
309+### 7.1 Sites 3 and 4, measured
310+
311+Two temporary `EC_CLASS_SWEEP` rungs (one on `read_block_tx_size_rect`'s
312+lossless arm, one on `decode_leaf8`'s `!allow_intrabc` entry), run over all 110
313+committed fixtures and both new 640x480 cells, then removed:
314+
315+```text
316+fixture rect_lossless_skip leaf8_!intrabc (of which inter-frame)
317+420_lossless_arf_1to4_320x240_5f.obu 29 140 (0)
318+420_lossless_tallinter_8x16.obu 1 --
319+420_mixll_altref_256x128_5f.obu 9 --
320+420_mixll_altref_640x480_5f.obu 6 226 (0)
321+420_mixll_altref_640x480_6f.obu 16 --
322+```
323+
324+Then the `skip` term of the rect lossless arm was patched on (publish
325+`(bw, bh)` when `skip`, nothing else changed) and every fixture that reaches it
326+re-run against the oracle:
327+
328+```text
329+SITE3-PATCHED 420_lossless_arf_1to4_320x240_5f: oracle=6 diffbytes=0
330+SITE3-PATCHED 420_lossless_tallinter_8x16: oracle=24 diffbytes=0
331+SITE3-PATCHED 420_mixll_altref_256x128_5f: oracle=6 diffbytes=0
332+SITE3-PATCHED 420_mixll_altref_640x480_5f: oracle=6 diffbytes=0
333+SITE3-PATCHED 420_mixll_altref_640x480_6f: oracle=7 diffbytes=0
334+```
335+
336+**Site 3 is reached and correcting it is a no-op on every fixture that reaches
337+ it** — so the divergence has no reader in the whole measured corpus, and it is
338+ named and handed over rather than shipped without a red-before. The patch was
339+ reverted; `git diff --stat` for this lane is the publish + counter + accessor +
340+ gate and nothing else.
341+
342+## 8. What is NOT measured
343+
344+* **Site 3 (§7) is not fixed and not gated.** It is a divergence derived from
345+ libaom's `set_txfm_ctxs` argument and MEASURED to be reached (29/1/9/6/16 hits
346+ across five fixtures), and correcting it measured as a no-op on every one of
347+ them. What I did NOT do is build the cell that would make it red, so "no
348+ fixture has a reader for it" is a measurement over what exists, not a proof
349+ that no such cell exists.
350+* **The HBD arm of the class sweep is not synthesized.** No >8-bit y4m was
351+ produced here; the committed HBD fixtures are covered by the §6 regression,
352+ which is a regression, not a sweep of this class at 10/12-bit.
353+* **The 6-frame 640x480 cell has a committed fixture but no gate.** It is
354+ measured byte-exact (§5.1) and pinned by fnv1a64 in the report, but the gate
355+ only asserts the 5-frame cell; the 6-frame one is a corpus row, not a gate.
356+* **Content outside `testsrc2`.** The class is content- and partition-dependent;
357+ everything above is the one recipe at one size, plus the 110-fixture corpus as
358+ regression evidence.
359+* **No `EC_TXCTXCOL` / `EC_TXUPD` / `EC_TXCTX` diagnostic, the forced-`ctx`
360+ override, or any probe bypass is in the tree.** The two temporary rungs this
361+ lane added (the column walk and the lossless-early-return tag) were removed
362+ before the commit; the pre-existing `EC_TXUPD` / `EC_TXCTX` / `EC_TXGRID_TRACE`
363+ rungs were left exactly as found. The shared oracle was never rebuilt or
364+ edited.
365+
366+## 9. Fix-now | deferred(<unblock>) | accepted
367+
368+* **fix-now** — the one-call publish, its route counter and accessor, the two
369+ fixtures and the gate. Landed in this commit.
370+* **fix-now** — the class sweep (§7), because it is what found the site.
371+* **deferred(unblock: a cell where a SKIPPED inter rect strip sits on a LOSSLESS
372+ segment AND a lossy block later reads its column — the five fixtures that
373+ reach §7 site 3 have no such reader, which is why correcting it moved nothing
374+ — then the `skip` term lands)** — `read_block_tx_size_rect`'s lossless arm is a
375+ real `context-band-not-published` divergence against libaom, one line wide,
376+ deliberately not shipped without its red.
377+* **accepted** — §7 site 2's missing publish on a `tx_mode != TX_MODE_SELECT`
378+ frame. Unreachable by construction (both readers are gated on SELECT); closing
379+ it would add a write nothing reads.
380+* **accepted** — the §6 residuals `lane-av1mixllconj` §7 names on the 6-frame
381+ 256x128 and the 320x240 arms. Not this class, not measured here, not claimed.
382+
383+## 10. Scoped test command and output
384+
385+```text
386+CARGO_TARGET_DIR=$HOME/.cache/cargo-target-av1txctxband2 EC_NOMEMGUARD=1 \
387+ cargo test -p ec-av1 --lib -- a_420_mixed_lossless_alt_ref_640x480_txfm_band_publish \
388+ a_420_mixed_lossless_alt_ref_sub8_vartx
389+```
390+
391+```text
392+running 2 tests
393+test stream::tests::a_420_mixed_lossless_alt_ref_640x480_txfm_band_publish_is_byte_exact_in_decode_order ... ok
394+test stream::tests::a_420_mixed_lossless_alt_ref_sub8_vartx_witness_is_byte_exact_in_decode_order ... ok
395+test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 805 filtered out; finished in 2.06s
396+```
397+
398+The corpus sweep (§6) is the regression evidence for everything else: 110
399+fixtures swept before and after with **zero rows changing**.
400+
401+## 11. Hunk scope
402+
403+* Authored here: `crates/ec-av1/src/decode.rs` (the publish + counter + accessor),
404+ `crates/ec-av1/src/stream.rs` (the gate), two fixtures under
405+ `crates/ec-av1/fixtures/`, and this report.
406+* No line outside those hunks was touched. The primary checkout was never
407+ edited — one `edit` call leaked into it early and was reverted with
408+ `git checkout --` before any build; `git status --porcelain` there is clean.
409+* The shared oracle at `~/.cache/aom-oracle` was read only.