From 3bebc9d8794d5aba40c5d82257a2064d9596df53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sun, 30 Aug 2026 09:42:35 +0300 Subject: [PATCH] fix(av1): revert rect coeff decode to refuse-by-name -- desync found, not isolated lane-rectwire r3: pinned stream rectwire-flake-1.obu (seed 55) reproduces deterministically and shows a genuine desync in r2's real (non-skip) 32x16/16x32 coefficient decode (93.5% of frame-0 luma mismatches land inside the one HORZ-split quadrant, both strips ~100% wrong from their first pixel). r2's three named suspects (base_ctx_rect offsets, chroma skip-ctx formula, dc_sign_ctx index) all cross-checked byte-for-byte against real libaom source and cleared. Range-ladder bisection stalled on the intra key-frame path having no traced symbol between partition and first coefficient in the oracle; next round's first move is patching that into aomdec. Reverted decode_block_rect's non-skip branch to refuse by name (r1 behavior); RECT_COEFF_HITS gate assert downgraded back to a SOFT-NOTE. Free-partition gate green (29 refusals incl. 3 new named ones, 11 matches, 0 desyncs), full lib suite 231/0. --- crates/ec-av1/src/decode.rs | 23 ++++++++ crates/ec-av1/src/stream.rs | 22 +++---- lanes/rectwire-r3.report.md | 112 ++++++++++++++++++++++++++++++++++++ 3 files changed, 147 insertions(+), 10 deletions(-) create mode 100644 lanes/rectwire-r3.report.md diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index d43f2668..fd55b897 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -2095,6 +2095,28 @@ fn decode_block_rect( } else { (&SCAN_16X32, &SCAN_8X16) }; + // lane-rectwire r3: real coefficients desync a pixel-exact gate + // (rectwire-flake-1.obu, seed 55) -- both 32x16 strips of frame 0's + // mi(8,8) HORZ quadrant come out ~100% wrong from their very first + // pixel (not a subtle context-table off-by-one), while the sibling + // non-rect quadrants of the same frame match. Range-ladder bisection + // against a real aomdec (EC_TRACE_COEFF/EC_TRACE_MODE) was started + // but the intra key-frame path has no traced symbol between the + // partition read and the first coefficient block (mode/skip/tx_depth + // reads are all untraced in libaom's decodeframe.c intra path, unlike + // the inter EC_TRACE_MODE this round added), so a same-length range + // comparison wasn't reachable within budget -- see + // lanes/rectwire-r3.report.md for what was ruled out (base_ctx_rect's + // 5-neighbour offsets, u/v_skip_ctx's above+left formula, and + // dc_sign_ctx's around-index all cross-checked byte-for-byte against + // libaom and match). Refusing by name again (r1 behavior) rather than + // risk landing the desync. + return Err(unsupported( + "a HORZ/VERT intra strip with real (non-skip) coefficients \ + (lane-rectwire r3: confirmed desync, not yet isolated)", + )); + #[allow(unreachable_code)] + { let around = neighbours.around_rect(at, bw, bh); let mut luma_coding = cdfs.txb(TxbSet::LumaRect32x16, mode); let (luma_levels, luma_tx_type) = read_coeffs_rect( @@ -2196,6 +2218,7 @@ fn decode_block_rect( ); neighbours.record_rect(at, bw, bh, mode, &[luma_levels, u_levels, v_levels]); RECT_COEFF_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); + } } neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, skip); neighbours.fill_lf_grid_rect((mi_r, mi_c), bw / MI, bh / MI, tx_w as u8, tx_h as u8, 0); diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index fc85b174..9c15b66e 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -4191,16 +4191,18 @@ mod tests { "{NAME}: SOFT-NOTE -- zero HORZ/VERT strips fired this run \ ({matched} matches, {named_refusals} refusals); sampling, not a regression" ); - } else { - // lane-rectwire r2: once a run fires any HORZ/VERT strip at all, - // real coefficient decode (not just the skip case) must also - // fire -- a rect_partition_hits>0, rect_coeff_hits==0 run would - // mean every fired strip happened to be skip, which the encoder - // recipe's rate target does not produce in practice. - assert!( - crate::decode::rect_coeff_hits() > 0, - "{NAME}: {} HORZ/VERT strips fired but zero coded real coefficients \ - (rect_coeff_hits==0) -- the rect coefficient reader is unexercised", + } else if crate::decode::rect_coeff_hits() == 0 { + // lane-rectwire r3: r2's real (non-skip) coefficient decode + // desyncs (rectwire-flake-1.obu, seed 55 -- both 32x16 strips of + // a fired quadrant come out ~100% wrong from their first pixel; + // see lanes/rectwire-r3.report.md). Reverted to refusing a coded + // rect strip by name, same as r1, so `rect_coeff_hits` is always + // 0 now -- this used to be a hard assert (r2), downgraded back to + // a SOFT-NOTE until the desync is isolated and the real decode + // path is safe to re-enable. + eprintln!( + "{NAME}: SOFT-NOTE -- {} HORZ/VERT strips fired but rect_coeff_hits==0 \ + (r3: non-skip rect strips refuse by name pending the desync fix)", crate::decode::rect_partition_hits() ); } diff --git a/lanes/rectwire-r3.report.md b/lanes/rectwire-r3.report.md new file mode 100644 index 00000000..c9008c25 --- /dev/null +++ b/lanes/rectwire-r3.report.md @@ -0,0 +1,112 @@ +# lane-rectwire round 3 + +VERDICT: reverted r2's real (non-skip) rect coefficient decode to refuse by +name -- the pixel-exact gate found a genuine desync (not a subtle context +bug), and this round's budget was exhausted before isolating its exact +symbol. No desync landed. Free-partition gate green, full lib suite +231/0. + +## What was confirmed a defect, and where it isn't + +`/tmp/claude-1000/rectwire-flake-1.obu` (seed 55, 64x64x24) reproduces +byte-identically from the pinned bytes across two runs (`scratch_decode_ +pinned_stream_once`, `OK: 24 frames` both times) -- this is a real decode +bug, not attempt-selection flake. + +`scratch_isolate_pinned_mismatch` on that stream: frame 0 luma has 1085/4096 +mismatches. The *first* one (row 28, col 31, delta 1) sits inside the +top-left 32x32 `PARTITION_NONE` intra block -- **not** a rect strip at all +(charter's step-3 question answered: no). But a quadrant breakdown shows +1015 of the 1085 luma mismatches (93.5%) land inside the one rect quadrant +this frame has: `mi(8,8)` reads `PARTITION_HORZ` (`TRACE partition_w32 +mi=(8,8) ctx=0 value=1`), splitting the bottom-right 32x32 into two true +32x16 strips. Sub-bucketing that quadrant: strip 0 (rows 32..48) is 503/512 +wrong, strip 1 (rows 48..64) is 512/512 wrong, both starting at their very +first pixel (strip 1's first pixel is 105 vs 72 -- a 33-level jump, not a +rounding-scale error). That magnitude and near-total coverage is a real +desync inside the rect coefficient path, not a context-table nudge; the +handful of TL/BL-quadrant mismatches are plausibly a small halo from +whatever downstream state the corrupted BR quadrant leaves (not itself +implicated). + +## Three suspects r2 named -- all checked and cleared, cross-referenced +against real libaom source this round, not memory: + +1. **`base_ctx_rect`'s 5-neighbour `TwoD` offset array.** Checked against + `get_nz_map_ctx_from_stats` / the `av1_nz_map_ctx_offset` comment in + `~/.cache/aom-oracle/src/av1/common/txb_common.h:189-224`: the 5 offsets + `(1,0),(0,1),(1,1),(2,0),(0,2)`, the `wh`/`col<2`→`+16` boundary branches, and the tx-size-independent + `row+col` fallback (verified `cdf::NZ_MAP_CTX_OFFSET_32` already encodes + exactly `row+col<2→1, row+col<4→6, else→21`) all match libaom + byte-for-byte. Not the bug. +2. **`u_skip_ctx`/`v_skip_ctx`'s `above + left` formula.** libaom's real + chroma rule (`get_txb_ctx_general`, same file, plane != 0 branch) is + `get_entropy_context(tx_size,a,l) + ctx_offset` where `ctx_offset` is 7 + for a lone TU (`plane_bsize == tx bsize`, our case) or 10 otherwise, and + `get_entropy_context` returns exactly `(above coded?)+(left coded?)` -- + i.e. the *same* 0..2 range our code computes. Cross-checked against the + **existing, tested** square `Chroma16` path (`read_plane`, + `decode.rs:2707`): it uses the identical `usize::from(around.0) + + usize::from(around.1)` formula with no `+7`, meaning the `txb_skip_ + chroma_16` default-CDF table was already transcribed with the `+7` + pre-baked into which 3 rows were picked -- consistent, not the bug. +3. **`dc_sign_ctx` reading the wrong `around` index.** `decode_block_rect` + indexes `around[0]` for luma, `around[1]` for u, `around[2]` for v -- + same convention the square path's `chroma_around[1]`/`[2]` uses. Not the + bug. + +Also checked `around_rect`/`record_rect`'s luma-mi-granularity span for +chroma (looked like a subsampling bug at first glance): both the write side +(`record_mi_rect`) and read side (`around_mi_rect`) use the same un-halved +`w_mi`/`h_mi` for all three planes, matching the square path's own +`around`/`record` convention exactly. Not a bug either. + +## Where the range-ladder bisection stalled + +Built the requested instrument check first: `~/.cache/aom-oracle/build/ +aomdec` with `EC_TRACE_COEFF=1`/`EC_TRACE_MODE=1` emits real per-block +`rng` -- confirmed live (`EC_PART`/`EC_COEFF`/`EC_MODE` all firing on this +stream). But the intra key-frame path in libaom's `decodeframe.c` has no +traced symbol between the partition read and the first `EC_COEFF` (mode/ +skip/tx_depth reads for an *intra* block are only traced by the new +`EC_TRACE_MODE` patch on the *inter* decodemv.c path, not here), so +`aomdec`'s post-partition `rng` and our own decoder's `rng` at coefficient +entry aren't directly comparable -- several untraced symbol reads (skip, +y_mode, uv_mode, tx_size_cat2 in `read_intra_mode_rect`) sit between them on +our side with no anchor on aomdec's. Extending `EC_TRACE_MODE`-style tracing +into libaom's intra mode-info reader (a second oracle patch) is the next +lane's first move, not attempted this round (budget). + +## The revert + +`decode.rs::decode_block_rect`'s non-skip branch now returns `Err(unsupported( +"a HORZ/VERT intra strip with real (non-skip) coefficients ..."))` before +any of r2's real-decode code runs (that code stays in the file, dead behind +the early return, so the next round doesn't re-derive it). The free-partition +gate's `RECT_COEFF_HITS` hard assert (r2) is downgraded back to a SOFT-NOTE +(`rect_coeff_hits` is now always 0 by construction) -- matches r1's original +posture. + +## Before/after refusal + firing counts + +This round, one gate run (`EC_AV1_REQUIRE_AOMENC=1`, n=40, seed 42+i): +- 29 named refusals, 11 pixel-exact matches, 0 mismatches (gate green). +- `rect_partition_hits=9` (real HORZ/VERT strips reached), `rect_coeff_hits=0` + (by construction now), `extended_partition_hits=0`, `partab_hits=2`. +- 3 of the 29 refusals are the new named one: "a HORZ/VERT intra strip with + real (non-skip) coefficients (lane-rectwire r3: confirmed desync, not yet + isolated)" (seeds 63, 67, 81) -- these are exactly the runs that would + previously have risked the r2 desync; they refuse cleanly now instead. + +Full `cargo test -p ec-av1 --release --lib`: 231 passed, 0 failed, 17 ignored. + +## Next round's first move + +Patch `~/.cache/aom-oracle`'s `decodeframe.c` intra mode-info reader +(`read_intra_frame_mode_info` or equivalent) with the same `rng`-emitting +pattern `EC_TRACE_MODE` already added for inter, so a same-length range +ladder can walk from the `mi(8,8)` `PARTITION_HORZ` read through skip/ +y_mode/uv_mode/tx_depth into the first `EC_COEFF` and find the exact +diverging symbol, rather than guessing between the coefficient-context +math (now cleared) and the prediction/transform math (untested this round).