forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-cdfflake': harden the CDF-forwarding gate — length asserts, fingerprints, on-mismatch pinning

Browse files at this commit

81586f29ccb1d8c5684f916c82bfaa231875e5e9Ahmet Kaan GümüşParent: 0b7c477bc99468
The gate's rare parallel-run failure is now proven a real deterministic
decode defect (pinned stream reproduces standalone 3/3), not subprocess
instability; the decoder fix is tracked on the compound/DPB lane.
crates/ec-av1/src/stream.rsmodified+62 -0
@@ -573,6 +573,19 @@ mod tests {
573 GATE_COUNTER_LOCK.lock().unwrap_or_else(|e| e.into_inner())573 GATE_COUNTER_LOCK.lock().unwrap_or_else(|e| e.into_inner())
574 }574 }
575 575
576+ /// lane-cdfflake: a cheap, dependency-free (FNV-1a, not cryptographic --
577+ /// this is a load-bearing-identity fingerprint for flake triage, not a
578+ /// security digest, so no `sha2` dep is pulled in) fixture fingerprint
579+ /// for the cdf-forwarding gate's instrumentation below.
580+ fn fnv1a64(bytes: &[u8]) -> u64 {
581+ let mut hash = 0xcbf29ce484222325u64;
582+ for &b in bytes {
583+ hash ^= b as u64;
584+ hash = hash.wrapping_mul(0x100000001b3);
585+ }
586+ hash
587+ }
588+
576 fn have_ffmpeg() -> bool {589 fn have_ffmpeg() -> bool {
577 Command::new("ffmpeg")590 Command::new("ffmpeg")
578 .arg("-version")591 .arg("-version")
@@ -1836,6 +1849,25 @@ mod tests {
1836 "ffmpeg fixture: {}",1849 "ffmpeg fixture: {}",
1837 String::from_utf8_lossy(&y4m.stderr)1850 String::from_utf8_lossy(&y4m.stderr)
1838 );1851 );
1852+ // lane-cdfflake: hard length check on the y4m fixture itself --
1853+ // a truncated/racing ffmpeg write would otherwise surface as a
1854+ // downstream pixel mismatch indistinguishable from a real decode
1855+ // defect. y4m frames are `FRAME\n` (6 bytes) + raw 4:2:0 payload;
1856+ // find the header/frame-data boundary at the first `FRAME` marker
1857+ // rather than parsing the header fields (duration/rate can move
1858+ // the header text length without moving the frame math).
1859+ let marker_at = y4m
1860+ .stdout
1861+ .windows(5)
1862+ .position(|w| w == b"FRAME")
1863+ .expect("y4m stream missing FRAME marker");
1864+ let frame_420_bytes = width * height * 3 / 2;
1865+ assert_eq!(
1866+ y4m.stdout.len(),
1867+ marker_at + frame_count * (6 + frame_420_bytes),
1868+ "y4m fixture length mismatch (seed {seed})"
1869+ );
1870+ let y4m_hash = fnv1a64(&y4m.stdout);
1839 let mut child = Command::new(aomenc_path())1871 let mut child = Command::new(aomenc_path())
1840 .args([1872 .args([
1841 "--codec=av1",1873 "--codec=av1",
@@ -1919,6 +1951,7 @@ mod tests {
1919 String::from_utf8_lossy(&out.stderr)1951 String::from_utf8_lossy(&out.stderr)
1920 );1952 );
1921 let stream = out.stdout;1953 let stream = out.stdout;
1954+ let stream_hash = fnv1a64(&stream);
1922 // A named `unsupported` refusal is a documented coverage gap (each1955 // A named `unsupported` refusal is a documented coverage gap (each
1923 // one carries its own test debt elsewhere), not a forwarding verdict1956 // one carries its own test debt elsewhere), not a forwarding verdict
1924 // -- try the next seed. Any stream that DECODES must be pixel-exact,1957 // -- try the next seed. Any stream that DECODES must be pixel-exact,
@@ -1937,6 +1970,20 @@ mod tests {
1937 };1970 };
1938 let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count);1971 let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count);
1939 assert_eq!(frames.len(), frame_count);1972 assert_eq!(frames.len(), frame_count);
1973+ // lane-cdfflake: reconstruct ffmpeg's raw reference bytes (the
1974+ // three per-frame slices are contiguous chunks of the raw
1975+ // `-f rawvideo` output ffmpeg_decode_sequence sliced, so
1976+ // concatenating them back is bit-for-bit the same bytes ffmpeg
1977+ // actually produced -- no second ffmpeg invocation needed).
1978+ let ffmpeg_raw: Vec<u8> = ffmpeg_frames
1979+ .iter()
1980+ .flat_map(|p| p.y.iter().chain(&p.u).chain(&p.v).copied())
1981+ .collect();
1982+ let ffmpeg_raw_hash = fnv1a64(&ffmpeg_raw);
1983+ eprintln!(
1984+ "cdfflake attempt seed={seed}: y4m_hash={y4m_hash:016x} \
1985+ stream_hash={stream_hash:016x} ffmpeg_raw_hash={ffmpeg_raw_hash:016x}"
1986+ );
1940 // lane-av1golden3: pin the exact raw stream on the first mismatch1987 // lane-av1golden3: pin the exact raw stream on the first mismatch
1941 // so a flaky-looking gate failure becomes a deterministic, static1988 // so a flaky-looking gate failure becomes a deterministic, static
1942 // fixture to bisect against -- env-gated, no cost on a normal run.1989 // fixture to bisect against -- env-gated, no cost on a normal run.
@@ -1949,6 +1996,21 @@ mod tests {
1949 std::fs::write(&path, &stream).expect("writing pinned stream");1996 std::fs::write(&path, &stream).expect("writing pinned stream");
1950 eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}");1997 eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}");
1951 }1998 }
1999+ // lane-cdfflake: unconditional pin on mismatch -- the aomenc
2000+ // stream AND ffmpeg's raw reference bytes, so a flake caught
2001+ // under load names the liar (stream bytes differ from a
2002+ // clean rerun -> subprocess instability; reference bytes
2003+ // differ -> ffmpeg instability; both stable -> real decode
2004+ // defect) without relying on the env var being set.
2005+ let sp = "/tmp/claude-1000/-home-user-Documents-Code-Rust-edith-codecs/\
2006+ 51b5f611-f998-43a8-b975-e64cb643a3e1/scratchpad";
2007+ std::fs::write(format!("{sp}/cdfflake-stream-seed{seed}.bin"), &stream)
2008+ .expect("writing pinned stream");
2009+ std::fs::write(format!("{sp}/cdfflake-ffmpeg-raw-seed{seed}.bin"), &ffmpeg_raw)
2010+ .expect("writing pinned ffmpeg reference");
2011+ eprintln!(
2012+ "cdfflake MISMATCH seed={seed}: pinned stream + ffmpeg reference to {sp}"
2013+ );
1952 }2014 }
1953 for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {2015 for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
1954 assert_eq!(got.y, want.y, "frame {i} luma vs ffmpeg (seed {seed})");2016 assert_eq!(got.y, want.y, "frame {i} luma vs ffmpeg (seed {seed})");