Revert rect coeff decode to refuse-by-name -- desync found, not isolated
Browse files at this commit3bebc9d8794d5aba40c5d82257a2064d9596df53Parent: a27a535- fix
- revert rect coeff decode to refuse-by-name -- desync found, not isolated
3 changed files +147 -10
- crates/ec-av1/src/decode.rs +23 -0
- crates/ec-av1/src/stream.rs +12 -10
- lanes/rectwire-r3.report.md +112 -0
crates/ec-av1/src/decode.rsmodified+23 -0
| @@ -2095,6 +2095,28 @@ fn decode_block_rect( | ||
| 2095 | 2095 | } else { |
| 2096 | 2096 | (&SCAN_16X32, &SCAN_8X16) |
| 2097 | 2097 | }; |
| 2098 | + // lane-rectwire r3: real coefficients desync a pixel-exact gate | |
| 2099 | + // (rectwire-flake-1.obu, seed 55) -- both 32x16 strips of frame 0's | |
| 2100 | + // mi(8,8) HORZ quadrant come out ~100% wrong from their very first | |
| 2101 | + // pixel (not a subtle context-table off-by-one), while the sibling | |
| 2102 | + // non-rect quadrants of the same frame match. Range-ladder bisection | |
| 2103 | + // against a real aomdec (EC_TRACE_COEFF/EC_TRACE_MODE) was started | |
| 2104 | + // but the intra key-frame path has no traced symbol between the | |
| 2105 | + // partition read and the first coefficient block (mode/skip/tx_depth | |
| 2106 | + // reads are all untraced in libaom's decodeframe.c intra path, unlike | |
| 2107 | + // the inter EC_TRACE_MODE this round added), so a same-length range | |
| 2108 | + // comparison wasn't reachable within budget -- see | |
| 2109 | + // lanes/rectwire-r3.report.md for what was ruled out (base_ctx_rect's | |
| 2110 | + // 5-neighbour offsets, u/v_skip_ctx's above+left formula, and | |
| 2111 | + // dc_sign_ctx's around-index all cross-checked byte-for-byte against | |
| 2112 | + // libaom and match). Refusing by name again (r1 behavior) rather than | |
| 2113 | + // risk landing the desync. | |
| 2114 | + return Err(unsupported( | |
| 2115 | + "a HORZ/VERT intra strip with real (non-skip) coefficients \ | |
| 2116 | + (lane-rectwire r3: confirmed desync, not yet isolated)", | |
| 2117 | + )); | |
| 2118 | + #[allow(unreachable_code)] | |
| 2119 | + { | |
| 2098 | 2120 | let around = neighbours.around_rect(at, bw, bh); |
| 2099 | 2121 | let mut luma_coding = cdfs.txb(TxbSet::LumaRect32x16, mode); |
| 2100 | 2122 | let (luma_levels, luma_tx_type) = read_coeffs_rect( |
| @@ -2196,6 +2218,7 @@ fn decode_block_rect( | ||
| 2196 | 2218 | ); |
| 2197 | 2219 | neighbours.record_rect(at, bw, bh, mode, &[luma_levels, u_levels, v_levels]); |
| 2198 | 2220 | RECT_COEFF_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); |
| 2221 | + } | |
| 2199 | 2222 | } |
| 2200 | 2223 | neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, skip); |
| 2201 | 2224 | neighbours.fill_lf_grid_rect((mi_r, mi_c), bw / MI, bh / MI, tx_w as u8, tx_h as u8, 0); |
crates/ec-av1/src/stream.rsmodified+12 -10
| @@ -4191,16 +4191,18 @@ mod tests { | ||
| 4191 | 4191 | "{NAME}: SOFT-NOTE -- zero HORZ/VERT strips fired this run \ |
| 4192 | 4192 | ({matched} matches, {named_refusals} refusals); sampling, not a regression" |
| 4193 | 4193 | ); |
| 4194 | - } else { | |
| 4195 | - // lane-rectwire r2: once a run fires any HORZ/VERT strip at all, | |
| 4196 | - // real coefficient decode (not just the skip case) must also | |
| 4197 | - // fire -- a rect_partition_hits>0, rect_coeff_hits==0 run would | |
| 4198 | - // mean every fired strip happened to be skip, which the encoder | |
| 4199 | - // recipe's rate target does not produce in practice. | |
| 4200 | - assert!( | |
| 4201 | - crate::decode::rect_coeff_hits() > 0, | |
| 4202 | - "{NAME}: {} HORZ/VERT strips fired but zero coded real coefficients \ | |
| 4203 | - (rect_coeff_hits==0) -- the rect coefficient reader is unexercised", | |
| 4194 | + } else if crate::decode::rect_coeff_hits() == 0 { | |
| 4195 | + // lane-rectwire r3: r2's real (non-skip) coefficient decode | |
| 4196 | + // desyncs (rectwire-flake-1.obu, seed 55 -- both 32x16 strips of | |
| 4197 | + // a fired quadrant come out ~100% wrong from their first pixel; | |
| 4198 | + // see lanes/rectwire-r3.report.md). Reverted to refusing a coded | |
| 4199 | + // rect strip by name, same as r1, so `rect_coeff_hits` is always | |
| 4200 | + // 0 now -- this used to be a hard assert (r2), downgraded back to | |
| 4201 | + // a SOFT-NOTE until the desync is isolated and the real decode | |
| 4202 | + // path is safe to re-enable. | |
| 4203 | + eprintln!( | |
| 4204 | + "{NAME}: SOFT-NOTE -- {} HORZ/VERT strips fired but rect_coeff_hits==0 \ | |
| 4205 | + (r3: non-skip rect strips refuse by name pending the desync fix)", | |
| 4204 | 4206 | crate::decode::rect_partition_hits() |
| 4205 | 4207 | ); |
| 4206 | 4208 | } |
lanes/rectwire-r3.report.mdadded+112 -0
| @@ -0,0 +1,112 @@ | ||
| 1 | +# lane-rectwire round 3 | |
| 2 | + | |
| 3 | +VERDICT: reverted r2's real (non-skip) rect coefficient decode to refuse by | |
| 4 | +name -- the pixel-exact gate found a genuine desync (not a subtle context | |
| 5 | +bug), and this round's budget was exhausted before isolating its exact | |
| 6 | +symbol. No desync landed. Free-partition gate green, full lib suite | |
| 7 | +231/0. | |
| 8 | + | |
| 9 | +## What was confirmed a defect, and where it isn't | |
| 10 | + | |
| 11 | +`/tmp/claude-1000/rectwire-flake-1.obu` (seed 55, 64x64x24) reproduces | |
| 12 | +byte-identically from the pinned bytes across two runs (`scratch_decode_ | |
| 13 | +pinned_stream_once`, `OK: 24 frames` both times) -- this is a real decode | |
| 14 | +bug, not attempt-selection flake. | |
| 15 | + | |
| 16 | +`scratch_isolate_pinned_mismatch` on that stream: frame 0 luma has 1085/4096 | |
| 17 | +mismatches. The *first* one (row 28, col 31, delta 1) sits inside the | |
| 18 | +top-left 32x32 `PARTITION_NONE` intra block -- **not** a rect strip at all | |
| 19 | +(charter's step-3 question answered: no). But a quadrant breakdown shows | |
| 20 | +1015 of the 1085 luma mismatches (93.5%) land inside the one rect quadrant | |
| 21 | +this frame has: `mi(8,8)` reads `PARTITION_HORZ` (`TRACE partition_w32 | |
| 22 | +mi=(8,8) ctx=0 value=1`), splitting the bottom-right 32x32 into two true | |
| 23 | +32x16 strips. Sub-bucketing that quadrant: strip 0 (rows 32..48) is 503/512 | |
| 24 | +wrong, strip 1 (rows 48..64) is 512/512 wrong, both starting at their very | |
| 25 | +first pixel (strip 1's first pixel is 105 vs 72 -- a 33-level jump, not a | |
| 26 | +rounding-scale error). That magnitude and near-total coverage is a real | |
| 27 | +desync inside the rect coefficient path, not a context-table nudge; the | |
| 28 | +handful of TL/BL-quadrant mismatches are plausibly a small halo from | |
| 29 | +whatever downstream state the corrupted BR quadrant leaves (not itself | |
| 30 | +implicated). | |
| 31 | + | |
| 32 | +## Three suspects r2 named -- all checked and cleared, cross-referenced | |
| 33 | +against real libaom source this round, not memory: | |
| 34 | + | |
| 35 | +1. **`base_ctx_rect`'s 5-neighbour `TwoD` offset array.** Checked against | |
| 36 | + `get_nz_map_ctx_from_stats` / the `av1_nz_map_ctx_offset` comment in | |
| 37 | + `~/.cache/aom-oracle/src/av1/common/txb_common.h:189-224`: the 5 offsets | |
| 38 | + `(1,0),(0,1),(1,1),(2,0),(0,2)`, the `w<h`/`row<2`→`+11` and | |
| 39 | + `w>h`/`col<2`→`+16` boundary branches, and the tx-size-independent | |
| 40 | + `row+col` fallback (verified `cdf::NZ_MAP_CTX_OFFSET_32` already encodes | |
| 41 | + exactly `row+col<2→1, row+col<4→6, else→21`) all match libaom | |
| 42 | + byte-for-byte. Not the bug. | |
| 43 | +2. **`u_skip_ctx`/`v_skip_ctx`'s `above + left` formula.** libaom's real | |
| 44 | + chroma rule (`get_txb_ctx_general`, same file, plane != 0 branch) is | |
| 45 | + `get_entropy_context(tx_size,a,l) + ctx_offset` where `ctx_offset` is 7 | |
| 46 | + for a lone TU (`plane_bsize == tx bsize`, our case) or 10 otherwise, and | |
| 47 | + `get_entropy_context` returns exactly `(above coded?)+(left coded?)` -- | |
| 48 | + i.e. the *same* 0..2 range our code computes. Cross-checked against the | |
| 49 | + **existing, tested** square `Chroma16` path (`read_plane`, | |
| 50 | + `decode.rs:2707`): it uses the identical `usize::from(around.0) + | |
| 51 | + usize::from(around.1)` formula with no `+7`, meaning the `txb_skip_ | |
| 52 | + chroma_16` default-CDF table was already transcribed with the `+7` | |
| 53 | + pre-baked into which 3 rows were picked -- consistent, not the bug. | |
| 54 | +3. **`dc_sign_ctx` reading the wrong `around` index.** `decode_block_rect` | |
| 55 | + indexes `around[0]` for luma, `around[1]` for u, `around[2]` for v -- | |
| 56 | + same convention the square path's `chroma_around[1]`/`[2]` uses. Not the | |
| 57 | + bug. | |
| 58 | + | |
| 59 | +Also checked `around_rect`/`record_rect`'s luma-mi-granularity span for | |
| 60 | +chroma (looked like a subsampling bug at first glance): both the write side | |
| 61 | +(`record_mi_rect`) and read side (`around_mi_rect`) use the same un-halved | |
| 62 | +`w_mi`/`h_mi` for all three planes, matching the square path's own | |
| 63 | +`around`/`record` convention exactly. Not a bug either. | |
| 64 | + | |
| 65 | +## Where the range-ladder bisection stalled | |
| 66 | + | |
| 67 | +Built the requested instrument check first: `~/.cache/aom-oracle/build/ | |
| 68 | +aomdec` with `EC_TRACE_COEFF=1`/`EC_TRACE_MODE=1` emits real per-block | |
| 69 | +`rng` -- confirmed live (`EC_PART`/`EC_COEFF`/`EC_MODE` all firing on this | |
| 70 | +stream). But the intra key-frame path in libaom's `decodeframe.c` has no | |
| 71 | +traced symbol between the partition read and the first `EC_COEFF` (mode/ | |
| 72 | +skip/tx_depth reads for an *intra* block are only traced by the new | |
| 73 | +`EC_TRACE_MODE` patch on the *inter* decodemv.c path, not here), so | |
| 74 | +`aomdec`'s post-partition `rng` and our own decoder's `rng` at coefficient | |
| 75 | +entry aren't directly comparable -- several untraced symbol reads (skip, | |
| 76 | +y_mode, uv_mode, tx_size_cat2 in `read_intra_mode_rect`) sit between them on | |
| 77 | +our side with no anchor on aomdec's. Extending `EC_TRACE_MODE`-style tracing | |
| 78 | +into libaom's intra mode-info reader (a second oracle patch) is the next | |
| 79 | +lane's first move, not attempted this round (budget). | |
| 80 | + | |
| 81 | +## The revert | |
| 82 | + | |
| 83 | +`decode.rs::decode_block_rect`'s non-skip branch now returns `Err(unsupported( | |
| 84 | +"a HORZ/VERT intra strip with real (non-skip) coefficients ..."))` before | |
| 85 | +any of r2's real-decode code runs (that code stays in the file, dead behind | |
| 86 | +the early return, so the next round doesn't re-derive it). The free-partition | |
| 87 | +gate's `RECT_COEFF_HITS` hard assert (r2) is downgraded back to a SOFT-NOTE | |
| 88 | +(`rect_coeff_hits` is now always 0 by construction) -- matches r1's original | |
| 89 | +posture. | |
| 90 | + | |
| 91 | +## Before/after refusal + firing counts | |
| 92 | + | |
| 93 | +This round, one gate run (`EC_AV1_REQUIRE_AOMENC=1`, n=40, seed 42+i): | |
| 94 | +- 29 named refusals, 11 pixel-exact matches, 0 mismatches (gate green). | |
| 95 | +- `rect_partition_hits=9` (real HORZ/VERT strips reached), `rect_coeff_hits=0` | |
| 96 | + (by construction now), `extended_partition_hits=0`, `partab_hits=2`. | |
| 97 | +- 3 of the 29 refusals are the new named one: "a HORZ/VERT intra strip with | |
| 98 | + real (non-skip) coefficients (lane-rectwire r3: confirmed desync, not yet | |
| 99 | + isolated)" (seeds 63, 67, 81) -- these are exactly the runs that would | |
| 100 | + previously have risked the r2 desync; they refuse cleanly now instead. | |
| 101 | + | |
| 102 | +Full `cargo test -p ec-av1 --release --lib`: 231 passed, 0 failed, 17 ignored. | |
| 103 | + | |
| 104 | +## Next round's first move | |
| 105 | + | |
| 106 | +Patch `~/.cache/aom-oracle`'s `decodeframe.c` intra mode-info reader | |
| 107 | +(`read_intra_frame_mode_info` or equivalent) with the same `rng`-emitting | |
| 108 | +pattern `EC_TRACE_MODE` already added for inter, so a same-length range | |
| 109 | +ladder can walk from the `mi(8,8)` `PARTITION_HORZ` read through skip/ | |
| 110 | +y_mode/uv_mode/tx_depth into the first `EC_COEFF` and find the exact | |
| 111 | +diverging symbol, rather than guessing between the coefficient-context | |
| 112 | +math (now cleared) and the prediction/transform math (untested this round). |