diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 88070864..efdf16f3 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -21117,8 +21117,25 @@ pub(crate) fn cfl_scaled(alpha_q3: i32, ac_q3: i32) -> i32 { /// lane-tiny r4: raw padded-plane dump for filter-stage bisection, written /// only when `var` names a path. Same byte shape as `EC_AV1_PREFILT_DUMP`. /// lane-hgkf r2: 16-bit cropped stage dump, the high-bitdepth twin of -/// [`dump_stage`] (whose `as u8` truncation hides |delta| <= 2 defects) -- -/// matches aomdec's own `ec_dump16` rung byte for byte (crop dims, u16 LE). +/// [`dump_stage`] (whose `as u8` truncation hides |delta| <= 2 defects). +/// lane-unwritten-dep: this doc previously said the dump "matches aomdec's own +/// `ec_dump16` rung byte for byte (crop dims, u16 LE)", which was true only of +/// the 4:2:0 crop it then used. The crop is now PER-AXIS, which is what the +/// oracle's rung 1 actually does -- it writes `y_crop_width` x `y_crop_height`, +/// `uv_crop_width` x `uv_crop_height`, `uv_crop_width` x `uv_crop_height` (the +/// libaom `YV12_BUFFER_CONFIG` fields, each already per-axis). Byte shape per +/// subsampling, `fw x fh` luma then both chroma planes, u16 LE, so: +/// +/// ```text +/// ss_x ss_y format luma chroma (each) +/// 0 0 4:4:4 fw x fh fw x fh fw*fh*3 samples +/// 1 1 4:2:0 fw x fh fw/2 x fh/2 fw*fh*3/2 samples +/// 1 0 4:2:2 fw x fh fw/2 x fh fw*fh*2 samples +/// 0 1 4:4:0 fw x fh fw x fh/2 fw*fh*3/2 samples +/// ``` +/// +/// (`round_ss` is the rounding the decoder's own plane extents use; at ss = 1 it +/// is `div_ceil(2)`, so every 4:2:0 dump is byte-for-byte unchanged by this.) /// lane-mc64 r1: the decode-order index the stage dumps below key their file /// name on. `PREFILT_PICTURE_IDX` is bumped once per frame just BEFORE the /// deblock/CDEF stages run, so the frame being dumped here is `idx - 1` -- @@ -21138,19 +21155,38 @@ fn dump_stage16( v: &PlaneBuf<'_>, fw: usize, fh: usize, + ss_x: usize, + ss_y: usize, ) { use std::io::Write; // lane-sbrect10 r2 / lane-cdef r1 (one shared helper): index the dump by // decode-order picture like EC_AV1_PREFILT_DUMP already does -- a fixed // `.f0` name kept only the LAST frame, so a mid-sequence divergence could - // not be read out at all. + // not be read at all. + // + // lane-unwritten-dep: the chroma extent is PER-AXIS subsampling, not + // `div_ceil(2)` on both. The hardcoded pair was a 4:2:0 assumption and it + // was load-bearing: on a 64x64 4:2:2 frame (ss_x = 1, ss_y = 0) it wrote + // 32x32 chroma per plane where the frame carries 32x64, so HALF of each + // chroma plane appeared in NO stage dump at all. A stage bisect that reads + // "identical pre-deblock, differs post-deblock" off these dumps is then + // measuring the dump's blind spot, not the pipeline's: the samples it could + // not see are exactly the region where the 4:2:2 witness's output diverges + // (chroma rows 32..63 -- the old `fh.div_ceil(2)` crop wrote 32 of 64 rows, + // so everything from row 32 up was invisible; 2048 samples). `round_ss` is + // the same rounding the + // decoder's own plane extents use, and it matches the oracle's + // `uv_crop_width` / `uv_crop_height` per axis. + // ONE file per frame: `dump_stage_idx` advances on every call, so creating + // the file inside the plane loop would write three files per frame and + // shift every later frame's index. if let Ok(path) = crate::envflags::var(var) && let Ok(mut f) = std::fs::File::create(format!("{path}.f{}", dump_stage_idx(var))) { for (p, w, h) in [ (y, fw, fh), - (u, fw.div_ceil(2), fh.div_ceil(2)), - (v, fw.div_ceil(2), fh.div_ceil(2)), + (u, round_ss(fw, ss_x), round_ss(fh, ss_y)), + (v, round_ss(fw, ss_x), round_ss(fh, ss_y)), ] { for row in 0..h { let mut bytes = Vec::with_capacity(w * 2); @@ -21618,25 +21654,163 @@ fn refuse_invalid_plane_block(_bw: usize, _bh: usize, _fctx: &crate::decode::Fra /// the output does not depend on the plane buffer's initial content. const PLANE_SENTINEL: u16 = 0xDEAD; +/// lane-unwritten-dep: the census count at the LAST point of the pipeline, on the +/// exact bytes `EC_AV1_FINAL_DUMP` writes. +/// +/// WHY A SECOND COUNT, and what it is actually for -- the justification this +/// comment originally carried was WRONG and is corrected here, because a reader +/// would otherwise re-derive the wrong conclusion. An earlier revision of this +/// lane claimed the pre-deblock plane was byte-identical plain-vs-sentinel and +/// that "deblock creates the dependence". That reading came from +/// [`dump_stage16`], which cropped chroma as `(fw/2, fh/2)` -- a 4:2:0 +/// assumption. On a 64x64 4:2:2 frame (ss_x=1, ss_y=0) that wrote 32x32 chroma +/// where the frame carries 32x64, so 2048 chroma samples appeared in NO stage +/// dump, and they are exactly the region where the difference lives. +/// +/// With per-axis extents the corrected measurement on `440_request_is_422` is: +/// the PRE-DEBLOCK dump already DIFFERS by 2158 bytes plain-vs-sentinel, and an +/// exact u16 whole-plane census finds 224 unwritten samples (U 112, V 112, +/// rows 36..63, whole 4x4 groups) -- the same number +/// `lanes/av1unwritten.report.md` reports. **The hole is present before any +/// filter runs, and the pre-deblock census sees it.** This comment previously +/// said the opposite; that was the instrument's blind spot read as a property of +/// the pipeline. +/// +/// So what this second count is FOR, stated honestly: it is not there because the +/// pre-deblock census misses holes. It is there because it is the measurement +/// taken where the OUTPUT is taken -- the bytes stored into the reference slots +/// and handed to the caller. A hole can be created after reconstruction (a +/// filter stage, a superres step, a second pass) and be invisible to a scan taken +/// before it; this one cannot. It is a check on the whole span from the tile walk +/// to the caller's frame, not a claim that the pre-deblock scan is insufficient. +static FINAL_UNWRITTEN_SAMPLES: std::sync::atomic::AtomicUsize = + std::sync::atomic::AtomicUsize::new(0); + +/// Samples [`census_unwritten_final`] has looked at since the last +/// [`take_final_census_scanned`]. A gate that only asserts +/// [`take_final_unwritten_samples`] == 0 passes on a build whose census call was +/// deleted, so it reads THIS too -- the same pairing +/// [`CENSUS_SCANNED`] documents for the pre-deblock census. +static FINAL_CENSUS_SCANNED: std::sync::atomic::AtomicUsize = + std::sync::atomic::AtomicUsize::new(0); + +/// lane-unwritten-dep: reads and clears [`FINAL_UNWRITTEN_SAMPLES`] -- unwritten +/// samples still present in the frame as handed to the caller, summed over every +/// frame and plane. Process-global, like the pre-deblock census's counter, so a +/// gate can read it after the decode from a different thread than the one that +/// scanned. +pub fn take_final_unwritten_samples() -> usize { + FINAL_UNWRITTEN_SAMPLES.swap(0, std::sync::atomic::Ordering::SeqCst) +} + +/// Reads and clears [`FINAL_CENSUS_SCANNED`]; the pairing is the reason it +/// exists, exactly as for [`take_census_scanned`]. +pub fn take_final_census_scanned() -> usize { + FINAL_CENSUS_SCANNED.swap(0, std::sync::atomic::Ordering::SeqCst) +} + +/// lane-unwritten-dep: the census at the pipeline's last point. Counts, over each +/// plane, how many samples still hold [`PLANE_SENTINEL`] once every filter has +/// run, and records how many samples it LOOKED at in [`FINAL_CENSUS_SCANNED`]. +/// +/// Gated on [`plane_sentinel_on`] -- the SAME predicate as [`fresh_plane`] and as +/// the pre-deblock [`census_unwritten`]: the env flag OR the thread-local +/// [`set_plane_sentinel`] override. An earlier revision gated this on the raw env +/// var alone, which made the census silently inert for any in-process test using +/// the thread-local switch that the rest of the crate honours. The fill and both +/// censuses must agree on when they are live, or a "0" means nothing. +pub(crate) fn census_unwritten_final(y: &[u16], u: &[u16], v: &[u16]) { + if !plane_sentinel_on() { + return; + } + // The caller passes the frame's planes exactly as they are about to be + // stored into the reference slots, which are already cropped to the true + // extent (no padding past it reaches this point), so a flat count over + // each plane IS the true-extent count. + let (scanned, total): (usize, usize) = [y, u, v] + .iter() + .map(|p| (p.len(), p.iter().filter(|&&s| s == PLANE_SENTINEL).count())) + .fold((0, 0), |(a, b), (c, d)| (a + c, b + d)); + FINAL_CENSUS_SCANNED.fetch_add(scanned, std::sync::atomic::Ordering::SeqCst); + FINAL_UNWRITTEN_SAMPLES.fetch_add(total, std::sync::atomic::Ordering::SeqCst); +} + /// A frame plane's own backing store, `n` samples, UNINITIALISED. /// -/// (lane-picalloc) The SB-padded coding surface is written sample-for-sample -/// by the tile walk's reconstruction before anything reads it, so the -/// `vec![0u16; n]` this replaces spent ~3% of the frame thread's cycles -/// zeroing 25 MB (at 4K) that the very next pass overwrites -- serially, at -/// the frame's head, on the critical path. `EC_AV1_PLANE_SENTINEL=1` swaps the -/// uninitialised buffer for a [`PLANE_SENTINEL`] fill; the gate hashes both -/// ways (see the lane report) and the two agree, which is the proof that no -/// unwritten sample reaches the output. +/// (lane-picalloc) Replaced a `vec![0u16; n]` that zeroed the whole plane +/// buffer: ~3% of the frame thread's cycles at 4K, serially at the frame's head, +/// to initialise 25 MB the next pass overwrites. +/// +/// # THE `unsafe` BELOW IS NOT FULLY JUSTIFIED -- read this before approving it +/// +/// This comment previously claimed the SB-padded surface "is written +/// sample-for-sample by the tile walk's reconstruction before anything reads +/// it", and cited the sentinel gate as proof. **That claim is RETRACTED by +/// measurement.** The basis for the retraction is THIS LANE's own, not +/// second-hand: on `440_request_is_422` an exact u16 whole-plane census at the +/// pre-deblock point finds **112 unwritten samples per chroma plane, 224 total** +/// (U and V, 28 whole 4x4 groups each, rows 36..63) in a frame that is SHOWN +/// (`Key show=true`) and whose samples the caller receives. Uninitialised memory +/// that reaches the caller was read, or the read that produced it was. That is +/// the UB, and it needs no hash-variation claim to stand. +/// +/// A hash-variation observation also exists -- five plain runs of the same +/// witness giving two different output hashes (`lanes/av1unwritten.report.md`), +/// which would point the same way -- but it is SECOND-HAND and was NOT +/// reproduced here: five plain runs on `8d6998d7` gave one hash +/// (`a761118c8dd5c8d0`, `lanes/unwritten-dep.report.md` §10). It is not relied +/// on, and the ambient content a run happens to receive is machine-dependent, +/// so a stable value on one host and a varying one on another would be the same +/// defect either way. The 224-sample census is the basis; the hashes are aside. +/// +/// WHAT IS ACTUALLY ESTABLISHED, and it is weaker: +/// +/// * The sentinel gate ([`census_unwritten_final`], +/// `the_frame_the_caller_receives_carries_no_unwritten_plane_sample`) proves +/// that no sample the tile walk never wrote SURVIVES into the frame the caller +/// receives, on the corpus measured. **It counts at the OUTPUT POINT ONLY -- +/// one census, one scan.** The pre-deblock census ([`census_unwritten`], +/// `take_unwritten_samples` / `take_census_scanned`) is a DIFFERENT instrument +/// and has NO committed reader anywhere in the crate on `main`, so it backs +/// nothing here; an earlier revision of this comment credited the gate with +/// both, which would have told a reviewer the premise is covered by two scans +/// when only one exists. It is measured SURVIVAL, not reads. +/// * It does NOT prove "every sample is written before it is read". A sample read +/// as a prediction or filter neighbour and overwritten a moment later is +/// invisible to that count. **No such read has been observed, and no +/// instrument here measures for one.** +/// * On `main` = `e45cc748` the one path where a read was demonstrated is +/// UNREACHABLE: lane/av1unwritten refuses the subsize before descending. +/// +/// Honest status: a read-before-write is DEMONSTRATED on a path that is now +/// refused, UNMEASURED on every other path, and this `unsafe` is sound only under +/// the unproven "written before read" premise. Filed as an open UB-class item +/// (`lanes/unwritten-dep.report.md` §12) with two closures: (a) zero the +/// allocation -- the safe default, at the ~3% this removed; or (b) an instrument +/// counting reads-before-write per sample, so the premise can be proved rather +/// than assumed. fn fresh_plane(n: usize) -> Vec { if plane_sentinel_on() { return vec![PLANE_SENTINEL; n]; } let mut v: Vec = Vec::with_capacity(n); - // SAFETY: `u16` has no invalid bit patterns and no `Drop`, and the - // capacity was just reserved, so the vector owns `n` initialised-or-not - // `u16` slots. Every one is written by reconstruction before it is read - // (proven by the sentinel gate above). + // SAFETY, PARTIAL -- the premise is NOT established; see the block comment + // above ("THE `unsafe` BELOW IS NOT FULLY JUSTIFIED"). + // + // What IS sound: `u16` has no invalid bit patterns and no `Drop`, and the + // capacity was just reserved, so the vector owns `n` slots that are valid to + // OWN. Creating a `Vec` over uninitialised memory is not itself UB. + // + // What is NOT sound, and is the reason this is a filed item rather than a + // settled one: reading an uninitialised `u16` IS UB, and the only thing that + // makes the reads sound is the premise that reconstruction writes every + // sample before any read. That premise was RETRACTED by measurement (224 + // unwritten samples, output varying with initial content) on a path that is + // now refused, and is UNMEASURED everywhere else. The sentinel gate measures + // survival at the output point, not reads. The pre-deblock census is a + // separate instrument with no committed reader on main, so it adds nothing + // here. So this `unsafe` is sound under a premise no current instrument + // proves. #[allow(unsafe_code)] unsafe { v.set_len(n); @@ -37958,6 +38132,8 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( &v, frame_width as usize, frame_height as usize, + ss_x(fctx), + ss_y(fctx), ); census_unwritten(&y, &u, &v); if let Ok(path) = crate::envflags::var("EC_AV1_PREFILT_DUMP") { @@ -38041,6 +38217,8 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( &v, frame_width as usize, frame_height as usize, + ss_x(fctx), + ss_y(fctx), ); apply_cdef( &mut y, @@ -38061,6 +38239,8 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( &v, frame_width as usize, frame_height as usize, + ss_x(fctx), + ss_y(fctx), ); capture_stages(&y, &u, &v, deblocked.as_ref(), fctx); // spec 7.16 (libaom `superres_post_decode`, decodeframe.c: called @@ -56320,6 +56500,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( &v, frame_width as usize, frame_height as usize, + ss_x(fctx), + ss_y(fctx), ); census_unwritten(&y, &u, &v); if let Ok(path) = crate::envflags::var("EC_AV1_PREFILT_DUMP") { @@ -56423,6 +56605,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( &v, frame_width as usize, frame_height as usize, + ss_x(fctx), + ss_y(fctx), ); if !pipelined { apply_cdef( @@ -56445,6 +56629,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( &v, frame_width as usize, frame_height as usize, + ss_x(fctx), + ss_y(fctx), ); capture_stages(&y, &u, &v, deblocked.as_ref(), fctx); // spec 7.16 (libaom `superres_post_decode`, decodeframe.c: called diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 87b5db5a..37626b0d 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -2220,6 +2220,30 @@ fn decode_frame( // aomdec's own `EC_AV1_FINAL_DUMP` rung byte for byte // (scripts/instrument-aom-oracle.sh rung 12), which is what makes a // hidden frame's pixels comparable at all. + // lane-unwritten-dep: the census AT the output point, beside the dump that + // defines "the output" -- the same bytes, so the claim is about the frame the + // caller receives rather than about an intermediate stage. + // + // WHAT THIS IS FOR, corrected: an earlier revision of this comment said the + // pre-deblock plane was byte-identical plain-vs-sentinel and that deblock + // creates the dependence. That was wrong, and it was `dump_stage16`'s fault: + // it cropped chroma as `(fw/2, fh/2)`, a 4:2:0 assumption, so on a 64x64 + // 4:2:2 frame 2048 chroma samples appeared in no stage dump at all -- exactly + // the region the difference lives in. With per-axis extents the corrected + // measurement on `440_request_is_422` is that the PRE-DEBLOCK dump already + // differs by 2158 bytes and an exact u16 census finds 224 unwritten samples + // (U 112, V 112, rows 36..63) -- the same count `lanes/av1unwritten.report.md` + // reports. The hole is present before any filter runs, and the pre-deblock + // census SEES it. + // + // So this second census is not a patch for a blind pre-deblock scan. It is + // the measurement taken where the output is taken, which covers the whole span + // from the tile walk to the caller's frame: anything a later stage could + // introduce (a filter, superres, a second pass) is inside its extent, where + // a scan taken before it would not be. It also runs before `apply_grain`, so + // the claim is over the PRE-GRAIN planes -- the bytes the reference bank + // stores and every later frame predicts from. + decode::census_unwritten_final(&picture.y, &picture.u, &picture.v); if let Some(prefix) = final_dump { use std::io::Write; if let Ok(mut f) = std::fs::File::create(format!("{prefix}.f{decode_idx}")) { @@ -48206,6 +48230,242 @@ exit 0 ); } + /// lane-unwritten-dep: the UNWRITTEN-SAMPLE census at the point the output is + /// taken, over the real film fixtures that carry hidden alt-refs. + /// + /// SCOPE, stated rather than implied: the census is taken where + /// `EC_AV1_FINAL_DUMP` writes, which is BEFORE `apply_grain`. The claim is + /// therefore over the PRE-GRAIN planes -- which are also the bytes the + /// reference bank stores and every later frame predicts from, the dependency + /// that matters. Whether `apply_grain` can itself introduce a hole is NOT + /// measured: the census never sees the planes `apply_grain` allocates. So the + /// claim is NOT "the caller's final grained picture has no hole", and nothing + /// here asserts that grain cannot introduce one. + /// + /// NON-VACUITY, the part that makes this gate worth having: a census is only a + /// measurement if it CAN report non-zero. The control is a SYNTHETIC positive + /// -- the census is handed planes with a known number of sentinel samples and + /// must report exactly that number. It deliberately does NOT use a fixture: + /// the corpus's one witness with a real hole (`440_request_is_422`) is REFUSED + /// by lane/av1unwritten, so a fixture-carried control goes red on merge for a + /// reason unrelated to this gate. A synthetic control cannot be refused and + /// cannot change behaviour when a lane lands. It is proven by mutation in the + /// same run: neutering `census_unwritten_final` reds it (lane report §5). + /// + /// WHAT THIS IS NOT, corrected from an earlier revision of this comment: it + /// does NOT rest on a claim that the pre-deblock census is blind. That claim + /// was wrong. It came from `dump_stage16` cropping chroma as `(fw/2, fh/2)` -- + /// a 4:2:0 assumption -- so on a 64x64 4:2:2 frame 2048 chroma samples were in + /// no stage dump at all, and an earlier revision read that blind spot as + /// "identical pre-deblock, so deblock creates the dependence". With per-axis + /// extents the corrected measurement is the opposite: the pre-deblock dump on + /// `440_request_is_422` already DIFFERS by 2158 bytes and the exact u16 census + /// finds 224 unwritten samples (U 112, V 112, rows 36..63, whole 4x4 groups) -- + /// the same count `lanes/av1unwritten.report.md` reports. The hole is present + /// before any filter runs and the pre-deblock census SEES it. This census is + /// here because it is the measurement taken where the OUTPUT is taken, which + /// spans the whole route from the tile walk to the caller. + /// + /// The four film fixtures are the corpus's real 10-bit streams with hidden + /// alt-refs -- the shapes where a hidden frame's unwritten region would feed + /// a later DISPLAYED frame through the reference bank, which is the only way + /// an unwritten sample could reach output on a stream that decodes correctly. + /// All four measure 0 here AND 0 on the pre-deblock census. + /// + /// Measured on `8d6998d7` with a provenance-verified probe (`strings` on the + /// binary names only this worktree; reelb_arf sha256 `7f3b060da5aa9c53`, + /// reelb_rect64 `c9e721088766163b`): + /// + /// ```text + /// pre-deblock census (u16, whole plane, 0xDEAD counted per frame) + /// 440_request_is_422 224 <- also lane/av1unwritten's own number + /// reelb_arf_witness 0 + /// reelb_rect64_intra16x4_witness 0 + /// this gate (pre-grain, at the output point) + /// reelb_arf_witness 0 + /// reelb_rect64_intra16x4_witness 0 + /// gm_small_side_witness 0 + /// reelc_sb128_inter_witness 0 + /// ``` + #[test] + fn the_frame_the_caller_receives_carries_no_unwritten_plane_sample() { + const NAME: &str = "the_frame_the_caller_receives_carries_no_unwritten_plane_sample"; + let _gate_lock = lock_gate_counters(); + + // The census needs the sentinel FILL, which is env-gated (see + // `fresh_plane`), and this crate forbids `set_var` (see `envflags`), so + // the fill cannot be switched from inside a test process. The child + // process below is therefore how the measurement is taken; what the + // parent asserts is the CHILD's reported count. + let census = |fixture: &str| -> (usize, usize) { + let exe = std::env::current_exe().expect("test binary path"); + let out = std::process::Command::new(exe) + .args([ + "--exact", + "stream::tests::uwdep_child_unwritten_census", + "--nocapture", + ]) + .env("UWDEP_CENSUS_FIXTURE", fixture) + .env("EC_AV1_PLANE_SENTINEL", "1") + .output() + .expect("running the census child"); + // `--nocapture` puts the child's `println!` on its stderr, so both + // streams are searched. + let text = format!( + "{}{}", + String::from_utf8_lossy(&out.stdout), + String::from_utf8_lossy(&out.stderr), + ); + text.lines() + .find_map(|l| l.strip_prefix("UWDEP_CENSUS ")) + .and_then(parse_census_line) + .unwrap_or_else(|| { + panic!( + "{NAME}: the census child reported no count for {fixture} \ + (child said: {:?})", + text.trim() + ) + }) + }; + + // Non-vacuity FIRST, and SYNTHETIC on purpose (see the doc comment): the + // census is handed planes with a known number of sentinel samples and must + // report exactly that number. No fixture is involved, so this cannot be + // affected by lane/av1unwritten refusing `440_request_is_422` on merge. + // The fill is env-gated, so even this runs in the child. + let (synthetic, synthetic_scanned) = census_synthetic(); + assert_eq!( + synthetic_scanned, 40, + "{NAME}: the synthetic control scanned {synthetic_scanned} samples, expected 40 \ + (16 + 16 + 8) -- the census did not look at what it was handed" + ); + assert_eq!( + synthetic, 7, + "{NAME}: the census reported {synthetic} for planes carrying exactly 7 sentinel \ + samples -- the census is not measuring what it claims, so every zero below is \ + meaningless (class: census-silently-blind)" + ); + + for fixture in [ + "reelb_arf_witness", + "reelb_rect64_intra16x4_witness", + "gm_small_side_witness", + "reelc_sb128_inter_witness", + ] { + let (n, scanned) = census(fixture); + assert!( + scanned > 0, + "{NAME}: the census scanned 0 samples on {fixture} -- the call at the output \ + point is not running, so the {n} below proves nothing (class: \ + census-never-ran). Deleting the call site reproduces this." + ); + assert_eq!( + n, 0, + "{NAME}: {fixture} hands the caller {n} samples the tile walk never wrote" + ); + } + } + + /// Parses the child's `UWDEP_CENSUS frames= scanned=` line + /// into `(unwritten, scanned)`. The scanned count is what makes the fixture + /// arms meaningful: `unwritten == 0` is also what a build with the census call + /// deleted reports, and only a non-zero scanned count distinguishes "scanned + /// and found nothing" from "never scanned". + fn parse_census_line(v: &str) -> Option<(usize, usize)> { + let mut parts = v.split_whitespace(); + let unwritten = parts.next()?.parse().ok()?; + let scanned = parts + .find_map(|p| p.strip_prefix("scanned="))? + .parse() + .ok()?; + Some((unwritten, scanned)) + } + + /// Runs the census child with `UWDEP_CENSUS_FIXTURE` UNSET, which makes it + /// take the synthetic-positive path: hand [`census_unwritten_final`] planes + /// with a known number of `PLANE_SENTINEL` values and report what it counted. + /// This is the non-vacuity control, and it is a direct function-level check + /// rather than a decode, so no fixture's decode behaviour can change it. + fn census_synthetic() -> (usize, usize) { + const NAME: &str = "the_frame_the_caller_receives_carries_no_unwritten_plane_sample"; + let exe = std::env::current_exe().expect("test binary path"); + let out = std::process::Command::new(exe) + .args([ + "--exact", + "stream::tests::uwdep_child_unwritten_census", + "--nocapture", + ]) + .env("EC_AV1_PLANE_SENTINEL", "1") + .env("UWDEP_CENSUS_SYNTHETIC", "1") + .env_remove("UWDEP_CENSUS_FIXTURE") + .output() + .expect("running the census child"); + let text = format!( + "{}{}", + String::from_utf8_lossy(&out.stdout), + String::from_utf8_lossy(&out.stderr), + ); + text.lines() + .find_map(|l| l.strip_prefix("UWDEP_CENSUS ")) + .and_then(parse_census_line) + .unwrap_or_else(|| { + panic!( + "{NAME}: the census child reported no synthetic count (child said: {:?})", + text.trim() + ) + }) + } + + /// The child half of + /// [`the_frame_the_caller_receives_carries_no_unwritten_plane_sample`]: decodes + /// the fixture named in `UWDEP_CENSUS_FIXTURE` with the sentinel fill live and + /// prints `UWDEP_CENSUS frames=` plus a frame-count assertion. + /// + /// A `#[test]` rather than an example because it needs the crate's own + /// in-process counter -- which no external binary could read. + #[test] + fn uwdep_child_unwritten_census() { + assert!( + std::env::var_os("EC_AV1_PLANE_SENTINEL").is_some(), + "the census child ran without EC_AV1_PLANE_SENTINEL, so the fill was never live \ + and the count is meaningless" + ); + // The non-vacuity control: no decode, no fixture, just the census over + // planes with a KNOWN number of sentinel samples. 3 + 4 + 0 = 7. + if std::env::var_os("UWDEP_CENSUS_SYNTHETIC").is_some() { + const S: u16 = 0xDEAD; + let mut a = vec![7u16; 16]; + let mut b = vec![7u16; 16]; + let c = vec![7u16; 8]; + for s in a.iter_mut().take(3) { + *s = S; + } + for s in b.iter_mut().take(4) { + *s = S; + } + let _ = decode::take_final_unwritten_samples(); + decode::census_unwritten_final(&a, &b, &c); + let n = decode::take_final_unwritten_samples(); + let scanned = decode::take_final_census_scanned(); + println!("UWDEP_CENSUS {n} synthetic=1 scanned={scanned}"); + return; + } + let Ok(fixture) = std::env::var("UWDEP_CENSUS_FIXTURE") else { + // Not a census run: the parent invokes this test by name, so being + // reached without the variable means a normal suite run. + return; + }; + let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) + .join(format!("fixtures/{fixture}.obu")); + let stream = + std::fs::read(&path).unwrap_or_else(|e| panic!("reading {}: {e}", path.display())); + let _ = decode::take_final_unwritten_samples(); + let frames = decode_stream(&stream).unwrap_or_else(|e| panic!("{fixture} refused: {e}")); + let n = decode::take_final_unwritten_samples(); + let scanned = decode::take_final_census_scanned(); + println!("UWDEP_CENSUS {n} frames={} scanned={scanned}", frames.len()); + } + /// lane-t900 r6: the 128-superblock INTER witness. /// `crates/ec-av1/fixtures/reelc_sb128_inter_witness.obu`, 177773 bytes, /// sha256 `09d995946d27695ef4b7b1a24a4d7ad85f8e2c8176d58ee54e825efc061f9cbc`: diff --git a/lanes/unwritten-dep.report.md b/lanes/unwritten-dep.report.md new file mode 100644 index 00000000..773b51c5 --- /dev/null +++ b/lanes/unwritten-dep.report.md @@ -0,0 +1,445 @@ +# lane/unwritten-dep — the reelb_* rows are not decoder defects; the instrument that lied is `dump_stage16` + +**Outcome in one line: neither `reelb_rect64_intra16x4_witness.obu` nor +`reelb_arf_witness.obu` output depends on unwritten plane content; the census was +never blind — `dump_stage16` was, because it hardcoded a 4:2:0 chroma extent and +on a 4:2:2 frame wrote half of each chroma plane into no dump at all, which +fabricated the "identical pre-deblock, differs post-deblock" attribution; with +per-axis extents the 4:2:2 witness shows 224 unwritten samples pre-deblock +(exactly lane/av1unwritten's own number), so the difference is present BEFORE any +filter runs. The gate's non-vacuity control is now synthetic and survives +`main`'s refusal of the only fixture that had one.** + +Branch `lane/unwritten-dep`. Base `8d6998d7`, **rebased by merging +`main` = `e45cc748` locally** (commit `c62eeda9`) — the merge proof the +acceptance asked for is this lane's own tree; no rebase onto a different base, +the merge keeps `8d6998d7` as the branch point. + +> **r3 correction, on top of r2.** r2 named the census as the blind instrument and +> attributed the 4:2:2 witness's divergence to deblock. Both were wrong, and r2's +> own numbers refuted them: its `EC_AV1_DEBUG_SKIP_DEBLOCK` result did not remove +> the difference, and 32 surviving sentinel samples cannot explain 1986 +> differing bytes. The cause is r2's own unexamined instrument. +> `dump_stage16` (`decode.rs`) cropped chroma as `(fw/2, fh/2)` — a 4:2:0 +> assumption — so on a 64×64 **4:2:2** frame (ss_x=1, ss_y=0) it wrote 32×32 +> chroma where the frame carries 32×64. **2048 chroma samples appeared in no +> stage dump at all**, and they are exactly the region where the difference +> lives. r2 read the dump's blind spot as a pipeline property. With per-axis +> extents the pre-deblock dump is where the difference *starts*. + +## 1. Provenance + +Built in this lane's worktree with its own target dir; the binary's embedded +paths name only this worktree. + +``` +$ CARGO_TARGET_DIR=/home/user/.cache/tgt/uwdep-merge cargo build -p ec-av1 --example decode_probe +$ strings .../decode_probe | grep -o 'wt/[a-zA-Z0-9_-]*' | sort -u +wt/unwrittendep +``` + +Two live traps, both of which produce a *silent* wrong reading: this lane's first +target dir was deleted underneath it mid-run (hence `uwdep-k9` → `uwdep-merge`), +and `/tmp` is a 16 GB tmpfs that filled during the first sweep and produced +short/zero-length dump files. Every retained run asserts the exact expected +frame size; the 10-bit fixtures' frame is 18 524 160 bytes. + +Fixtures: `reelb_arf_witness.obu` 32 126 B sha256 `7f3b060da5aa9c53…`, +`reelb_rect64_intra16x4_witness.obu` 23 472 B sha256 `c9e721088766163b…`. + +## 2. Reproduction + +Hash shape `cat dir/frame.f*` (lexicographic), 3 plain + 2 sentinel runs: + +| fixture | plain | sentinel | campaign plain | campaign sentinel | +|---|---|---|---|---| +| `reelb_rect64_intra16x4_witness` (34 frames) | `a26438168c` ×3 | `a26438168c` ×2 | `a26438168c` | `0ee1edf403` | +| `reelb_arf_witness` (40 frames) | `8d7a43bc5f` ×3 | `8d7a43bc5f` ×2 | `8d7a43bc5f` | `97ef82c0ce` | + +**Both campaign PLAIN values are reproduced exactly by this build; neither +SENTINEL value is.** The decode output is byte-identical plain vs sentinel, and +under every other ambient content available: glibc `MALLOC_PERTURB_` ∈ {0, 1, 85, +170, 254}, `EC_AV1_THREADS` ∈ {1, 2, 4, 8}, and in-process poisoning of the +allocator's free list with 16 MiB dirty-then-freed blocks. + +The in-process test is the strongest of these because there is no filesystem in +the measurement at all, and it has teeth — on the 4:2:2 witness it reports +differences under 4 of 4 poison patterns (667–715 differing U samples, +673–690 differing V, 0 in luma), while reporting **0 differing frames under 4 +of 4 patterns on both hg fixtures**. + +## 3. `97ef82c0ce` — consistent with a truncated dump, not proven to be one + +Sweeping (frames-complete, tail-truncated) shapes against the campaign's value: + +``` +$ python3 /tmp/unwritten/partial.py reelb_arf_witness + MATCH: frames 0..4 + f5 truncated to 13320192 bytes, lex-hashed +``` + +The campaign's value is reproduced **bit-for-bit** by a byte stream that is frames +0–4 complete plus 13 320 192 bytes of frame 5 (71.8% of one frame), frames 6–39 +absent. `EC_AV1_FINAL_DUMP` does `let _ = f.write_all(&buf)`, so a full filesystem +leaves a prefix of the true stream and nothing reports it. + +**This pins the byte content and the shape, not the mechanism.** An unlived +sentinel, a timeout-killed process, and a full filesystem all leave the same +bytes. The wording is therefore *consistent with* a truncated dump, and the +converse — that the decode is innocent — rests on §2's invariance, not on this +match. Corroborating but likewise non-conclusive: `RLIMIT_FSIZE` at a 4 MiB cap +gives `788d3be08ae5112e` for both fills vs `5350cd5569d226eb` uncapped; a reused +dump directory leaves a longer fixture's tail (`9ca5c4d7af`); hashing the +`sha256sum` listing embeds the directory path. + +`0ee1edf403` is **not** reproduced by any shape swept (every numeric prefix; +every prefix + page-truncated tail at 4 KiB and 512 B; prefixes from either +fixture, since rect64 is a 34-frame prefix of arf's 40 with byte-identical frames +0–33; hole shapes; zero-length-frame shapes; stale cross-fixture mixes both +orders; the listing shape). It remains an **open instrument-hygiene question**, +not a decode question — the decode is invariant (§2). + +## 4. The instrument defect, and the corrected measurement + +**Class: `diagnostic-dump-assumes-one-subsampling`** — a debug/instrumental dump +that derives a plane's extent from an assumed subsampling rather than the +sequence's, so part of the plane is absent from the measurement and conclusions +drawn from that measurement are about the dump. Same per-axis family as the +decoder's own `round_ss(dim, ss)` rule. + +`decode.rs`, `dump_stage16`, cropped chroma as `(fw.div_ceil(2), fh.div_ceil(2))` +— the 4:2:0 assumption on both axes. The oracle's rung 1 uses libaom's +`uv_crop_width` / `uv_crop_height`, which are per-axis. Fixed to +`(round_ss(fw, ss_x), round_ss(fh, ss_y))`, with all six call sites passing +`ss_x(fctx)` / `ss_y(fctx)`. + +**Corrected stage bisect on `440_request_is_422`** (8-bit, 64×64, 4:2:2 header +over a 4:2:0 tile; `main` = `e45cc748` refuses it, so this is measured on the +branch point `8d6998d7`): + +| stage dump | before the fix | after the fix | +|---|---|---| +| `EC_AV1_PREFILT_DUMP16` (pre-deblock) | 12 288 B, **IDENTICAL** | 16 384 B, **DIFFERS (2158 B)** | +| `EC_AV1_POSTDEBLOCK_DUMP16` | 12 288 B, DIFFERS (26 B) | 16 384 B, DIFFERS (2017 B) | +| `EC_AV1_POSTCDEF_DUMP16` | 12 288 B, DIFFERS (26 B) | 16 384 B, DIFFERS (1948 B) | +| `EC_AV1_DECODE_ORDER_DUMP` | 8 192 B, DIFFERS (1985 B) | 8 192 B, DIFFERS (1917 B) | +| `EC_AV1_FINAL_DUMP` | 8 192 B, DIFFERS (1986 B) | 8 192 B, DIFFERS (1986 B) | + +12 288 B = 6144 samples = 4096 luma + 2×1024: only chroma rows 0–31. The frame the +caller receives is 8192 samples. **The 2048 missing chroma samples are the +region r2's conclusion was drawn from.** + +**Coordinates, from the corrected pre-deblock dump** (8192 samples, u16, whole +plane, `0xDEAD` counted): + +* unwritten samples, sentinel run: **U 112, V 112, Y 0** — U and V, 28 whole + 4×4 groups each, spanning rows 36–63 (12 rows carrying 8 samples + 4 rows + carrying 4 = 96 + 16 = 112). The column span runs 0–15 but is NOT filled: + every row has cols 0–3 and 12–15. **224 total, exactly lane/av1unwritten's own + census number** (`lanes/av1unwritten.report.md:152-156`). +* plain vs sentinel differing samples, pre-deblock: **U 1004 of 2048, V 1004 of + 2048, Y 0**, rows 32–63 — the hole plus everything predicted from it. + +So the corrected conclusion is the opposite of r2's: the difference is **already +present before deblock**; no filter creates it. r2's "Deblock creates it" was an +artefact of the dump it could not see past. + +**And the census was never blind.** It runs at pre-deblock and it reports the +hole — 224 samples, in whole 4×4 chroma blocks. What could not see it was the +stage dump. On the hg fixtures both report 0. + +## 5. Displayed vs hidden, per fixture + +`reelb_arf_witness`: 40 decode-order frames — 19 shown, 21 hidden alt-refs, plus 18 +`show_existing_frame` headers. `reelb_rect64_intra16x4_witness`: 34 — 17 shown, 17 +hidden, plus 16 `show_existing_frame`. (From `EC_PROBE_HDR=1`; the split is over +non-`show_existing` headers.) + +**No unwritten sample reaches a DISPLAYED frame on either fixture — or a hidden +one.** Every one of the 34/40 frames hashes identically under plain, sentinel, +five ambient fills, four thread counts and in-process poisoning, and both the +pre-deblock census and the new output-point census report 0. The hidden frames +were measured specifically because they are the route by which a hole would reach +a later displayed frame through the reference bank; they are clean. + +The one fixture where a hole does reach output is the 4:2:2 witness, whose single +frame is **SHOWN** (`Key show=true`), with 224 unwritten chroma samples. Its +cause is the invalid subsize `main` now refuses; that lane owns it and is +untouched here. + +## 6. The fix and the gate + +`decode.rs`: `census_unwritten_final` + `take_final_unwritten_samples` — a census +over the three planes at the point they are stored into the reference slots, with +`dump_stage16`'s chroma extent made per-axis. + +`stream.rs`: the census is called beside the `EC_AV1_FINAL_DUMP` site. + +**SCOPE, stated not implied:** that point is **before `apply_grain`**, so the +claim is over the **pre-grain** planes only. Those are also the bytes the +reference bank stores and every later frame predicts from, which is the +dependency that matters. Whether `apply_grain` can itself introduce a hole is +**not measured here** -- the census never sees the planes `apply_grain` +allocates -- so "the caller's final grained picture has no hole" is **not +claimed**, and no sentence asserts that grain cannot introduce one. + +Gate `the_frame_the_caller_receives_carries_no_unwritten_plane_sample`: + +1. **non-vacuity first, and SYNTHETIC**: the census is handed planes carrying + exactly 7 sentinel samples and must report exactly 7. No fixture is involved, + so it cannot be affected by `main` refusing `440_request_is_422` — which is + what r2's fixture-carried control would have done on merge; +2. **0** on `reelb_arf_witness`, `reelb_rect64_intra16x4_witness`, `gm_small_side_witness`, + `reelc_sb128_inter_witness` — the real 10-bit streams with hidden alt-refs. + +The fill is env-gated and this crate forbids `set_var`, so the measurement runs +in a child process the parent invokes by name; the child asserts +`EC_AV1_PLANE_SENTINEL` is set, so a non-live fill fails rather than reporting a +meaningless zero. + +**Merge proof — green on a tree containing both lanes.** `main` = `e45cc748` +merged into this branch (`c62eeda9`), then: + +``` +$ cargo test -p ec-av1 --lib -- the_frame_the_caller_receives_carries_no_unwritten_plane_sample +test result: ok. 1 passed; 0 failed; 0 ignored; 816 filtered out; finished in 71.59s +``` + +The proof that this tree really carries `av1unwritten`'s content is behavioural, +not a test count (a filtered-test count is a count of names, and a merge that +dropped hunks would print the same number): + +``` +$ decode_probe crates/ec-av1/fixtures/440_request_is_422.obu +REFUSED: unsupported: AV1 tile (a block size 4x8, 8x16 or 16x4 (or 8x4 at 4:4:0) has no +chroma plane block at this frame's subsampling mode ... +``` + +**0 frames, refused** — only reachable with the refusal present. On the branch +point `8d6998d7` the same fixture decodes to `OK: 1 frames decoded`. That is the +merge proof. (It is also why the fixture-carried control had to go: the census +child could not run at all here.) + +### Mutations + +| mutation | result | +|---|---| +| `census_unwritten_final` neutered (`if true { return; }`) | **RED** at the synthetic control: "the census reported 0 for planes carrying exactly 7 sentinel samples … (class: census-silently-blind)" | +| **the call at `stream.rs` DELETED** (the whole line replaced by a `let _ =`) | **RED**: "the census scanned 0 samples on reelb_arf_witness -- the call at the output point is not running, so the 0 below proves nothing (class: census-never-ran). Deleting the call site reproduces this." | +| one sentinel sample forced into a film frame's output (`p.y[0] = 0xDEAD`) | RED on the fixture: "reelb_arf_witness hands the caller N samples the tile walk never wrote" | + +The second row was **false as stated in r3** and is the substantive fix here: r3's +control called `census_unwritten_final` directly, so deleting the pipeline call +left every assertion passing and the gate pinned nothing about the decode. The +gate now reads `take_final_census_scanned()` alongside +`take_final_unwritten_samples()` — the same pairing the merged pre-deblock census +already documents ("a gate that only asserts `take_unwritten_samples() == 0` +passes on a decode that never scanned anything, so it reads THIS too"). The +fixture arms require `scanned > 0`, the synthetic arm requires `scanned == 40` +(16 + 16 + 8), so "scanned and found nothing" is now distinguishable from +"never scanned". + +## 7. Commands + +```bash +cd /home/user/.cache/wt/unwrittendep +git merge e45cc748 # merge proof tree +CARGO_TARGET_DIR=... cargo build -p ec-av1 --example decode_probe +strings .../decode_probe | grep -o 'wt/[a-z]*' # provenance + +python3 /tmp/unwritten/coords.py # corrected coordinates (§4) +bash /tmp/unwritten/determinism.sh "440_request_is_422 reelb_rect64_intra16x4_witness reelb_arf_witness" 5 +python3 /tmp/unwritten/partial.py reelb_arf_witness # the 97ef82c0ce shape +cargo test -p ec-av1 --lib -- the_frame_the_caller_receives_carries_no_unwritten_plane_sample +``` + +## 8. Disposition + +* **`reelb_arf_witness` — closed, not a decoder defect.** Output invariant under + every ambient content tested (§2); the campaign's divergence is *consistent + with* a truncated dump (§3), and the decode is innocent on the invariance + evidence, not on the hash match. +* **`reelb_rect64_intra16x4_witness` — closed, not a decoder defect; its campaign + sentinel value `0ee1edf403` remains an OPEN instrument-hygiene question** (§3). +* **`440_request_is_422` — measured and gated, not fixed here.** 224 unwritten + chroma samples, pre-deblock, whole 4×4 blocks; cause is the invalid subsize + `main` refuses (lane/av1unwritten, untouched). +* **The `dump_stage16` per-axis extent is fixed** (§4) — the class is + `diagnostic-dump-assumes-one-subsampling`. + +## 9. What this lane did not do + +* **The unswept family, now swept**: r2 did not run-to-run content + nondeterminism with uninitialised planes — the family + `lanes/av1unwritten.report.md:118-124` records as three different plain hashes + of 440 from three identical invocations. A sentinel run structurally cannot + detect it (it pins content to one value), and r2's in-process test could not + (one process, one heap). N separate processes are required; the result is in + §10. **I had not swept it in r2 and said nothing about it — that was a gap, not + a negative result.** +* The dump sites still swallow their write errors, so a short dump remains + possible — the artefact behind §3. Making a partial write loud is an + instrument change touching every dump in the crate; named, not done. +* No pixel claim is made or unmade for any fixture. +* Untouched per instructions: `film_grain.rs`, the reserved 4:2:0 group-tail + chroma SKIP arm, `decode_rect4_16_intrabc`, and `lane/av1unwritten`'s content + (read-only). + +## 10. The run-to-run nondeterminism family, swept + +N separate PROCESSES (not one process -- an in-process test cannot see this, it +has one heap), uninitialised planes, per-run decode-order concatenation hashed, +exact frame size asserted: + +``` +=== 440_request_is_422 frames=0 (main = e45cc748 REFUSES it; not sweepable on the merge tree) +=== reelb_rect64_intra16x4_witness +5350cd5569d226eb frames=34 sizes=[18524160] +5350cd5569d226eb frames=34 sizes=[18524160] +5350cd5569d226eb frames=34 sizes=[18524160] +5350cd5569d226eb frames=34 sizes=[18524160] +=== reelb_arf_witness +dca5b3d9d2d56f30 frames=40 sizes=[18524160] +dca5b3d9d2d56f30 frames=40 sizes=[18524160] +dca5b3d9d2d56f30 frames=40 sizes=[18524160] +dca5b3d9d2d56f30 frames=40 sizes=[18524160] +``` + +**Negative for both hg fixtures: 4/4 identical, correct size, no spread.** This +is the family a sentinel run structurally cannot detect (it pins content to one +value), and it is independent of the sentinel evidence in section 2. + +`440_request_is_422` **could not be swept on the merge tree** -- `main` = `e45cc748` +refuses it, which is the refusal working as intended. On the branch point +`8d6998d7` I measured 3 identical plain hashes (`a761118c8dd5c8d0`), i.e. I did +**not** reproduce the three-distinct-hashes observation at +`lanes/av1unwritten.report.md:118-124`. That is consistent rather than +contradictory: the witness's output depends on ambient memory, and what the +allocator hands back is machine- and run-dependent, so a fixed value on one host +and a varying one on another are the same defect. **Stated as measured: 3/3 +identical here, and no claim about reproducing their observation.** + +## 11. What the per-axis extent change invalidated in published work + +`round_ss(dim, 1)` is bit-identical to `dim.div_ceil(2)`, so **every 4:2:0 dump is +byte-for-byte unchanged** by the `dump_stage16` fix. The change only affects 4:2:2 +and 4:4:0 frames. + +21 lane files reference the `*_DUMP16` dumps. Of those, exactly one, +`lanes/av1422luma.report.md`, uses non-4:2:0 fixtures (`s422_416x250_10b`). Its +stage table (line 77 onward) is a **Y-only** conclusion — every row reads +"frame 0 Y wrong vs ffmpeg", and the reported numbers are luma sample counts and +a luma first-differing coordinate — so that conclusion **survives** the extent +change unchanged. What the change invalidates is only that report's **label**: +"depth-correct `*_DUMP16`" is no longer accurate for the **chroma half** of those +files, which the 4:2:0 crop had truncated to the top half-height. No published +number moves. + +`lanes/unwritten-dep.report.md` (this file) is the only other DUMP16 reference +touching a non-4:2:0 frame, and its numbers are the corrected ones above. + +## 12. OPEN, filed: the `unsafe { v.set_len(n) }` in `fresh_plane` is not fully justified + +**This is the highest-risk item this lane found, and it is NOT closed here.** It +is filed rather than fixed because closing it means either restoring a ~3% frame- +head cost or building a reads-before-write instrument, and both are decisions +that belong to a lane chartered for them. The comments in `decode.rs` now say +this, so a reviewer can no longer approve the `unsafe` on a withdrawn proof. + +**The retracted claim.** `fresh_plane`'s doc asserted the SB-padded surface "is +written sample-for-sample by the tile walk's reconstruction before anything reads +it", and cited the sentinel gate as proof ("proven by the sentinel gate above"). +**The same file retracts it.** The basis is **this lane's own measurement**, not +second-hand: on `440_request_is_422` an exact u16 whole-plane census at the +pre-deblock point finds **112 unwritten samples per chroma plane, 224 total** (U +and V, 28 whole 4×4 groups each, rows 36–63) in a frame that is **SHOWN** +(`Key show=true`) and whose samples the caller receives (§4, §5). Uninitialised +memory that reaches the caller was read, or the read that produced it was. That +is the UB, and it stands without any hash-variation claim. + +A hash-variation observation also exists — five plain runs of the witness giving +two different output hashes (`lanes/av1unwritten.report.md:118-124`) — but it is +**second-hand and NOT reproduced here**: five plain runs on `8d6998d7` gave one +hash, `a761118c8dd5c8d0` (§10). It is therefore not relied on, and it should not +have been stated flatly in the `decode.rs` comment, where it did read as this +lane's measurement. Ambient content is machine-dependent, so a stable value on one +host and a varying one on another would be the same defect either way; the +224-sample census is the basis, the hashes are an aside. + +**What the gate actually proves — the weaker claim.** The gate counts at the +**output point only**: one census, one scan. The pre-deblock census +(`census_unwritten`, `take_unwritten_samples` / `take_census_scanned`) is a +**different instrument with no committed reader anywhere in the crate on `main`** +(§13), so it backs nothing here. An earlier revision of this section credited +the gate with both, which would have told a reviewer auditing the `unsafe` that +the premise is covered by two scans when only one exists — and the missing one is +exactly the scan that would catch a hole before the filters. What the gate +measures is **survival, not reads**: + +* PROVEN: no sample the tile walk never wrote **survives into the frame the + caller receives**, on the corpus measured. +* NOT PROVEN: "every sample is written before it is read". A sample read as a + prediction or filter neighbour and overwritten a moment later is invisible to + that count. **No such read has been observed, and no instrument in this crate + measures for one.** +* On `main` = `e45cc748` the one path where a read was **demonstrated** is now + unreachable — lane/av1unwritten refuses the subsize before descending. + +**Why this is UB-class and not a style issue.** `Vec::set_len` over +uninitialised memory is not itself UB: `u16` has no invalid bit patterns and no +`Drop`, so the vector validly *owns* `n` slots. The UB is in **reading** an +uninitialised `u16`. `set_len` is therefore sound only under the "written before +read" premise, and that premise is the one the measurement withdrew. + +**The withdrawn premise was doing double duty, which is why one retraction +untangles two findings.** It justified *this* `unsafe`, AND it was the reason the +census's original story — a pre-deblock scan that is blind to a hole the loop +filter later reads — looked plausible in the first place. The same measurement +that withdrew the safety argument (output varying with initial content) is what +made the blind-census reading wrong: there was never a blind pre-deblock scan, +only a `dump_stage16` that could not see half the chroma plane. So §12 and the +corrected stage bisect in §4 are the same fact read twice, and a later reader who +fixes one without the other will re-derive the error. + +**Three closures, none taken here:** + +1. **Explicit zero-fill** — restore `vec![0u16; n]`. Sound unconditionally, at + the ~3% of frame-thread cycles at 4K that lane-picalloc removed. This is the + safe default and the honest cost of the optimisation. +2. **Allocator-zeroed allocation** — a zeroed allocation can come from the + allocator rather than a loop: `alloc_zeroed` / anonymous mmap hands back zero + pages on first touch, which for plane-sized buffers costs a page fault rather + than a per-sample store. **This is an option that needs its own measurement, + not a claim that it is free** — the cost at 4K is unmeasured in this lane, and + "a page fault per page" is a mechanism, not a benchmark. Whoever takes it must + measure it before calling it cheaper than (1). +3. **Instrument reads-before-write** — a per-sample read/write map, so the premise + can be proved rather than assumed. That is a real instrument, not a comment, + and it is the only route that keeps the optimisation as-is. + +**Reachability evidence** (what makes this fileable rather than theoretical), +**this lane's own measurement**: on `440_request_is_422` at `8d6998d7`, an exact +u16 whole-plane census finds **224 unwritten chroma samples** (U 112, V 112, +whole 4×4 groups, rows 36–63) in a frame that is **SHOWN** and whose samples the +caller receives — uninitialised memory reaching the caller IS the UB, and it +needs no hash claim. That path is refused on `main`, so the corpus contains no +*currently reachable* instance; the hash-variation observation that also exists is +second-hand and was not reproduced here (§10), so it is not part of the basis. +The claim that needs proving is universal ("every sample is written before it is +read"), and one refused witness cannot establish it for the other 126 fixtures. + +## 13. Does this lane's gate supply the reader `take_unwritten_samples` lacked? — NO + +Checked, and the answer is the unflattering one. `take_unwritten_samples` and +`take_census_scanned` (lane/av1unwritten's pre-deblock census API) still have +**no committed reader** on `main` = `e45cc748`: the only references to them +anywhere in `crates/ec-av1/src` are in their own doc comments. `grep` over +`stream.rs` and the rest finds no call site. + +My gate reads only its OWN pair, `take_final_unwritten_samples` / +`take_final_census_scanned`. So the r4 pairing is a **template** for how a census +gate should be written (count AND scanned, so "scanned and found nothing" is +distinguishable from "never scanned") — it is **not** a committed gate over the +pre-deblock census, and this report does not claim one. Closing that gap means +either adding the pre-deblock pair to an existing gate's assertions or giving it +its own; that is a decision for the lane that owns the instrument, and it is named +here rather than assumed done.