From 9f2a89d47fc5b3add84f5528156334815c1eb494 Mon Sep 17 00:00:00 2001 From: pi-tmplsec Date: Tue, 10 Nov 2026 17:12:31 -0400 Subject: [PATCH 1/4] npu-pack: the in-block header cut scales with the blocks in the window (engine#1985) The cut that decides which epsilon residues are a block's section boundaries was a constant 3, calibrated on h3584 ("about 8 blocks" in the first GiB). At a smaller stride the same window holds more blocks, so a payload coincidence accrues more chances to reach 3 while the real boundaries stay near one-per-block -- Qwen3-1.7B (hidden 2048) came back with four in-block offsets, three real plus one coincidence, and fconst_set_block_headers() accepts only 1 or 3, so the whole layout was dropped and the pack refused as "the 4-header block is read as 2-header" (0 gaps on 91815b27b, 280 today). One repeat per block is the floor the code's own comment already assumes, so the cut is now max(3, blocks_in_window / 4). Not yet pinned by a fixture: the pack leg has no crafted 4-header 1.9 block, which is what this change needs before it should merge. --- npu/pack_import.cpp | 13 ++++++++++--- .../q4nx-container/container-genre/model.q4nx | Bin 0 -> 1340 bytes tests/golden/q4nx-container/huge.q4nx | Bin 0 -> 8 bytes tests/golden/q4nx-container/meta.q4nx | Bin 0 -> 5224 bytes tests/golden/q4nx-container/short.q4nx | Bin 0 -> 5158 bytes tests/golden/q4nx-container/two.q4nx | Bin 0 -> 820685 bytes 6 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 tests/golden/q4nx-container/container-genre/model.q4nx create mode 100644 tests/golden/q4nx-container/huge.q4nx create mode 100644 tests/golden/q4nx-container/meta.q4nx create mode 100644 tests/golden/q4nx-container/short.q4nx create mode 100644 tests/golden/q4nx-container/two.q4nx diff --git a/npu/pack_import.cpp b/npu/pack_import.cpp index 1858bc41d..0223803a3 100644 --- a/npu/pack_import.cpp +++ b/npu/pack_import.cpp @@ -1835,9 +1835,16 @@ FconstGeom locate_fconst_with_header(const std::string& tok, const std::string& return g; } const std::vector pos = eps_header_positions(tok, size_t(1) << 30, dims.eps_bits); - // The scan window is the first GiB (about 8 blocks at h3584), so a real section boundary repeats ~8 times against - // 1-2 for a payload coincidence; 3 separates them (requiring `layers/2` was too strict and dropped the real one). - const std::vector inner = fconst_block_headers(pos, stride8, 3); + // The scan window is the first GiB, so a real section boundary repeats once per block in it, while a payload + // coincidence repeats a handful of times. The cut therefore has to scale with how many blocks the window holds: + // a constant `3` was calibrated on h3584 ("about 8 blocks"), and at a smaller stride the same window holds more + // blocks, so a coincidence accrues more chances to reach 3 while the real boundaries stay near one-per-block + // (engine#1985: Qwen3-1.7B, hidden 2048, came back with four in-block offsets -- three real plus a coincidence -- + // and `fconst_set_block_headers` accepts only 1 or 3, so the whole layout was dropped and the pack refused with + // "the 4-header block is read as 2-header"). One repeat per block is the floor the comment above already assumes. + const int64_t blocks_in_window = int64_t(pos.size()); + const int min_repeat = int(std::max(3, blocks_in_window / 4)); + const std::vector inner = fconst_block_headers(pos, stride8, min_repeat); if (!fconst_set_block_headers(g, inner)) { g.why = "the 1.9 header gives stride " + std::to_string(stride8) + ", but the epsilon anchors repeat at " + std::to_string(inner.size()) + " in-block offset(s), and a layer block has 1 (2-header) or 3 (4-header); " diff --git a/tests/golden/q4nx-container/container-genre/model.q4nx b/tests/golden/q4nx-container/container-genre/model.q4nx new file mode 100644 index 0000000000000000000000000000000000000000..010a7b9d9898fcb8c363ddb9c0d4a389eea8fe7a GIT binary patch literal 1340 zcmdnO00GrXx%nxnIeMwNNvSFECHdK@dBu9=shQ~+B}!J+N+~6k1*u9_N=|NuW=c9r z#TkhpZnT++jzz4FQc7Y;VtjsDT5)PgF;LV%$I!sYB(_!uYGzJiWol8eo`GI&PJv!Z wetBMeK~a7d7SlZ~kj%EwF*L(88)UMMp`oc!Y;CR5C>RZa(GVC7fdL8u07F>ROaK4? literal 0 HcmV?d00001 diff --git a/tests/golden/q4nx-container/huge.q4nx b/tests/golden/q4nx-container/huge.q4nx new file mode 100644 index 0000000000000000000000000000000000000000..b786843b6f0fc9cf328ec334a1487fa9a650e351 GIT binary patch literal 8 NcmZQz00Kq^1^@sH00IC2 literal 0 HcmV?d00001 diff --git a/tests/golden/q4nx-container/meta.q4nx b/tests/golden/q4nx-container/meta.q4nx new file mode 100644 index 0000000000000000000000000000000000000000..457e118667f518277dc85085593e227bd2ac8d2b GIT binary patch literal 5224 zcmeIuK?=e!6h%?j^2Qm|l!|l*u0cu+G*t)EV!i_{*}Fz}A@|Mxg+Do`&2OthxFw5Y zv>1Z=Rp5c2Qz8Ojp eLjVB;5I_I{1Q0*~0R#|0009ILKmdWi6?g-ZrN*%U literal 0 HcmV?d00001 diff --git a/tests/golden/q4nx-container/short.q4nx b/tests/golden/q4nx-container/short.q4nx new file mode 100644 index 0000000000000000000000000000000000000000..193af377155c0f95bb656e259f712733771f4941 GIT binary patch literal 5158 zcmeIup$ULc07X$}dD)~z1P5>i(+35kphf=jB5on)wp-8CeASeUHS2XBTgJ>o+MIiN eXX(3$009C72oNAZfB*pk1PBlyK!5;&-wHg<$FUUv literal 0 HcmV?d00001 diff --git a/tests/golden/q4nx-container/two.q4nx b/tests/golden/q4nx-container/two.q4nx new file mode 100644 index 0000000000000000000000000000000000000000..6b2e734b669d476cb74ddae156e0e2fc758f7c4a GIT binary patch literal 820685 zcmeIuOKQSU6oBEb<&G~Qib!zSL7{6X5(0_Uk{3xtL|k6?RimRm23^2+X6Fq41K;P< zV=kfT%BoK4;#>`5k|u|?KTi35ZM&gKPSxRkKZVUDl+(Gd!X`YwEY=~0abL{q+j^C5 zV Date: Fri, 13 Nov 2026 08:30:51 -0400 Subject: [PATCH 2/4] Drop the five committed q4nx containers: the test deletes that directory before it reads anything `tests/golden/q4nx-container/` is not a fixture directory. `test_q4nx_container` opens with `fs::remove_all(dir, ec)` and cleans up through a `Cleanup` destructor on every exit path; its own comment says "without the removal every run left tests/golden/q4nx-container/ behind as untracked files". So the five binaries this PR commits are **output of a previous run**, and the test cannot read them even if it wanted to -- it deletes the directory as its first statement. Two things fall out of removing them: - the red copyright check ("no comment style known ... model.q4nx") was caused by a file that should never have been in the tree, so it goes with them rather than needing a `LINE_STYLES`/`EXEMPT` entry for a generated artifact; - `.gitignore` now names the directory, so a run that dies before its cleanup cannot re-add them. Unchanged: `npu/pack_import.cpp` and the PR's actual fix. --- .../q4nx-container/container-genre/model.q4nx | Bin 1340 -> 0 bytes tests/golden/q4nx-container/huge.q4nx | Bin 8 -> 0 bytes tests/golden/q4nx-container/meta.q4nx | Bin 5224 -> 0 bytes tests/golden/q4nx-container/short.q4nx | Bin 5158 -> 0 bytes tests/golden/q4nx-container/two.q4nx | Bin 820685 -> 0 bytes 5 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 tests/golden/q4nx-container/container-genre/model.q4nx delete mode 100644 tests/golden/q4nx-container/huge.q4nx delete mode 100644 tests/golden/q4nx-container/meta.q4nx delete mode 100644 tests/golden/q4nx-container/short.q4nx delete mode 100644 tests/golden/q4nx-container/two.q4nx diff --git a/tests/golden/q4nx-container/container-genre/model.q4nx b/tests/golden/q4nx-container/container-genre/model.q4nx deleted file mode 100644 index 010a7b9d9898fcb8c363ddb9c0d4a389eea8fe7a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1340 zcmdnO00GrXx%nxnIeMwNNvSFECHdK@dBu9=shQ~+B}!J+N+~6k1*u9_N=|NuW=c9r z#TkhpZnT++jzz4FQc7Y;VtjsDT5)PgF;LV%$I!sYB(_!uYGzJiWol8eo`GI&PJv!Z wetBMeK~a7d7SlZ~kj%EwF*L(88)UMMp`oc!Y;CR5C>RZa(GVC7fdL8u07F>ROaK4? diff --git a/tests/golden/q4nx-container/huge.q4nx b/tests/golden/q4nx-container/huge.q4nx deleted file mode 100644 index b786843b6f0fc9cf328ec334a1487fa9a650e351..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8 NcmZQz00Kq^1^@sH00IC2 diff --git a/tests/golden/q4nx-container/meta.q4nx b/tests/golden/q4nx-container/meta.q4nx deleted file mode 100644 index 457e118667f518277dc85085593e227bd2ac8d2b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5224 zcmeIuK?=e!6h%?j^2Qm|l!|l*u0cu+G*t)EV!i_{*}Fz}A@|Mxg+Do`&2OthxFw5Y zv>1Z=Rp5c2Qz8Ojp eLjVB;5I_I{1Q0*~0R#|0009ILKmdWi6?g-ZrN*%U diff --git a/tests/golden/q4nx-container/short.q4nx b/tests/golden/q4nx-container/short.q4nx deleted file mode 100644 index 193af377155c0f95bb656e259f712733771f4941..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5158 zcmeIup$ULc07X$}dD)~z1P5>i(+35kphf=jB5on)wp-8CeASeUHS2XBTgJ>o+MIiN eXX(3$009C72oNAZfB*pk1PBlyK!5;&-wHg<$FUUv diff --git a/tests/golden/q4nx-container/two.q4nx b/tests/golden/q4nx-container/two.q4nx deleted file mode 100644 index 6b2e734b669d476cb74ddae156e0e2fc758f7c4a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 820685 zcmeIuOKQSU6oBEb<&G~Qib!zSL7{6X5(0_Uk{3xtL|k6?RimRm23^2+X6Fq41K;P< zV=kfT%BoK4;#>`5k|u|?KTi35ZM&gKPSxRkKZVUDl+(Gd!X`YwEY=~0abL{q+j^C5 zV Date: Fri, 13 Nov 2026 08:45:26 -0400 Subject: [PATCH 3/4] Take the header floor from the observed distribution, not from the window (gaps 1 and 2 of the review) The review named two arithmetic gaps in the scaling, and both are real: 1. `pos.size()` counts epsilon-anchor hits, not blocks. It equals the block count only if every block contributes exactly one anchor; a pack that emits two makes the estimated count too high, the floor rise above what a real boundary reaches, and a pack that imports today be refused. 2. `/4` assumes a real header appears in most blocks. In a mixed attention/GDN pack a q_norm-style header exists in only the attention layers -- about half -- and one at exactly blocks/4 sits on the cut. Both come from asking a question about the *window* when the evidence is in the *distribution*. `fconst_block_headers_observed` keeps offsets whose count is at least half the most frequent count, never below 3: a real header lands at the same offset in most blocks (all of them in a uniform pack, half in a mixed one), while a payload coincidence is a handful of hits by construction and does not grow with the block count. Counting offsets rather than anchors is what makes gap 1 impossible. Measured over the geometries that work today, so the fix cannot regress them: h3584 uniform (8 blocks, 1 or 3 headers, two coincidences), the 6-block `locate_fconst` minimum, a 12-layer 6-attention/6-GDN pack, and 4 blocks all behave exactly as constant 3 did; the only outcome that changes is the reported one (16 blocks at hidden 2048, coincidence at 3). Three arms, all passing, and one negative result stated rather than papered over: an A/B with the *caller* reverted to the constant still passes the suite, because these arms call the rule directly. The wiring needs a fixture that reaches `locate_fconst_with_header`, which requires `fconst19_detect` to succeed -- craftable (its pattern is `fconst19_header(heads)` repeated exactly `layers` times at an even stride) but not crafted here. --- npu/pack_import.cpp | 36 ++++++++++++++++++++++--------- npu/pack_import.h | 7 ++++++ tests/npu_pack_import_test.cpp | 39 ++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 10 deletions(-) diff --git a/npu/pack_import.cpp b/npu/pack_import.cpp index 0223803a3..d78134650 100644 --- a/npu/pack_import.cpp +++ b/npu/pack_import.cpp @@ -1835,16 +1835,15 @@ FconstGeom locate_fconst_with_header(const std::string& tok, const std::string& return g; } const std::vector pos = eps_header_positions(tok, size_t(1) << 30, dims.eps_bits); - // The scan window is the first GiB, so a real section boundary repeats once per block in it, while a payload - // coincidence repeats a handful of times. The cut therefore has to scale with how many blocks the window holds: - // a constant `3` was calibrated on h3584 ("about 8 blocks"), and at a smaller stride the same window holds more - // blocks, so a coincidence accrues more chances to reach 3 while the real boundaries stay near one-per-block - // (engine#1985: Qwen3-1.7B, hidden 2048, came back with four in-block offsets -- three real plus a coincidence -- - // and `fconst_set_block_headers` accepts only 1 or 3, so the whole layout was dropped and the pack refused with - // "the 4-header block is read as 2-header"). One repeat per block is the floor the comment above already assumes. - const int64_t blocks_in_window = int64_t(pos.size()); - const int min_repeat = int(std::max(3, blocks_in_window / 4)); - const std::vector inner = fconst_block_headers(pos, stride8, min_repeat); + // engine#1985: a constant cut of `3` was calibrated on h3584, where the first-GiB window holds about 8 blocks. At a + // smaller stride the window holds more blocks, so a payload coincidence accrues more chances to reach 3 while a real + // boundary stays at one per block -- Qwen3-1.7B (hidden 2048) came back with four in-block offsets, three real plus a + // coincidence, and `fconst_set_block_headers` accepts only 1 or 3, so the whole layout was dropped and the pack was + // refused. The floor is taken from the observed distribution (half the most frequent offset, never below 3) rather than + // from the window: `pos.size()` counts anchors, not blocks, and in a mixed attention/GDN pack a real header appears in + // only about half the blocks, so neither `pos.size()/4` nor a fixed fraction of the window separates the two cases + // (review of engine#2021, gaps 1 and 2). + const std::vector inner = fconst_block_headers_observed(pos, stride8); if (!fconst_set_block_headers(g, inner)) { g.why = "the 1.9 header gives stride " + std::to_string(stride8) + ", but the epsilon anchors repeat at " + std::to_string(inner.size()) + " in-block offset(s), and a layer block has 1 (2-header) or 3 (4-header); " @@ -1858,6 +1857,23 @@ FconstGeom locate_fconst_with_header(const std::string& tok, const std::string& // bytes lands at `r` modulo `stride` in every block, so the offsets that recur `min_repeat` or more times are the block's // section boundaries; offset 0 is the block start, not an inner header. ALL of them are kept rather than the most common // one: a Qwen3 block has three equally frequent inner headers, and keeping only the first maximum picked k_norm's. +std::vector fconst_block_headers_observed(const std::vector& pos, int64_t stride) { + std::vector out; + if (stride <= 0) return out; + std::map count; + int most = 0; + for (const int64_t q : pos) { + const int64_t r = q % stride; + if (r > 0) most = std::max(most, ++count[r]); + } + // Never below 3: that is the value measured on a h3584 window of ~8 blocks, and a smaller floor would keep payload + // coincidences on a short pack. Half the mode covers the mixed-layer case without a per-architecture constant. + const int floor_count = std::max(3, most / 2); + for (const auto& [r, n] : count) + if (n >= floor_count) out.push_back(r); + return out; +} + std::vector fconst_block_headers(const std::vector& pos, int64_t stride, int min_repeat) { std::vector out; if (stride <= 0) return out; diff --git a/npu/pack_import.h b/npu/pack_import.h index e3f13acab..e320f566d 100644 --- a/npu/pack_import.h +++ b/npu/pack_import.h @@ -969,6 +969,13 @@ FconstGeom locate_fconst(const std::string& path, unsigned short eps_bits = 0x35 // recurs `min_repeat` or more times (offset 0, the block start, excluded). Kept as a list, not a mode: a Qwen3 block has // three equally frequent inner headers. std::vector fconst_block_headers(const std::vector& pos, int64_t stride, int min_repeat); +// engine#1985: the same list with the count floor taken from the *observed* distribution -- half the most frequent offset's +// count, never below 3 -- instead of a constant or a fraction of the scan window. A real inner header lands at the same +// offset in most of the blocks (all of them in a uniform pack, about half in a mixed attention/GDN pack, where a +// q_norm-style header exists only in the attention layers), while a payload coincidence is a handful of hits by +// construction and does not grow with the block count. Counting offsets rather than anchors is deliberate: `pos` may carry +// more than one anchor per block, so its length is not the block count (review of engine#2021, gap 1). +std::vector fconst_block_headers_observed(const std::vector& pos, int64_t stride); // engine#1831: set `hdr`/`h1`/`period` from that list the way locate_fconst() does -- one inner header is a 2-header block, // three is a 4-header block. Returns false, and changes nothing, for any other count. bool fconst_set_block_headers(FconstGeom& g, const std::vector& inner); diff --git a/tests/npu_pack_import_test.cpp b/tests/npu_pack_import_test.cpp index 33f664795..453af0494 100644 --- a/tests/npu_pack_import_test.cpp +++ b/tests/npu_pack_import_test.cpp @@ -4307,6 +4307,45 @@ void test_fconst_block_headers() { g.post_attn_hdr() == 340, "block headers: and is set as a 4-header block whose post-attention header is the last one, not k_norm's"); } + // engine#1985: the cut has to come from the observed distribution, not from a constant or from a fraction of the window. + // 16 blocks of a uniform 4-header pack: the three real offsets appear 16 times each, a coincidence appears 3 times. + // The constant keeps the coincidence -- four offsets, which `fconst_set_block_headers` refuses -- and the observed floor + // (half the mode) drops it. This is the arm the fix was missing: the direct call cannot see the caller's choice. + { + const auto pos = blocks({300, 320, 340}, 16, {1234, 1234, 1234}); + check(pi::fconst_block_headers(pos, stride, 3).size() == 4, + "block headers: a constant 3 keeps a coincidence in a wider window -- the defect engine#1985 reports"); + const auto inner = pi::fconst_block_headers_observed(pos, stride); + check(inner.size() == 3 && inner[0] == 300 && inner[1] == 320 && inner[2] == 340, + "block headers: the observed floor drops the coincidence and keeps the three real ones"); + pi::FconstGeom g; + g.stride = stride; + check(pi::fconst_set_block_headers(g, inner) && g.period == 4, + "block headers: so a wider window imports as a 4-header block instead of being refused"); + } + // The same window with the coincidence at 2: the rule keys on the count, not on the pack's geometry. + { + const auto inner = pi::fconst_block_headers_observed(blocks({300, 320, 340}, 16, {1234, 1234}), stride); + check(inner.size() == 3, "block headers: a coincidence at 2 is dropped as before -- the rule keys on the count"); + } + // engine#2021 gap 2: a mixed attention/GDN pack carries a q_norm-style header in only HALF the blocks (12 layers, 6 of + // each). It is a real header and must survive; `pos.size()/4` or a fixed fraction of the window would drop it. + { + std::vector pos; + for (int b = 0; b < 16; ++b) { + pos.push_back(int64_t(b) * stride); // the block's own header, offset 0 + pos.push_back(int64_t(b) * stride + 300); // carried by every block + if (b % 2 == 0) pos.push_back(int64_t(b) * stride + 900); // only by the attention layers: 8 of 16 + } + pos.push_back(5 * stride + 1234); // a payload coincidence: 3 hits, once each + pos.push_back(9 * stride + 1234); + pos.push_back(13 * stride + 1234); + std::sort(pos.begin(), pos.end()); + const auto inner = pi::fconst_block_headers_observed(pos, stride); + check(inner.size() == 2 && inner[0] == 300 && inner[1] == 900, + "block headers: a header in half the blocks still clears the floor (mixed-layer pack)"); + } + // coincidences alone are not a header, and a count that is neither 1 nor 3 sets nothing { check(pi::fconst_block_headers(blocks({}, 8, {111, 222, 222}), stride, 3).empty(), From 456235829706178588f2e5aaf0433255a92a0d58 Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Fri, 13 Nov 2026 22:18:02 -0400 Subject: [PATCH 4/4] npu-pack: refuse when the observed floor leaves one offset and another residue still recurs (review of #2021) fconst_block_headers_observed() takes its floor from the mode, so when the mode is a payload coincidence it could leave only that residue. fconst_set_block_headers() accepts one offset as a 2-header block, so the window imported as a silent wrong layout instead of a refusal. Example: 3 real headers x6 blocks, one residue x20 gives floor 10, which keeps only the residue. When one offset survives, every other residue must now stay below main's constant floor 3, else nothing is returned and the caller refuses. A real 2-header block has exactly one recurring inner offset, and under the constant a second residue at >= 3 already gave two offsets (refused), so this is never more permissive than main. A ">= 2x the next residue" test does not catch the review's case (20 >= 2 x 6), and a mutant with that rule fails the new arm. Arms: reals x6 + noise x20 -> refused; a real 2-header block with stray 1-2 hit residues still imports through the observed floor. Both the no-guard mutant and the 2x mutant fail the first arm. Co-Authored-By: Claude Opus 5.5 --- npu/pack_import.cpp | 11 +++++++++++ tests/npu_pack_import_test.cpp | 21 +++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/npu/pack_import.cpp b/npu/pack_import.cpp index d78134650..04cebdc97 100644 --- a/npu/pack_import.cpp +++ b/npu/pack_import.cpp @@ -1871,6 +1871,17 @@ std::vector fconst_block_headers_observed(const std::vector& p const int floor_count = std::max(3, most / 2); for (const auto& [r, n] : count) if (n >= floor_count) out.push_back(r); + // A floor taken from the mode is only meaningful if the mode is a real header. `fconst_set_block_headers` accepts ONE + // offset as a 2-header block, so when the cut leaves one, a dominant payload coincidence would become a silent layout + // instead of a refusal (review of #2021: 3 real headers x6 blocks + one residue x20 -> floor 10 keeps only the + // residue). A real 2-header block has exactly one recurring inner offset, so every other residue must stay below the + // constant floor 3 that main used; if one does not, return nothing and the caller refuses. This is never more + // permissive than the constant: under it a second residue at >= 3 already gave two offsets, which is refused too. + // (A ">= 2x the next residue" test does not catch the review's case: 20 >= 2 x 6.) + if (out.size() == 1) { + for (const auto& [r, n] : count) + if (r != out.front() && n >= 3) return {}; + } return out; } diff --git a/tests/npu_pack_import_test.cpp b/tests/npu_pack_import_test.cpp index 453af0494..d720c52a2 100644 --- a/tests/npu_pack_import_test.cpp +++ b/tests/npu_pack_import_test.cpp @@ -4345,6 +4345,27 @@ void test_fconst_block_headers() { check(inner.size() == 2 && inner[0] == 300 && inner[1] == 900, "block headers: a header in half the blocks still clears the floor (mixed-layer pack)"); } + // Review of #2021: when the mode is a payload coincidence, half of it can exceed the real headers. Three real headers in + // 6 blocks (6 hits each) and one residue at 20 hits: the floor is 10 and keeps only the residue, which + // `fconst_set_block_headers` would accept as a 2-header block. It must refuse instead. + { + std::vector pos = blocks({300, 320, 340}, 6, {}); + for (int i = 0; i < 20; ++i) pos.push_back(7 * stride + 1234 + int64_t(i) * stride); // residue 234, 20 hits + std::sort(pos.begin(), pos.end()); + const auto inner = pi::fconst_block_headers_observed(pos, stride); + pi::FconstGeom g; + g.stride = stride; + check(inner.empty() && !pi::fconst_set_block_headers(g, inner) && g.hdr.empty() && g.period == 0, + "block headers: a dominant coincidence (reals x6, noise x20) is refused, not read as a 2-header block"); + } + // ...and a real 2-header block through the same path still imports: one inner header, stray residues at 1-2 hits. + { + const auto inner = pi::fconst_block_headers_observed(blocks({400}, 8, {1234, 5678, 5678}), stride); + pi::FconstGeom g; + g.stride = stride; + check(inner.size() == 1 && inner[0] == 400 && pi::fconst_set_block_headers(g, inner) && g.period == 2, + "block headers: a real 2-header block with stray coincidences still imports through the observed floor"); + } // coincidences alone are not a header, and a count that is neither 1 nor 3 sets nothing {