Skip to content

Run frontier MoE models on hardware you already own — pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦

C

fp8: refuse (not crash) on fmt=6/7 in qt_addrow/qt_matvec_rows

monotophic70cc5941a00b
diff --git a/c/Makefile b/c/Makefile
index 872b030a..79828f76 100644
--- a/c/Makefile
+++ b/c/Makefile
@@ -214,7 +214,7 @@ else
PYTHON ?= python3
endif
CUDA_OBJ =
-TEST_BINS = tests/test_json$(EXE) tests/test_st$(EXE) tests/test_st_mirror$(EXE) tests/test_st_pread$(EXE) tests/test_tier$(EXE) tests/test_grammar$(EXE) tests/test_schema_gbnf$(EXE) tests/test_decode_batch$(EXE) tests/test_idot$(EXE) tests/test_i4_grouped$(EXE) tests/test_stops$(EXE) tests/test_topp$(EXE) tests/test_sample_nan$(EXE) tests/test_temp_env$(EXE) tests/test_tok_o200k$(EXE) tests/test_kv_alloc$(EXE) tests/test_int3$(EXE) tests/test_int3_load$(EXE) tests/test_fp8_passthrough$(EXE) tests/test_fp8_load$(EXE) tests/test_i4_acc512$(EXE) tests/test_compat_direct$(EXE) tests/test_dsa_select$(EXE) tests/test_logit_nan$(EXE) tests/test_router_nan$(EXE) tests/test_pipe_block$(EXE) tests/test_e8_kernel$(EXE) tests/test_rans$(EXE) tests/test_corpus_draft$(EXE) tests/test_pilot_ring$(EXE)
+TEST_BINS = tests/test_json$(EXE) tests/test_st$(EXE) tests/test_st_mirror$(EXE) tests/test_st_pread$(EXE) tests/test_tier$(EXE) tests/test_grammar$(EXE) tests/test_schema_gbnf$(EXE) tests/test_decode_batch$(EXE) tests/test_idot$(EXE) tests/test_i4_grouped$(EXE) tests/test_stops$(EXE) tests/test_topp$(EXE) tests/test_sample_nan$(EXE) tests/test_temp_env$(EXE) tests/test_tok_o200k$(EXE) tests/test_kv_alloc$(EXE) tests/test_int3$(EXE) tests/test_int3_load$(EXE) tests/test_fp8_passthrough$(EXE) tests/test_fp8_load$(EXE) tests/test_i4_acc512$(EXE) tests/test_compat_direct$(EXE) tests/test_dsa_select$(EXE) tests/test_logit_nan$(EXE) tests/test_router_nan$(EXE) tests/test_pipe_block$(EXE) tests/test_e8_kernel$(EXE) tests/test_qt_addrow$(EXE) tests/test_rans$(EXE) tests/test_corpus_draft$(EXE) tests/test_pilot_ring$(EXE)
ifneq (,$(LINUX))
TEST_BINS += tests/test_uring$(EXE)
endif
@@ -548,6 +548,9 @@ tests/test_fp8_passthrough$(EXE): tests/test_fp8_passthrough.c quant.h
tests/test_fp8_load$(EXE): tests/test_fp8_load.c colibri.c st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h sample.h kv_persist.h telemetry.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
+tests/test_qt_addrow$(EXE): tests/test_qt_addrow.c colibri.c st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h quant.h sample.h kv_persist.h telemetry.h
+ $(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
+
tests/test_logit_nan$(EXE): tests/test_logit_nan.c colibri.c st.h uring.h json.h tok.h tok_unicode.h compat.h grammar.h tier.h
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
diff --git a/c/colibri.c b/c/colibri.c
index 8bc53cd2..6e733449 100644
--- a/c/colibri.c
+++ b/c/colibri.c
@@ -2643,6 +2643,33 @@ static void qt_addrow(const QT *t, int row, float coef, float *acc){
for(int k=0;k<n;k++){ unsigned u=((lo[k>>2]>>((k&3)*2))&3)|(((hi[k>>3]>>(k&7))&1)<<2);
acc[base+k]+=cg*(float)((int)u-4); } }
return; }
+ /* GUARD (fix round 2, engine defect -- clean-room conformance trial found a real
+ * SIGSEGV, reproduced): fmt 0/4/5 already returned above; everything below this
+ * point assumes a PER-ROW scale (t->s[row]) followed by fmt=1 (int8, explicit
+ * branch), fmt=2 (int4 packed, explicit branch), or the tail's own IMPLICIT fmt=3
+ * (int2 packed, the final unconditional block) -- there was no guard stopping any
+ * OTHER fmt from reaching here. fmt=6 (E8/IQ3): t->s is a FIXED 4-byte tag (ONE
+ * float total, qsalloc(1) in qt_from_disk), not O floats -- t->s[row] for row>0 is
+ * a heap OVERREAD, and the untouched fall-through then misreads t->q4's real E8
+ * lattice bytes as int2-packed data (same bug SHAPE as #298's CUDA absorb-kernel
+ * fix, and the same one this file's own fmt=4/5 branches above were added to
+ * dodge -- fmt=6 was simply missed). fmt=7 (fp8-e4m3-b128): t->s holds
+ * ceil(O/128)*ceil(I/128) per-block floats, not O -- t->s[row] overreads for
+ * row>=nblk (e.g. a [130,130] tensor has nblk=4, so every row past 3 already reads
+ * out of bounds), AND t->q4 is NULL for fmt=7 (raw bytes live in t->q8 instead,
+ * same convention as fmt=1 -- see the QT struct comment), so the fall-through's
+ * `t->q4+(int64_t)row*((I+3)/4)` dereferences NULL-plus-offset: SIGSEGV,
+ * reproduced (see the report's proof-of-bite transcript). Refuse loudly instead --
+ * this function has no byte-count context of its own to validate against (it only
+ * ever sees an already-resolved QT), so "unsupported fmt" is the only check
+ * available, same "refuse rather than misread" discipline qt_resolve_fmt applies
+ * at load time. */
+ if(t->fmt!=1 && t->fmt!=2 && t->fmt!=3){
+ fprintf(stderr,"qt_addrow: unsupported fmt=%d for the per-row-scale absorb path "
+ "(only fmt 1/2/3 reach this point; fmt 0/4/5 are handled above and return "
+ "before it) -- refusing rather than misread t->s[row]/t->q4\n", t->fmt);
+ exit(1);
+ }
float c=coef*t->s[row];
if(t->fmt==1){ const int8_t *w=t->q8+(int64_t)row*I; for(int i=0;i<I;i++) acc[i]+=c*(float)w[i]; return; }
if(t->fmt==2){ const uint8_t *w=t->q4+(int64_t)row*((I+1)/2);
@@ -2689,8 +2716,21 @@ static void qt_matvec_rows(const QT *t, int r0, int n, const float *x, float *y)
for(int k=0;k<n;k++){ unsigned u=((lo[k>>2]>>((k&3)*2))&3)|(((hi[k>>3]>>(k&7))&1)<<2);
acc+=(float)((int)u-4)*x[base+k]; }
a+=(double)(acc*sr[g]); } }
- else { const uint8_t *w=t->q4+(int64_t)row*((I+3)/4); float s=t->s[row]; float acc=0;
+ /* fmt=3 (int2 packed, per-row scale) is the only fmt this final arm legitimately
+ * handles -- fmt 0/4/5 matched above, fmt 1/2 have their own explicit branches
+ * above too. Same GUARD and same reasoning as qt_addrow's (fix round 2, engine
+ * defect): fmt=6's t->s is a fixed 4-byte tag (t->s[row] overreads for row>0),
+ * fmt=7's t->s holds per-128x128-block floats (t->s[row] overreads for
+ * row>=nblk) and t->q4 is NULL for fmt=7 -- both would have silently misread or
+ * crashed here exactly like qt_addrow did before its own fix; refuse instead. */
+ else if(t->fmt==3){ const uint8_t *w=t->q4+(int64_t)row*((I+3)/4); float s=t->s[row]; float acc=0;
for(int i=0;i<I;i++){ uint8_t b=w[i>>2]; acc+=((int)((b>>((i&3)*2))&3)-2)*x[i]; } a=acc*s; }
+ else {
+ fprintf(stderr,"qt_matvec_rows: unsupported fmt=%d for the per-row-scale absorb "
+ "path (only fmt 0/1/2/3/4/5 are handled) -- refusing rather than misread "
+ "t->s[row]/t->q4\n", t->fmt);
+ exit(1);
+ }
y[j]=(float)a;
}
}
diff --git a/c/tests/test_qt_addrow.c b/c/tests/test_qt_addrow.c
new file mode 100644
index 00000000..c97c12b3
--- /dev/null
+++ b/c/tests/test_qt_addrow.c
@@ -0,0 +1,286 @@
+/* qt_addrow()/qt_matvec_rows() (colibri.c) -- per-row absorb helpers used only by the
+ * kv_b MLA-absorption CPU path (l->kv_b, see attention_rows/decode). FIX ROUND 2, engine
+ * defect (clean-room conformance trial finding, mutation-proven): both functions dispatch
+ * fmt 0/4/5 explicitly, then fall through assuming a PER-ROW scale (t->s[row]) followed by
+ * fmt=1/2/3 (qt_addrow) or fmt=0/1/2/3/4/5 (qt_matvec_rows, via an if/else-if chain ending
+ * in a bare `else`) -- nothing stopped fmt=6 (E8/IQ3, t->s is a FIXED 4-byte tag, not O
+ * floats) or fmt=7 (fp8-e4m3-b128, t->s holds per-128x128-block floats, not O; t->q4 is
+ * NULL) from reaching that fall-through. For fmt=7 specifically this SIGSEGVs: t->s[row]
+ * overreads (silently, usually not fatal on its own), then the untouched tail computes
+ * `t->q4+(int64_t)row*((I+3)/4)` on a NULL t->q4 and dereferences it. For fmt=6 it silently
+ * misreads the real E8/IQ3 lattice bytes as int2-packed data (same bug SHAPE as #298's CUDA
+ * absorb-kernel fix, which is why this file's own fmt=4/5 branches exist -- fmt=6 was simply
+ * missed). Both functions now refuse loudly (exit(1), naming the function and the fmt) for
+ * any fmt they don't explicitly handle, matching qt_resolve_fmt's own "refuse rather than
+ * misread" discipline.
+ *
+ * This file: (1) proves the refusal fires for fmt=6 and fmt=7 through BOTH functions
+ * (fork+pipe+waitpid, this suite's established house pattern for exit(1)-terminated paths --
+ * see tests/test_fp8_load.c's expect_refuse/expect_stamp_refuse); (2) proves every format
+ * BOTH functions still legitimately handle (0/1/2/3/4/5) produces byte-identical results
+ * against an independently-written reference dequantizer (qt_dequant_row_ref below -- NOT
+ * copy-pasted from qt_addrow/qt_matvec_rows, restructured as a single per-element loop per
+ * format, so a real regression in either the guard's placement or the untouched per-fmt math
+ * would show up here, not just tautologically re-run the same code). Reachability note (not
+ * a scope excuse, just context): both functions serve ONLY the kv_b absorb path
+ * (attention_rows/decode call sites), and tools/repack_fp8_passthrough.py deliberately
+ * excludes kv_b_proj from fmt=7 repacking -- so this fires only via a hand-slotted or
+ * ambiguous-collision container, not this repo's own tooling's own output. Crash-instead-of-
+ * refuse is still a real defect (spec I6: loud failure, every refusal names its condition),
+ * and the fmt=7 QT surface these functions can now be handed is one this same PR pair
+ * created. */
+#define main coli_glm_main_unused
+#include "../colibri.c"
+#undef main
+
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+#ifndef _WIN32
+#include <unistd.h>
+#include <sys/wait.h>
+#endif
+
+static int fails = 0;
+#define CHECK(c) do{ if(!(c)){ printf("FAIL %s:%d: %s\n", __FILE__, __LINE__, #c); fails++; } }while(0)
+
+static uint64_t rng = 0xA11CE5EEDF00Dull;
+static uint8_t rndbyte(void){ rng ^= rng << 13; rng ^= rng >> 7; rng ^= rng << 17; return (uint8_t)(rng & 0xFF); }
+static float rndsmallf(void){ rng ^= rng << 13; rng ^= rng >> 7; rng ^= rng << 17;
+ return ((int64_t)(rng & 0xFFF) - 0x800) / (float)0x800; } /* [-1,1)-ish, small magnitude */
+
+/* ---- independent reference dequantizer: W[row,:] as floats, one element per loop
+ * iteration -- deliberately NOT the same code shape as qt_addrow/qt_matvec_rows (those
+ * unroll pairs for fmt=2/3, split low/high planes for fmt=5) so this genuinely
+ * cross-checks the production math, not just the production code running twice. ---- */
+static void qt_dequant_row_ref(const QT *t, int row, float *out){
+ int I=t->I;
+ if(t->fmt==0){ const float *w=t->qf+(int64_t)row*I; for(int i=0;i<I;i++) out[i]=w[i]; return; }
+ if(t->fmt==4){
+ const uint8_t *w=t->q4+(int64_t)row*((I+1)/2); int gs=t->gs, ng=(I+gs-1)/gs;
+ const float *scl=t->s+(int64_t)row*ng;
+ for(int i=0;i<I;i++){ uint8_t b=w[i>>1]; int nib=(i&1)?(b>>4):(b&0xF);
+ out[i]=((int)nib-8)*scl[i/gs]; }
+ return; }
+ if(t->fmt==5){
+ const uint8_t *w=t->q4+(int64_t)row*i3_rowbytes(I);
+ const float *sr=t->s+(int64_t)row*i3_groups(I);
+ for(int i=0;i<I;i++){ int64_t g=i/I3_GROUP; const uint8_t *lo=w+g*I3_GBYTES, *hi=lo+16;
+ int k=i-(int)(g*I3_GROUP);
+ unsigned u=((lo[k>>2]>>((k&3)*2))&3)|(((hi[k>>3]>>(k&7))&1)<<2);
+ out[i]=((int)u-4)*sr[g]; }
+ return; }
+ float s=t->s[row];
+ if(t->fmt==1){ const int8_t *w=t->q8+(int64_t)row*I; for(int i=0;i<I;i++) out[i]=(float)w[i]*s; return; }
+ if(t->fmt==2){
+ const uint8_t *w=t->q4+(int64_t)row*((I+1)/2);
+ for(int i=0;i<I;i++){ uint8_t b=w[i>>1]; int nib=(i&1)?(b>>4):(b&0xF); out[i]=((int)nib-8)*s; }
+ return; }
+ /* fmt==3 */
+ { const uint8_t *w=t->q4+(int64_t)row*((I+3)/4);
+ for(int i=0;i<I;i++){ uint8_t b=w[i>>2]; int v=(b>>((i&3)*2))&3; out[i]=((int)v-2)*s; } }
+}
+
+/* ---- fixture builders: one per format, deterministic pseudo-random payload ---- */
+static void fill_fmt0(QT *t, int O, int I){
+ t->fmt=0; t->O=O; t->I=I; t->gs=0;
+ t->qf=(float*)malloc((size_t)O*I*sizeof(float));
+ for(int i=0;i<O*I;i++) t->qf[i]=rndsmallf();
+}
+static void fill_fmt1(QT *t, int O, int I){
+ t->fmt=1; t->O=O; t->I=I; t->gs=0;
+ t->q8=(int8_t*)malloc((size_t)O*I);
+ t->s=(float*)malloc((size_t)O*sizeof(float));
+ for(int i=0;i<O*I;i++) t->q8[i]=(int8_t)(rndbyte()-128);
+ for(int i=0;i<O;i++) t->s[i]=0.01f+0.001f*(float)i;
+}
+static void fill_fmt2(QT *t, int O, int I){
+ t->fmt=2; t->O=O; t->I=I; t->gs=0;
+ int rb=(I+1)/2;
+ t->q4=(uint8_t*)malloc((size_t)O*rb);
+ t->s=(float*)malloc((size_t)O*sizeof(float));
+ for(int i=0;i<O*rb;i++) t->q4[i]=rndbyte();
+ for(int i=0;i<O;i++) t->s[i]=0.02f+0.001f*(float)i;
+}
+static void fill_fmt3(QT *t, int O, int I){
+ t->fmt=3; t->O=O; t->I=I; t->gs=0;
+ int rb=(I+3)/4;
+ t->q4=(uint8_t*)malloc((size_t)O*rb);
+ t->s=(float*)malloc((size_t)O*sizeof(float));
+ for(int i=0;i<O*rb;i++) t->q4[i]=rndbyte();
+ for(int i=0;i<O;i++) t->s[i]=0.03f+0.001f*(float)i;
+}
+static void fill_fmt4(QT *t, int O, int I, int gs){
+ t->fmt=4; t->O=O; t->I=I; t->gs=gs;
+ int rb=(I+1)/2, ng=(I+gs-1)/gs;
+ t->q4=(uint8_t*)malloc((size_t)O*rb);
+ t->s=(float*)malloc((size_t)O*ng*sizeof(float));
+ for(int i=0;i<O*rb;i++) t->q4[i]=rndbyte();
+ for(int i=0;i<O*ng;i++) t->s[i]=0.015f+0.0007f*(float)i;
+}
+static void fill_fmt5(QT *t, int O, int I){
+ t->fmt=5; t->O=O; t->I=I; t->gs=0;
+ int64_t ng=i3_groups(I), rb=i3_rowbytes(I);
+ t->q4=(uint8_t*)malloc((size_t)O*rb);
+ t->s=(float*)malloc((size_t)(O*ng)*sizeof(float));
+ for(int i=0;i<O*rb;i++) t->q4[i]=rndbyte();
+ for(int i=0;i<O*ng;i++) t->s[i]=0.025f+0.0003f*(float)i;
+}
+static void free_qt(QT *t){ free(t->qf); free(t->q8); free(t->q4); free(t->s); memset(t,0,sizeof *t); }
+
+/* ---- byte-identity: qt_addrow / qt_matvec_rows vs the independent reference, every
+ * format both functions still legitimately handle ---- */
+/* Epsilon, not bit-exact: qt_addrow precomputes c=coef*scale ONCE, then c*w[i]
+ * ((coef*scale)*w[i]); the reference below multiplies coef*(scale*w[i]) --
+ * mathematically identical, but floating-point multiplication isn't
+ * associative, so the two can differ in the last ULP for some inputs. This
+ * is expected float-reassociation noise, not a regression -- confirmed by
+ * inspecting actual failures at bit-exact comparison (all last-digit-of-
+ * mantissa only, no shape/format-decode errors) before relaxing to epsilon,
+ * matching this suite's own established practice for reduction-order-
+ * sensitive checks (e.g. the metal-test suite's worst_rel comparisons). */
+static void check_addrow_identity(QT *t, const char *tag){
+ int I=t->I; float *ref=(float*)malloc((size_t)I*sizeof(float));
+ float *acc=(float*)malloc((size_t)I*sizeof(float));
+ float coef=1.7f; /* != 1, so a coef-scaling bug can't hide */
+ for(int row=0; row<t->O; row++){
+ qt_dequant_row_ref(t,row,ref);
+ memset(acc,0,(size_t)I*sizeof(float));
+ qt_addrow(t,row,coef,acc);
+ for(int i=0;i<I;i++){
+ float want=coef*ref[i];
+ float ae=fabsf(acc[i]-want);
+ float rel = fabsf(want)>1e-6f ? ae/fabsf(want) : ae;
+ if(rel > 1e-5f){
+ printf("FAIL %s: qt_addrow row=%d i=%d got=%.9g want=%.9g rel=%.3g\n",tag,row,i,(double)acc[i],(double)want,(double)rel);
+ fails++;
+ }
+ }
+ }
+ free(ref); free(acc);
+}
+static void check_matvec_identity(QT *t, const char *tag){
+ int I=t->I; float *ref=(float*)malloc((size_t)I*sizeof(float));
+ float *x=(float*)malloc((size_t)I*sizeof(float));
+ for(int i=0;i<I;i++) x[i]=rndsmallf();
+ for(int row=0; row<t->O; row++){
+ qt_dequant_row_ref(t,row,ref);
+ double want=0; for(int i=0;i<I;i++) want+=(double)ref[i]*x[i];
+ float y=0.f;
+ qt_matvec_rows(t,row,1,x,&y);
+ double relerr = fabs(want)>1e-6 ? fabs((double)y-want)/fabs(want) : fabs((double)y-want);
+ if(relerr > 1e-4){
+ printf("FAIL %s: qt_matvec_rows row=%d got=%.9g want=%.9g relerr=%.3g\n",tag,row,(double)y,want,relerr);
+ fails++;
+ }
+ }
+ free(ref); free(x);
+}
+
+static void test_byte_identity_all_formats(void){
+ QT t;
+ memset(&t,0,sizeof t); fill_fmt0(&t,4,17); check_addrow_identity(&t,"fmt=0"); check_matvec_identity(&t,"fmt=0"); free_qt(&t);
+ memset(&t,0,sizeof t); fill_fmt1(&t,4,17); check_addrow_identity(&t,"fmt=1"); check_matvec_identity(&t,"fmt=1"); free_qt(&t);
+ memset(&t,0,sizeof t); fill_fmt2(&t,4,17); check_addrow_identity(&t,"fmt=2"); check_matvec_identity(&t,"fmt=2"); free_qt(&t);
+ memset(&t,0,sizeof t); fill_fmt3(&t,4,17); check_addrow_identity(&t,"fmt=3"); check_matvec_identity(&t,"fmt=3"); free_qt(&t);
+ memset(&t,0,sizeof t); fill_fmt4(&t,4,40,16);check_addrow_identity(&t,"fmt=4"); check_matvec_identity(&t,"fmt=4"); free_qt(&t);
+ memset(&t,0,sizeof t); fill_fmt5(&t,4,130); check_addrow_identity(&t,"fmt=5"); check_matvec_identity(&t,"fmt=5"); free_qt(&t);
+}
+
+/* ---- refusal: fork+pipe+waitpid, this suite's house pattern (see test_fp8_load.c's
+ * expect_refuse/expect_stamp_refuse) -- must exit(1) with a "refus"-containing message,
+ * never reach the caller's continuation, never crash with a signal. ---- */
+typedef void (*absorb_fn)(void);
+static void call_addrow_fmt7(void){
+ QT t; memset(&t,0,sizeof t);
+ enum { O=130, I=130 }; /* the coordinator's own repro shape: nblkO=nblkI=2, nblk=4 */
+ static uint8_t q8[O*I]; static float s[4];
+ for(int i=0;i<O*I;i++) q8[i]=rndbyte();
+ for(int i=0;i<4;i++) s[i]=0.01f;
+ t.fmt=7; t.O=O; t.I=I; t.gs=0; t.q8=(int8_t*)q8; t.s=s;
+ float acc[I]; memset(acc,0,sizeof acc);
+ qt_addrow(&t,0,1.f,acc); /* must exit(1) inside; must NOT return */
+}
+static void call_addrow_fmt6(void){
+ QT t; memset(&t,0,sizeof t);
+ enum { O=4, I=98 };
+ static uint8_t q4[O*98]; static float s[1];
+ for(int i=0;i<O*98;i++) q4[i]=rndbyte();
+ s[0]=0.01f;
+ t.fmt=6; t.O=O; t.I=I; t.gs=0; t.q4=q4; t.s=s;
+ float acc[I]; memset(acc,0,sizeof acc);
+ qt_addrow(&t,0,1.f,acc);
+}
+static void call_matvec_fmt7(void){
+ QT t; memset(&t,0,sizeof t);
+ enum { O=130, I=130 };
+ static uint8_t q8[O*I]; static float s[4];
+ for(int i=0;i<O*I;i++) q8[i]=rndbyte();
+ for(int i=0;i<4;i++) s[i]=0.01f;
+ t.fmt=7; t.O=O; t.I=I; t.gs=0; t.q8=(int8_t*)q8; t.s=s;
+ static float x[I]; for(int i=0;i<I;i++) x[i]=rndsmallf();
+ float y=0.f;
+ qt_matvec_rows(&t,0,1,x,&y);
+}
+static void call_matvec_fmt6(void){
+ QT t; memset(&t,0,sizeof t);
+ enum { O=4, I=98 };
+ static uint8_t q4[O*98]; static float s[1];
+ for(int i=0;i<O*98;i++) q4[i]=rndbyte();
+ s[0]=0.01f;
+ t.fmt=6; t.O=O; t.I=I; t.gs=0; t.q4=q4; t.s=s;
+ static float x[I]; for(int i=0;i<I;i++) x[i]=rndsmallf();
+ float y=0.f;
+ qt_matvec_rows(&t,0,1,x,&y);
+}
+
+static int expect_refuse_call(absorb_fn fn, const char *tag){
+#ifndef _WIN32
+ int pipefd[2]; if(pipe(pipefd)!=0) return 0;
+ pid_t pid = fork();
+ if(pid < 0) return 0;
+ if(pid == 0){
+ dup2(pipefd[1],2); close(pipefd[0]); close(pipefd[1]);
+ fn();
+ _exit(42); /* reaching here (surviving the call without exit(1)) is the bug */
+ }
+ close(pipefd[1]);
+ char err[1024]={0}; ssize_t n=read(pipefd[0],err,sizeof(err)-1); (void)n;
+ close(pipefd[0]);
+ int status=0; waitpid(pid,&status,0);
+ if(WIFSIGNALED(status)){
+ printf("FAIL %s: crashed with signal %d instead of refusing (exit(1)) -- this IS the "
+ "engine defect this test exists to catch\n", tag, WTERMSIG(status));
+ return 0;
+ }
+ int ok = WIFEXITED(status) && WEXITSTATUS(status)==1;
+ if(!ok){
+ printf("FAIL %s: expected exit(1) refusal, got status=%d, stderr=%.200s\n", tag, status, err);
+ return 0;
+ }
+ if(!strstr(err,"refus")){
+ printf("FAIL %s: exited(1) but message lacked a refusal explanation: %.200s\n", tag, err);
+ return 0;
+ }
+ return 1;
+#else
+ printf("skipped on Windows (no fork): %s\n", tag);
+ (void)fn;
+ return 1;
+#endif
+}
+
+static void test_refusals(void){
+ CHECK(expect_refuse_call(call_addrow_fmt7, "qt_addrow refuses fmt=7 (was SIGSEGV)"));
+ CHECK(expect_refuse_call(call_addrow_fmt6, "qt_addrow refuses fmt=6"));
+ CHECK(expect_refuse_call(call_matvec_fmt7, "qt_matvec_rows refuses fmt=7"));
+ CHECK(expect_refuse_call(call_matvec_fmt6, "qt_matvec_rows refuses fmt=6"));
+}
+
+int main(void){
+ test_byte_identity_all_formats();
+ test_refusals();
+ if(fails){ printf("qt_addrow/qt_matvec_rows tests: %d FAILED\n", fails); return 1; }
+ printf("qt_addrow/qt_matvec_rows tests: ok\n");
+ return 0;
+}