From 9a5d27b6d20f2a85318ca00878d2a131ed8e1057 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Sat, 31 Oct 2026 07:52:35 -0500 Subject: [PATCH 1/8] DRA-65: chunked prefill for the single door's prompt rows; pinned 32-prompt set and chip window The 35B single door fed nearly every prompt token through a decode step (session feed_rows -> prefill_rows MoE branch). prefill_state feeds the rows before the snapshot point as chip prefill chunks (AIEN_Q36_PREFILL_CHUNK, default 128, 0 = the old path); prefill_rows chunks all but its last token. Pure split rules (snapshot_point, rows_by_steps, q36_chunk_lengths) with host tests. evidence/dra65-prefill-20261031: 32-prompt set pinned to token-by-token goldens (bin-5b726818), long goldens (bin-16b0e6f8), window script (mutant 4 red first, identity, TTFT/e2e). --- .../src/qwen38_omega/prefill.rs | 122 +- .../src/qwen38_omega/session.rs | 114 +- evidence/dra65-prefill-20261031/README.md | 86 ++ evidence/dra65-prefill-20261031/SHA256SUMS | 7 + evidence/dra65-prefill-20261031/long-512.txt | 1 + .../dra65-prefill-20261031/long-goldens.json | 104 ++ evidence/dra65-prefill-20261031/set32.json | 1134 +++++++++++++++++ .../dra65-prefill-20261031/window-dra65.sh | 67 + 8 files changed, 1609 insertions(+), 26 deletions(-) create mode 100644 evidence/dra65-prefill-20261031/README.md create mode 100644 evidence/dra65-prefill-20261031/SHA256SUMS create mode 100644 evidence/dra65-prefill-20261031/long-512.txt create mode 100644 evidence/dra65-prefill-20261031/long-goldens.json create mode 100644 evidence/dra65-prefill-20261031/set32.json create mode 100755 evidence/dra65-prefill-20261031/window-dra65.sh diff --git a/crates/aien-inference-abi/src/qwen38_omega/prefill.rs b/crates/aien-inference-abi/src/qwen38_omega/prefill.rs index ff794b03..6c81c078 100644 --- a/crates/aien-inference-abi/src/qwen38_omega/prefill.rs +++ b/crates/aien-inference-abi/src/qwen38_omega/prefill.rs @@ -330,6 +330,34 @@ impl Qwen38Omega { Ok((next, logits, st)) } + /// Feeds `tokens` at head 0's next positions for their state only: no head, no residual read + /// back (a session's prompt rows before its snapshot point, DRA-65). The 35B: chunks of + /// [`q36_prefill_chunk`] through the chip prefill (L369, any length, the state bit for bit as + /// token by token; with 0 every token is stepped through the decode graph and the stats' + /// `chunks` is 0); other models: [`Self::prefill_rows`] with `chunk` (at least + /// [`q::GDN_PF_MIN_T`] tokens). Nothing to feed is a no-op. + pub fn prefill_state(&mut self, tokens: &[u32], chunk: usize) -> Result { + let t0 = Instant::now(); + if !self.is_moe() { + return self.prefill_rows(tokens, chunk, false).map(|(_, st)| st); + } + let c = q36_prefill_chunk()?; + let mut chunks = 0; + if c == 0 { + for &t in tokens { + self.step(t)?; + } + } else if !tokens.is_empty() { + chunks = self.prefill_moe_head(0, tokens, c, false)?.1; + } + Ok(PrefillStats { + tokens: tokens.len(), + chunks, + wall_ns: ns(t0), + ..Default::default() + }) + } + /// The final norm and the bf16 lm_head on one residual row (`[hidden]`): `[vocab]` logits. pub fn head_logits(&mut self, residual: &[f32]) -> Result, String> { let h = self.config.hidden; @@ -361,19 +389,25 @@ impl Qwen38Omega { let n = tokens.len(); let (h, v) = (self.config.hidden, self.config.vocab); if self.is_moe() { - // As prefill: token by token through the decode graph; the rows are its residual x. + // The 35B's chip prefill (L369) keeps its rows in its own buffers, not in the decode + // graph's x, so the rows asked for come from decode steps: every token's when `all`; + // else the others go in as chunks ([`Self::prefill_state`]) and the last is stepped. + let (head, stepped) = if all || n == 0 { + (&tokens[..0], tokens) + } else { + tokens.split_at(n - 1) + }; + let chunks = self.prefill_state(head, chunk)?.chunks; let mut rows = Vec::with_capacity(if all { n * h } else { h }); - for (i, &t) in tokens.iter().enumerate() { + for &t in stepped { self.step(t)?; - if all || i + 1 == n { - rows.extend(self.residual()?); - } + rows.extend(self.residual()?); } - let _ = (chunk, v); return Ok(( rows, PrefillStats { tokens: n, + chunks, wall_ns: ns(t0), ..Default::default() }, @@ -581,18 +615,35 @@ impl Qwen38Omega { /// Prompt tokens per 35B prefill chunk (`AIEN_Q36_PREFILL_CHUNK`, default the graph's most, /// [`q::q36::PREFILL_MAX_ROWS`]); 0 = token by token through the decode graph. pub fn q36_prefill_chunk() -> Result { - match std::env::var("AIEN_Q36_PREFILL_CHUNK") { - Ok(v) => match v.parse::() { + parse_q36_chunk(std::env::var("AIEN_Q36_PREFILL_CHUNK").ok().as_deref()) +} + +fn parse_q36_chunk(v: Option<&str>) -> Result { + match v { + Some(v) => match v.parse::() { Ok(n) if n <= q::q36::PREFILL_MAX_ROWS => Ok(n), _ => Err(format!( "AIEN_Q36_PREFILL_CHUNK={v}: 0 (off) ..= {}", q::q36::PREFILL_MAX_ROWS )), }, - Err(_) => Ok(q::q36::PREFILL_MAX_ROWS), + None => Ok(q::q36::PREFILL_MAX_ROWS), } } +/// The lengths of the 35B prefill's chunks for `n` tokens: whole chunks of `chunk` and the rest +/// last (the q36 prefill takes any length from 1, unlike the 27B's [`chunk_lengths`]). +pub fn q36_chunk_lengths(n: usize, chunk: usize) -> Vec { + if chunk == 0 { + return Vec::new(); + } + let mut out = vec![chunk; n / chunk]; + if n % chunk > 0 { + out.push(n % chunk); + } + out +} + impl Qwen38Omega { /// L369: fp8 GEMM weight bytes the 35B prefill has streamed so far on this graph (0 for other /// models); see `Graph::prefill_streamed`. @@ -647,9 +698,13 @@ impl Qwen38Omega { } let mut next = None; let mut pos = pos0; - let n_chunks = tokens.len().div_ceil(chunk); - for (i, c) in tokens.chunks(chunk).enumerate() { - let mut x = vec![0f32; c.len() * h]; + let lengths = q36_chunk_lengths(tokens.len(), chunk); + let n_chunks = lengths.len(); + let mut at = 0; + for (i, &m) in lengths.iter().enumerate() { + let c = &tokens[at..at + m]; + at += m; + let mut x = vec![0f32; m * h]; for (row, &t) in x.chunks_mut(h).zip(c) { let t = t as usize; for (d, &b) in row.iter_mut().zip(&embed[t * h..(t + 1) * h]) { @@ -663,7 +718,7 @@ impl Qwen38Omega { if last { next = tok; } - pos += c.len(); + pos += m; } *self.head_pos_mut(head)? = pos; Ok((next, n_chunks)) @@ -691,6 +746,47 @@ mod tests { assert_eq!(chunk_lengths(131_072, 4096).len(), 32); } + /// DRA-65: the 35B chunk boundaries at the prompt lengths the window measures, at the served + /// chunk (128) and at a small one; every token in exactly one chunk, none longer than the cap. + #[test] + fn q36_chunks_at_the_boundaries() { + let cap = q::q36::PREFILL_MAX_ROWS; + assert_eq!(cap, 128); + let cases: [(usize, &[usize]); 4] = + [(1, &[1]), (127, &[127]), (128, &[128]), (129, &[128, 1])]; + for (n, want) in cases { + assert_eq!(q36_chunk_lengths(n, cap), want, "n {n}"); + } + assert_eq!(q36_chunk_lengths(2048, cap), vec![128; 16]); + assert_eq!(q36_chunk_lengths(8192, cap), vec![128; 64]); + assert_eq!(q36_chunk_lengths(8210, cap).len(), 65); + assert_eq!(q36_chunk_lengths(8210, cap)[64], 18); + assert!(q36_chunk_lengths(0, cap).is_empty()); + assert!(q36_chunk_lengths(5, 0).is_empty()); + for chunk in [1, 7, 64, cap] { + for n in [1, chunk - 1, chunk, chunk + 1, 2048, 8192] { + let c = q36_chunk_lengths(n, chunk); + assert_eq!(c.iter().sum::(), n, "n {n} chunk {chunk}"); + assert_eq!(c.len(), n.div_ceil(chunk), "n {n} chunk {chunk}"); + assert!( + c.iter().all(|&m| (1..=chunk).contains(&m)), + "n {n} chunk {chunk}: {c:?}" + ); + } + } + } + + #[test] + fn q36_chunk_switch_parses_off_default_and_cap() { + let cap = q::q36::PREFILL_MAX_ROWS; + assert_eq!(parse_q36_chunk(None), Ok(cap)); + assert_eq!(parse_q36_chunk(Some("0")), Ok(0)); + assert_eq!(parse_q36_chunk(Some("16")), Ok(16)); + assert_eq!(parse_q36_chunk(Some("128")), Ok(128)); + assert!(parse_q36_chunk(Some("129")).is_err()); + assert!(parse_q36_chunk(Some("x")).is_err()); + } + #[test] fn argmax_takes_the_first_maximum() { assert_eq!(argmax(&[0.0, 2.0, 1.0, 2.0]), 1); diff --git a/crates/aien-inference-abi/src/qwen38_omega/session.rs b/crates/aien-inference-abi/src/qwen38_omega/session.rs index 9611537a..15b046df 100644 --- a/crates/aien-inference-abi/src/qwen38_omega/session.rs +++ b/crates/aien-inference-abi/src/qwen38_omega/session.rs @@ -78,8 +78,10 @@ pub struct FeedStats { pub reuse: Option, /// Prompt tokens fed this turn (prompt length minus the reused prefix). pub fed: usize, - /// Of those, fed one at a time through the decode graph (pieces shorter than the prefill's - /// minimum). + /// Of those, fed one at a time through the decode graph: pieces shorter than the 27B + /// prefill's minimum, and on the 35B only with `AIEN_Q36_PREFILL_CHUNK=0` or a last piece + /// shorter than [`q::GDN_PF_MIN_T`] (DRA-65: the 35B's rows before the snapshot point go in + /// as chip prefill chunks at any length). pub stepped: usize, pub prefill: PrefillStats, pub restore_ns: u64, @@ -91,6 +93,24 @@ fn ns(t: Instant) -> u64 { t.elapsed().as_nanos() as u64 } +/// The snapshot point of `prompt` when the first `from` tokens are already fed: its last +/// `<|im_start|>` (the header of the turn being answered) at or past `from`. The session feeds +/// `prompt[from..k]` without the head, snapshots there, then feeds `prompt[k..]` with the head; +/// `None`: no such header, the whole rest goes in with the head and no snapshot is taken. +pub fn snapshot_point(prompt: &[u32], from: usize) -> Option { + prompt + .iter() + .rposition(|&t| t == IM_START) + .filter(|&k| k >= from) +} + +/// Whether a row piece of `len` tokens (no head) is stepped token by token rather than fed by +/// [`Qwen38Omega::prefill_state`]: only the 27B's pieces under its prefill minimum; the 35B's +/// chip prefill takes any length (DRA-65). +pub fn rows_by_steps(len: usize, moe: bool) -> bool { + !moe && len < q::GDN_PF_MIN_T +} + fn add(sum: &mut PrefillStats, s: &PrefillStats) { sum.tokens += s.tokens; sum.chunks += s.chunks; @@ -107,6 +127,16 @@ fn add(sum: &mut PrefillStats, s: &PrefillStats) { sum.head_ns += s.head_ns; } +/// Books one prefill call: the 35B with `AIEN_Q36_PREFILL_CHUNK=0` reports no chunks for tokens +/// it stepped through the decode graph, which count as stepped. +fn count(st: &mut FeedStats, s: &PrefillStats) { + if s.chunks == 0 && s.tokens > 0 { + st.stepped += s.tokens; + } else { + add(&mut st.prefill, s); + } +} + /// The resident model plus the token record of its live state and of its snapshot. #[derive(Debug)] pub struct Qwen38Session { @@ -204,11 +234,7 @@ impl Qwen38Session { let from = self.history.len(); st.fed = prompt.len() - from; // The snapshot point: the last turn header not yet inside the reused prefix. - if let Some(k) = prompt - .iter() - .rposition(|&t| t == IM_START) - .filter(|&k| k >= from) - { + if let Some(k) = snapshot_point(prompt, from) { self.feed_rows(&prompt[from..k], &mut st)?; if self.snap_tokens.as_deref() != Some(&prompt[..k]) && k > 0 { let t = Instant::now(); @@ -224,16 +250,16 @@ impl Qwen38Session { Ok((logits, st)) } - /// Feeds `tokens` without the head (the residual rows are dropped). + /// Feeds `tokens` without the head (no residual read back). fn feed_rows(&mut self, tokens: &[u32], st: &mut FeedStats) -> Result<(), String> { - if tokens.len() >= q::GDN_PF_MIN_T { - let (_, s) = self.model.prefill_rows(tokens, self.chunk, false)?; - add(&mut st.prefill, &s); - } else { + if rows_by_steps(tokens.len(), self.model.is_moe()) { for &t in tokens { self.model.step(t)?; } st.stepped += tokens.len(); + } else { + let s = self.model.prefill_state(tokens, self.chunk)?; + count(st, &s); } self.history.extend_from_slice(tokens); Ok(()) @@ -246,7 +272,7 @@ impl Qwen38Session { } let logits = if tokens.len() >= q::GDN_PF_MIN_T { let (_, logits, s) = self.model.prefill(tokens, self.chunk)?; - add(&mut st.prefill, &s); + count(st, &s); logits } else { for &t in tokens { @@ -330,4 +356,66 @@ mod tests { Reuse::Snapshot(2) ); } + + /// A rendered single-turn prompt of `len` tokens whose answer header (`<|im_start|>` + /// assistant ... , 7 tokens with thinking off) closes it, plus an earlier user header at 0. + fn rendered(len: usize) -> Vec { + let mut p: Vec = (0..len as u32).map(|i| 1000 + i).collect(); + p[0] = IM_START; + if len > 7 { + p[len - 7] = IM_START; + } + p + } + + /// DRA-65: where start_inner splits a prompt at the lengths the chunk tests use: the rows + /// before the answer header (fed without the head, as 35B prefill chunks at any length), + /// the snapshot at the header, the header and what follows fed with the head. + #[test] + fn snapshot_point_splits_rows_and_last_piece() { + let cap = q::q36::PREFILL_MAX_ROWS; + for len in [1, cap - 1, cap, cap + 1, 2048, 8192] { + let p = rendered(len); + let k = snapshot_point(&p, 0).expect("a header"); + let want = if len > 7 { len - 7 } else { 0 }; + assert_eq!(k, want, "len {len}"); + assert_eq!(p[k], IM_START); + // The rows piece and the last piece cover the prompt once, the last starts at the header. + let (rows, last) = p.split_at(k); + assert_eq!(rows.len() + last.len(), len); + assert!(!last.is_empty() && last[0] == IM_START); + // The 35B never steps the rows piece; its chunks cover it. + assert!(!rows_by_steps(rows.len(), true)); + let c = super::super::prefill::q36_chunk_lengths(rows.len(), cap); + assert_eq!(c.iter().sum::(), rows.len(), "len {len}"); + } + // 2048: 2041 rows = 15 chunks of 128 + 121; the answer header's 7 tokens go in with the head. + let c = super::super::prefill::q36_chunk_lengths(2048 - 7, cap); + assert_eq!((c.len(), c[15]), (16, 121)); + } + + #[test] + fn snapshot_point_respects_the_reused_prefix() { + // Turn 2: the reused snapshot ends at turn 1's answer header (k1); the new answer header + // is past it, so the rows between are fed and the snapshot moves there. + let mut p = rendered(40); + let k1 = 33; + p.extend([2000, 2001, 2002, IM_START, 2003, 2004]); + assert_eq!(snapshot_point(&p, k1), Some(43)); + // The header right at the reused end: an empty rows piece, the same snapshot. + assert_eq!(snapshot_point(&p, 43), Some(43)); + // A live state past the last header: no snapshot, the rest goes in with the head. + assert_eq!(snapshot_point(&p, 44), None); + // No header at all. + assert_eq!(snapshot_point(&[5, 6, 7], 0), None); + } + + #[test] + fn only_short_27b_row_pieces_are_stepped() { + for len in [0, 1, 2, 3, 127, 128, 129, 8192] { + assert!(!rows_by_steps(len, true), "35B len {len}"); + } + assert!(rows_by_steps(2, false)); + assert!(!rows_by_steps(q::GDN_PF_MIN_T, false)); + } } diff --git a/evidence/dra65-prefill-20261031/README.md b/evidence/dra65-prefill-20261031/README.md new file mode 100644 index 00000000..110354b6 --- /dev/null +++ b/evidence/dra65-prefill-20261031/README.md @@ -0,0 +1,86 @@ +# DRA-65: chunked prefill through the door (2026-10-31) + +Refs aien-dev/aien-sovereign-core-mv#856, Linear DRA-65. + +## Which door serves, and what still read prompts one token at a time (source, origin/main d3dec0eb) + +- Production 35B (last start 2026-10-30T18:49:06Z, `start-35b-batch.sh`, bin-19173f9e, `--batch-slots 8`) is the + **batch door**: `main.rs` sends `--batch-slots > 0` with a MoE dir to `Qwen36BatchDoor::load`. It already reads + prompts in chip chunks of 128 (L369; `qwen36_batch.rs` chunk block, BUILD.txt "L369 prefill (chunks of 128)"). + The Linear premise "the door reads prompts one token per beat" is **stale for the batch door**. What it still + steps token by token: a stretch shorter than `AIEN_Q36_PREFILL_MIN` (16) before the snapshot point, and the + answer header after the snapshot (~7 tokens), fed per token in the same beat. +- The **single door** (`Qwen38Door`, `--batch-slots 0`) read nearly the whole prompt one token per decode step: + `session.rs` feed_rows -> `prefill_rows` MoE branch -> `self.step(t)` per token (chunk ignored). Only the last + piece (`feed_last` -> `prefill`) was chunked. + +## Change (IMPLEMENTED) + +- `prefill.rs`: `Qwen38Omega::prefill_state(tokens, chunk)` feeds tokens for their state only; on the 35B as chip + prefill chunks of `AIEN_Q36_PREFILL_CHUNK` (default 128, 0 = the old token-by-token path, same binary) at any + length from 1. `prefill_rows` on the 35B now chunks all but the last token and steps the last one for its + residual (the chip prefill keeps its rows in `pf.x`, not the decode graph's x, so `residual()` is only valid + after a step); `all=true` still steps every token (its rows are not exported by the chip prefill). + `q36_chunk_lengths` is the one chunk plan `prefill_moe_head` iterates. +- `session.rs`: `feed_rows` uses `prefill_state` (35B: never stepped); `snapshot_point` and `rows_by_steps` are + the pure split rules start_inner uses; off-mode tokens are counted in `FeedStats::stepped`. +- Signatures of `Qwen38Session::{start, advance, advance_greedy}` and `RowStep::{step_rows, prefill_row}` + unchanged. Batch door code unchanged (see "Next lever"). + +## 32-prompt set (pinned) + +`set32.json` = the merge train's concurrent-32 prompts (`evidence/q36-batch-20261021/prompts.txt`, max_tokens +`i==0 ? 24 : 8 + (i*7) % 41`), goldens = reference build **bin-5b726818** ("plain correct path: prompt fed token +by token, no speed levers"), each request alone, recorded 2026-10-21 (before this change). Prompt 0's ids equal +the host-oracle golden `evidence/q36-host-20261020/gen-chat-max-24.json`. `long-goldens.json` adds the 365 / +2486 / 8210-token prompts with goldens from bin-16b0e6f8 (batch door, prompts token by token). 35 cases in all. +Judge: exact id identity (the door returns no logit margins, so the 0.1-logit band cannot be judged through it; +any flip is FAIL). `SHA256SUMS` pins every input; the script refuses to run if one changed. + +## Host evidence (EXERCISED on host, not chip) + +`nice -n 19 taskset -c 0-9 cargo test -p aien-inference-abi --lib qwen38_omega`: 9 passed (chunk boundaries at +1, 127, 128, 129, 2048, 8192 and 8210; env switch 0/default/cap/129/garbage; snapshot point and rows/last split at +the same lengths and on turn 2; 35B rows never stepped). Negative control: `q36_chunk_lengths` mutated to drop a +remainder of 1 -> `q36_chunks_at_the_boundaries` FAILED, then restored. Judge exercised against a mock door +(exact goldens / one id changed): green PASS + red FAIL, and green FAIL (exit 1) + red PASS. + +Mutant 4 wiring (source, omega 474197e4f): `AIEN_Q36_TEST_MUTANT=4` -> `moe.rs` `graph_mutant()` -> +`test_set_mutant` on the main graph and (`rows.rs` wire) every row and stroke graph; in C mutant 4 swaps K_CN for +K_CN_M3 in the decode path and in `omega_gpu_q36_graph_prefill` (the chunk path), K_CN_R for K_CN_R_M3 in rows. +So the env mutant reaches the chunked prefill. The per-request `aien_test` mutant does not (the batch door steps +such rows token by token), so the window uses the env mutant. + +## Window (Main; chip gates NOT_RUN until then) + +Quiet exclusive window per the usual procedure (marker, stop 18091 and Flint, `spark-window open ... --gb10 +exclusive --quiet exclusive`). NEW = the build of this branch. Each line: start the server, run, stop. + +1. Single door, NEW, `AIEN_Q36_TEST_MUTANT=4`: `window-dra65.sh golden PORT OUT/w1-mutant red` -> must PASS (red). +2. Single door, NEW: `window-dra65.sh golden PORT OUT/w2-single green` -> PASS = 35/35 identical. +3. Batch door (`--batch-slots 8`), NEW: `window-dra65.sh golden PORT OUT/w3-batch green`. +4. `window-dra65.sh time PORT OUT/w4-` on: single NEW; single NEW with `AIEN_Q36_PREFILL_CHUNK=0` (before + arm); batch NEW; batch NEW with `AIEN_Q36_PREFILL_MIN=1` (chunks the answer header too). + Receipts: `time.jsonl` (t0, first content delta, end, usage per run). TTFT = t_first - t0; e2e tok/s = + completion_tokens / (t_end - t_first). Medians of the 3 runs through Wolfram (`Median[{...}]`). + Target 1 compares e2e against chip-only decode from DRA-66's `chip_ns` in the same runs. + +## Predictions (MODELED, Wolfram) + +- Single door before: 1 token per decode step, 20.1 ms -> `N[1/0.0201]` = 49.75 tok/s; 512 tokens + `N[512*0.0201]` = 10.29 s; 8210 tokens `N[8210*0.0201]` = 165.0 s. +- Single door after, at the measured prefill-gate rates (250 tok/s at 2k, 196.8 at 8k): 512 tokens + `N[512/250.]` = 2.05 s; 8210 tokens `N[8210/196.8]` = 41.7 s. +- Target 2 (2,000 tok/s at 2k) needs `N[2000/250.]` = 8x the current chunked rate: not reachable by + chunking alone. + +## Next lever (batch and single door alike; omega kernel work, not host-testable) + +Expert bytes per 128-token chunk if every expert is read once per layer: `256*(3145728+384)*40` = 32,216,186,880 +B; at 273 GB/s `N[perChunk/273*^9]` = 0.118 s, i.e. a byte floor of `N[128/0.118...]` = 1,084.7 tok/s; the +measured 250 tok/s is `N[(128/250.)/0.118...]` = 4.34x above that floor, so the chunk is not bytes-bound. The +FLOP floor for 2,048 tokens at ~3e9 active parameters and 237.5 TFLOPS is `N[2*3*^9*2048/237.5*^12]` = 0.052 s. +The lever is compute efficiency of the prefill GEMMs: a tensor-core grouped expert GEMM (OMEGA.md bar C3) in +`omega_gpu_q36_graph_prefill`, then chunks above 128 (the 1024-row fp8 GEMM cap). The batch door's remaining +per-token stretches (< 16 before the snapshot, the ~7-token header) are an env A/B (`AIEN_Q36_PREFILL_MIN=1`, +step 4) because small-chunk chip cost is unmeasured. diff --git a/evidence/dra65-prefill-20261031/SHA256SUMS b/evidence/dra65-prefill-20261031/SHA256SUMS new file mode 100644 index 00000000..bc6e0d75 --- /dev/null +++ b/evidence/dra65-prefill-20261031/SHA256SUMS @@ -0,0 +1,7 @@ +7a171b54c2effda998d2884e3f6868b55123fa8ba779dcf2762dff4c64a1fa29 evidence/q36-batch-20261021/prompts.txt +c1d4696b8e8d3ef7a81953fe4191db4bb51160276b5ccdf93a146a284b90dd3e evidence/dra65-prefill-20261031/set32.json +06441284f2300e384b7d4cd55bc0d307c71825f4f233edebe228a79e14286141 evidence/dra65-prefill-20261031/long-goldens.json +3b27d724b10446308d0c0b0a68b72573cdb26e22f0d1994bde88880988bec8d3 evidence/dra65-prefill-20261031/long-512.txt +153a5f88932393b2be56fd81f8914d44218169c614ebc5b2753069c9a09bc3a1 evidence/merge-train/l369/long-256.txt +26a44c508412e213de876eb54bb90390426b086c887a68b90fa78f7470425ee3 evidence/merge-train/l369/long-2048.txt +2bcc84b25c418cba83df9546344fd4ae28962c314e03defe2aab62a8e6c8abb9 evidence/merge-train/l369/long-8192.txt diff --git a/evidence/dra65-prefill-20261031/long-512.txt b/evidence/dra65-prefill-20261031/long-512.txt new file mode 100644 index 00000000..1caa9cc9 --- /dev/null +++ b/evidence/dra65-prefill-20261031/long-512.txt @@ -0,0 +1 @@ +ne 503-511, VERIFIED), so an unseen file is free until found. 23. FS adapter: reversible filename from the key, `.tmp` suffix + `os.replace`, unlink of the temp on failure; no `fsync` anywhere in the file (fs_l2_adapter.py:99-135, 518-532, 640-662, VERIFIED; absence of `fsync` VERIFIED by grep). 24. Tests adapted (test_nixl_store_dynamic_l2_adapter.py): `test_salted_objects_recover_independently_after_restart` (745), `test_store_rejected_when_capacity_exceeded` (985), `test_batched_store_reports_failure_when_capacity_exceeded` (1034), `test_secondary_lookup_finds_key` (1113), `test_secondary_lookup_and_load_data` (1138), `test_load_partial_failure_marks_only_successful` (561), `test_delete_skips_pinned_key` (887). Each is re-expressed as a Rust test; none is copied. Attribution: an Apache-2.0 header on `crates/aien-kv-store/src/identity.rs` (the prefix-chain idea) and the test file that adapts the cases, plus a THIRD_PARTY.md row ("LMCache, Apache-2.0, ideas adapted: deterministic rolling prefix keys, completed-object publication by temp+rename, lazy disk recovery; no code copied"). The LMCache clone has a LICENSE and no NOTICE file (VERIFIED by `ls`). ### Prior art in this repository (not depended on) 25. OWN-30B serve branch `own30b/serve` (sc-own30b, unmerged, pinned at commit 69459db): in-memory prefix reuse for one conversation, `reused = common.min(prompt.len() - 1)` so at least the last prompt token is always recomputed to produce logits (crates/aien-inference-abi/src/qwen3_moe_omega.rs:2163 at 69459db, VERIFIED), test `prefix_reuse_prefills_only_the_new_tokens_and_matches_a_cold_run` (fn at 2421 at 69459db, VERIF \ No newline at end of file diff --git a/evidence/dra65-prefill-20261031/long-goldens.json b/evidence/dra65-prefill-20261031/long-goldens.json new file mode 100644 index 00000000..540e6ece --- /dev/null +++ b/evidence/dra65-prefill-20261031/long-goldens.json @@ -0,0 +1,104 @@ +{ + "about": "long-prompt goldens from reference build bin-16b0e6f8 (batch door, prompts token by token), each alone, 2026-10-21T22:11:19Z", + "prompts": [ + { + "name": "long-256", + "file": "evidence/merge-train/l369/long-256.txt", + "file_sha256": "153a5f88932393b2be56fd81f8914d44218169c614ebc5b2753069c9a09bc3a1", + "prompt_tokens": 365, + "golden_ids": [ + 760, + 1414, + 369, + 449, + 14991, + 1830, + 42724, + 279, + 61079, + 43555, + 2552, + 314, + 3050, + 8684, + 13753, + 364, + 279, + 41879, + 321, + 14791, + 923, + 5757, + 430, + 314 + ], + "max_tokens": 24 + }, + { + "name": "long-2048", + "file": "evidence/merge-train/l369/long-2048.txt", + "file_sha256": "26a44c508412e213de876eb54bb90390426b086c887a68b90fa78f7470425ee3", + "prompt_tokens": 2486, + "golden_ids": [ + 760, + 1414, + 369, + 264, + 10597, + 24332, + 42724, + 279, + 2790, + 314, + 264, + 2243, + 290, + 11540, + 9284, + 1785, + 364, + 264, + 81726, + 6297, + 3436, + 11, + 25471, + 1204 + ], + "max_tokens": 24 + }, + { + "name": "long-8192", + "file": "evidence/merge-train/l369/long-8192.txt", + "file_sha256": "2bcc84b25c418cba83df9546344fd4ae28962c314e03defe2aab62a8e6c8abb9", + "prompt_tokens": 8210, + "golden_ids": [ + 760, + 1414, + 3447, + 264, + 10597, + 2790, + 364, + 264, + 81726, + 6297, + 1785, + 421, + 5004, + 264, + 328, + 27795, + 321, + 14519, + 1, + 16456, + 310, + 21640, + 321, + 25147 + ], + "max_tokens": 24 + } + ] +} diff --git a/evidence/dra65-prefill-20261031/set32.json b/evidence/dra65-prefill-20261031/set32.json new file mode 100644 index 00000000..f1725fed --- /dev/null +++ b/evidence/dra65-prefill-20261031/set32.json @@ -0,0 +1,1134 @@ +{ + "set": "dra65-32", + "about": "DRA-65 32-prompt set = the merge train concurrent-32 prompts (evidence/q36-batch-20261021/prompts.txt, ntok rule i==0?24:8+(i*7)%41); goldens = reference build bin-5b726818 (plain correct path: prompt fed token by token, no speed levers), each request alone, recorded 2026-10-21T02:44:22Z, imported to the merge-train store 2026-10-21T14:36:32Z; pre-DRA-65 by date", + "prompts_file": "evidence/q36-batch-20261021/prompts.txt", + "prompts_sha256": "7a171b54c2effda998d2884e3f6868b55123fa8ba779dcf2762dff4c64a1fa29", + "defaults": { + "temperature": 0, + "chat_template_kwargs": { + "enable_thinking": false + }, + "aien_return_token_ids": true + }, + "judge": "exact id identity per prompt (the door returns no logit margins, so the 0.1-logit band cannot be judged here: any flip is FAIL)", + "prompts": [ + { + "i": 0, + "user": "Write a C function that returns the larger of two ints.", + "max_tokens": 24, + "prompt_tokens": 24, + "golden_ids": [ + 71093, + 66, + 198, + 390, + 1866, + 1494, + 264, + 11, + 514, + 292, + 8, + 313, + 198, + 262, + 460, + 318, + 64, + 835, + 292, + 8, + 907, + 264, + 535, + 292 + ], + "finish": "length", + "ref_sha256": "1160441d7c54df52ee42250ae40cdc4b04671da9e1b6742fd10a25fbd400985f" + }, + { + "i": 1, + "user": "What is the capital of Australia? Answer in one sentence.", + "max_tokens": 15, + "prompt_tokens": 24, + "golden_ids": [ + 760, + 6511, + 314, + 8071, + 369, + 66463, + 13 + ], + "finish": "stop", + "ref_sha256": "d89145567b7eba7b4585ffe60941f5ef9c5d4b3106f15e2533f7f609a1d5185c" + }, + { + "i": 2, + "user": "Explain in two sentences why the sky is blue.", + "max_tokens": 22, + "prompt_tokens": 23, + "golden_ids": [ + 29108, + 4009, + 23716, + 8964, + 579, + 16078, + 321, + 369, + 35742, + 303, + 660, + 17425, + 539, + 660, + 279, + 43034, + 321, + 18167, + 303, + 279, + 3594, + 13 + ], + "finish": "length", + "ref_sha256": "0e3cd9ab0c23c929a9a6357a08e43228194ad04e92f4535016ba3a5197dc9bc0" + }, + { + "i": 3, + "user": "List five prime numbers greater than 100.", + "max_tokens": 29, + "prompt_tokens": 23, + "golden_ids": [ + 8160, + 513, + 4097, + 9944, + 4947, + 6826, + 1056, + 220, + 16, + 15, + 15, + 25, + 271, + 16, + 13, + 2972, + 16, + 15, + 16, + 332, + 198, + 17, + 13, + 2972, + 16, + 15, + 18, + 332, + 198 + ], + "finish": "length", + "ref_sha256": "9c10e0160d0ec6d3b686cf69f9928055936f979250ba2b3ff235655c95980803" + }, + { + "i": 4, + "user": "Translate to French: The train leaves at seven in the morning.", + "max_tokens": 36, + "prompt_tokens": 25, + "golden_ids": [ + 2229, + 5257, + 919, + 3656, + 33190, + 72491, + 3717, + 175926, + 13 + ], + "finish": "stop", + "ref_sha256": "3bdf30ac3ad47d0f37b51943bcf622772b94fd26a768e07c972b0fbc08dfd19d" + }, + { + "i": 5, + "user": "Write a haiku about a lighthouse in winter.", + "max_tokens": 43, + "prompt_tokens": 23, + "golden_ids": [ + 60187, + 16563, + 383, + 279, + 9506, + 11, + 198, + 3320, + 21682, + 14663, + 279, + 19088, + 6121, + 11, + 198, + 91986, + 337, + 2785, + 279, + 13071, + 13 + ], + "finish": "stop", + "ref_sha256": "3db756863a419713f68fb147da9182ed46c4d8252c7524aef2f602619f7dbe76" + }, + { + "i": 6, + "user": "What is 17 times 23? Show the steps.", + "max_tokens": 9, + "prompt_tokens": 26, + "golden_ids": [ + 1206, + 10724, + 393, + 16, + 22, + 1088, + 14695, + 220, + 17 + ], + "finish": "length", + "ref_sha256": "0dd734e6877fdb926c41be7ba2afcc86801d37a528882bd39b76f8e3c20dcaa2" + }, + { + "i": 7, + "user": "Give three tips for writing clear commit messages.", + "max_tokens": 16, + "prompt_tokens": 21, + "golden_ids": [ + 8160, + 513, + 2250, + 7326, + 10104, + 364, + 4237, + 2708, + 321, + 7139, + 5099, + 6397, + 25, + 271, + 16, + 13 + ], + "finish": "length", + "ref_sha256": "4194298c7d7b55c120180bae0e985afeaa478a2c4bb83f1ba5cbd836ed3a1097" + }, + { + "i": 8, + "user": "Write a Rust function that reverses a string.", + "max_tokens": 23, + "prompt_tokens": 22, + "golden_ids": [ + 71093, + 34602, + 198, + 9299, + 5003, + 9637, + 3773, + 1104, + 25, + 594, + 485, + 8, + 1411, + 894, + 313, + 198, + 262, + 274, + 82127, + 973, + 7055, + 973, + 16873 + ], + "finish": "length", + "ref_sha256": "cb4ce8306f3398464f0222f357f19045d2779ac88a72dd2fd2964ea1b3ba9e38" + }, + { + "i": 9, + "user": "Summarize the plot of Romeo and Juliet in three sentences.", + "max_tokens": 30, + "prompt_tokens": 25, + "golden_ids": [ + 11280, + 3777, + 31059, + 494, + 1115, + 49058, + 8259, + 11, + 67815, + 9503, + 4511, + 321, + 68613, + 7761, + 46805, + 11, + 40361, + 30774, + 1238, + 6236, + 506, + 264, + 4776, + 13, + 10643, + 10973, + 369, + 53507, + 948, + 67815 + ], + "finish": "length", + "ref_sha256": "2006031bcddb5bf56ee7b575a9e0c96a359eb7a92bedc9b7f2277f68f50a74fd" + }, + { + "i": 10, + "user": "What does a transformer's attention layer compute? Be brief.", + "max_tokens": 37, + "prompt_tokens": 24, + "golden_ids": [ + 2064, + 55288, + 264, + 35604, + 2542, + 314, + 869, + 22166, + 11, + 1332, + 279, + 13914, + 318, + 51319, + 11857, + 8, + 513, + 10521, + 539, + 279, + 23967, + 1881, + 3134, + 321, + 1328, + 22166, + 13 + ], + "finish": "stop", + "ref_sha256": "ee7a975635266296abbdbff1f987105ae4a6ea5f5e159d1f80d03fa1a9958eac" + }, + { + "i": 11, + "user": "Name the planets of the solar system in order from the Sun.", + "max_tokens": 44, + "prompt_tokens": 25, + "golden_ids": [ + 8160, + 513, + 279, + 7810, + 31784, + 314, + 279, + 12570, + 1785, + 303, + 1906, + 494, + 279, + 7806, + 25, + 271, + 16, + 13, + 2972, + 25863, + 24648, + 332, + 198, + 17, + 13, + 2972, + 53, + 36614, + 332, + 198, + 18, + 13, + 2972, + 42373, + 332, + 198, + 19, + 13, + 2972, + 44, + 1506, + 332, + 198, + 20 + ], + "finish": "length", + "ref_sha256": "5f7796407586354c677537bd952108b5c78f05976bb1c1983da9660ab463da3a" + }, + { + "i": 12, + "user": "Write a SQL query that counts orders per customer.", + "max_tokens": 10, + "prompt_tokens": 22, + "golden_ids": [ + 71093, + 3427, + 198, + 4703, + 5813, + 816, + 11, + 23241, + 27733, + 5574 + ], + "finish": "length", + "ref_sha256": "21649ba27a51bbe56a600c62a4e80e5950adcc2a6a2fe96927e3b722ff996117" + }, + { + "i": 13, + "user": "Why does ice float on water?", + "max_tokens": 17, + "prompt_tokens": 19, + "golden_ids": [ + 49604, + 46303, + 383, + 2919, + 1521, + 424, + 369, + 2972, + 1657, + 27044, + 332, + 1056, + 14058, + 2919, + 13, + 271, + 7732 + ], + "finish": "length", + "ref_sha256": "9115ce326ccb9ed8b594df270866729abc7dea04c8e0d7849183a1b6a4013b34" + }, + { + "i": 14, + "user": "Write a bash one-liner that counts lines in all .txt files in a folder.", + "max_tokens": 24, + "prompt_tokens": 30, + "golden_ids": [ + 71093, + 44675, + 198, + 3772, + 641, + 471, + 2721, + 17038, + 220, + 16, + 471, + 591, + 57129, + 8324, + 1, + 471, + 11411, + 25700, + 471, + 75, + 4535, + 478, + 735, + 9495 + ], + "finish": "length", + "ref_sha256": "2e8db9effc918a567c93ebc9a002215a7aca716003bc8c055a2f54ee62e7acbd" + }, + { + "i": 15, + "user": "Describe a bicycle gear system to a ten-year-old.", + "max_tokens": 31, + "prompt_tokens": 23, + "golden_ids": [ + 49338, + 488, + 513, + 19232, + 678, + 12591, + 685, + 264, + 2098, + 30239, + 23198, + 13, + 1049, + 725, + 2503, + 944, + 11, + 1245, + 30, + 4465, + 13795, + 2579, + 8545, + 11, + 321, + 488, + 3029, + 6992, + 2184, + 13569, + 13 + ], + "finish": "length", + "ref_sha256": "990ee87702c062286443413a43f7b211302ad3af15ec95bf84e0624e836c4d9f" + }, + { + "i": 16, + "user": "What is the difference between TCP and UDP? Two sentences.", + "max_tokens": 38, + "prompt_tokens": 24, + "golden_ids": [ + 48218, + 369, + 264, + 3511, + 33924, + 11176, + 421, + 34475, + 14294, + 11, + 11128, + 9403, + 314, + 795, + 1472, + 1412, + 15464, + 286, + 321, + 311, + 1405, + 2641, + 23038, + 13, + 733, + 12503, + 11, + 40986, + 369, + 264, + 3511, + 1657, + 11176, + 421, + 43195, + 4603, + 4478, + 321 + ], + "finish": "length", + "ref_sha256": "c6cc3038fc9751cd5f686e0c8bf9e96c268a2ba0d5794d4684ff8f1285857efe" + }, + { + "i": 17, + "user": "Write a limerick about a cat who learned to code.", + "max_tokens": 45, + "prompt_tokens": 25, + "golden_ids": [ + 32, + 7993, + 852, + 1362, + 913, + 383, + 264, + 13232, + 11, + 198, + 54, + 5356, + 1970, + 421, + 557, + 16724, + 430, + 264, + 57131, + 13, + 198, + 1465, + 7156, + 3438, + 440, + 264, + 3865, + 81, + 11, + 198, + 2939, + 8097, + 1396, + 27583, + 11, + 198, + 6820, + 551, + 725, + 279, + 11808, + 314, + 279, + 3421, + 13 + ], + "finish": "length", + "ref_sha256": "d3181419484825b2029340cf6af228cc2fc3dbae2207073c940bec8c0aec64ab" + }, + { + "i": 18, + "user": "Convert 100 degrees Fahrenheit to Celsius and explain the formula.", + "max_tokens": 11, + "prompt_tokens": 26, + "golden_ids": [ + 13962, + 12650, + 21134, + 198, + 332, + 16, + 15, + 15, + 11995, + 66401, + 369 + ], + "finish": "length", + "ref_sha256": "2e810d7ed4b007385e06b9f646225ecb46fa1af428e540dd989addfe51239f63" + }, + { + "i": 19, + "user": "Give a short definition of entropy in thermodynamics.", + "max_tokens": 18, + "prompt_tokens": 22, + "golden_ids": [ + 623, + 28868, + 76214, + 11, + 2972, + 47500, + 332, + 369, + 264, + 1528, + 709, + 421, + 10633, + 279, + 8122, + 314, + 18684, + 11 + ], + "finish": "length", + "ref_sha256": "df16bacb0096b417348b5b09202ec3036574e81b75dbe194b7051640e62c5b05" + }, + { + "i": 20, + "user": "Write a Python-free pseudocode for binary search.", + "max_tokens": 25, + "prompt_tokens": 22, + "golden_ids": [ + 8160, + 369, + 279, + 48939, + 42242, + 364, + 279, + 2972, + 20682, + 7304, + 332, + 11767, + 13, + 271, + 13962, + 2601, + 367, + 1255, + 198, + 9, + 256, + 561, + 1879, + 1287, + 1510 + ], + "finish": "length", + "ref_sha256": "76a00aef96743aae5f035055f92cbb0850ae3183b77edd04f201a5717c85fa92" + }, + { + "i": 21, + "user": "What are the three primary colors of light?", + "max_tokens": 32, + "prompt_tokens": 21, + "golden_ids": [ + 27775, + 383, + 279, + 15694, + 314, + 2972, + 698, + 3295, + 1829, + 25936, + 332, + 318, + 7949, + 16298, + 310, + 3000, + 7916, + 1040, + 6165, + 14864, + 11, + 7712, + 38685, + 11, + 321, + 6228, + 17188, + 681, + 279, + 2250, + 5839, + 7736 + ], + "finish": "length", + "ref_sha256": "8af1b096cf45a772446b309ec704e4ecf1a2d6f8b16a201ec4e5181a771f6aa4" + }, + { + "i": 22, + "user": "Suggest a name for a coffee shop run by robots, and say why.", + "max_tokens": 39, + "prompt_tokens": 28, + "golden_ids": [ + 8160, + 369, + 264, + 23032, + 364, + 264, + 803, + 11, + 3055, + 440, + 279, + 31626, + 4661, + 424, + 25, + 271, + 13962, + 2972, + 657, + 25, + 561, + 38989, + 291, + 20284, + 332, + 271, + 13962, + 2972, + 9930, + 411, + 803, + 4138, + 64700, + 271, + 16, + 13, + 220, + 2972, + 8864 + ], + "finish": "length", + "ref_sha256": "4af3e06ce741e8b6199a7a040cd3be9fb24f712be611e281d09cfdac63d6174a" + }, + { + "i": 23, + "user": "Explain what a hash map is in one paragraph.", + "max_tokens": 46, + "prompt_tokens": 23, + "golden_ids": [ + 32, + 5010, + 2336, + 369, + 264, + 795, + 5759, + 421, + 5004, + 449, + 66571, + 1287, + 7859, + 795, + 913, + 11, + 264, + 5759, + 421, + 628, + 2336, + 6679, + 310, + 2663, + 11, + 539, + 1608, + 264, + 5010, + 709, + 310, + 12204, + 449, + 1857, + 1083, + 449, + 1287, + 314, + 40718, + 466, + 15250, + 494, + 864, + 279, + 12321, + 869 + ], + "finish": "length", + "ref_sha256": "3ea511c6a6c81cb8d195187e8f8030e141edef306768c44944658a4f030162f2" + }, + { + "i": 24, + "user": "Write the first four lines of a sea shanty.", + "max_tokens": 12, + "prompt_tokens": 23, + "golden_ids": [ + 760, + 9662, + 424, + 1204, + 4577, + 3808, + 279, + 30065, + 11, + 198, + 760, + 16382 + ], + "finish": "length", + "ref_sha256": "14045453e1920ab5e473ab357dde290c7d2bb44e8c8a9584647ef541b235077c" + }, + { + "i": 25, + "user": "How many seconds are in a day? Show the multiplication.", + "max_tokens": 19, + "prompt_tokens": 24, + "golden_ids": [ + 1206, + 10724, + 279, + 1324, + 314, + 6283, + 303, + 264, + 1834, + 11, + 567, + 1387, + 1441, + 279, + 7896, + 314, + 854, + 2923, + 13909 + ], + "finish": "length", + "ref_sha256": "d0c0ac7e377f47eaa255866d0d387aefb51b9d2b2fedb7982798a0cfa4d4b44f" + }, + { + "i": 26, + "user": "What is the boiling point of water at the top of Mount Everest, roughly?", + "max_tokens": 26, + "prompt_tokens": 28, + "golden_ids": [ + 13962, + 59977, + 48704, + 2567, + 271, + 1206, + 7995, + 279, + 48161, + 1406, + 314, + 2919, + 506, + 279, + 1844, + 314, + 10113, + 83489, + 11, + 567, + 1902, + 3418, + 279, + 4864, + 1881, + 42900 + ], + "finish": "length", + "ref_sha256": "f2cd985dda2a49869a5cab6952577804225ce0dad8d36732c2bef342c6aba159" + }, + { + "i": 27, + "user": "Write a JavaScript function that checks whether a number is even.", + "max_tokens": 33, + "prompt_tokens": 24, + "golden_ids": [ + 71093, + 13670, + 198, + 1628, + 369, + 12777, + 7815, + 8, + 313, + 198, + 262, + 460, + 1572, + 984, + 220, + 17, + 1981, + 220, + 15, + 26, + 198, + 92, + 198, + 71093 + ], + "finish": "stop", + "ref_sha256": "c3d491b3023dd54ee733b536d7ee7f83516e95f9c43f2781000ff610813d6c36" + }, + { + "i": 28, + "user": "Explain photosynthesis in plain words.", + "max_tokens": 40, + "prompt_tokens": 20, + "golden_ids": [ + 37405, + 314, + 7022, + 71163, + 430, + 264, + 2972, + 981, + 10430, + 1817, + 332, + 421, + 10462, + 958, + 310, + 1236, + 836, + 1765, + 3487, + 13, + 271, + 8160, + 725, + 1204, + 424, + 4138, + 303, + 4145, + 7123, + 25, + 271, + 13962, + 10838, + 234, + 109, + 561, + 49453, + 198, + 2052, + 1720 + ], + "finish": "length", + "ref_sha256": "e6f92c8632513565cab6270765fb40f2d84db8d7b842471efdf8907789cd8179" + }, + { + "i": 29, + "user": "Give two reasons a bridge might use a suspension design.", + "max_tokens": 47, + "prompt_tokens": 23, + "golden_ids": [ + 8160, + 513, + 1330, + 5839, + 7715, + 264, + 13759, + 2493, + 958, + 264, + 23538, + 2790, + 25, + 271, + 13962, + 220, + 16, + 13, + 34791, + 310, + 11564, + 5546, + 26709, + 2924, + 198, + 90898, + 2558, + 37683, + 513, + 1968, + 40541, + 15873, + 364, + 25786, + 1546, + 6669, + 12497, + 314, + 2919, + 466, + 5365, + 82446, + 13, + 25215, + 22690, + 466, + 5157 + ], + "finish": "length", + "ref_sha256": "ca5f6f9e1cd0de542c8ca6c1c3a9adc8f1adfbd76b6b0209db49dd16eb631d68" + }, + { + "i": 30, + "user": "Write a polite email declining a meeting invitation.", + "max_tokens": 13, + "prompt_tokens": 21, + "golden_ids": [ + 12646, + 25, + 997, + 25, + 28107, + 80370, + 471, + 498, + 62394, + 31819, + 14, + 1851, + 60 + ], + "finish": "length", + "ref_sha256": "babd437d849e8ceca3ee5632b4e1e12327574cfa3ce5383e0c5d76e2023b3d64" + }, + { + "i": 31, + "user": "What is a mutex and when would you use one?", + "max_tokens": 20, + "prompt_tokens": 23, + "golden_ids": [ + 2, + 63979, + 318, + 49708, + 899, + 1326, + 8686, + 8, + 271, + 550, + 3437, + 2091, + 264, + 63979, + 30, + 271, + 32, + 2972, + 21670, + 332 + ], + "finish": "length", + "ref_sha256": "705bf4bdc3d0d99530c5a567ba128998c3b437a09dabc12bd4ba1fe396de5cc8" + } + ] +} diff --git a/evidence/dra65-prefill-20261031/window-dra65.sh b/evidence/dra65-prefill-20261031/window-dra65.sh new file mode 100755 index 00000000..b007b305 --- /dev/null +++ b/evidence/dra65-prefill-20261031/window-dra65.sh @@ -0,0 +1,67 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: Apache-2.0 +# DRA-65 chip window (Main runs it inside a quiet exclusive spark-window; see README.md "Window"). +# The script never starts or stops a server: Main starts each server as README.md lists, then runs +# window-dra65.sh golden PORT OUT green|red 32-prompt set + long prompts vs the pinned goldens +# window-dra65.sh time PORT OUT TTFT and end-to-end tok/s, 512 and ~8k prompts, 3 runs each +# Exit: golden 0 = verdict as expected (green: 35/35 identical; red: at least one differs), 1 = not as +# expected, 2 = no verdict (server unreachable, unparsable replies). time: 0 = receipts written, 2 = none. +set -uo pipefail +HERE=$(cd "$(dirname "$0")" && pwd); REPO=$(cd "$HERE/../.." && pwd) +MODE=${1:?golden|time}; PORT=${2:?port}; OUT=${3:?out dir}; mkdir -p "$OUT" +URL=http://127.0.0.1:$PORT +MODEL=$(curl -s -m 10 "$URL/v1/models" | jq -r '.data[0].id // empty') +[ -n "$MODEL" ] || { echo "window-dra65: no model on $URL" >&2; exit 2; } +DEF=$(jq -c .defaults "$HERE/set32.json") +body() { # [stream] + jq -cn --arg m "$MODEL" --arg u "$1" --argjson n "$2" --argjson d "$DEF" --argjson s "${3:-false}" \ + '$d + {model:$m, messages:[{role:"user",content:$u}], max_tokens:$n} + (if $s then {stream:true, stream_options:{include_usage:true}} else {} end)' +} +ask() { curl -s -m 1800 "$URL/v1/chat/completions" -H 'Content-Type: application/json' -d "$1"; } +# pins: the set, the prompt files and the long goldens must hash as committed +(cd "$REPO" && sha256sum -c --quiet "$HERE/SHA256SUMS") || { echo "window-dra65: pinned inputs changed" >&2; exit 2; } + +case $MODE in +golden) + EXPECT=${4:?green|red}; same=0; diff=0; bad=0 + for i in $(seq 0 31); do + u=$(jq -r ".prompts[$i].user" "$HERE/set32.json"); n=$(jq -r ".prompts[$i].max_tokens" "$HERE/set32.json") + ask "$(body "$u" "$n")" > "$OUT/p$i.raw" + got=$(jq -c '.usage.aien_token_ids // empty' "$OUT/p$i.raw" 2>/dev/null); want=$(jq -c ".prompts[$i].golden_ids" "$HERE/set32.json") + if [ -z "$got" ]; then bad=$((bad+1)); v=NO_IDS; elif [ "$got" = "$want" ]; then same=$((same+1)); v=SAME; else diff=$((diff+1)); v=DIFF; fi + jq -cn --arg id "p$i" --arg v $v --argjson g "${got:-null}" --argjson w "$want" '{id:$id, verdict:$v, got:$g, golden:$w}' >> "$OUT/golden.jsonl" + done + for k in 0 1 2; do + f=$(jq -r ".prompts[$k].file" "$HERE/long-goldens.json"); name=$(jq -r ".prompts[$k].name" "$HERE/long-goldens.json") + ask "$(body "$(cat "$REPO/$f")" 24)" > "$OUT/$name.raw" + got=$(jq -c '.usage.aien_token_ids // empty' "$OUT/$name.raw" 2>/dev/null); want=$(jq -c ".prompts[$k].golden_ids" "$HERE/long-goldens.json") + if [ -z "$got" ]; then bad=$((bad+1)); v=NO_IDS; elif [ "$got" = "$want" ]; then same=$((same+1)); v=SAME; else diff=$((diff+1)); v=DIFF; fi + jq -cn --arg id "$name" --arg v $v --argjson g "${got:-null}" --argjson w "$want" '{id:$id, verdict:$v, got:$g, golden:$w}' >> "$OUT/golden.jsonl" + done + if [ $bad -gt 0 ]; then verdict=INCONCLUSIVE; rc=2 + elif [ "$EXPECT" = green ] && [ $same -eq 35 ]; then verdict=PASS; rc=0 + elif [ "$EXPECT" = red ] && [ $diff -gt 0 ]; then verdict=PASS; rc=0 + else verdict=FAIL; rc=1; fi + jq -cn --arg e "$EXPECT" --arg v $verdict --argjson s $same --argjson d $diff --argjson b $bad --arg port "$PORT" --arg at "$(date -u +%FT%TZ)" \ + '{case:"golden", expect:$e, verdict:$v, identical:$s, differ:$d, no_ids:$b, of:35, port:$port, at:$at}' | tee "$OUT/golden-receipt.json" + exit $rc ;; +time) + # One streamed request per run: TTFT = first content delta (client clock), e2e tok/s = completion + # tokens / (last byte - first content delta). Medians go through Wolfram afterwards (README). + for name in long-512 long-8192; do + f=$HERE/$name.txt; [ -f "$f" ] || f=$REPO/evidence/merge-train/l369/$name.txt + for run in 1 2 3; do + o=$OUT/$name-r$run; t0=$(date +%s.%N); first="" + while IFS= read -r line; do + case $line in data:*'"content":"'?*) [ -z "$first" ] && first=$(date +%s.%N);; esac + printf '%s\n' "$line" >> "$o.sse" + done < <(curl -s -N -m 1800 "$URL/v1/chat/completions" -H 'Content-Type: application/json' -d "$(body "$(cat "$f")" 256 true)") + t1=$(date +%s.%N) + usage=$(grep '"usage"' "$o.sse" | grep -v '"usage":null' | tail -n 1 | sed 's/^data: //' | jq -c '.usage // null' 2>/dev/null) + jq -cn --arg n "$name" --argjson r $run --arg t0 "$t0" --arg tf "${first:-}" --arg t1 "$t1" --argjson u "${usage:-null}" \ + '{prompt:$n, run:$r, t0:$t0, t_first:$tf, t_end:$t1, usage:$u}' | tee -a "$OUT/time.jsonl" + done + done + exit 0 ;; +*) echo "window-dra65: mode golden|time" >&2; exit 2 ;; +esac From d1c5a9d513f60715d7647b39dba9f563470e0304 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Sat, 31 Oct 2026 08:08:12 -0500 Subject: [PATCH 2/8] DRA-65 window: prefill-only red arm, turn-2 snapshot case, strict judge, red-before-green Review Rev862 on #862: AIEN_OMEGA_Q36_PF_MUTANT=2 red with chunking and green with CHUNK=0 proves the chunk path runs; turn 2 of long-2048 restores a snapshot taken after a chunked prefill; empty/short ids and HTTP errors are INCONCLUSIVE, never red PASS; time mode exits 2 on a failed run; green needs two red PASS receipts of the same binary sha; golden sources sha-pinned; CHUNK=0 wording corrected. --- evidence/dra65-prefill-20261031/README.md | 71 +++++++--- evidence/dra65-prefill-20261031/SHA256SUMS | 5 +- .../dra65-prefill-20261031/long-goldens.json | 37 ++++- evidence/dra65-prefill-20261031/set32.json | 4 +- .../turn2.messages.json | 1 + .../dra65-prefill-20261031/window-dra65.sh | 130 ++++++++++++------ 6 files changed, 181 insertions(+), 67 deletions(-) create mode 100644 evidence/dra65-prefill-20261031/turn2.messages.json diff --git a/evidence/dra65-prefill-20261031/README.md b/evidence/dra65-prefill-20261031/README.md index 110354b6..737c9e41 100644 --- a/evidence/dra65-prefill-20261031/README.md +++ b/evidence/dra65-prefill-20261031/README.md @@ -17,8 +17,11 @@ Refs aien-dev/aien-sovereign-core-mv#856, Linear DRA-65. ## Change (IMPLEMENTED) - `prefill.rs`: `Qwen38Omega::prefill_state(tokens, chunk)` feeds tokens for their state only; on the 35B as chip - prefill chunks of `AIEN_Q36_PREFILL_CHUNK` (default 128, 0 = the old token-by-token path, same binary) at any - length from 1. `prefill_rows` on the 35B now chunks all but the last token and steps the last one for its + prefill chunks of `AIEN_Q36_PREFILL_CHUNK` (default 128) at any length from 1. `AIEN_Q36_PREFILL_CHUNK=0` makes + the new binary feed EVERY prompt token through the decode graph, the answer-header piece included; the base + binary's default already chunked that last piece when it was >= 3 tokens, so the CHUNK=0 arm is slower than the + old production single door by about one header (`N[7*0.0201]` = 0.14 s), not equal to it. `prefill_rows` on + the 35B now chunks all but the last token and steps the last one for its residual (the chip prefill keeps its rows in `pf.x`, not the decode graph's x, so `residual()` is only valid after a step); `all=true` still steps every token (its rows are not exported by the chip prefill). `q36_chunk_lengths` is the one chunk plan `prefill_moe_head` iterates. @@ -33,37 +36,67 @@ Refs aien-dev/aien-sovereign-core-mv#856, Linear DRA-65. `i==0 ? 24 : 8 + (i*7) % 41`), goldens = reference build **bin-5b726818** ("plain correct path: prompt fed token by token, no speed levers"), each request alone, recorded 2026-10-21 (before this change). Prompt 0's ids equal the host-oracle golden `evidence/q36-host-20261020/gen-chat-max-24.json`. `long-goldens.json` adds the 365 / -2486 / 8210-token prompts with goldens from bin-16b0e6f8 (batch door, prompts token by token). 35 cases in all. -Judge: exact id identity (the door returns no logit margins, so the 0.1-logit band cannot be judged through it; -any flip is FAIL). `SHA256SUMS` pins every input; the script refuses to run if one changed. +2486 / 8210-token prompts and **turn 2** of long-2048 (2528 tokens, three messages, `turn2.messages.json`) with +goldens from bin-16b0e6f8 (prompts token by token). The script sends turn 2 right after long-2048, so the door +restores the snapshot it took at long-2048's answer header after a chunked prefill (`plan_reuse` -> +`Reuse::Snapshot`). 36 cases in all. + +Provenance: both files name `source_dir` (the merge-train store); every case carries `ref_sha256` of its source +golden (`alone/.json`, `l369-long/.json`), and `long-goldens.json` carries the store's `done` receipt +text and sha256 (it names bin-16b0e6f8). `SHA256SUMS` pins every committed input; the script refuses to run if +one changed. + +Judge: exact id identity (the door returns no logit margins, so the 0.1-logit band cannot be judged through it). +Per case SAME / DIFF (a flip inside the common length, or more ids than the golden) / SHORT (a strict prefix: no +flip shown) / NO_IDS (HTTP error, missing or empty ids). Red PASS needs a DIFF and no SHORT/NO_IDS (else +INCONCLUSIVE); green PASS needs 36 SAME (NO_IDS -> INCONCLUSIVE, else FAIL). Green refuses to run without two red +PASS receipts with distinct labels for the same server binary sha256. ## Host evidence (EXERCISED on host, not chip) `nice -n 19 taskset -c 0-9 cargo test -p aien-inference-abi --lib qwen38_omega`: 9 passed (chunk boundaries at 1, 127, 128, 129, 2048, 8192 and 8210; env switch 0/default/cap/129/garbage; snapshot point and rows/last split at the same lengths and on turn 2; 35B rows never stepped). Negative control: `q36_chunk_lengths` mutated to drop a -remainder of 1 -> `q36_chunks_at_the_boundaries` FAILED, then restored. Judge exercised against a mock door -(exact goldens / one id changed): green PASS + red FAIL, and green FAIL (exit 1) + red PASS. +remainder of 1 -> `q36_chunks_at_the_boundaries` FAILED, then restored. The host tests cover only the pure split +rules: a `prefill_state` or `feed_rows` that loses a token stays green on the host (review Rev862 M4/M5), which is +why the window's prefill-only red arm (step 2) is required. + +Script against a mock door (`/tmp/dra65mock/mock2.py`): red with one turn-2 id changed PASS rc 0; red on exact +goldens FAIL rc 1; red on empty ids, short ids or HTTP 500 INCONCLUSIVE rc 2; green with 0 or 1 red receipt, or +with receipts of another binary sha, refused rc 2; green with two receipts: exact PASS rc 0, one id changed FAIL +rc 1, empty ids INCONCLUSIVE rc 2; time: exact RECORDED rc 0 (6/6 runs ok), HTTP 500 and missing usage +INCONCLUSIVE rc 2. Mutant 4 wiring (source, omega 474197e4f): `AIEN_Q36_TEST_MUTANT=4` -> `moe.rs` `graph_mutant()` -> `test_set_mutant` on the main graph and (`rows.rs` wire) every row and stroke graph; in C mutant 4 swaps K_CN for K_CN_M3 in the decode path and in `omega_gpu_q36_graph_prefill` (the chunk path), K_CN_R for K_CN_R_M3 in rows. -So the env mutant reaches the chunked prefill. The per-request `aien_test` mutant does not (the batch door steps -such rows token by token), so the window uses the env mutant. +So the env mutant reaches the chunked prefill. It also breaks decode, so it cannot show the chunk path runs. The +prefill-only mutant does: `AIEN_OMEGA_Q36_PF_MUTANT` is read by `omega_gpu_q36_graph.c` L925 when the prefill +buffers are set up in the server process (header L146: 2 = every expert segment one row short); the decode graph +never reads it, and with `AIEN_Q36_PREFILL_CHUNK=0` the single door runs no chip prefill at all +(`prefill.rs` L298, L344). So PF_MUTANT=2 must be red with chunking and green with CHUNK=0. ## Window (Main; chip gates NOT_RUN until then) Quiet exclusive window per the usual procedure (marker, stop 18091 and Flint, `spark-window open ... --gb10 -exclusive --quiet exclusive`). NEW = the build of this branch. Each line: start the server, run, stop. - -1. Single door, NEW, `AIEN_Q36_TEST_MUTANT=4`: `window-dra65.sh golden PORT OUT/w1-mutant red` -> must PASS (red). -2. Single door, NEW: `window-dra65.sh golden PORT OUT/w2-single green` -> PASS = 35/35 identical. -3. Batch door (`--batch-slots 8`), NEW: `window-dra65.sh golden PORT OUT/w3-batch green`. -4. `window-dra65.sh time PORT OUT/w4-` on: single NEW; single NEW with `AIEN_Q36_PREFILL_CHUNK=0` (before - arm); batch NEW; batch NEW with `AIEN_Q36_PREFILL_MIN=1` (chunks the answer header too). - Receipts: `time.jsonl` (t0, first content delta, end, usage per run). TTFT = t_first - t0; e2e tok/s = - completion_tokens / (t_end - t_first). Medians of the 3 runs through Wolfram (`Median[{...}]`). - Target 1 compares e2e against chip-only decode from DRA-66's `chip_ns` in the same runs. +exclusive --quiet exclusive`). NEW = the build of this branch, `B=$(sha256sum | cut -c1-64)`. +Each line: start the server with the env shown, run, stop. Steps 1-2 must come first; step 3 onward need their +receipts. + +1. Single door, `AIEN_Q36_TEST_MUTANT=4`: `window-dra65.sh golden PORT OUT/w1 red $B mutant4` -> PASS (red). +2. Single door, `AIEN_OMEGA_Q36_PF_MUTANT=2`: `window-dra65.sh golden PORT OUT/w2 red $B pf2` -> PASS (red: the + chunk path runs). +3. Single door, `AIEN_OMEGA_Q36_PF_MUTANT=2 AIEN_Q36_PREFILL_CHUNK=0`: `window-dra65.sh golden PORT OUT/w3 green + $B pf2-chunk0 OUT/w1/golden-receipt.json OUT/w2/golden-receipt.json` -> PASS (the mutant lives on the chunk + path only). +4. Single door, plain: `... golden PORT OUT/w4 green $B single OUT/w1/... OUT/w2/...` -> PASS = 36/36. +5. Batch door (`--batch-slots 8`), plain: `... golden PORT OUT/w5 green $B batch OUT/w1/... OUT/w2/...`. +6. `window-dra65.sh time PORT OUT/w6- $B ` on: single; single with `AIEN_Q36_PREFILL_CHUNK=0` (the + all-token-steps arm above); batch; batch with `AIEN_Q36_PREFILL_MIN=1` (chunks the answer header too). Exit 0 + only if all 6 runs have HTTP 200, a first content delta and usage. Receipts: `time.jsonl`. TTFT = t_first - t0; + e2e tok/s = completion_tokens / (t_end - t_first). Medians of the 3 runs through Wolfram (`Median[{...}]`). + Record `usage.prompt_tokens` of long-512 (the host has no tokenizer). Target 1 compares e2e against chip-only + decode from DRA-66's `chip_ns` in the same runs. ## Predictions (MODELED, Wolfram) diff --git a/evidence/dra65-prefill-20261031/SHA256SUMS b/evidence/dra65-prefill-20261031/SHA256SUMS index bc6e0d75..3c062f43 100644 --- a/evidence/dra65-prefill-20261031/SHA256SUMS +++ b/evidence/dra65-prefill-20261031/SHA256SUMS @@ -1,7 +1,8 @@ 7a171b54c2effda998d2884e3f6868b55123fa8ba779dcf2762dff4c64a1fa29 evidence/q36-batch-20261021/prompts.txt -c1d4696b8e8d3ef7a81953fe4191db4bb51160276b5ccdf93a146a284b90dd3e evidence/dra65-prefill-20261031/set32.json -06441284f2300e384b7d4cd55bc0d307c71825f4f233edebe228a79e14286141 evidence/dra65-prefill-20261031/long-goldens.json +d0bcb237803b0299d0a45ceb3bf1660628a369d286fcd82da617a7a31d5f2941 evidence/dra65-prefill-20261031/set32.json +05b01b70caa2b21d6c1051eeaebbb7e65d208bd988ff49b5b7a202d13a46fe89 evidence/dra65-prefill-20261031/long-goldens.json 3b27d724b10446308d0c0b0a68b72573cdb26e22f0d1994bde88880988bec8d3 evidence/dra65-prefill-20261031/long-512.txt +7a3661c1159cae61e2747eaf9047a6083367be1f643e386d9b80c27131ce7b3e evidence/dra65-prefill-20261031/turn2.messages.json 153a5f88932393b2be56fd81f8914d44218169c614ebc5b2753069c9a09bc3a1 evidence/merge-train/l369/long-256.txt 26a44c508412e213de876eb54bb90390426b086c887a68b90fa78f7470425ee3 evidence/merge-train/l369/long-2048.txt 2bcc84b25c418cba83df9546344fd4ae28962c314e03defe2aab62a8e6c8abb9 evidence/merge-train/l369/long-8192.txt diff --git a/evidence/dra65-prefill-20261031/long-goldens.json b/evidence/dra65-prefill-20261031/long-goldens.json index 540e6ece..a2b68de9 100644 --- a/evidence/dra65-prefill-20261031/long-goldens.json +++ b/evidence/dra65-prefill-20261031/long-goldens.json @@ -1,5 +1,9 @@ { - "about": "long-prompt goldens from reference build bin-16b0e6f8 (batch door, prompts token by token), each alone, 2026-10-21T22:11:19Z", + "about": "long-prompt and turn-2 goldens from reference build bin-16b0e6f8 (prompts token by token), each alone, 2026-10-21T22:11:19Z", + "source_dir": "~/.local/state/aien-q36/merge-train/refs/qwen3.6-35b-a3b-fp8-95a723d0/5b726818/", + "done_receipt": "l369-long/done", + "done_sha256": "f9435cbb8e39b9467a59d95f7f2e8282a3b92ed31ede7642c1f21673012c322e", + "done_text": "2026-10-21T22:11:19Z port 18091 model qwen3.6-35b-a3b-fp8 {\"build\":null} reference build bin-16b0e6f8 (live 18091, prompts token by token), each request alone; L387", "prompts": [ { "name": "long-256", @@ -32,7 +36,9 @@ 430, 314 ], - "max_tokens": 24 + "max_tokens": 24, + "ref": "l369-long/long-256.json", + "ref_sha256": "0998d4c6d9734b24a282aac8bb0ca61c3ea832f0551033bb4dda7f1470ea523b" }, { "name": "long-2048", @@ -65,7 +71,9 @@ 25471, 1204 ], - "max_tokens": 24 + "max_tokens": 24, + "ref": "l369-long/long-2048.json", + "ref_sha256": "3dff923dc6932a1828d864b565a6c89e12805839ce80758370bd47081af3c3c9" }, { "name": "long-8192", @@ -98,7 +106,28 @@ 321, 25147 ], - "max_tokens": 24 + "max_tokens": 24, + "ref": "l369-long/long-8192.json", + "ref_sha256": "cdcef9435130dbff56628c3a6b01cf1824fd2f1feeeecd80de378cb054147cca" + }, + { + "name": "turn2", + "messages": "evidence/dra65-prefill-20261031/turn2.messages.json", + "file_sha256": "7a3661c1159cae61e2747eaf9047a6083367be1f643e386d9b80c27131ce7b3e", + "prompt_tokens": 2528, + "golden_ids": [ + 79852, + 6297, + 11540, + 9284, + 2790, + 13 + ], + "max_tokens": 16, + "ref": "l369-long/turn2.json", + "ref_sha256": "19fb7084e0df36faee9c574627d1ff9a10b059afc1884cd62963f14690e59cf4", + "after": "long-2048", + "about": "turn 2 of long-2048 (its golden reply as the assistant turn): run right after long-2048 so the door restores the snapshot taken at long-2048 answer header after a chunked prefill" } ] } diff --git a/evidence/dra65-prefill-20261031/set32.json b/evidence/dra65-prefill-20261031/set32.json index f1725fed..97744947 100644 --- a/evidence/dra65-prefill-20261031/set32.json +++ b/evidence/dra65-prefill-20261031/set32.json @@ -1130,5 +1130,7 @@ "finish": "length", "ref_sha256": "705bf4bdc3d0d99530c5a567ba128998c3b437a09dabc12bd4ba1fe396de5cc8" } - ] + ], + "source_dir": "~/.local/state/aien-q36/merge-train/refs/qwen3.6-35b-a3b-fp8-95a723d0/5b726818/", + "ref_note": "prompts[i].ref_sha256 = sha256 of source_dir/alone/.json" } diff --git a/evidence/dra65-prefill-20261031/turn2.messages.json b/evidence/dra65-prefill-20261031/turn2.messages.json new file mode 100644 index 00000000..db731f47 --- /dev/null +++ b/evidence/dra65-prefill-20261031/turn2.messages.json @@ -0,0 +1 @@ +[{"role":"user","content":"ne 503-511, VERIFIED), so an unseen file is free until found. 23. FS adapter: reversible filename from the key, `.tmp` suffix + `os.replace`, unlink of the temp on failure; no `fsync` anywhere in the file (fs_l2_adapter.py:99-135, 518-532, 640-662, VERIFIED; absence of `fsync` VERIFIED by grep). 24. Tests adapted (test_nixl_store_dynamic_l2_adapter.py): `test_salted_objects_recover_independently_after_restart` (745), `test_store_rejected_when_capacity_exceeded` (985), `test_batched_store_reports_failure_when_capacity_exceeded` (1034), `test_secondary_lookup_finds_key` (1113), `test_secondary_lookup_and_load_data` (1138), `test_load_partial_failure_marks_only_successful` (561), `test_delete_skips_pinned_key` (887). Each is re-expressed as a Rust test; none is copied. Attribution: an Apache-2.0 header on `crates/aien-kv-store/src/identity.rs` (the prefix-chain idea) and the test file that adapts the cases, plus a THIRD_PARTY.md row (\"LMCache, Apache-2.0, ideas adapted: deterministic rolling prefix keys, completed-object publication by temp+rename, lazy disk recovery; no code copied\"). The LMCache clone has a LICENSE and no NOTICE file (VERIFIED by `ls`). ### Prior art in this repository (not depended on) 25. OWN-30B serve branch `own30b/serve` (sc-own30b, unmerged, pinned at commit 69459db): in-memory prefix reuse for one conversation, `reused = common.min(prompt.len() - 1)` so at least the last prompt token is always recomputed to produce logits (crates/aien-inference-abi/src/qwen3_moe_omega.rs:2163 at 69459db, VERIFIED), test `prefix_reuse_prefills_only_the_new_tokens_and_matches_a_cold_run` (fn at 2421 at 69459db, VERIFIED). Line numbers move on that branch; the pin is the commit. This ADR adopts the same \"never restore the last prompt token\" rule (section 6.5) and the same warm-equals-cold test shape. Nothing else overlaps: that branch has no disk, no identity, no sharing across requests. ## Decision drivers 1. Correctness before speed: no byte is reused unless its identity proves compatibility, and validation happens before any allocation or copy. 2. The runtime mutex and the KV lock are never held across storage I/O. 3. Everything is bounded: queue depth, bytes in flight, recovery memory, disk quota including objects never looked up. 4. One record header for host and native, so tooling and tests read both; payloads differ by backend format and are never cross-loaded. 5. The native side keeps the single-command, bounce-buffered NVMe contract and the freestanding no_std rule. 6. Conversation history stays authoritative; the KV store is a cache that may be dropped at any time. ## 1. Versioned chunk identity ### 1.1 Units - A **chunk** is `chunk_tokens = chunk_blocks * block_size` consecutive positions of one sequence, aligned to a multiple of `chunk_tokens`. `chunk_blocks` is a setting fixed into the namespace (default 16 blocks; with the 16-token blocks of `model_dir.rs` that is 256 tokens (calc:ceaa1589), LMCache's default). A chunk is **full** when it holds `chunk_tokens` positions. The last chunk of a parked sequence may be **partial** (`token_count < chunk_tokens`); partial chunks are keyed with their exact token count and therefore only ever match an identical prefix of identical length. Only full chunks are prefix-share candidates. - Hash everywhere is SHA-256 (host: `sha2`, already in the lockfile; native: argus `sha256.h`, used by `store_v1.h`). blake3 is not used because native has no blake3. ### 1.2 Namespace id (binds everything that must be equal for bytes to be reusable) `namespace_id = SHA-256( \"AIEN-PKV-NS-V2\\0\" || fields )` (V1 until sc#504; the domain moved when field 14 started to bind the engine, section 1.2.2, so no V1 namespace can match) where `fields`, in this order, little-endian: | # | field | type | source | |---|---|---|---| | 1 | format_version | u16 = 1 | this ADR | | 2 | model_sha256 | [u8;32] | `ModelIdentity.model_sha256` decoded from hex (generation.rs:25) | | 3 | model_digest_kind | u8 len + bytes | `ModelIdentity.model_digest_kind` (generation.rs:26) | | 4 | model_id | u16 len + bytes | `ModelConfig.model_id` | | 5 | num_layers, num_kv_heads, head_dim, block_size | 4 x u32 | `ModelConfig` | | 6 | rope_theta | u32 (f32 bits) | `ModelConfig.rope_theta` | | 7 | rope_scaling | u8 tag (0 none, 1 llama3) then, if 1: factor f64 bits, low_freq_factor f64 bits, high_freq_factor f64 bits, original_max_position_embeddings u64 | `Llama3RopeScaling` (abi-core lib.rs:45-50) | | 8 | qk_norm | u8 | `ModelConfig.qk_norm` | | 9 | dtype | u8 (1 Fp4, 2 Fp8, 3 Bf16, 4 Fp16, 5 Fp32) | `KvDType` | | 10 | layout | 5 x u64 strides (head, token, kv_plane, layer, block) + u64 element_bytes | `KvLayout` (lib.rs:143-156) | | 11 | backend_format | u8 (1 = host paged pool v1; 2 = native f32 decode state v1) | section 2.3 | | 12 | chunk_tokens | u32 | setting | | 13 | sharing_namespace | u16 len + bytes | setting `AIEN_KV_STORE_NAMESPACE` (host); sealed Store uuid + identity class + subject id (native, section 9) | | 14 | compute_config_digest | [u8;32] | `ComputeConfig::digest_with_engine(engine)`, sections 1.2.1 and 1.2.2 (added by the review, C1 delta in section 12; binds the engine since sc#504) | Rationale: fields 2-8 cover \"which weights, which geometry, which RoPE\"; 9-11 cover \"which bytes\"; 13 is the authorization scope; 14 covers every other number that changes what the forward pass computes. Two runtimes with different `block_size` or `chunk_tokens` cannot share objects, by design: positions and chunk boundaries are part of identity. #### 1.2.1 Compute configuration digest (review finding 1) The review showed (VERIFIED by the orchestrator) that two model directories with the same weights digest and the same fields 1-13 but a different `rms_norm_eps` in `config.json` produce different K/V: the backend reads `weights.config.rms_norm_eps` for every RMSNorm (transformer_backend.rs:738, 1111, 1391, 1760) and the value comes from `config.json` (model_dir.rs:112, 239). The weights digest covers the safetensors bytes only, not `config.json`. `ComputeConfig::digest() = SHA-256(\"AIEN-PKV-CFG-V1\\0\" || ComputeConfig)` (namespace field 14 until sc#504; field 14 is now the V2 digest of section 1.2.2, which hashes the same nine fields first) where `ComputeConfig` is, little-endian and in this order: | # | field | type | source | |---|---|---|---| | 1 | num_heads | u32 | `ModelConfig.num_heads` | | 2 | hidden_dim | u64 | `ModelConfig.hidden_dim` | | 3 | intermediate_dim | u64 | `ModelConfig.intermediate_dim` | | 4 | vocab_size | u64 | `ModelConfig.vocab_size` | | 5 | rms_norm_eps | u32 (f32 bits) | `ModelConfig.rms_norm_eps` | | 6 | tie_word_embeddings | u8 | `ModelConfig.tie_word_embeddings` | | 7 | hidden_act | u8 (1 = silu) | `config.json` `hidden_act`; the loader refuses everything but silu (model_dir.rs:198-199, VERIFIED), so the byte is a constant today and exists so a future activation cannot alias | | 8 | arith_id | u8 len + bytes | `TensorBackend::name()` (backend.rs:131, VERIFIED trait method; implementations return `\"ReferenceCpuBackend\"` at backend.rs:509-511, `\"NativeCpuBackend (Rayon Multi-Core)\"` at mojo_backend.rs:242-244, and an availability-dependent string at omega_backend.rs:815-820, all VERIFIED) | | 9 | arith_epoch | u32 | a constant `KV_ARITH_EPOCH` in `aien-inference-abi`, bumped by any change that alters numeric results of the forward pass | Fields not listed and why (each is a decision, not an omission): `model_id` (field 4 of the namespace), `num_layers`, `num_kv_heads`, `head_dim`, `block_size`, `rope_theta`, `rope_scaling`, `qk_norm` (namespace fields 5-8), `max_sequence_length` (caps context, does not change a K/V value; the cap is applied to the restorable prefix, section 6.3), `eos_token_ids` (decides when to stop, not what is computed), `attention_bias` and `mlp_bias` (the loader refuses true, model_dir.rs:201-203, so they cannot vary). **Why the resolved `ModelConfig` and not a digest of the raw `config.json`** (INFERRED, decision): (a) the raw file carries fields that cannot change a K/V value (`torch_dtype`, `transformers_version`, `use_cache`, `initializer_range`; model_dir.rs:22-52 lists the\n\nIn one sentence, what is the text above about?"},{"role":"assistant","content":"The text is a technical specification detailing the design of a versioned chunk identity system for a KV cache store, defining how"},{"role":"user","content":"Now say it again in five words."}] diff --git a/evidence/dra65-prefill-20261031/window-dra65.sh b/evidence/dra65-prefill-20261031/window-dra65.sh index b007b305..56a36d7e 100755 --- a/evidence/dra65-prefill-20261031/window-dra65.sh +++ b/evidence/dra65-prefill-20261031/window-dra65.sh @@ -2,66 +2,114 @@ # SPDX-License-Identifier: Apache-2.0 # DRA-65 chip window (Main runs it inside a quiet exclusive spark-window; see README.md "Window"). # The script never starts or stops a server: Main starts each server as README.md lists, then runs -# window-dra65.sh golden PORT OUT green|red 32-prompt set + long prompts vs the pinned goldens -# window-dra65.sh time PORT OUT TTFT and end-to-end tok/s, 512 and ~8k prompts, 3 runs each -# Exit: golden 0 = verdict as expected (green: 35/35 identical; red: at least one differs), 1 = not as -# expected, 2 = no verdict (server unreachable, unparsable replies). time: 0 = receipts written, 2 = none. +# window-dra65.sh golden PORT OUT red BIN_SHA256 LABEL +# window-dra65.sh golden PORT OUT green BIN_SHA256 LABEL RED_RECEIPT RED_RECEIPT [...] +# 36 cases (32-prompt set, 3 long prompts, turn 2 restoring the long-2048 snapshot) vs the pinned goldens. +# green refuses to run unless it is handed at least two red receipts (verdict PASS, distinct labels) +# of the same server binary sha256: red before green. +# window-dra65.sh time PORT OUT BIN_SHA256 LABEL +# TTFT and end-to-end tok/s, ~512 and 8210-token prompts, 3 runs each. +# Per case: SAME (ids equal), DIFF (a flip inside the common length, or more ids than the golden), +# SHORT (a strict prefix of the golden: no flip shown), NO_IDS (HTTP error, missing or empty ids). +# golden red: PASS = at least one DIFF and no NO_IDS/SHORT; NO_IDS/SHORT -> INCONCLUSIVE; else FAIL. +# golden green: PASS = all SAME; any NO_IDS -> INCONCLUSIVE; else FAIL. +# Exit 0 = PASS, 1 = FAIL, 2 = INCONCLUSIVE or refused. time: 0 only if every run has HTTP 200, a +# first content delta and usage with completion_tokens > 0; else 2 (INCONCLUSIVE). set -uo pipefail HERE=$(cd "$(dirname "$0")" && pwd); REPO=$(cd "$HERE/../.." && pwd) -MODE=${1:?golden|time}; PORT=${2:?port}; OUT=${3:?out dir}; mkdir -p "$OUT" +die() { echo "window-dra65: $*" >&2; exit 2; } +MODE=${1:-}; PORT=${2:-}; OUT=${3:-} +[ -n "$MODE" ] && [ -n "$PORT" ] && [ -n "$OUT" ] || die "usage: see the header" URL=http://127.0.0.1:$PORT -MODEL=$(curl -s -m 10 "$URL/v1/models" | jq -r '.data[0].id // empty') -[ -n "$MODEL" ] || { echo "window-dra65: no model on $URL" >&2; exit 2; } +(cd "$REPO" && sha256sum -c --quiet "$HERE/SHA256SUMS") || die "pinned inputs changed" +mkdir -p "$OUT" +MODEL=$(curl -s -m 10 "$URL/v1/models" | jq -r '.data[0].id // empty' 2>/dev/null) +[ -n "$MODEL" ] || die "no model on $URL" DEF=$(jq -c .defaults "$HERE/set32.json") -body() { # [stream] - jq -cn --arg m "$MODEL" --arg u "$1" --argjson n "$2" --argjson d "$DEF" --argjson s "${3:-false}" \ - '$d + {model:$m, messages:[{role:"user",content:$u}], max_tokens:$n} + (if $s then {stream:true, stream_options:{include_usage:true}} else {} end)' +SET=$HERE/set32.json; LONG=$HERE/long-goldens.json +req() { # [stream] + jq -cn --arg m "$MODEL" --argjson msg "$1" --argjson n "$2" --argjson d "$DEF" --argjson s "${3:-false}" \ + '$d + {model:$m, messages:$msg, max_tokens:$n} + (if $s then {stream:true, stream_options:{include_usage:true}} else {} end)' +} +user() { jq -cn --arg u "$1" '[{role:"user",content:$u}]'; } +# ask : prints the HTTP code +ask() { curl -s -m 1800 -o "$3" -w '%{http_code}' "$URL/v1/chat/completions" -H 'Content-Type: application/json' -d "$(req "$1" "$2")"; } +judge() { # : prints SAME|DIFF|SHORT|NO_IDS + local got; [ "$1" = 200 ] || { echo NO_IDS; return; } + got=$(jq -c '.usage.aien_token_ids | select(type == "array" and length > 0)' "$2" 2>/dev/null) + [ -n "$got" ] || { echo NO_IDS; return; } + jq -rn --argjson g "$got" --argjson w "$3" ' + ([$g, $w] | map(length) | min) as $m + | if $g == $w then "SAME" + elif ([range(0; $m) | select($g[.] != $w[.])] | length) > 0 then "DIFF" + elif ($g | length) > ($w | length) then "DIFF" + else "SHORT" end' } -ask() { curl -s -m 1800 "$URL/v1/chat/completions" -H 'Content-Type: application/json' -d "$1"; } -# pins: the set, the prompt files and the long goldens must hash as committed -(cd "$REPO" && sha256sum -c --quiet "$HERE/SHA256SUMS") || { echo "window-dra65: pinned inputs changed" >&2; exit 2; } case $MODE in golden) - EXPECT=${4:?green|red}; same=0; diff=0; bad=0 + EXPECT=${4:-}; BIN=${5:-}; LABEL=${6:-} + case $EXPECT in red|green) ;; *) die "golden needs red|green";; esac + [[ $BIN =~ ^[0-9a-f]{64}$ ]] || die "BIN_SHA256 must be the server binary's sha256" + [ -n "$LABEL" ] || die "LABEL missing" + if [ "$EXPECT" = green ]; then + shift 6; reds=$(for r in "$@"; do jq -r --arg b "$BIN" \ + 'select(.case == "golden" and .expect == "red" and .verdict == "PASS" and .bin_sha256 == $b) | .label' "$r" 2>/dev/null; done | sort -u | wc -l) + [ "$reds" -ge 2 ] || die "green refused: needs >= 2 red PASS receipts (distinct labels) for binary $BIN, got $reds" + fi + : > "$OUT/golden.jsonl"; declare -A n=([SAME]=0 [DIFF]=0 [SHORT]=0 [NO_IDS]=0) + rec() { jq -cn --arg id "$1" --arg v "$2" --arg h "$3" --argjson w "$4" --slurpfile r <(jq -c . "$5" 2>/dev/null || echo null) \ + '{id:$id, verdict:$v, http:$h, got:($r[0].usage.aien_token_ids // null), golden:$w}' >> "$OUT/golden.jsonl"; } for i in $(seq 0 31); do - u=$(jq -r ".prompts[$i].user" "$HERE/set32.json"); n=$(jq -r ".prompts[$i].max_tokens" "$HERE/set32.json") - ask "$(body "$u" "$n")" > "$OUT/p$i.raw" - got=$(jq -c '.usage.aien_token_ids // empty' "$OUT/p$i.raw" 2>/dev/null); want=$(jq -c ".prompts[$i].golden_ids" "$HERE/set32.json") - if [ -z "$got" ]; then bad=$((bad+1)); v=NO_IDS; elif [ "$got" = "$want" ]; then same=$((same+1)); v=SAME; else diff=$((diff+1)); v=DIFF; fi - jq -cn --arg id "p$i" --arg v $v --argjson g "${got:-null}" --argjson w "$want" '{id:$id, verdict:$v, got:$g, golden:$w}' >> "$OUT/golden.jsonl" + u=$(jq -r ".prompts[$i].user" "$SET"); m=$(jq -r ".prompts[$i].max_tokens" "$SET"); w=$(jq -c ".prompts[$i].golden_ids" "$SET") + h=$(ask "$(user "$u")" "$m" "$OUT/p$i.raw"); v=$(judge "$h" "$OUT/p$i.raw" "$w"); n[$v]=$((n[$v]+1)); rec "p$i" "$v" "$h" "$w" "$OUT/p$i.raw" done - for k in 0 1 2; do - f=$(jq -r ".prompts[$k].file" "$HERE/long-goldens.json"); name=$(jq -r ".prompts[$k].name" "$HERE/long-goldens.json") - ask "$(body "$(cat "$REPO/$f")" 24)" > "$OUT/$name.raw" - got=$(jq -c '.usage.aien_token_ids // empty' "$OUT/$name.raw" 2>/dev/null); want=$(jq -c ".prompts[$k].golden_ids" "$HERE/long-goldens.json") - if [ -z "$got" ]; then bad=$((bad+1)); v=NO_IDS; elif [ "$got" = "$want" ]; then same=$((same+1)); v=SAME; else diff=$((diff+1)); v=DIFF; fi - jq -cn --arg id "$name" --arg v $v --argjson g "${got:-null}" --argjson w "$want" '{id:$id, verdict:$v, got:$g, golden:$w}' >> "$OUT/golden.jsonl" + # turn2 right after long-2048: the door restores the snapshot it took at long-2048's answer header. + for name in long-256 long-8192 long-2048 turn2; do + c=$(jq -c --arg n "$name" '.prompts[] | select(.name == $n)' "$LONG"); w=$(jq -c .golden_ids <<<"$c"); m=$(jq -r .max_tokens <<<"$c") + if [ "$name" = turn2 ]; then msg=$(jq -c . "$REPO/$(jq -r .messages <<<"$c")"); else msg=$(user "$(cat "$REPO/$(jq -r .file <<<"$c")")"); fi + h=$(ask "$msg" "$m" "$OUT/$name.raw"); v=$(judge "$h" "$OUT/$name.raw" "$w"); n[$v]=$((n[$v]+1)); rec "$name" "$v" "$h" "$w" "$OUT/$name.raw" done - if [ $bad -gt 0 ]; then verdict=INCONCLUSIVE; rc=2 - elif [ "$EXPECT" = green ] && [ $same -eq 35 ]; then verdict=PASS; rc=0 - elif [ "$EXPECT" = red ] && [ $diff -gt 0 ]; then verdict=PASS; rc=0 - else verdict=FAIL; rc=1; fi - jq -cn --arg e "$EXPECT" --arg v $verdict --argjson s $same --argjson d $diff --argjson b $bad --arg port "$PORT" --arg at "$(date -u +%FT%TZ)" \ - '{case:"golden", expect:$e, verdict:$v, identical:$s, differ:$d, no_ids:$b, of:35, port:$port, at:$at}' | tee "$OUT/golden-receipt.json" + if [ "$EXPECT" = red ]; then + if [ $((n[NO_IDS] + n[SHORT])) -gt 0 ]; then verdict=INCONCLUSIVE; rc=2 + elif [ "${n[DIFF]}" -gt 0 ]; then verdict=PASS; rc=0; else verdict=FAIL; rc=1; fi + else + if [ "${n[NO_IDS]}" -gt 0 ]; then verdict=INCONCLUSIVE; rc=2 + elif [ "${n[SAME]}" -eq 36 ]; then verdict=PASS; rc=0; else verdict=FAIL; rc=1; fi + fi + jq -cn --arg e "$EXPECT" --arg v $verdict --arg b "$BIN" --arg l "$LABEL" --argjson s "${n[SAME]}" --argjson d "${n[DIFF]}" \ + --argjson sh "${n[SHORT]}" --argjson x "${n[NO_IDS]}" --arg port "$PORT" --arg at "$(date -u +%FT%TZ)" \ + '{case:"golden", expect:$e, verdict:$v, bin_sha256:$b, label:$l, same:$s, diff:$d, short:$sh, no_ids:$x, of:36, port:$port, at:$at}' \ + | tee "$OUT/golden-receipt.json" exit $rc ;; time) - # One streamed request per run: TTFT = first content delta (client clock), e2e tok/s = completion - # tokens / (last byte - first content delta). Medians go through Wolfram afterwards (README). + BIN=${4:-}; LABEL=${5:-} + [[ $BIN =~ ^[0-9a-f]{64}$ ]] || die "BIN_SHA256 must be the server binary's sha256" + [ -n "$LABEL" ] || die "LABEL missing" + # TTFT = first content delta - t0 (client clock); e2e tok/s = completion_tokens / (t_end - t_first). + # Medians of the 3 runs go through Wolfram afterwards (README). + : > "$OUT/time.jsonl"; ok=1 for name in long-512 long-8192; do f=$HERE/$name.txt; [ -f "$f" ] || f=$REPO/evidence/merge-train/l369/$name.txt for run in 1 2 3; do - o=$OUT/$name-r$run; t0=$(date +%s.%N); first="" + o=$OUT/$name-r$run; : > "$o.sse"; t0=$(date +%s.%N); first="" while IFS= read -r line; do - case $line in data:*'"content":"'?*) [ -z "$first" ] && first=$(date +%s.%N);; esac + [ -z "$first" ] && [[ $line =~ ^data:.*\"content\":\ *\"[^\"] ]] && first=$(date +%s.%N) printf '%s\n' "$line" >> "$o.sse" - done < <(curl -s -N -m 1800 "$URL/v1/chat/completions" -H 'Content-Type: application/json' -d "$(body "$(cat "$f")" 256 true)") + done < <(curl -s -N -m 1800 -w '\nHTTP %{http_code}\n' "$URL/v1/chat/completions" -H 'Content-Type: application/json' \ + -d "$(req "$(user "$(cat "$f")")" 256 true)") t1=$(date +%s.%N) - usage=$(grep '"usage"' "$o.sse" | grep -v '"usage":null' | tail -n 1 | sed 's/^data: //' | jq -c '.usage // null' 2>/dev/null) - jq -cn --arg n "$name" --argjson r $run --arg t0 "$t0" --arg tf "${first:-}" --arg t1 "$t1" --argjson u "${usage:-null}" \ - '{prompt:$n, run:$r, t0:$t0, t_first:$tf, t_end:$t1, usage:$u}' | tee -a "$OUT/time.jsonl" + code=$(grep -o '^HTTP [0-9]*' "$o.sse" | tail -n 1 | cut -c6-) + usage=$(grep '^data: {' "$o.sse" | sed 's/^data: //' | jq -c 'select(.usage != null) | .usage' 2>/dev/null | tail -n 1) + good=$(jq -n --arg c "${code:-}" --arg f "$first" --argjson u "${usage:-null}" \ + '$c == "200" and $f != "" and ($u | type) == "object" and (($u.completion_tokens // 0) > 0)') + [ "$good" = true ] || ok=0 + jq -cn --arg n "$name" --argjson r $run --arg b "$BIN" --arg l "$LABEL" --arg h "${code:-}" --arg t0 "$t0" --arg tf "$first" \ + --arg t1 "$t1" --argjson u "${usage:-null}" --argjson g "$good" \ + '{prompt:$n, run:$r, bin_sha256:$b, label:$l, http:$h, ok:$g, t0:$t0, t_first:$tf, t_end:$t1, usage:$u}' | tee -a "$OUT/time.jsonl" done done - exit 0 ;; -*) echo "window-dra65: mode golden|time" >&2; exit 2 ;; + if [ $ok = 1 ]; then echo '{"case":"time","verdict":"RECORDED"}'; exit 0; fi + echo '{"case":"time","verdict":"INCONCLUSIVE","why":"a run had no HTTP 200, no first content delta or no usage"}'; exit 2 ;; +*) die "mode golden|time" ;; esac From b75034ebaac0b1e3c64f11523db5bc99323787aa Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Sat, 31 Oct 2026 08:14:11 -0500 Subject: [PATCH 3/8] DRA-65: host test of the feed path; window script runs only inside a chip window feed_prompt/feed_rows/feed_last (session) and q36_state/q36_chunk_walk (prefill) now carry the routing over two small traits the model implements; every_prompt_token_is_fed_once_in_order drives them with a recording fake (lengths 1, 127, 128, 129, 259; cached prefix 0, 61, len-3; chunk 128 and 0) and goes red under review Rev862's M4 and M5. window-dra65.sh refuses (exit 3, NOT_RUN) outside spark-window run with the chip lock held, stamps window id + binary sha into every receipt, prints per-step estimates (plan). --- .../src/qwen38_omega/prefill.rs | 76 +++-- .../src/qwen38_omega/session.rs | 313 +++++++++++++++--- evidence/dra65-prefill-20261031/README.md | 53 ++- .../dra65-prefill-20261031/window-dra65.sh | 53 ++- 4 files changed, 401 insertions(+), 94 deletions(-) diff --git a/crates/aien-inference-abi/src/qwen38_omega/prefill.rs b/crates/aien-inference-abi/src/qwen38_omega/prefill.rs index 6c81c078..218b0249 100644 --- a/crates/aien-inference-abi/src/qwen38_omega/prefill.rs +++ b/crates/aien-inference-abi/src/qwen38_omega/prefill.rs @@ -341,15 +341,7 @@ impl Qwen38Omega { if !self.is_moe() { return self.prefill_rows(tokens, chunk, false).map(|(_, st)| st); } - let c = q36_prefill_chunk()?; - let mut chunks = 0; - if c == 0 { - for &t in tokens { - self.step(t)?; - } - } else if !tokens.is_empty() { - chunks = self.prefill_moe_head(0, tokens, c, false)?.1; - } + let chunks = q36_state(self, tokens, q36_prefill_chunk()?)?; Ok(PrefillStats { tokens: tokens.len(), chunks, @@ -644,6 +636,57 @@ pub fn q36_chunk_lengths(n: usize, chunk: usize) -> Vec { out } +/// What the 35B's state feed drives: one decode step, or chip prefill chunks of `chunk` at head +/// 0's next positions without the head (the model; a recording fake in the session tests). +pub(crate) trait Q36Feed { + fn q36_step(&mut self, t: u32) -> Result<(), String>; + /// Returns the chunks run. + fn q36_chunks(&mut self, tokens: &[u32], chunk: usize) -> Result; +} + +impl Q36Feed for Qwen38Omega { + fn q36_step(&mut self, t: u32) -> Result<(), String> { + self.step(t).map(|_| ()) + } + + fn q36_chunks(&mut self, tokens: &[u32], chunk: usize) -> Result { + Ok(self.prefill_moe_head(0, tokens, chunk, false)?.1) + } +} + +/// [`Qwen38Omega::prefill_state`] on the 35B: `c == 0` steps every token, else chunks of `c`. +/// Returns the chunks run (0 when stepped or nothing to feed). +pub(crate) fn q36_state(f: &mut F, tokens: &[u32], c: usize) -> Result { + if c == 0 { + for &t in tokens { + f.q36_step(t)?; + } + return Ok(0); + } + if tokens.is_empty() { + return Ok(0); + } + f.q36_chunks(tokens, c) +} + +/// Walks `tokens` in the chunks of [`q36_chunk_lengths`] from position `pos0`: `each(chunk, pos, +/// last)`. Returns the chunks walked and the position after the last token. +pub(crate) fn q36_chunk_walk( + tokens: &[u32], + chunk: usize, + pos0: usize, + mut each: impl FnMut(&[u32], usize, bool) -> Result<(), String>, +) -> Result<(usize, usize), String> { + let lengths = q36_chunk_lengths(tokens.len(), chunk); + let (mut at, mut pos) = (0, pos0); + for (i, &m) in lengths.iter().enumerate() { + each(&tokens[at..at + m], pos, i + 1 == lengths.len())?; + at += m; + pos += m; + } + Ok((lengths.len(), pos)) +} + impl Qwen38Omega { /// L369: fp8 GEMM weight bytes the 35B prefill has streamed so far on this graph (0 for other /// models); see `Graph::prefill_streamed`. @@ -697,29 +740,22 @@ impl Qwen38Omega { g.prefill_alloc(chunk).map_err(gpu("q36 prefill_alloc"))?; } let mut next = None; - let mut pos = pos0; - let lengths = q36_chunk_lengths(tokens.len(), chunk); - let n_chunks = lengths.len(); - let mut at = 0; - for (i, &m) in lengths.iter().enumerate() { - let c = &tokens[at..at + m]; - at += m; - let mut x = vec![0f32; m * h]; + let (n_chunks, pos) = q36_chunk_walk(tokens, chunk, pos0, |c, pos, last| { + let mut x = vec![0f32; c.len() * h]; for (row, &t) in x.chunks_mut(h).zip(c) { let t = t as usize; for (d, &b) in row.iter_mut().zip(&embed[t * h..(t + 1) * h]) { *d = bf16_to_f32(b); } } - let last = i + 1 == n_chunks; let (tok, _) = g .prefill(head, &x, pos, last && want_token) .map_err(gpu("q36 prefill"))?; if last { next = tok; } - pos += m; - } + Ok(()) + })?; *self.head_pos_mut(head)? = pos; Ok((next, n_chunks)) } diff --git a/crates/aien-inference-abi/src/qwen38_omega/session.rs b/crates/aien-inference-abi/src/qwen38_omega/session.rs index 15b046df..4c4a7725 100644 --- a/crates/aien-inference-abi/src/qwen38_omega/session.rs +++ b/crates/aien-inference-abi/src/qwen38_omega/session.rs @@ -137,6 +137,112 @@ fn count(st: &mut FeedStats, s: &PrefillStats) { } } +/// What a session feeds a prompt into: the model, or a recording fake in the tests. +pub(crate) trait PromptFeed { + fn is_moe(&self) -> bool; + fn step_token(&mut self, t: u32) -> Result<(), String>; + /// The rows before the snapshot point, for their state only ([`Qwen38Omega::prefill_state`]). + fn feed_state(&mut self, tokens: &[u32], chunk: usize) -> Result; + /// At least [`q::GDN_PF_MIN_T`] tokens with the head ([`Qwen38Omega::prefill`]): the logits. + fn feed_head( + &mut self, + tokens: &[u32], + chunk: usize, + ) -> Result<(Vec, PrefillStats), String>; + fn last_logits(&mut self) -> Result, String>; +} + +impl PromptFeed for Qwen38Omega { + fn is_moe(&self) -> bool { + Qwen38Omega::is_moe(self) + } + + fn step_token(&mut self, t: u32) -> Result<(), String> { + self.step(t).map(|_| ()) + } + + fn feed_state(&mut self, tokens: &[u32], chunk: usize) -> Result { + self.prefill_state(tokens, chunk) + } + + fn feed_head( + &mut self, + tokens: &[u32], + chunk: usize, + ) -> Result<(Vec, PrefillStats), String> { + self.prefill(tokens, chunk) + .map(|(_, logits, s)| (logits, s)) + } + + fn last_logits(&mut self) -> Result, String> { + self.logits() + } +} + +/// Feeds `prompt[from..]` into a state holding `prompt[..from]`: the rows before the snapshot point +/// without the head, then `snap(m, k)` at that point (its ns, if it took one), then the rest with +/// the head. Returns the logits after the last token. +fn feed_prompt( + m: &mut M, + prompt: &[u32], + from: usize, + chunk: usize, + st: &mut FeedStats, + mut snap: impl FnMut(&mut M, usize) -> Result, String>, +) -> Result, String> { + let mut at = from; + // The snapshot point: the last turn header not yet inside the reused prefix. + if let Some(k) = snapshot_point(prompt, from) { + feed_rows(m, &prompt[from..k], chunk, st)?; + at = k; + if let Some(t) = snap(m, k)? { + st.snapshot_ns = t; + } + } + feed_last(m, &prompt[at..], chunk, st) +} + +/// Feeds `tokens` without the head (no residual read back). +fn feed_rows( + m: &mut M, + tokens: &[u32], + chunk: usize, + st: &mut FeedStats, +) -> Result<(), String> { + if rows_by_steps(tokens.len(), m.is_moe()) { + for &t in tokens { + m.step_token(t)?; + } + st.stepped += tokens.len(); + } else { + let s = m.feed_state(tokens, chunk)?; + count(st, &s); + } + Ok(()) +} + +/// Feeds `tokens` (at least one) and returns the logits after the last. +fn feed_last( + m: &mut M, + tokens: &[u32], + chunk: usize, + st: &mut FeedStats, +) -> Result, String> { + if tokens.is_empty() { + return Err("qwen38 session: nothing to feed".into()); + } + if tokens.len() >= q::GDN_PF_MIN_T { + let (logits, s) = m.feed_head(tokens, chunk)?; + count(st, &s); + return Ok(logits); + } + for &t in tokens { + m.step_token(t)?; + } + st.stepped += tokens.len(); + m.last_logits() +} + /// The resident model plus the token record of its live state and of its snapshot. #[derive(Debug)] pub struct Qwen38Session { @@ -233,58 +339,29 @@ impl Qwen38Session { } let from = self.history.len(); st.fed = prompt.len() - from; - // The snapshot point: the last turn header not yet inside the reused prefix. - if let Some(k) = snapshot_point(prompt, from) { - self.feed_rows(&prompt[from..k], &mut st)?; - if self.snap_tokens.as_deref() != Some(&prompt[..k]) && k > 0 { + let (snap, snap_tokens) = (&mut self.snap, &mut self.snap_tokens); + let logits = feed_prompt( + &mut self.model, + prompt, + from, + self.chunk, + &mut st, + |m, k| { + if k == 0 || snap_tokens.as_deref() == Some(&prompt[..k]) { + return Ok(None); + } let t = Instant::now(); - self.snap_tokens = None; - self.model.snapshot(&mut self.snap)?; - self.snap_tokens = Some(prompt[..k].to_vec()); - st.snapshot_ns = ns(t); - } - } - let rest = &prompt[self.history.len()..]; - let logits = self.feed_last(rest, &mut st)?; + *snap_tokens = None; + m.snapshot(snap)?; + *snap_tokens = Some(prompt[..k].to_vec()); + Ok(Some(ns(t))) + }, + )?; + self.history.extend_from_slice(&prompt[from..]); st.wall_ns = ns(t0); Ok((logits, st)) } - /// Feeds `tokens` without the head (no residual read back). - fn feed_rows(&mut self, tokens: &[u32], st: &mut FeedStats) -> Result<(), String> { - if rows_by_steps(tokens.len(), self.model.is_moe()) { - for &t in tokens { - self.model.step(t)?; - } - st.stepped += tokens.len(); - } else { - let s = self.model.prefill_state(tokens, self.chunk)?; - count(st, &s); - } - self.history.extend_from_slice(tokens); - Ok(()) - } - - /// Feeds `tokens` (at least one) and returns the logits after the last. - fn feed_last(&mut self, tokens: &[u32], st: &mut FeedStats) -> Result, String> { - if tokens.is_empty() { - return Err("qwen38 session: nothing to feed".into()); - } - let logits = if tokens.len() >= q::GDN_PF_MIN_T { - let (_, logits, s) = self.model.prefill(tokens, self.chunk)?; - count(st, &s); - logits - } else { - for &t in tokens { - self.model.step(t)?; - } - st.stepped += tokens.len(); - self.model.logits()? - }; - self.history.extend_from_slice(tokens); - Ok(logits) - } - /// Feeds one reply token through the decode graph without reading the logits: the graph's /// greedy token after it (chosen on the chip) and the step's chip time (ns). For greedy /// replies (L356: no 1 MB logits copy and host argmax per token). @@ -324,6 +401,7 @@ impl Qwen38Session { #[cfg(test)] mod tests { use super::*; + use crate::qwen38_omega::prefill::{q36_chunk_walk, q36_state, Q36Feed}; #[test] fn reuse_takes_the_longest_strict_prefix() { @@ -418,4 +496,145 @@ mod tests { assert!(rows_by_steps(2, false)); assert!(!rows_by_steps(q::GDN_PF_MIN_T, false)); } + + /// Records every token the feed path hands over, with the position it lands at and how + /// (`s` decode step, `r` state chunk, `h` chunk with the head), through the same routing as + /// the 35B: [`q36_state`] for the rows, [`q36_chunk_walk`] for every chunk run. + struct Fake { + c: usize, + pos: usize, + fed: Vec<(usize, u32, char)>, + chunks: Vec, + } + + impl Fake { + fn take(&mut self, tokens: &[u32], pos: usize, how: char) -> Result<(), String> { + if pos != self.pos { + return Err(format!("fed at {pos}, the state is at {}", self.pos)); + } + for &t in tokens { + self.fed.push((self.pos, t, how)); + self.pos += 1; + } + Ok(()) + } + + fn walk(&mut self, tokens: &[u32], chunk: usize, how: char) -> Result { + let pos0 = self.pos; + let (n, end) = q36_chunk_walk(tokens, chunk, pos0, |c, pos, _| { + self.chunks.push(c.len()); + self.take(c, pos, how) + })?; + assert_eq!(end, self.pos); + Ok(n) + } + } + + impl Q36Feed for Fake { + fn q36_step(&mut self, t: u32) -> Result<(), String> { + let p = self.pos; + self.take(&[t], p, 's') + } + + fn q36_chunks(&mut self, tokens: &[u32], chunk: usize) -> Result { + self.walk(tokens, chunk, 'r') + } + } + + impl PromptFeed for Fake { + fn is_moe(&self) -> bool { + true + } + + fn step_token(&mut self, t: u32) -> Result<(), String> { + self.q36_step(t) + } + + fn feed_state(&mut self, tokens: &[u32], _chunk: usize) -> Result { + let c = self.c; + let chunks = q36_state(self, tokens, c)?; + Ok(PrefillStats { + tokens: tokens.len(), + chunks, + ..Default::default() + }) + } + + fn feed_head( + &mut self, + tokens: &[u32], + _chunk: usize, + ) -> Result<(Vec, PrefillStats), String> { + let mut chunks = 0; + if self.c == 0 { + for &t in tokens { + self.q36_step(t)?; + } + } else { + let c = self.c; + chunks = self.walk(tokens, c, 'h')?; + } + let s = PrefillStats { + tokens: tokens.len(), + chunks, + ..Default::default() + }; + Ok((vec![0.0], s)) + } + + fn last_logits(&mut self) -> Result, String> { + Ok(vec![0.0]) + } + } + + /// DRA-65: through the session's feed path every prompt token past the reused prefix is fed + /// exactly once, in order, at its own position, across chunk boundaries and from a cached + /// prefix that ends mid-chunk; the snapshot is taken right after the rows; with chunking on + /// no row is stepped, with `AIEN_Q36_PREFILL_CHUNK=0` every token is. + #[test] + fn every_prompt_token_is_fed_once_in_order() { + let cap = q::q36::PREFILL_MAX_ROWS; + for c in [cap, 0] { + for len in [1, cap - 1, cap, cap + 1, 2 * cap + 3] { + // 61: a cached prefix ending mid-chunk; len - 3: a live state past the header. + for from in [0, 61, len.saturating_sub(3)] { + if from >= len { + continue; + } + let p = rendered(len); + let mut f = Fake { + c, + pos: from, + fed: Vec::new(), + chunks: Vec::new(), + }; + let mut st = FeedStats::default(); + let mut snaps = Vec::new(); + let r = feed_prompt(&mut f, &p, from, 512, &mut st, |m, k| { + snaps.push((k, m.pos)); + Ok(None) + }); + let at = format!("c {c} len {len} from {from}"); + r.unwrap_or_else(|e| panic!("{at}: {e}")); + let got: Vec<(usize, u32)> = f.fed.iter().map(|&(i, t, _)| (i, t)).collect(); + let want: Vec<(usize, u32)> = (from..len).map(|i| (i, p[i])).collect(); + assert_eq!(got, want, "{at}"); + let k = snapshot_point(&p, from); + assert_eq!( + snaps, + k.map(|k| (k, k)).into_iter().collect::>(), + "{at}" + ); + assert!(f.chunks.iter().all(|&m| m >= 1 && m <= cap), "{at}"); + if c == 0 { + assert!(f.fed.iter().all(|&(_, _, how)| how == 's'), "{at}"); + assert_eq!(st.stepped, len - from, "{at}"); + } else if let Some(k) = k { + let stepped_row = f.fed.iter().any(|&(i, _, how)| i < k && how == 's'); + assert!(!stepped_row, "{at}"); + } + } + } + } + } } diff --git a/evidence/dra65-prefill-20261031/README.md b/evidence/dra65-prefill-20261031/README.md index 737c9e41..20948103 100644 --- a/evidence/dra65-prefill-20261031/README.md +++ b/evidence/dra65-prefill-20261031/README.md @@ -54,18 +54,30 @@ PASS receipts with distinct labels for the same server binary sha256. ## Host evidence (EXERCISED on host, not chip) -`nice -n 19 taskset -c 0-9 cargo test -p aien-inference-abi --lib qwen38_omega`: 9 passed (chunk boundaries at +`nice -n 19 taskset -c 0-9 cargo test -p aien-inference-abi --lib qwen38_omega`: 10 passed (chunk boundaries at 1, 127, 128, 129, 2048, 8192 and 8210; env switch 0/default/cap/129/garbage; snapshot point and rows/last split at -the same lengths and on turn 2; 35B rows never stepped). Negative control: `q36_chunk_lengths` mutated to drop a -remainder of 1 -> `q36_chunks_at_the_boundaries` FAILED, then restored. The host tests cover only the pure split -rules: a `prefill_state` or `feed_rows` that loses a token stays green on the host (review Rev862 M4/M5), which is -why the window's prefill-only red arm (step 2) is required. - -Script against a mock door (`/tmp/dra65mock/mock2.py`): red with one turn-2 id changed PASS rc 0; red on exact -goldens FAIL rc 1; red on empty ids, short ids or HTTP 500 INCONCLUSIVE rc 2; green with 0 or 1 red receipt, or -with receipts of another binary sha, refused rc 2; green with two receipts: exact PASS rc 0, one id changed FAIL -rc 1, empty ids INCONCLUSIVE rc 2; time: exact RECORDED rc 0 (6/6 runs ok), HTTP 500 and missing usage -INCONCLUSIVE rc 2. +the same lengths and on turn 2; 35B rows never stepped; the feed path below). Negative control: `q36_chunk_lengths` +mutated to drop a remainder of 1 -> `q36_chunks_at_the_boundaries` FAILED, then restored. + +Feed path: `start_inner`'s feed is `session::feed_prompt` -> `feed_rows` / `feed_last` over the `PromptFeed` +trait, and the 35B's state feed is `prefill::q36_state` + `q36_chunk_walk` (the loop `prefill_moe_head` runs on +the chip) over `Q36Feed`; the model implements both. `every_prompt_token_is_fed_once_in_order` drives that same +code with a fake that records (position, token id, step/row chunk/head chunk) and refuses a chunk at a position +other than its own: lengths 1, 127, 128, 129, 259 (2*128+3), cached prefix 0, 61 (ends mid-chunk) and len-3 +(past the header), chunk 128 and 0. It asserts each token of `prompt[from..]` fed exactly once, in order, at its +position; the snapshot taken at the header right after the rows; chunks within 1..=128; no row stepped with +chunking, every token stepped with 0. Review Rev862's mutations, each applied alone and reverted: M4 +(`q36_state` drops the last row token) -> FAILED; M5 (`feed_rows` skips the first row token) -> FAILED; restored +-> 10 passed. What stays chip-only: the wrappers (`prefill_state`'s env read, the embed + `g.prefill` per chunk), +hence the window's prefill-only red arm (step 2). + +Script against a mock door (`/tmp/dra65mock/mock2.py`, run with `SPARK_WINDOW=w-test-1 AIEN_GB10_LOCK_HELD=1`): +red with one turn-2 id changed PASS rc 0; red on exact goldens FAIL rc 1; red on empty ids, short ids or HTTP 500 +INCONCLUSIVE rc 2; green with 0 or 1 red receipt, or with receipts of another binary sha, refused rc 2; green with +two receipts: exact PASS rc 0, one id changed FAIL rc 1, empty ids INCONCLUSIVE rc 2; time: exact RECORDED rc 0 +(6/6 runs ok), HTTP 500 and missing usage INCONCLUSIVE rc 2. Without `SPARK_WINDOW`, or with +`AIEN_GB10_LOCK_HELD=0`: NOT_RUN rc 3. Every `golden.jsonl` / `time.jsonl` line and receipt carried +`window: w-test-1` and the binary sha. Mutant 4 wiring (source, omega 474197e4f): `AIEN_Q36_TEST_MUTANT=4` -> `moe.rs` `graph_mutant()` -> `test_set_mutant` on the main graph and (`rows.rs` wire) every row and stroke graph; in C mutant 4 swaps K_CN for @@ -74,14 +86,25 @@ So the env mutant reaches the chunked prefill. It also breaks decode, so it cann prefill-only mutant does: `AIEN_OMEGA_Q36_PF_MUTANT` is read by `omega_gpu_q36_graph.c` L925 when the prefill buffers are set up in the server process (header L146: 2 = every expert segment one row short); the decode graph never reads it, and with `AIEN_Q36_PREFILL_CHUNK=0` the single door runs no chip prefill at all -(`prefill.rs` L298, L344). So PF_MUTANT=2 must be red with chunking and green with CHUNK=0. +(`prefill.rs` L298, `q36_state`). So PF_MUTANT=2 must be red with chunking and green with CHUNK=0. ## Window (Main; chip gates NOT_RUN until then) Quiet exclusive window per the usual procedure (marker, stop 18091 and Flint, `spark-window open ... --gb10 -exclusive --quiet exclusive`). NEW = the build of this branch, `B=$(sha256sum | cut -c1-64)`. -Each line: start the server with the env shown, run, stop. Steps 1-2 must come first; step 3 onward need their -receipts. +exclusive --quiet exclusive --lease 20`). Every step runs as `spark-window run bash window-dra65.sh ...`; the +script refuses with exit 3 (NOT_RUN) unless `SPARK_WINDOW` is set and `AIEN_GB10_LOCK_HELD=1`, never takes +`/tmp/aien-gb10.lock` itself, and stamps the window id and binary sha into every receipt line. NEW = the build +of this branch, `B=$(sha256sum | cut -c1-64)`. Each line: start the server with the env shown +(~33 s), run, stop. Steps 1-2 must come first; step 3 onward need their receipts (from any earlier lease). + +Estimated durations (MODELED, upper bounds at max_tokens; `window-dra65.sh plan` prints them), with decode +0.0201 s/token, chunked prompts 250 tok/s (8210 tokens at 196.8), stepped prompts 0.0201 s/token, +33 s start: +golden chunked `dec*(756 + 49 + 876) + 365/250. + 2486/250. + 8210/196.8` = 86.9 s -> 120 s with start; +golden all-stepped (step 3) `dec*(756 + 365 + 2486 + 8210 + 49 + 876)` = 256.1 s -> 289 s; time chunked +`3*(512/250. + 8210/196.8) + 6*256*dec` = 162.2 s -> 195 s; time all-stepped `dec*(3*(512 + 8210) + 6*256)` = +556.8 s -> 590 s (756 = the set's prompt tokens, 876 = its decode tokens 798 + 3*24 + 6; 49 = turn 2 past the +snapshot; 512 = planning size of long-512). 20-min leases: L1 = steps 1-5 (`4*119.91 + 289.11` = 769 s), L2 = +6a + 6b (785 s), L3 = 6c + 6d (390 s). 1. Single door, `AIEN_Q36_TEST_MUTANT=4`: `window-dra65.sh golden PORT OUT/w1 red $B mutant4` -> PASS (red). 2. Single door, `AIEN_OMEGA_Q36_PF_MUTANT=2`: `window-dra65.sh golden PORT OUT/w2 red $B pf2` -> PASS (red: the diff --git a/evidence/dra65-prefill-20261031/window-dra65.sh b/evidence/dra65-prefill-20261031/window-dra65.sh index 56a36d7e..50747ee2 100755 --- a/evidence/dra65-prefill-20261031/window-dra65.sh +++ b/evidence/dra65-prefill-20261031/window-dra65.sh @@ -1,7 +1,11 @@ #!/usr/bin/env bash # SPDX-License-Identifier: Apache-2.0 -# DRA-65 chip window (Main runs it inside a quiet exclusive spark-window; see README.md "Window"). -# The script never starts or stops a server: Main starts each server as README.md lists, then runs +# DRA-65 chip window. Main runs each step as `spark-window run bash window-dra65.sh ...` inside a +# `--gb10 exclusive --quiet exclusive` window; anywhere else it refuses with exit 3 (NOT_RUN): it needs +# SPARK_WINDOW (the window id) and AIEN_GB10_LOCK_HELD=1, both set by `spark-window run`. It never takes +# /tmp/aien-gb10.lock itself (the window holds it) and never starts or stops a server: Main starts each +# server as README.md lists (~33 s per arm), then runs +# window-dra65.sh plan (no window needed: the steps with their estimated durations) # window-dra65.sh golden PORT OUT red BIN_SHA256 LABEL # window-dra65.sh golden PORT OUT green BIN_SHA256 LABEL RED_RECEIPT RED_RECEIPT [...] # 36 cases (32-prompt set, 3 long prompts, turn 2 restoring the long-2048 snapshot) vs the pinned goldens. @@ -13,11 +17,35 @@ # SHORT (a strict prefix of the golden: no flip shown), NO_IDS (HTTP error, missing or empty ids). # golden red: PASS = at least one DIFF and no NO_IDS/SHORT; NO_IDS/SHORT -> INCONCLUSIVE; else FAIL. # golden green: PASS = all SAME; any NO_IDS -> INCONCLUSIVE; else FAIL. -# Exit 0 = PASS, 1 = FAIL, 2 = INCONCLUSIVE or refused. time: 0 only if every run has HTTP 200, a -# first content delta and usage with completion_tokens > 0; else 2 (INCONCLUSIVE). +# Exit 0 = PASS, 1 = FAIL, 2 = INCONCLUSIVE or refused, 3 = NOT_RUN (not inside a chip window). time: 0 +# only if every run has HTTP 200, a first content delta and usage with completion_tokens > 0; else 2. +# Every receipt line carries the window id and the binary sha256. set -uo pipefail HERE=$(cd "$(dirname "$0")" && pwd); REPO=$(cd "$HERE/../.." && pwd) die() { echo "window-dra65: $*" >&2; exit 2; } +if [ "${1:-}" = plan ]; then + # MODELED (Wolfram, README "Window"): decode 0.0201 s/token, chunked prompts 250 tok/s (8210: 196.8), + # stepped prompts 0.0201 s/token; upper bounds at max_tokens; plus ~33 s server start per arm. + cat <<'EOF' +step arm mode est_s (incl. 33 s start) +1 single NEW AIEN_Q36_TEST_MUTANT=4 red 120 +2 single NEW AIEN_OMEGA_Q36_PF_MUTANT=2 red 120 +3 single NEW PF_MUTANT=2 + CHUNK=0 green 289 (every prompt token stepped) +4 single NEW plain green 120 +5 batch NEW --batch-slots 8 green 120 +6a time single NEW time 195 +6b time single NEW CHUNK=0 time 590 +6c time batch NEW time 195 +6d time batch NEW AIEN_Q36_PREFILL_MIN=1 time 195 +20-min leases: L1 = steps 1-5 (769 s), L2 = 6a + 6b (785 s), L3 = 6c + 6d (390 s). +EOF + exit 0 +fi +if [ -z "${SPARK_WINDOW:-}" ] || [ "${AIEN_GB10_LOCK_HELD:-}" != 1 ]; then + echo "window-dra65: NOT_RUN: run inside a --gb10 exclusive window via 'spark-window run' (SPARK_WINDOW='${SPARK_WINDOW:-}', AIEN_GB10_LOCK_HELD='${AIEN_GB10_LOCK_HELD:-}')" >&2 + exit 3 +fi +WIN=$SPARK_WINDOW MODE=${1:-}; PORT=${2:-}; OUT=${3:-} [ -n "$MODE" ] && [ -n "$PORT" ] && [ -n "$OUT" ] || die "usage: see the header" URL=http://127.0.0.1:$PORT @@ -58,8 +86,9 @@ golden) [ "$reds" -ge 2 ] || die "green refused: needs >= 2 red PASS receipts (distinct labels) for binary $BIN, got $reds" fi : > "$OUT/golden.jsonl"; declare -A n=([SAME]=0 [DIFF]=0 [SHORT]=0 [NO_IDS]=0) - rec() { jq -cn --arg id "$1" --arg v "$2" --arg h "$3" --argjson w "$4" --slurpfile r <(jq -c . "$5" 2>/dev/null || echo null) \ - '{id:$id, verdict:$v, http:$h, got:($r[0].usage.aien_token_ids // null), golden:$w}' >> "$OUT/golden.jsonl"; } + rec() { jq -cn --arg id "$1" --arg v "$2" --arg h "$3" --argjson w "$4" --arg win "$WIN" --arg b "$BIN" \ + --slurpfile r <(jq -c . "$5" 2>/dev/null || echo null) \ + '{id:$id, verdict:$v, http:$h, got:($r[0].usage.aien_token_ids // null), golden:$w, window:$win, bin_sha256:$b}' >> "$OUT/golden.jsonl"; } for i in $(seq 0 31); do u=$(jq -r ".prompts[$i].user" "$SET"); m=$(jq -r ".prompts[$i].max_tokens" "$SET"); w=$(jq -c ".prompts[$i].golden_ids" "$SET") h=$(ask "$(user "$u")" "$m" "$OUT/p$i.raw"); v=$(judge "$h" "$OUT/p$i.raw" "$w"); n[$v]=$((n[$v]+1)); rec "p$i" "$v" "$h" "$w" "$OUT/p$i.raw" @@ -78,8 +107,8 @@ golden) elif [ "${n[SAME]}" -eq 36 ]; then verdict=PASS; rc=0; else verdict=FAIL; rc=1; fi fi jq -cn --arg e "$EXPECT" --arg v $verdict --arg b "$BIN" --arg l "$LABEL" --argjson s "${n[SAME]}" --argjson d "${n[DIFF]}" \ - --argjson sh "${n[SHORT]}" --argjson x "${n[NO_IDS]}" --arg port "$PORT" --arg at "$(date -u +%FT%TZ)" \ - '{case:"golden", expect:$e, verdict:$v, bin_sha256:$b, label:$l, same:$s, diff:$d, short:$sh, no_ids:$x, of:36, port:$port, at:$at}' \ + --argjson sh "${n[SHORT]}" --argjson x "${n[NO_IDS]}" --arg port "$PORT" --arg at "$(date -u +%FT%TZ)" --arg win "$WIN" \ + '{case:"golden", expect:$e, verdict:$v, bin_sha256:$b, label:$l, window:$win, same:$s, diff:$d, short:$sh, no_ids:$x, of:36, port:$port, at:$at}' \ | tee "$OUT/golden-receipt.json" exit $rc ;; time) @@ -105,11 +134,11 @@ time) '$c == "200" and $f != "" and ($u | type) == "object" and (($u.completion_tokens // 0) > 0)') [ "$good" = true ] || ok=0 jq -cn --arg n "$name" --argjson r $run --arg b "$BIN" --arg l "$LABEL" --arg h "${code:-}" --arg t0 "$t0" --arg tf "$first" \ - --arg t1 "$t1" --argjson u "${usage:-null}" --argjson g "$good" \ - '{prompt:$n, run:$r, bin_sha256:$b, label:$l, http:$h, ok:$g, t0:$t0, t_first:$tf, t_end:$t1, usage:$u}' | tee -a "$OUT/time.jsonl" + --arg t1 "$t1" --argjson u "${usage:-null}" --argjson g "$good" --arg win "$WIN" \ + '{prompt:$n, run:$r, bin_sha256:$b, label:$l, window:$win, http:$h, ok:$g, t0:$t0, t_first:$tf, t_end:$t1, usage:$u}' | tee -a "$OUT/time.jsonl" done done - if [ $ok = 1 ]; then echo '{"case":"time","verdict":"RECORDED"}'; exit 0; fi - echo '{"case":"time","verdict":"INCONCLUSIVE","why":"a run had no HTTP 200, no first content delta or no usage"}'; exit 2 ;; + if [ $ok = 1 ]; then jq -cn --arg win "$WIN" --arg b "$BIN" --arg l "$LABEL" '{case:"time", verdict:"RECORDED", window:$win, bin_sha256:$b, label:$l}'; exit 0; fi + jq -cn --arg win "$WIN" --arg b "$BIN" --arg l "$LABEL" '{case:"time", verdict:"INCONCLUSIVE", window:$win, bin_sha256:$b, label:$l, why:"a run had no HTTP 200, no first content delta or no usage"}'; exit 2 ;; *) die "mode golden|time" ;; esac From 6bd5f1532122edc9a98e605827340d5a014905f5 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Sat, 31 Oct 2026 08:18:16 -0500 Subject: [PATCH 4/8] DRA-65: window script takes the gb10 lock itself and starts each server as its child chip_reservation accepts /tmp/aien-gb10.lock only from an ancestor of the server, and spark-window's holder never is. window-dra65.sh run BIN OUT STEP... (inside --gb10 none --quiet exclusive) takes flock -n on the lock, verifies the holder is its ancestor, refuses (exit 3) on a foreign holder, live 18091/Flint, chip compute apps or a lease too short for the steps' estimates, starts single/batch servers with the step env and AIEN_GB10_LOCK_HELD=1, and writes a step receipt with window id, binary sha256, est and elapsed seconds. --- evidence/dra65-prefill-20261031/README.md | 77 +++++--- .../dra65-prefill-20261031/window-dra65.sh | 187 ++++++++++++++---- 2 files changed, 201 insertions(+), 63 deletions(-) diff --git a/evidence/dra65-prefill-20261031/README.md b/evidence/dra65-prefill-20261031/README.md index 20948103..78037ffb 100644 --- a/evidence/dra65-prefill-20261031/README.md +++ b/evidence/dra65-prefill-20261031/README.md @@ -71,13 +71,16 @@ chunking, every token stepped with 0. Review Rev862's mutations, each applied al -> 10 passed. What stays chip-only: the wrappers (`prefill_state`'s env read, the embed + `g.prefill` per chunk), hence the window's prefill-only red arm (step 2). -Script against a mock door (`/tmp/dra65mock/mock2.py`, run with `SPARK_WINDOW=w-test-1 AIEN_GB10_LOCK_HELD=1`): -red with one turn-2 id changed PASS rc 0; red on exact goldens FAIL rc 1; red on empty ids, short ids or HTTP 500 -INCONCLUSIVE rc 2; green with 0 or 1 red receipt, or with receipts of another binary sha, refused rc 2; green with -two receipts: exact PASS rc 0, one id changed FAIL rc 1, empty ids INCONCLUSIVE rc 2; time: exact RECORDED rc 0 -(6/6 runs ok), HTTP 500 and missing usage INCONCLUSIVE rc 2. Without `SPARK_WINDOW`, or with -`AIEN_GB10_LOCK_HELD=0`: NOT_RUN rc 3. Every `golden.jsonl` / `time.jsonl` line and receipt carried -`window: w-test-1` and the binary sha. +Script probes against a mock door (`/tmp/dra65mock/mock2.py`, `SPARK_WINDOW=w-test-2`): red with one turn-2 id +changed PASS rc 0; red on exact goldens FAIL rc 1; red on empty ids, short ids or HTTP 500 INCONCLUSIVE rc 2; green +with 0 or 1 red receipt, or with receipts of another binary sha, refused rc 2; green with two receipts: exact PASS +rc 0, one id changed FAIL rc 1, empty ids INCONCLUSIVE rc 2; time: exact RECORDED rc 0 (6/6 runs ok), HTTP 500 and +missing usage INCONCLUSIVE rc 2; no `SPARK_WINDOW` NOT_RUN rc 3. Every `golden.jsonl` / `time.jsonl` line and +receipt carried `window: w-test-2` and the binary sha. `run` guard, with `DRA65_TEST_LOCK` pointing at a scratch +lock (it never reaches the chip): no `SPARK_WINDOW` rc 3; lock held by another process rc 3 ("held by another +process"); `DRA65_LOCKED` spoofed without holding the lock rc 3 ("held by pid(s) ..., none an ancestor"); lock +free: taken, its flock(1) holder found among the script's ancestors, then rc 3 as the test lock demands. The +part past the guard (lease, listener and chip checks, server start, step loop) is NOT_RUN on host. Mutant 4 wiring (source, omega 474197e4f): `AIEN_Q36_TEST_MUTANT=4` -> `moe.rs` `graph_mutant()` -> `test_set_mutant` on the main graph and (`rows.rs` wire) every row and stroke graph; in C mutant 4 swaps K_CN for @@ -90,12 +93,23 @@ never reads it, and with `AIEN_Q36_PREFILL_CHUNK=0` the single door runs no chip ## Window (Main; chip gates NOT_RUN until then) -Quiet exclusive window per the usual procedure (marker, stop 18091 and Flint, `spark-window open ... --gb10 -exclusive --quiet exclusive --lease 20`). Every step runs as `spark-window run bash window-dra65.sh ...`; the -script refuses with exit 3 (NOT_RUN) unless `SPARK_WINDOW` is set and `AIEN_GB10_LOCK_HELD=1`, never takes -`/tmp/aien-gb10.lock` itself, and stamps the window id and binary sha into every receipt line. NEW = the build -of this branch, `B=$(sha256sum | cut -c1-64)`. Each line: start the server with the env shown -(~33 s), run, stop. Steps 1-2 must come first; step 3 onward need their receipts (from any earlier lease). +Main opens a quiet exclusive window without the chip lock (marker, `spark-window open ... --gb10 none --quiet +exclusive --lease 20`), stops 18091 and Flint, and runs one lease's steps: +`spark-window run bash evidence/dra65-prefill-20261031/window-dra65.sh run BIN OUT STEP ...`, BIN = the server +binary built from this branch, OUT = one receipt root for every lease (step N writes `OUT/N/`). The 35B server's +chip reservation (`crates/aien-serve-http/src/chip_reservation.rs` L88-95) accepts `/tmp/aien-gb10.lock` only +when one of its ancestors holds it, and spark-window's holder never is; so the script takes `flock -n` on the +lock itself (flock(1) holds it and runs the script as its child), checks in `/proc/locks` that the exclusive +holder is its ancestor, and starts each server as its own child with `AIEN_GB10_LOCK_HELD=1`. Exit 3 (NOT_RUN, +chip untouched): no `SPARK_WINDOW`; the lock held by anyone else; a listener on 18091, 18300, 18310 or the test +port 18192; a compute app on the chip; BIN or the model missing; green steps without the red receipts in +`OUT/1`, `OUT/2`; or the steps' estimates longer than the lease has left (`$SPARK_WINDOW_DIR/held` + `lease`). +Servers: the live `start-35b.sh` flags (`--max-context 131072`) for the single door, `start-35b-batch.sh` +(`--max-context 49152 --batch-slots 8`) for the batch door, `--bind 127.0.0.1 --max-tokens-cap 16384 --thinking +off AIEN_Q36_STROKE=0`, plus the step's env. Each step writes `OUT/N/step-receipt.json` (window id, binary path +and sha256, door, env, est_s, server_ready_s, elapsed_s, rc, lock holder pid, the probe's receipt) beside the +probe's own receipts; `run` stops at the first step that does not exit 0, and posts GPU-START/GPU-END lines on +the board. Estimated durations (MODELED, upper bounds at max_tokens; `window-dra65.sh plan` prints them), with decode 0.0201 s/token, chunked prompts 250 tok/s (8210 tokens at 196.8), stepped prompts 0.0201 s/token, +33 s start: @@ -103,23 +117,26 @@ golden chunked `dec*(756 + 49 + 876) + 365/250. + 2486/250. + 8210/196.8` = 86.9 golden all-stepped (step 3) `dec*(756 + 365 + 2486 + 8210 + 49 + 876)` = 256.1 s -> 289 s; time chunked `3*(512/250. + 8210/196.8) + 6*256*dec` = 162.2 s -> 195 s; time all-stepped `dec*(3*(512 + 8210) + 6*256)` = 556.8 s -> 590 s (756 = the set's prompt tokens, 876 = its decode tokens 798 + 3*24 + 6; 49 = turn 2 past the -snapshot; 512 = planning size of long-512). 20-min leases: L1 = steps 1-5 (`4*119.91 + 289.11` = 769 s), L2 = -6a + 6b (785 s), L3 = 6c + 6d (390 s). - -1. Single door, `AIEN_Q36_TEST_MUTANT=4`: `window-dra65.sh golden PORT OUT/w1 red $B mutant4` -> PASS (red). -2. Single door, `AIEN_OMEGA_Q36_PF_MUTANT=2`: `window-dra65.sh golden PORT OUT/w2 red $B pf2` -> PASS (red: the - chunk path runs). -3. Single door, `AIEN_OMEGA_Q36_PF_MUTANT=2 AIEN_Q36_PREFILL_CHUNK=0`: `window-dra65.sh golden PORT OUT/w3 green - $B pf2-chunk0 OUT/w1/golden-receipt.json OUT/w2/golden-receipt.json` -> PASS (the mutant lives on the chunk - path only). -4. Single door, plain: `... golden PORT OUT/w4 green $B single OUT/w1/... OUT/w2/...` -> PASS = 36/36. -5. Batch door (`--batch-slots 8`), plain: `... golden PORT OUT/w5 green $B batch OUT/w1/... OUT/w2/...`. -6. `window-dra65.sh time PORT OUT/w6- $B ` on: single; single with `AIEN_Q36_PREFILL_CHUNK=0` (the - all-token-steps arm above); batch; batch with `AIEN_Q36_PREFILL_MIN=1` (chunks the answer header too). Exit 0 - only if all 6 runs have HTTP 200, a first content delta and usage. Receipts: `time.jsonl`. TTFT = t_first - t0; - e2e tok/s = completion_tokens / (t_end - t_first). Medians of the 3 runs through Wolfram (`Median[{...}]`). - Record `usage.prompt_tokens` of long-512 (the host has no tokenizer). Target 1 compares e2e against chip-only - decode from DRA-66's `chip_ns` in the same runs. +snapshot; 512 = planning size of long-512). 20-min leases: L1 = `run BIN OUT 1 2 3 4 5` +(`4*119.91 + 289.11` = 769 s), L2 = `6a 6b` (785 s), L3 = `6c 6d` (390 s). + +| step | door | server env | probe | expect | est_s | +|---|---|---|---|---|---| +| 1 | single | `AIEN_Q36_TEST_MUTANT=4` | golden red `mutant4` | PASS (red) | 120 | +| 2 | single | `AIEN_OMEGA_Q36_PF_MUTANT=2` | golden red `pf2` | PASS (red: the chunk path runs) | 120 | +| 3 | single | `AIEN_OMEGA_Q36_PF_MUTANT=2 AIEN_Q36_PREFILL_CHUNK=0` | golden green `pf2-chunk0` | PASS (the mutant lives on the chunk path only) | 289 | +| 4 | single | - | golden green `single` | PASS = 36/36 | 120 | +| 5 | batch | - | golden green `batch` | PASS = 36/36 | 120 | +| 6a | single | - | time `single` | RECORDED | 195 | +| 6b | single | `AIEN_Q36_PREFILL_CHUNK=0` (all token steps) | time `single-chunk0` | RECORDED | 590 | +| 6c | batch | - | time `batch` | RECORDED | 195 | +| 6d | batch | `AIEN_Q36_PREFILL_MIN=1` (chunks the answer header too) | time `batch-min1` | RECORDED | 195 | + +Green steps get `OUT/1/golden-receipt.json` and `OUT/2/golden-receipt.json` and refuse unless both are red PASS +of the same binary sha. Time steps: exit 0 only if all 6 runs have HTTP 200, a first content delta and usage; +receipts `time.jsonl`. TTFT = t_first - t0; e2e tok/s = completion_tokens / (t_end - t_first). Medians of the 3 +runs through Wolfram (`Median[{...}]`). Record `usage.prompt_tokens` of long-512 (the host has no tokenizer). +Target 1 compares e2e against chip-only decode from DRA-66's `chip_ns` in the same runs. ## Predictions (MODELED, Wolfram) diff --git a/evidence/dra65-prefill-20261031/window-dra65.sh b/evidence/dra65-prefill-20261031/window-dra65.sh index 50747ee2..ed8527ad 100755 --- a/evidence/dra65-prefill-20261031/window-dra65.sh +++ b/evidence/dra65-prefill-20261031/window-dra65.sh @@ -1,11 +1,18 @@ #!/usr/bin/env bash # SPDX-License-Identifier: Apache-2.0 -# DRA-65 chip window. Main runs each step as `spark-window run bash window-dra65.sh ...` inside a -# `--gb10 exclusive --quiet exclusive` window; anywhere else it refuses with exit 3 (NOT_RUN): it needs -# SPARK_WINDOW (the window id) and AIEN_GB10_LOCK_HELD=1, both set by `spark-window run`. It never takes -# /tmp/aien-gb10.lock itself (the window holds it) and never starts or stops a server: Main starts each -# server as README.md lists (~33 s per arm), then runs -# window-dra65.sh plan (no window needed: the steps with their estimated durations) +# DRA-65 chip window. Main opens `spark-window open ... --gb10 none --quiet exclusive --lease 20`, stops 18091 and +# Flint, then runs one lease's steps as +# spark-window run bash window-dra65.sh run BIN OUT STEP [STEP ...] +# BIN = the server binary built from this branch, OUT = a receipt root shared by every lease (step N writes +# OUT/N/). The server's chip reservation (aien-serve-http chip_reservation.rs) only accepts /tmp/aien-gb10.lock +# held by one of its ancestors, so this script takes `flock -n` on it itself and starts every server as its +# child with AIEN_GB10_LOCK_HELD=1. Exit 3 = NOT_RUN, chip untouched: no SPARK_WINDOW, the lock held by someone +# else, a listener on 18091/18300/18310 or the test port, a compute app on the chip, the binary or model +# missing, or the steps' estimated time longer than the lease has left. +# window-dra65.sh plan (no window needed: the steps, their server env and estimated durations) +# Every receipt line carries the window id and the binary sha256. +# +# Probes (an already running server on PORT; `run` calls them, the host checks them against a mock door): # window-dra65.sh golden PORT OUT red BIN_SHA256 LABEL # window-dra65.sh golden PORT OUT green BIN_SHA256 LABEL RED_RECEIPT RED_RECEIPT [...] # 36 cases (32-prompt set, 3 long prompts, turn 2 restoring the long-2048 snapshot) vs the pinned goldens. @@ -17,34 +24,148 @@ # SHORT (a strict prefix of the golden: no flip shown), NO_IDS (HTTP error, missing or empty ids). # golden red: PASS = at least one DIFF and no NO_IDS/SHORT; NO_IDS/SHORT -> INCONCLUSIVE; else FAIL. # golden green: PASS = all SAME; any NO_IDS -> INCONCLUSIVE; else FAIL. -# Exit 0 = PASS, 1 = FAIL, 2 = INCONCLUSIVE or refused, 3 = NOT_RUN (not inside a chip window). time: 0 -# only if every run has HTTP 200, a first content delta and usage with completion_tokens > 0; else 2. -# Every receipt line carries the window id and the binary sha256. +# Exit 0 = PASS, 1 = FAIL, 2 = INCONCLUSIVE or refused, 3 = NOT_RUN. time: 0 only if every run has HTTP 200, +# a first content delta and usage with completion_tokens > 0; else 2. `run` stops at the first step that +# does not exit 0 and returns its code. set -uo pipefail -HERE=$(cd "$(dirname "$0")" && pwd); REPO=$(cd "$HERE/../.." && pwd) +HERE=$(cd "$(dirname "$0")" && pwd); REPO=$(cd "$HERE/../.." && pwd); SELF=$HERE/$(basename "$0") die() { echo "window-dra65: $*" >&2; exit 2; } -if [ "${1:-}" = plan ]; then - # MODELED (Wolfram, README "Window"): decode 0.0201 s/token, chunked prompts 250 tok/s (8210: 196.8), - # stepped prompts 0.0201 s/token; upper bounds at max_tokens; plus ~33 s server start per arm. - cat <<'EOF' -step arm mode est_s (incl. 33 s start) -1 single NEW AIEN_Q36_TEST_MUTANT=4 red 120 -2 single NEW AIEN_OMEGA_Q36_PF_MUTANT=2 red 120 -3 single NEW PF_MUTANT=2 + CHUNK=0 green 289 (every prompt token stepped) -4 single NEW plain green 120 -5 batch NEW --batch-slots 8 green 120 -6a time single NEW time 195 -6b time single NEW CHUNK=0 time 590 -6c time batch NEW time 195 -6d time batch NEW AIEN_Q36_PREFILL_MIN=1 time 195 -20-min leases: L1 = steps 1-5 (769 s), L2 = 6a + 6b (785 s), L3 = 6c + 6d (390 s). -EOF - exit 0 -fi -if [ -z "${SPARK_WINDOW:-}" ] || [ "${AIEN_GB10_LOCK_HELD:-}" != 1 ]; then - echo "window-dra65: NOT_RUN: run inside a --gb10 exclusive window via 'spark-window run' (SPARK_WINDOW='${SPARK_WINDOW:-}', AIEN_GB10_LOCK_HELD='${AIEN_GB10_LOCK_HELD:-}')" >&2 - exit 3 -fi +not_run() { echo "window-dra65: NOT_RUN: $*" >&2; exit 3; } + +# step -> door, server env, probe, estimated seconds. MODELED (Wolfram, README "Window"): decode 0.0201 s/token, +# chunked prompts 250 tok/s (8210: 196.8), stepped prompts 0.0201 s/token; upper bounds at max_tokens; each +# includes ~33 s server start. +step_def() { + ENVS=(); case $1 in + 1) DOOR=single; ENVS=(AIEN_Q36_TEST_MUTANT=4); PROBE="golden red mutant4"; EST=120 ;; + 2) DOOR=single; ENVS=(AIEN_OMEGA_Q36_PF_MUTANT=2); PROBE="golden red pf2"; EST=120 ;; + 3) DOOR=single; ENVS=(AIEN_OMEGA_Q36_PF_MUTANT=2 AIEN_Q36_PREFILL_CHUNK=0); PROBE="golden green pf2-chunk0"; EST=289 ;; + 4) DOOR=single; PROBE="golden green single"; EST=120 ;; + 5) DOOR=batch; PROBE="golden green batch"; EST=120 ;; + 6a) DOOR=single; PROBE="time single"; EST=195 ;; + 6b) DOOR=single; ENVS=(AIEN_Q36_PREFILL_CHUNK=0); PROBE="time single-chunk0"; EST=590 ;; + 6c) DOOR=batch; PROBE="time batch"; EST=195 ;; + 6d) DOOR=batch; ENVS=(AIEN_Q36_PREFILL_MIN=1); PROBE="time batch-min1"; EST=195 ;; + *) return 1 ;; + esac +} + +case ${1:-} in +plan) + printf '%-4s %-7s %-55s %-24s %s\n' step door "server env" probe est_s + for s in 1 2 3 4 5 6a 6b 6c 6d; do + step_def $s; printf '%-4s %-7s %-55s %-24s %s\n' $s $DOOR "${ENVS[*]:--}" "$PROBE" $EST + done + echo "Steps 1-2 (red) come first; 3-5 need their receipts in OUT/1 and OUT/2 (any earlier lease)." + echo "20-min leases: L1 = run BIN OUT 1 2 3 4 5 (769 s), L2 = 6a 6b (785 s), L3 = 6c 6d (390 s)." + exit 0 ;; +run) + [ -n "${SPARK_WINDOW:-}" ] || not_run "no SPARK_WINDOW: run as 'spark-window run bash $0 run ...' inside a --quiet exclusive window" + [ $# -ge 4 ] || die "usage: run BIN OUT STEP [STEP ...]" + # DRA65_TEST_LOCK (host check of this guard only): use another lock file and stop before any chip contact. + LOCK=${DRA65_TEST_LOCK:-/tmp/aien-gb10.lock} + if [ "${DRA65_LOCKED:-}" != "$SPARK_WINDOW" ]; then + # flock(1) holds the lock in its own process and runs us as its child: the holder is an ancestor of + # this shell and of every server it starts. + DRA65_LOCKED=$SPARK_WINDOW flock -n -E 75 "$LOCK" bash "$SELF" "$@"; rc=$? + [ $rc = 75 ] && not_run "$LOCK is held by another process; this script takes it itself (open the window with --gb10 none)" + exit $rc + fi + BIN=$(readlink -f "$2"); OUT=$3; shift 3; STEPS=("$@") + WIN=$SPARK_WINDOW + # 1. An exclusive flock on LOCK held by an ancestor of this shell (/proc/locks: "N: FLOCK ADVISORY WRITE pid maj:min:ino"). + ino=$(stat -c %i "$LOCK") || not_run "$LOCK missing" + holders=$(awk -v ino="$ino" '$2 == "FLOCK" && $4 == "WRITE" { split($6, a, ":"); if (a[3] == ino) print $5 }' /proc/locks | sort -u) + anc=" "; p=$$ + while [ "$p" -gt 1 ]; do anc="$anc$p "; p=$(awk '{print $4}' "/proc/$p/stat" 2>/dev/null) || break; done + HOLDER=; for h in $holders; do case "$anc" in *" $h "*) HOLDER=$h ;; esac; done + [ -n "$HOLDER" ] || not_run "$LOCK held by pid(s) '${holders}', none an ancestor of $$ ($anc)" + [ -z "${DRA65_TEST_LOCK:-}" ] || not_run "test lock $LOCK held by ancestor $HOLDER; DRA65_TEST_LOCK never reaches the chip" + # 2. Steps known; red receipts there for the green steps. + total=0; have_red=0 + for s in "${STEPS[@]}"; do + step_def "$s" || die "unknown step $s (see: $0 plan)" + total=$((total + EST)); case $s in 1|2) have_red=1 ;; esac + done + for s in "${STEPS[@]}"; do case $s in 3|4|5) + [ $have_red = 1 ] || { [ -f "$OUT/1/golden-receipt.json" ] && [ -f "$OUT/2/golden-receipt.json" ]; } \ + || not_run "step $s needs the red receipts $OUT/1 and $OUT/2 (run steps 1 and 2 first)" ;; esac + done + # 3. The lease has room for the steps' estimates. + lease=$(cat "${SPARK_WINDOW_DIR:-/nonexistent}/lease" 2>/dev/null); held=$(cat "${SPARK_WINDOW_DIR:-/nonexistent}/held" 2>/dev/null) + [ -n "$lease" ] && [ -n "$held" ] || not_run "no lease/held in SPARK_WINDOW_DIR='${SPARK_WINDOW_DIR:-}'" + left=$(( $(date -d "$held" +%s) + lease * 60 - $(date +%s) )) + [ "$total" -le "$left" ] || not_run "steps ${STEPS[*]} estimate $total s, the lease has $left s left" + # 4. Live 35B, Flint and the chip idle; binary, model, port, tools there. + PORT=18192; MODEL=$HOME/models/qwen3.6-35b-a3b-fp8-95a723d0 + for t in curl jq ss flock sha256sum nvidia-smi; do command -v $t > /dev/null || not_run "$t missing"; done + for port in 18091 18300 18310 $PORT; do [ -z "$(ss -ltnH "sport = :$port")" ] || not_run "a listener is on $port"; done + apps=$(nvidia-smi --query-compute-apps=pid,process_name,used_memory --format=csv,noheader 2>&1) || not_run "nvidia-smi failed: $apps" + [ -z "$apps" ] || not_run "compute apps on the chip: $apps" + [ -x "$BIN" ] || not_run "binary $BIN missing" + [ -f "$MODEL/config.json" ] || not_run "model $MODEL missing" + SHA=$(sha256sum < "$BIN" | cut -c1-64) + mkdir -p "$OUT" || not_run "cannot create $OUT" + log() { echo "$(date -u +%FT%TZ) $*" | tee -a "$OUT/run.log" >&2; } + board() { echo "$(date -u +%FT%TZ) DRA65Prefill: $*" >> "$HOME/handoffs/BOARD.md"; } + SERVER= + stop_server() { + [ -n "$SERVER" ] || return 0 + kill -TERM "$SERVER" 2>/dev/null + for _ in $(seq 60); do kill -0 "$SERVER" 2>/dev/null || break; sleep 1; done + kill -KILL "$SERVER" 2>/dev/null; wait "$SERVER" 2>/dev/null; SERVER= + } + # start_server LOG: DOOR and ENVS from step_def; the live start-35b(-batch).sh flags on a loopback test port. + start_server() { + local flags=(--max-context 131072) + [ "$DOOR" = batch ] && flags=(--max-context 49152 --batch-slots 8) + (cd "$(dirname "$BIN")" && exec env AIEN_GB10_LOCK_HELD=1 AIEN_SERVE_GPU_LOCK=/tmp/aien-serve-$PORT.lock AIEN_Q36_STROKE=0 \ + "${ENVS[@]}" "$BIN" --engine omega --model-dir "$MODEL" --port $PORT --bind 127.0.0.1 \ + --max-tokens-cap 16384 --thinking off "${flags[@]}") > "$1" 2>&1 & + SERVER=$! + for _ in $(seq 300); do + kill -0 "$SERVER" 2>/dev/null || { log "server exited during load: $1"; SERVER=; return 1; } + curl -s -m 2 127.0.0.1:$PORT/health > /dev/null && break; sleep 1 + done + curl -s -m 2 127.0.0.1:$PORT/health > /dev/null || { log "server not healthy in 300 s"; stop_server; return 1; } + local l; l=$(ss -ltnH "sport = :$PORT" | awk '{print $4}') + if [ -z "$l" ] || echo "$l" | grep -qv '^127\.0\.0\.1:'; then log "listener check FAILED on $PORT: $l"; stop_server; return 1; fi + } + trap 'stop_server; board "GPU-END dra-65 window-dra65.sh window $WIN steps ${STEPS[*]} -> $OUT (rc ${RC:-?})"' EXIT + trap 'log "interrupted"; exit 4' INT TERM + board "GPU-START dra-65 window-dra65.sh window $WIN steps ${STEPS[*]} (est $total s, lease left $left s; gb10 lock held by our pid $HOLDER; bin $SHA)" + log "window $WIN lock holder $HOLDER bin $BIN sha256 $SHA steps ${STEPS[*]} est $total s left $left s" + RC=0 + for s in "${STEPS[@]}"; do + step_def "$s"; D=$OUT/$s; mkdir -p "$D"; t0=$(date +%s) + log "step $s: $DOOR door, env '${ENVS[*]:-}', $PROBE, est $EST s" + if start_server "$D/server.log"; then + ready=$(( $(date +%s) - t0 )) + read -r kind a1 a2 <<<"$PROBE" + if [ "$kind" = golden ]; then + args=(golden $PORT "$D" "$a1" "$SHA" "$a2") + [ "$a1" = green ] && args+=("$OUT/1/golden-receipt.json" "$OUT/2/golden-receipt.json") + else + args=(time $PORT "$D" "$SHA" "$a1") + fi + bash "$SELF" "${args[@]}" > "$D/probe.out"; RC=$? + stop_server + else + ready=-1; RC=3 + fi + el=$(( $(date +%s) - t0 )) + pj=$(tail -n 1 "$D/probe.out" 2>/dev/null | jq -c . 2>/dev/null); [ -n "$pj" ] || pj=null + jq -cn --arg s "$s" --arg w "$WIN" --arg b "$BIN" --arg h "$SHA" --arg d "$DOOR" --arg e "${ENVS[*]:-}" --arg p "$PROBE" \ + --argjson est $EST --argjson ready $ready --argjson el $el --argjson rc $RC --arg hold "$HOLDER" --arg at "$(date -u +%FT%TZ)" \ + --argjson probe "$pj" \ + '{step:$s, window:$w, bin:$b, bin_sha256:$h, door:$d, env:$e, probe:$p, est_s:$est, server_ready_s:$ready, elapsed_s:$el, rc:$rc, lock_holder:$hold, at:$at, result:$probe}' \ + | tee "$D/step-receipt.json" + [ $RC = 0 ] || { log "step $s rc $RC: stopping"; exit $RC; } + done + exit 0 ;; +esac + +[ -n "${SPARK_WINDOW:-}" ] || not_run "no SPARK_WINDOW: the probes run from '$0 run' inside a window" WIN=$SPARK_WINDOW MODE=${1:-}; PORT=${2:-}; OUT=${3:-} [ -n "$MODE" ] && [ -n "$PORT" ] && [ -n "$OUT" ] || die "usage: see the header" @@ -140,5 +261,5 @@ time) done if [ $ok = 1 ]; then jq -cn --arg win "$WIN" --arg b "$BIN" --arg l "$LABEL" '{case:"time", verdict:"RECORDED", window:$win, bin_sha256:$b, label:$l}'; exit 0; fi jq -cn --arg win "$WIN" --arg b "$BIN" --arg l "$LABEL" '{case:"time", verdict:"INCONCLUSIVE", window:$win, bin_sha256:$b, label:$l, why:"a run had no HTTP 200, no first content delta or no usage"}'; exit 2 ;; -*) die "mode golden|time" ;; +*) die "mode plan|run|golden|time" ;; esac From a109ca70855cd0fa79e968c6eb4e103ba29a6b64 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Sat, 31 Oct 2026 08:46:41 -0500 Subject: [PATCH 5/8] DRA-65: window lease deadline and watchdog, server in own session, snapshot-restore check, step-receipt-gated green (Rev862b) --- evidence/dra65-prefill-20261031/README.md | 53 +++- .../hosttest/fake-serve.sh | 8 + .../dra65-prefill-20261031/hosttest/mock2.py | 29 ++ .../hosttest/runtests.sh | 60 +++++ .../dra65-prefill-20261031/window-dra65.sh | 253 ++++++++++++------ 5 files changed, 313 insertions(+), 90 deletions(-) create mode 100755 evidence/dra65-prefill-20261031/hosttest/fake-serve.sh create mode 100644 evidence/dra65-prefill-20261031/hosttest/mock2.py create mode 100755 evidence/dra65-prefill-20261031/hosttest/runtests.sh diff --git a/evidence/dra65-prefill-20261031/README.md b/evidence/dra65-prefill-20261031/README.md index 78037ffb..a39da3ea 100644 --- a/evidence/dra65-prefill-20261031/README.md +++ b/evidence/dra65-prefill-20261031/README.md @@ -79,8 +79,23 @@ missing usage INCONCLUSIVE rc 2; no `SPARK_WINDOW` NOT_RUN rc 3. Every `golden.j receipt carried `window: w-test-2` and the binary sha. `run` guard, with `DRA65_TEST_LOCK` pointing at a scratch lock (it never reaches the chip): no `SPARK_WINDOW` rc 3; lock held by another process rc 3 ("held by another process"); `DRA65_LOCKED` spoofed without holding the lock rc 3 ("held by pid(s) ..., none an ancestor"); lock -free: taken, its flock(1) holder found among the script's ancestors, then rc 3 as the test lock demands. The -part past the guard (lease, listener and chip checks, server start, step loop) is NOT_RUN on host. +free: taken, its flock(1) holder found among the script's ancestors, then rc 3 as the test lock demands. + +`run` end to end on host (review Rev862b; `nice -n 19 taskset -c 0-9 bash +evidence/dra65-prefill-20261031/hosttest/runtests.sh`, scratch lock under `/tmp/dra65-hosttest`, +`DRA65_TEST_PORT=18978`, BIN = `hosttest/fake-serve.sh`, a shell mock door that execs `hosttest/mock2.py`; test +mode (`DRA65_TEST_LOCK`) refuses an ELF BIN and skips the chip, model and live-port checks; board lines go to +`OUT/board.log`). L1 `run BIN OUT 1 2 3 4 5` started +under `taskset -c 5`: rc 0, steps 1-2 red PASS (35/36 same), steps 3-5 green PASS (36/36); every server pid == +its sid, 0 fds on the lock, `Cpus_allowed_list 0-9`; turn 2 matched `reuse Snapshot(2479) (2479 tok)`; lock free +and no process left after. Green step 4 alone on that OUT: rc 0 (reds from step receipts). `4 1 2` on an empty +OUT: NOT_RUN rc 3. Golden receipts without step receipts: `run 4` NOT_RUN rc 3, the probe itself refused rc 2. +Green probe without `DRA65_SERVER_LOG`: turn 2 NO_SNAP, FAIL rc 1; door that never logs the restore: FAIL rc 1. +Lease 45 s with a 30 s/request door: step INCONCLUSIVE rc 2 at 46 s ("probe stopped at the lease deadline"), +`lease_expired: true`, lock free. `expired` created mid-step: INCONCLUSIVE rc 2. SIGKILL of the run shell +mid-step: the watchdog TERMed the server group, server gone, lock free. TERM of the flock(1) holder: the +watchdog stopped the server group and the run shell, lock free. Not host-testable: the real server, the +nvidia-smi/model/18091 checks and the chip. Mutant 4 wiring (source, omega 474197e4f): `AIEN_Q36_TEST_MUTANT=4` -> `moe.rs` `graph_mutant()` -> `test_set_mutant` on the main graph and (`rows.rs` wire) every row and stroke graph; in C mutant 4 swaps K_CN for @@ -98,18 +113,34 @@ exclusive --lease 20`), stops 18091 and Flint, and runs one lease's steps: `spark-window run bash evidence/dra65-prefill-20261031/window-dra65.sh run BIN OUT STEP ...`, BIN = the server binary built from this branch, OUT = one receipt root for every lease (step N writes `OUT/N/`). The 35B server's chip reservation (`crates/aien-serve-http/src/chip_reservation.rs` L88-95) accepts `/tmp/aien-gb10.lock` only -when one of its ancestors holds it, and spark-window's holder never is; so the script takes `flock -n` on the -lock itself (flock(1) holds it and runs the script as its child), checks in `/proc/locks` that the exclusive -holder is its ancestor, and starts each server as its own child with `AIEN_GB10_LOCK_HELD=1`. Exit 3 (NOT_RUN, -chip untouched): no `SPARK_WINDOW`; the lock held by anyone else; a listener on 18091, 18300, 18310 or the test -port 18192; a compute app on the chip; BIN or the model missing; green steps without the red receipts in -`OUT/1`, `OUT/2`; or the steps' estimates longer than the lease has left (`$SPARK_WINDOW_DIR/held` + `lease`). +when one of its ancestors holds it, and spark-window's holder never is; so the script takes `flock -n -o` on the +lock itself (flock(1) holds it and runs the script as its child; `-o` closes the fd before the exec, so no +descendant inherits the lock), checks in `/proc/locks` that the exclusive holder is its ancestor, and starts each +server as its own child, in its own session (`setsid`, pid file `OUT/.server..pid`), with +`AIEN_GB10_LOCK_HELD=1` and the affinity reset of the live start scripts (`taskset -c` over every online CPU, so a +core5/nice19 parent does not pin the 35B to one core; `nice` is inherited and cannot be lowered: do not start +`run` under `nice`). Exit 3 (NOT_RUN, chip untouched): no `SPARK_WINDOW`; the lock held by anyone else; a listener +on 18091, 18300, 18310 or the test port 18192; a compute app on the chip; BIN or the model missing; a green step +(3-5) not preceded by both red steps in the same run and without their passing step receipts in `OUT/1`, `OUT/2` +(rc 0, same bin_sha256, a lock holder, lease not expired); `$SPARK_WINDOW_DIR/expired` present; or the steps' +estimates longer than the lease has left. + +Lease: deadline = `held` + `lease` x `SPARK_LEASE_UNIT_S` (default 60). The server wait (at most 300 s), each probe +(`timeout` to the deadline) and every request (`curl -m` = min(1800 s, time left); none sent when no time is +left) are bounded by it. A watchdog in its own session stops the server's process group (TERM, KILL after 20 s) +and then the run shell at the deadline, or as soon as the run shell or the flock(1) holder dies (SIGKILL included); +the run shell's exit ends flock(1), which releases the lock. A step that ends after the deadline or with +`$SPARK_WINDOW_DIR/expired` present is INCONCLUSIVE rc 2, never PASS/RECORDED; a step that cannot fit its estimate +in the time left is not started (NOT_RUN rc 3). + Servers: the live `start-35b.sh` flags (`--max-context 131072`) for the single door, `start-35b-batch.sh` (`--max-context 49152 --batch-slots 8`) for the batch door, `--bind 127.0.0.1 --max-tokens-cap 16384 --thinking off AIEN_Q36_STROKE=0`, plus the step's env. Each step writes `OUT/N/step-receipt.json` (window id, binary path -and sha256, door, env, est_s, server_ready_s, elapsed_s, rc, lock holder pid, the probe's receipt) beside the -probe's own receipts; `run` stops at the first step that does not exit 0, and posts GPU-START/GPU-END lines on -the board. +and sha256, door, env, est_s, server_ready_s, elapsed_s, rc, verdict, why, lease_expired, deadline, lock holder +pid, the probe's receipt) beside the probe's own receipts; `run` stops at the first step that does not exit 0, and +posts GPU-START/GPU-END lines on the board. The turn2 case also needs the door's snapshot-restore line in that +step's `server.log` for the turn2 request (single door `reuse Snapshot(` from `qwen38_engine.rs`, batch door +`tok (snapshot, row` from `qwen36_batch.rs`); without it the case is NO_SNAP: FAIL for green, INCONCLUSIVE for red. Estimated durations (MODELED, upper bounds at max_tokens; `window-dra65.sh plan` prints them), with decode 0.0201 s/token, chunked prompts 250 tok/s (8210 tokens at 196.8), stepped prompts 0.0201 s/token, +33 s start: diff --git a/evidence/dra65-prefill-20261031/hosttest/fake-serve.sh b/evidence/dra65-prefill-20261031/hosttest/fake-serve.sh new file mode 100755 index 00000000..599973d1 --- /dev/null +++ b/evidence/dra65-prefill-20261031/hosttest/fake-serve.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +# dra65 mock door for the host check of window-dra65.sh run (never the real server) +port=; while [ $# -gt 0 ]; do [ "$1" = --port ] && port=$2; shift; done +M=exact +if [ "${AIEN_Q36_TEST_MUTANT:-}" = 4 ] || { [ "${AIEN_OMEGA_Q36_PF_MUTANT:-}" = 2 ] && [ "${AIEN_Q36_PREFILL_CHUNK:-128}" != 0 ]; }; then M=mut; fi +[ -n "${MOCK_M:-}" ] && M=$MOCK_M +echo "fake-serve pid $$ sid $(ps -o sid= -p $$ | tr -d " ") M=$M lock_fds=$(ls -l /proc/$$/fd | grep -c "$(basename "$DRA65_TEST_LOCK")") $(grep Cpus_allowed_list /proc/self/status)" >&2 +M=$M exec python3 "$(dirname "$0")/mock2.py" "$REPO" "$port" diff --git a/evidence/dra65-prefill-20261031/hosttest/mock2.py b/evidence/dra65-prefill-20261031/hosttest/mock2.py new file mode 100644 index 00000000..8bc52ecf --- /dev/null +++ b/evidence/dra65-prefill-20261031/hosttest/mock2.py @@ -0,0 +1,29 @@ +# dra65 mock door (host check of window-dra65.sh only): serves set32 goldens; M=exact|mut|nosnap|slow|slow1 +import json, os, sys, time, http.server +R=sys.argv[1]; D=R+'/evidence/dra65-prefill-20261031'; M=os.environ.get('M','exact') +g={p['user']:p['golden_ids'] for p in json.load(open(D+'/set32.json'))['prompts']} +for p in json.load(open(D+'/long-goldens.json'))['prompts']: + if 'file' in p: g[open(R+'/'+p['file']).read()]=p['golden_ids'] + else: g['TURN2']=p['golden_ids'] +class H(http.server.BaseHTTPRequestHandler): + def log_message(s,*a): pass + def out(s,code,b,ct='application/json'): + s.send_response(code); s.send_header('Content-Type',ct); s.send_header('Content-Length',str(len(b))); s.end_headers(); s.wfile.write(b) + def do_GET(s): s.out(200,json.dumps({'data':[{'id':'mock'}]}).encode()) + def do_POST(s): + q=json.loads(s.rfile.read(int(s.headers['Content-Length']))) + if M=='500': return s.out(500,b'{"error":"x"}') + msgs=q['messages']; key='TURN2' if len(msgs)==3 else msgs[0]['content']; ids=list(g.get(key,[1,2,3])) + if M=='slow': time.sleep(30) + if M=='slow1': time.sleep(0.25) + if M=='mut' and key=='TURN2': ids[2]+=1 + sys.stderr.write('aien-serve-http: qwen38: prompt 9 tok, reuse %s\n' % ('Snapshot(2479) (2479 tok)' if key=='TURN2' and M!='nosnap' else 'Cold (0 tok)')); sys.stderr.flush() + if M=='empty': ids=[] + if M=='short': ids=ids[:-1] + if q.get('stream'): + ev=[{'choices':[{'delta':{'content':'x'}}]}] + if M!='nousage': ev.append({'choices':[],'usage':{'prompt_tokens':9,'completion_tokens':len(ids)}}) + b=''.join('data: '+json.dumps(e)+'\n\n' for e in ev)+'data: [DONE]\n\n' + return s.out(200,b.encode(),'text/event-stream') + s.out(200,json.dumps({'choices':[{'message':{'content':'x'},'finish_reason':'stop'}],'usage':{'aien_token_ids':ids}}).encode()) +http.server.ThreadingHTTPServer(('127.0.0.1',int(sys.argv[2])),H).serve_forever() diff --git a/evidence/dra65-prefill-20261031/hosttest/runtests.sh b/evidence/dra65-prefill-20261031/hosttest/runtests.sh new file mode 100755 index 00000000..65810a14 --- /dev/null +++ b/evidence/dra65-prefill-20261031/hosttest/runtests.sh @@ -0,0 +1,60 @@ +#!/usr/bin/env bash +# Host check of window-dra65.sh run against the mock door (fake-serve.sh); scratch lock, never the chip. +# Run as: nice -n 19 taskset -c 0-9 bash evidence/dra65-prefill-20261031/hosttest/runtests.sh (ports 18978, 18979) +set -u +H=$(cd "$(dirname "$0")" && pwd) +S=$(cd "$H/.." && pwd)/window-dra65.sh # the canonical path the script re-execs itself under +export REPO; REPO=$(git -C "$H" rev-parse --show-toplevel) +T=${DRA65_HOSTTEST_DIR:-/tmp/dra65-hosttest}; rm -rf "$T"; mkdir -p "$T/win" +export SPARK_WINDOW=w-test-3 SPARK_WINDOW_DIR=$T/win DRA65_TEST_LOCK=$T/t3.lock DRA65_TEST_PORT=18978 +: > "$DRA65_TEST_LOCK" +B=$H/fake-serve.sh +win() { rm -f "$T/win/expired"; date -u +%FT%TZ > "$T/win/held"; echo "$1" > "$T/win/lease"; export SPARK_LEASE_UNIT_S=$2; } +lockfree() { flock -n "$DRA65_TEST_LOCK" true && echo lock=free || echo lock=HELD; } +left() { pgrep -f 'mock2.py|_watch' | grep -v $$ | wc -l; } +sr() { jq -c '{step, rc, verdict, why, lease_expired, v: .result.verdict, same: .result.same, no_snap: .result.no_snap}' "$1/step-receipt.json" 2>/dev/null || echo "no receipt $1"; } +t() { echo; echo "== $*"; } + +t "T1 L1 steps 1 2 3 4 5 (lease 20 min), under taskset -c 5" +win 20 60; taskset -c 5 bash "$S" run "$B" "$T/o1" 1 2 3 4 5 > "$T/t1.out" 2> "$T/t1.err"; echo "rc=$?" +for s in 1 2 3 4 5; do sr "$T/o1/$s"; done +grep -h fake-serve "$T"/o1/*/server.log | sed 's/pid [0-9]* sid [0-9]*/pid P sid P/' | sort | uniq -c +for s in 1 4; do echo "server pid==sid: $(grep -ho 'pid [0-9]* sid [0-9]*' "$T/o1/$s/server.log" | awk '{print ($2==$4)}')"; done +jq -c 'select(.id=="turn2") | {id, verdict, snapshot_log}' "$T/o1/4/golden.jsonl" +jq -c '{window, bin_sha256: .bin_sha256[0:12]}' "$T/o1/5/golden-receipt.json"; sleep 2; lockfree; echo "leftover=$(left)"; cat "$T/o1/board.log" + +t "T2 green 4 alone on o1 (reds from step receipts)"; win 20 60 +bash "$S" run "$B" "$T/o1" 4 > /dev/null 2> "$T/t2.err"; echo "rc=$?"; sr "$T/o1/4" +t "T3 order: 4 1 2 on empty o3"; bash "$S" run "$B" "$T/o3" 4 1 2 2>&1 >/dev/null | tail -n 1; echo "rc=${PIPESTATUS[0]}" +t "T4 golden receipts without step receipts (o4): run 4" +mkdir -p "$T/o4/1" "$T/o4/2"; cp "$T/o1/1/golden-receipt.json" "$T/o4/1/"; cp "$T/o1/2/golden-receipt.json" "$T/o4/2/" +bash "$S" run "$B" "$T/o4" 4 2>&1 >/dev/null | tail -n 1 +t "T4b probe green directly with those receipts (mock up on 18979)" +M=exact python3 "$H/mock2.py" "$REPO" 18979 2>/dev/null & mp=$!; sleep 1 +SHA=$(sha256sum < "$B" | cut -c1-64) +bash "$S" golden 18979 "$T/o4/g" green "$SHA" x "$T/o4/1/golden-receipt.json" "$T/o4/2/golden-receipt.json" > /dev/null 2> "$T/t4b.err"; echo "rc=$?"; cat "$T/t4b.err" +t "T4c same probe with o1's receipts (step receipts present) but no DRA65_SERVER_LOG -> turn2 NO_SNAP -> FAIL" +bash "$S" golden 18979 "$T/o4/g2" green "$SHA" x "$T/o1/1/golden-receipt.json" "$T/o1/2/golden-receipt.json" | jq -c '{verdict, same, no_snap}'; echo "rc=${PIPESTATUS[0]}" +kill $mp + +t "T5 nosnap door, step 4 on o1"; win 20 60 +MOCK_M=nosnap bash "$S" run "$B" "$T/o1" 4 > /dev/null 2>&1; echo "rc=$?"; sr "$T/o1/4" +jq -c 'select(.id=="turn2") | {id, verdict, snapshot_log}' "$T/o1/4/golden.jsonl" + +t "T6 deadline: slow door (30 s/request), lease 1 x 45 s, step 4"; win 1 45 +s0=$(date +%s); MOCK_M=slow bash "$S" run "$B" "$T/o1" 4 > /dev/null 2> "$T/t6.err"; echo "rc=$? after $(( $(date +%s) - s0 )) s" +sr "$T/o1/4"; sleep 2; lockfree; echo "leftover=$(left)"; tail -n 2 "$T/t6.err" + +t "T7 expired file appears mid-step (slow1 door), step 4"; win 20 60 +( sleep 4; touch "$T/win/expired" ) & MOCK_M=slow1 bash "$S" run "$B" "$T/o1" 4 > /dev/null 2>&1; echo "rc=$?"; sr "$T/o1/4"; wait + +t "T8 SIGKILL the run shell mid-step (slow door)"; win 20 60 +MOCK_M=slow bash "$S" run "$B" "$T/o8" 1 > /dev/null 2>&1 & sleep 6 +inner=$(pgrep -f "bash $S run $B $T/o8" | while read -r p; do [ "$(ps -o comm= -p "$p")" = bash ] && [ "$(ps -o comm= -p "$(ps -o ppid= -p "$p" | tr -d ' ')")" = flock ] && echo "$p"; done) +sp=$(cat $T/o8/.server.*.pid 2>/dev/null); echo "inner=$inner server=$sp"; kill -KILL "$inner"; sleep 4 +echo "server alive: $(kill -0 -- "-$sp" 2>/dev/null && echo yes || echo no)"; sleep 2; lockfree; echo "leftover=$(left)"; cat "$T/o8/watch.log"; wait + +t "T9 TERM the flock holder mid-step (slow door)"; win 20 60 +MOCK_M=slow bash "$S" run "$B" "$T/o9" 1 > /dev/null 2>&1 & sleep 6 +fl=$(pgrep -x flock | while read -r p; do grep -q "o9" "/proc/$p/cmdline" && echo "$p"; done); echo "flock=$fl"; kill -TERM "$fl"; sleep 25 +sleep 2; lockfree; echo "leftover=$(left)"; cat "$T/o9/watch.log"; wait diff --git a/evidence/dra65-prefill-20261031/window-dra65.sh b/evidence/dra65-prefill-20261031/window-dra65.sh index ed8527ad..3d22cdb9 100755 --- a/evidence/dra65-prefill-20261031/window-dra65.sh +++ b/evidence/dra65-prefill-20261031/window-dra65.sh @@ -5,10 +5,18 @@ # spark-window run bash window-dra65.sh run BIN OUT STEP [STEP ...] # BIN = the server binary built from this branch, OUT = a receipt root shared by every lease (step N writes # OUT/N/). The server's chip reservation (aien-serve-http chip_reservation.rs) only accepts /tmp/aien-gb10.lock -# held by one of its ancestors, so this script takes `flock -n` on it itself and starts every server as its -# child with AIEN_GB10_LOCK_HELD=1. Exit 3 = NOT_RUN, chip untouched: no SPARK_WINDOW, the lock held by someone -# else, a listener on 18091/18300/18310 or the test port, a compute app on the chip, the binary or model -# missing, or the steps' estimated time longer than the lease has left. +# held by one of its ancestors, so this script takes `flock -n -o` on it itself (the lock stays in flock(1), an +# ancestor; no descendant inherits the fd) and starts every server as its child, in its own session +# (setsid, pid file OUT/.server..pid), with AIEN_GB10_LOCK_HELD=1 and the affinity reset of the live start scripts. +# Exit 3 = NOT_RUN, chip untouched: no SPARK_WINDOW, the lock held by someone else, a listener on +# 18091/18300/18310 or the test port, a compute app on the chip, the binary or model missing, a green step +# without passing red steps (listed before it, or their step receipts in OUT/1 and OUT/2), or the steps' +# estimated time longer than the lease has left. +# Lease: deadline = SPARK_WINDOW_DIR/held + lease * SPARK_LEASE_UNIT_S (default 60). Every server wait and +# probe is bounded by the time left (timeout, curl -m). A watchdog in its own session stops the server group +# at the deadline (and this script if it has not ended 40 s later), or at once when this script or the lock +# holder dies; the lock is then released. +# A step that ends after the deadline or with SPARK_WINDOW_DIR/expired present is INCONCLUSIVE (rc 2). # window-dra65.sh plan (no window needed: the steps, their server env and estimated durations) # Every receipt line carries the window id and the binary sha256. # @@ -16,21 +24,31 @@ # window-dra65.sh golden PORT OUT red BIN_SHA256 LABEL # window-dra65.sh golden PORT OUT green BIN_SHA256 LABEL RED_RECEIPT RED_RECEIPT [...] # 36 cases (32-prompt set, 3 long prompts, turn 2 restoring the long-2048 snapshot) vs the pinned goldens. -# green refuses to run unless it is handed at least two red receipts (verdict PASS, distinct labels) -# of the same server binary sha256: red before green. +# green refuses to run unless it is handed at least two red receipts (verdict PASS, distinct labels) of +# the same server binary sha256, each next to a step-receipt.json of `run` with rc 0, the same +# bin_sha256, a lock holder and the lease not expired: red before green. +# With DRA65_SERVER_LOG (set by `run`), turn2 also needs the door's snapshot-restore log line for that +# request (single: `reuse Snapshot(`, qwen38_engine.rs; batch: `tok (snapshot, row`, qwen36_batch.rs). # window-dra65.sh time PORT OUT BIN_SHA256 LABEL # TTFT and end-to-end tok/s, ~512 and 8210-token prompts, 3 runs each. # Per case: SAME (ids equal), DIFF (a flip inside the common length, or more ids than the golden), -# SHORT (a strict prefix of the golden: no flip shown), NO_IDS (HTTP error, missing or empty ids). -# golden red: PASS = at least one DIFF and no NO_IDS/SHORT; NO_IDS/SHORT -> INCONCLUSIVE; else FAIL. -# golden green: PASS = all SAME; any NO_IDS -> INCONCLUSIVE; else FAIL. -# Exit 0 = PASS, 1 = FAIL, 2 = INCONCLUSIVE or refused, 3 = NOT_RUN. time: 0 only if every run has HTTP 200, -# a first content delta and usage with completion_tokens > 0; else 2. `run` stops at the first step that -# does not exit 0 and returns its code. +# SHORT (a strict prefix of the golden: no flip shown), NO_IDS (HTTP error, missing or empty ids), +# NO_SNAP (turn2 without the snapshot-restore log line). +# golden red: PASS = at least one DIFF and no NO_IDS/SHORT/NO_SNAP; those -> INCONCLUSIVE; else FAIL. +# golden green: PASS = all SAME; any NO_IDS -> INCONCLUSIVE; else (NO_SNAP included) FAIL. +# Exit 0 = PASS, 1 = FAIL, 2 = INCONCLUSIVE or refused, 3 = NOT_RUN, 4 = interrupted. time: 0 only if every run +# has HTTP 200, a first content delta and usage with completion_tokens > 0; else 2. `run` stops at the first +# step that does not exit 0 and returns its code. set -uo pipefail HERE=$(cd "$(dirname "$0")" && pwd); REPO=$(cd "$HERE/../.." && pwd); SELF=$HERE/$(basename "$0") die() { echo "window-dra65: $*" >&2; exit 2; } not_run() { echo "window-dra65: NOT_RUN: $*" >&2; exit 3; } +# left_s [CAP]: seconds to DRA65_DEADLINE (unset: CAP), at most CAP; returns 1 when none are left. +left_s() { + local cap=${1:-999999} l + if [ -n "${DRA65_DEADLINE:-}" ]; then l=$((DRA65_DEADLINE - $(date +%s))); [ "$l" -lt "$cap" ] || l=$cap; else l=$cap; fi + echo "$l"; [ "$l" -gt 0 ] +} # step -> door, server env, probe, estimated seconds. MODELED (Wolfram, README "Window"): decode 0.0201 s/token, # chunked prompts 250 tok/s (8210: 196.8), stepped prompts 0.0201 s/token; upper bounds at max_tokens; each @@ -49,6 +67,11 @@ step_def() { *) return 1 ;; esac } +# red_ok OUT STEP SHA: that red step's run receipt passed for this binary inside the lease. +red_ok() { + jq -e --arg b "$3" '.rc == 0 and .bin_sha256 == $b and (.lock_holder | length) > 0 and .lease_expired == false + and .result.case == "golden" and .result.expect == "red" and .result.verdict == "PASS"' "$1/$2/step-receipt.json" > /dev/null 2>&1 +} case ${1:-} in plan) @@ -56,22 +79,39 @@ plan) for s in 1 2 3 4 5 6a 6b 6c 6d; do step_def $s; printf '%-4s %-7s %-55s %-24s %s\n' $s $DOOR "${ENVS[*]:--}" "$PROBE" $EST done - echo "Steps 1-2 (red) come first; 3-5 need their receipts in OUT/1 and OUT/2 (any earlier lease)." + echo "Steps 1-2 (red) come first; 3-5 need them earlier in the same run or their step receipts in OUT/1 and OUT/2." echo "20-min leases: L1 = run BIN OUT 1 2 3 4 5 (769 s), L2 = 6a 6b (785 s), L3 = 6c 6d (390 s)." exit 0 ;; +_watch) # _watch MAIN HOLDER DEADLINE PIDFILE (own session; started by run) + M=$2; H=$3; DL=$4; PF=$5 + while kill -0 "$M" 2>/dev/null && kill -0 "$H" 2>/dev/null && [ "$(date +%s)" -lt "$DL" ]; do sleep 1; done + why="deadline"; kill -0 "$M" 2>/dev/null || why="run shell $M gone"; kill -0 "$H" 2>/dev/null || why="lock holder $H gone" + pg=$(cat "$PF" 2>/dev/null) + if [ -n "$pg" ] && kill -0 -- "-$pg" 2>/dev/null; then + echo "$(date -u +%FT%TZ) watchdog: $why: TERM server group $pg" + kill -TERM -- "-$pg" 2>/dev/null + for _ in $(seq 20); do kill -0 -- "-$pg" 2>/dev/null || break; sleep 1; done + kill -KILL -- "-$pg" 2>/dev/null; rm -f "$PF" + fi + # At the deadline the run shell's own bounds (probe timeout, stop_server) end the step as INCONCLUSIVE and it + # exits: give it 40 s to write that receipt. Its exit ends flock(1), which releases the lock. + if [ "$why" = deadline ]; then for _ in $(seq 40); do kill -0 "$M" 2>/dev/null || break; sleep 1; done; fi + kill -0 "$M" 2>/dev/null && { echo "$(date -u +%FT%TZ) watchdog: $why: TERM run shell $M"; kill -TERM "$M"; } + exit 0 ;; run) [ -n "${SPARK_WINDOW:-}" ] || not_run "no SPARK_WINDOW: run as 'spark-window run bash $0 run ...' inside a --quiet exclusive window" [ $# -ge 4 ] || die "usage: run BIN OUT STEP [STEP ...]" - # DRA65_TEST_LOCK (host check of this guard only): use another lock file and stop before any chip contact. - LOCK=${DRA65_TEST_LOCK:-/tmp/aien-gb10.lock} + # DRA65_TEST_LOCK (host check only): another lock file; the binary must be a script (a mock door, never the + # ELF server), the chip and live-port checks are skipped and board lines go to OUT/board.log. + LOCK=${DRA65_TEST_LOCK:-/tmp/aien-gb10.lock}; TEST=${DRA65_TEST_LOCK:+1} if [ "${DRA65_LOCKED:-}" != "$SPARK_WINDOW" ]; then - # flock(1) holds the lock in its own process and runs us as its child: the holder is an ancestor of - # this shell and of every server it starts. - DRA65_LOCKED=$SPARK_WINDOW flock -n -E 75 "$LOCK" bash "$SELF" "$@"; rc=$? + # flock(1) holds the lock in its own process (-o: closed before exec, so no descendant inherits it) and + # runs us as its child: the holder is an ancestor of this shell and of every server it starts. + DRA65_LOCKED=$SPARK_WINDOW flock -n -o -E 75 "$LOCK" bash "$SELF" "$@"; rc=$? [ $rc = 75 ] && not_run "$LOCK is held by another process; this script takes it itself (open the window with --gb10 none)" exit $rc fi - BIN=$(readlink -f "$2"); OUT=$3; shift 3; STEPS=("$@") + BIN=$(readlink -f "$2"); OUT=$(readlink -m "$3"); shift 3; STEPS=("$@") WIN=$SPARK_WINDOW # 1. An exclusive flock on LOCK held by an ancestor of this shell (/proc/locks: "N: FLOCK ADVISORY WRITE pid maj:min:ino"). ino=$(stat -c %i "$LOCK") || not_run "$LOCK missing" @@ -80,66 +120,94 @@ run) while [ "$p" -gt 1 ]; do anc="$anc$p "; p=$(awk '{print $4}' "/proc/$p/stat" 2>/dev/null) || break; done HOLDER=; for h in $holders; do case "$anc" in *" $h "*) HOLDER=$h ;; esac; done [ -n "$HOLDER" ] || not_run "$LOCK held by pid(s) '${holders}', none an ancestor of $$ ($anc)" - [ -z "${DRA65_TEST_LOCK:-}" ] || not_run "test lock $LOCK held by ancestor $HOLDER; DRA65_TEST_LOCK never reaches the chip" - # 2. Steps known; red receipts there for the green steps. - total=0; have_red=0 + if [ -n "$TEST" ]; then + [ -x "$BIN" ] && [ "$(head -c 4 "$BIN" | od -An -c | tr -d ' ')" != '177ELF' ] \ + || not_run "test lock $LOCK held by ancestor $HOLDER; DRA65_TEST_LOCK only runs a script mock door, never the server binary" + fi + [ -x "$BIN" ] || not_run "binary $BIN missing" + SHA=$(sha256sum < "$BIN" | cut -c1-64) + # 2. Steps known; each green step after both red steps in this run, or their passing step receipts in OUT. + total=0; seen1=0; seen2=0 for s in "${STEPS[@]}"; do step_def "$s" || die "unknown step $s (see: $0 plan)" - total=$((total + EST)); case $s in 1|2) have_red=1 ;; esac - done - for s in "${STEPS[@]}"; do case $s in 3|4|5) - [ $have_red = 1 ] || { [ -f "$OUT/1/golden-receipt.json" ] && [ -f "$OUT/2/golden-receipt.json" ]; } \ - || not_run "step $s needs the red receipts $OUT/1 and $OUT/2 (run steps 1 and 2 first)" ;; esac + [ -n "$TEST" ] && EST=5 + total=$((total + EST)) + case $s in + 1) seen1=1 ;; 2) seen2=1 ;; + 3|4|5) { [ $seen1 = 1 ] || red_ok "$OUT" 1 "$SHA"; } && { [ $seen2 = 1 ] || red_ok "$OUT" 2 "$SHA"; } \ + || not_run "green step $s needs red steps 1 and 2 before it in this run, or their passing step receipts in $OUT/1 and $OUT/2 for bin $SHA" ;; + esac done # 3. The lease has room for the steps' estimates. lease=$(cat "${SPARK_WINDOW_DIR:-/nonexistent}/lease" 2>/dev/null); held=$(cat "${SPARK_WINDOW_DIR:-/nonexistent}/held" 2>/dev/null) [ -n "$lease" ] && [ -n "$held" ] || not_run "no lease/held in SPARK_WINDOW_DIR='${SPARK_WINDOW_DIR:-}'" - left=$(( $(date -d "$held" +%s) + lease * 60 - $(date +%s) )) + [ -e "$SPARK_WINDOW_DIR/expired" ] && not_run "the lease has expired ($SPARK_WINDOW_DIR/expired)" + heldt=$(date -d "$held" +%s) || not_run "cannot read held time '$held'" + DEADLINE=$(( heldt + lease * ${SPARK_LEASE_UNIT_S:-60} )); export DRA65_DEADLINE=$DEADLINE + left=$(( DEADLINE - $(date +%s) )) [ "$total" -le "$left" ] || not_run "steps ${STEPS[*]} estimate $total s, the lease has $left s left" - # 4. Live 35B, Flint and the chip idle; binary, model, port, tools there. - PORT=18192; MODEL=$HOME/models/qwen3.6-35b-a3b-fp8-95a723d0 - for t in curl jq ss flock sha256sum nvidia-smi; do command -v $t > /dev/null || not_run "$t missing"; done - for port in 18091 18300 18310 $PORT; do [ -z "$(ss -ltnH "sport = :$port")" ] || not_run "a listener is on $port"; done - apps=$(nvidia-smi --query-compute-apps=pid,process_name,used_memory --format=csv,noheader 2>&1) || not_run "nvidia-smi failed: $apps" - [ -z "$apps" ] || not_run "compute apps on the chip: $apps" - [ -x "$BIN" ] || not_run "binary $BIN missing" - [ -f "$MODEL/config.json" ] || not_run "model $MODEL missing" - SHA=$(sha256sum < "$BIN" | cut -c1-64) + # 4. Live 35B, Flint and the chip idle; model, port, tools there. + PORT=${DRA65_TEST_PORT:-18192}; [ -n "$TEST" ] || PORT=18192 + MODEL=$HOME/models/qwen3.6-35b-a3b-fp8-95a723d0 + for t in curl jq ss flock setsid timeout sha256sum; do command -v $t > /dev/null || not_run "$t missing"; done + [ -z "$(ss -ltnH "sport = :$PORT")" ] || not_run "a listener is on $PORT" + if [ -z "$TEST" ]; then + command -v nvidia-smi > /dev/null || not_run "nvidia-smi missing" + for port in 18091 18300 18310; do [ -z "$(ss -ltnH "sport = :$port")" ] || not_run "a listener is on $port"; done + apps=$(nvidia-smi --query-compute-apps=pid,process_name,used_memory --format=csv,noheader 2>&1) || not_run "nvidia-smi failed: $apps" + [ -z "$apps" ] || not_run "compute apps on the chip: $apps" + [ -f "$MODEL/config.json" ] || not_run "model $MODEL missing" + fi mkdir -p "$OUT" || not_run "cannot create $OUT" + PIDF=$OUT/.server.$$.pid # per run: a previous run's watchdog never sees this run's server log() { echo "$(date -u +%FT%TZ) $*" | tee -a "$OUT/run.log" >&2; } - board() { echo "$(date -u +%FT%TZ) DRA65Prefill: $*" >> "$HOME/handoffs/BOARD.md"; } + board() { + if [ -n "$TEST" ]; then echo "$(date -u +%FT%TZ) DRA65Prefill: $*" >> "$OUT/board.log" + else echo "$(date -u +%FT%TZ) DRA65Prefill: $*" >> "$HOME/handoffs/BOARD.md"; fi + } SERVER= - stop_server() { + stop_server() { # TERM the server's process group (its own session), KILL after 20 s [ -n "$SERVER" ] || return 0 - kill -TERM "$SERVER" 2>/dev/null - for _ in $(seq 60); do kill -0 "$SERVER" 2>/dev/null || break; sleep 1; done - kill -KILL "$SERVER" 2>/dev/null; wait "$SERVER" 2>/dev/null; SERVER= + kill -TERM -- "-$SERVER" 2>/dev/null + for _ in $(seq 20); do kill -0 -- "-$SERVER" 2>/dev/null || break; sleep 1; done + kill -KILL -- "-$SERVER" 2>/dev/null; wait "$SERVER" 2>/dev/null; rm -f "$PIDF"; SERVER= } # start_server LOG: DOOR and ENVS from step_def; the live start-35b(-batch).sh flags on a loopback test port. start_server() { - local flags=(--max-context 131072) + local flags=(--max-context 131072) aff cpus lim l [ "$DOOR" = batch ] && flags=(--max-context 49152 --batch-slots 8) - (cd "$(dirname "$BIN")" && exec env AIEN_GB10_LOCK_HELD=1 AIEN_SERVE_GPU_LOCK=/tmp/aien-serve-$PORT.lock AIEN_Q36_STROKE=0 \ - "${ENVS[@]}" "$BIN" --engine omega --model-dir "$MODEL" --port $PORT --bind 127.0.0.1 \ - --max-tokens-cap 16384 --thinking off "${flags[@]}") > "$1" 2>&1 & - SERVER=$! - for _ in $(seq 300); do - kill -0 "$SERVER" 2>/dev/null || { log "server exited during load: $1"; SERVER=; return 1; } + # As start-35b(-batch).sh: undo an inherited affinity (a core5/nice19 parent) so the server gets every core + # (test mode: cores 0-9, the host budget). + cpus=$(cat /sys/devices/system/cpu/online); [ -n "$TEST" ] && cpus=0-9 + aff=(taskset -c "$cpus"); "${aff[@]}" true 2> /dev/null || aff=() + # A background subshell is not a group leader, so setsid(1) does not fork: SERVER is the session and group id. + (cd "$(dirname "$BIN")" && exec setsid "${aff[@]}" env AIEN_GB10_LOCK_HELD=1 AIEN_SERVE_GPU_LOCK=/tmp/aien-serve-$PORT.lock \ + AIEN_Q36_STROKE=0 "${ENVS[@]}" "$BIN" --engine omega --model-dir "$MODEL" --port $PORT --bind 127.0.0.1 \ + --max-tokens-cap 16384 --thinking off "${flags[@]}") > "$1" 2>&1 < /dev/null & + SERVER=$!; echo "$SERVER" > "$PIDF" + lim=$(left_s 300) || { log "no lease time left to start the server"; stop_server; return 1; } + for _ in $(seq "$lim"); do + kill -0 "$SERVER" 2>/dev/null || { log "server exited during load: $1"; wait "$SERVER" 2>/dev/null; rm -f "$PIDF"; SERVER=; return 1; } curl -s -m 2 127.0.0.1:$PORT/health > /dev/null && break; sleep 1 done - curl -s -m 2 127.0.0.1:$PORT/health > /dev/null || { log "server not healthy in 300 s"; stop_server; return 1; } - local l; l=$(ss -ltnH "sport = :$PORT" | awk '{print $4}') + curl -s -m 2 127.0.0.1:$PORT/health > /dev/null || { log "server not healthy in $lim s"; stop_server; return 1; } + [ "$(ps -o sid= -p "$SERVER" | tr -d ' ')" = "$SERVER" ] || { log "server $SERVER is not its own session leader"; stop_server; return 1; } + l=$(ss -ltnH "sport = :$PORT" | awk '{print $4}') if [ -z "$l" ] || echo "$l" | grep -qv '^127\.0\.0\.1:'; then log "listener check FAILED on $PORT: $l"; stop_server; return 1; fi } trap 'stop_server; board "GPU-END dra-65 window-dra65.sh window $WIN steps ${STEPS[*]} -> $OUT (rc ${RC:-?})"' EXIT - trap 'log "interrupted"; exit 4' INT TERM + trap 'log "interrupted"; RC=4; exit 4' INT TERM + setsid bash "$SELF" _watch $$ "$HOLDER" "$DEADLINE" "$PIDF" >> "$OUT/watch.log" 2>&1 < /dev/null & board "GPU-START dra-65 window-dra65.sh window $WIN steps ${STEPS[*]} (est $total s, lease left $left s; gb10 lock held by our pid $HOLDER; bin $SHA)" - log "window $WIN lock holder $HOLDER bin $BIN sha256 $SHA steps ${STEPS[*]} est $total s left $left s" + log "window $WIN lock holder $HOLDER bin $BIN sha256 $SHA steps ${STEPS[*]} est $total s left $left s deadline $(date -u -d @$DEADLINE +%FT%TZ)" RC=0 for s in "${STEPS[@]}"; do - step_def "$s"; D=$OUT/$s; mkdir -p "$D"; t0=$(date +%s) + step_def "$s"; [ -n "$TEST" ] && EST=5 + D=$OUT/$s; mkdir -p "$D"; t0=$(date +%s); why= log "step $s: $DOOR door, env '${ENVS[*]:-}', $PROBE, est $EST s" - if start_server "$D/server.log"; then + if [ $((t0 + EST)) -gt "$DEADLINE" ]; then + ready=-1; RC=3; why="not started: est $EST s, $((DEADLINE - t0)) s left"; : > "$D/probe.out" + elif start_server "$D/server.log"; then ready=$(( $(date +%s) - t0 )) read -r kind a1 a2 <<<"$PROBE" if [ "$kind" = golden ]; then @@ -148,19 +216,29 @@ run) else args=(time $PORT "$D" "$SHA" "$a1") fi - bash "$SELF" "${args[@]}" > "$D/probe.out"; RC=$? + if lim=$(left_s); then + DRA65_SERVER_LOG=$D/server.log timeout -k 10 "$lim" bash "$SELF" "${args[@]}" > "$D/probe.out"; RC=$? + case $RC in 124|137) RC=2; why="probe stopped at the lease deadline" ;; esac + else + RC=2; why="no lease time left for the probe" + fi stop_server else - ready=-1; RC=3 + ready=-1; RC=3; why="server did not come up" + fi + el=$(( $(date +%s) - t0 )); expired=false + if [ -e "$SPARK_WINDOW_DIR/expired" ] || [ "$(date +%s)" -ge "$DEADLINE" ]; then + expired=true; [ $RC = 3 ] || { RC=2; why="lease expired before the step ended${why:+ ($why)}"; } fi - el=$(( $(date +%s) - t0 )) pj=$(tail -n 1 "$D/probe.out" 2>/dev/null | jq -c . 2>/dev/null); [ -n "$pj" ] || pj=null + case $RC in 0) v=$(jq -r '.verdict // "PASS"' <<<"$pj") ;; 1) v=FAIL ;; 2) v=INCONCLUSIVE ;; 3) v=NOT_RUN ;; *) v=INCONCLUSIVE ;; esac jq -cn --arg s "$s" --arg w "$WIN" --arg b "$BIN" --arg h "$SHA" --arg d "$DOOR" --arg e "${ENVS[*]:-}" --arg p "$PROBE" \ --argjson est $EST --argjson ready $ready --argjson el $el --argjson rc $RC --arg hold "$HOLDER" --arg at "$(date -u +%FT%TZ)" \ - --argjson probe "$pj" \ - '{step:$s, window:$w, bin:$b, bin_sha256:$h, door:$d, env:$e, probe:$p, est_s:$est, server_ready_s:$ready, elapsed_s:$el, rc:$rc, lock_holder:$hold, at:$at, result:$probe}' \ + --argjson probe "$pj" --argjson x $expired --arg v "$v" --arg why "$why" --argjson dl "$DEADLINE" \ + '{step:$s, window:$w, bin:$b, bin_sha256:$h, door:$d, env:$e, probe:$p, est_s:$est, server_ready_s:$ready, elapsed_s:$el, + rc:$rc, verdict:$v, why:$why, lease_expired:$x, deadline:$dl, lock_holder:$hold, at:$at, result:$probe}' \ | tee "$D/step-receipt.json" - [ $RC = 0 ] || { log "step $s rc $RC: stopping"; exit $RC; } + [ $RC = 0 ] || { log "step $s rc $RC ($v${why:+: $why}): stopping"; exit $RC; } done exit 0 ;; esac @@ -181,8 +259,11 @@ req() { # [stream] '$d + {model:$m, messages:$msg, max_tokens:$n} + (if $s then {stream:true, stream_options:{include_usage:true}} else {} end)' } user() { jq -cn --arg u "$1" '[{role:"user",content:$u}]'; } -# ask : prints the HTTP code -ask() { curl -s -m 1800 -o "$3" -w '%{http_code}' "$URL/v1/chat/completions" -H 'Content-Type: application/json' -d "$(req "$1" "$2")"; } +# ask : prints the HTTP code (000 without lease time left) +ask() { + local m; m=$(left_s 1800) || { : > "$3"; echo 000; return; } + curl -s -m "$m" -o "$3" -w '%{http_code}' "$URL/v1/chat/completions" -H 'Content-Type: application/json' -d "$(req "$1" "$2")" +} judge() { # : prints SAME|DIFF|SHORT|NO_IDS local got; [ "$1" = 200 ] || { echo NO_IDS; return; } got=$(jq -c '.usage.aien_token_ids | select(type == "array" and length > 0)' "$2" 2>/dev/null) @@ -202,34 +283,46 @@ golden) [[ $BIN =~ ^[0-9a-f]{64}$ ]] || die "BIN_SHA256 must be the server binary's sha256" [ -n "$LABEL" ] || die "LABEL missing" if [ "$EXPECT" = green ]; then - shift 6; reds=$(for r in "$@"; do jq -r --arg b "$BIN" \ - 'select(.case == "golden" and .expect == "red" and .verdict == "PASS" and .bin_sha256 == $b) | .label' "$r" 2>/dev/null; done | sort -u | wc -l) - [ "$reds" -ge 2 ] || die "green refused: needs >= 2 red PASS receipts (distinct labels) for binary $BIN, got $reds" + # A red receipt counts only next to run's step receipt for it: rc 0, same binary, lock held, lease not expired. + shift 6; reds=$(for r in "$@"; do + d=$(dirname "$r"); red_ok "$(dirname "$d")" "$(basename "$d")" "$BIN" || continue + jq -r --arg b "$BIN" 'select(.case == "golden" and .expect == "red" and .verdict == "PASS" and .bin_sha256 == $b) | .label' "$r" 2>/dev/null + done | sort -u | wc -l) + [ "$reds" -ge 2 ] || die "green refused: needs >= 2 red PASS receipts (distinct labels) for binary $BIN, each with a passing step-receipt.json of 'run', got $reds" fi - : > "$OUT/golden.jsonl"; declare -A n=([SAME]=0 [DIFF]=0 [SHORT]=0 [NO_IDS]=0) - rec() { jq -cn --arg id "$1" --arg v "$2" --arg h "$3" --argjson w "$4" --arg win "$WIN" --arg b "$BIN" \ + : > "$OUT/golden.jsonl"; declare -A n=([SAME]=0 [DIFF]=0 [SHORT]=0 [NO_IDS]=0 [NO_SNAP]=0) + rec() { jq -cn --arg id "$1" --arg v "$2" --arg h "$3" --argjson w "$4" --arg win "$WIN" --arg b "$BIN" --arg sn "${6:-}" \ --slurpfile r <(jq -c . "$5" 2>/dev/null || echo null) \ - '{id:$id, verdict:$v, http:$h, got:($r[0].usage.aien_token_ids // null), golden:$w, window:$win, bin_sha256:$b}' >> "$OUT/golden.jsonl"; } + '{id:$id, verdict:$v, http:$h, got:($r[0].usage.aien_token_ids // null), golden:$w, window:$win, bin_sha256:$b} + + (if $sn == "" then {} else {snapshot_log:$sn} end)' >> "$OUT/golden.jsonl"; } for i in $(seq 0 31); do u=$(jq -r ".prompts[$i].user" "$SET"); m=$(jq -r ".prompts[$i].max_tokens" "$SET"); w=$(jq -c ".prompts[$i].golden_ids" "$SET") h=$(ask "$(user "$u")" "$m" "$OUT/p$i.raw"); v=$(judge "$h" "$OUT/p$i.raw" "$w"); n[$v]=$((n[$v]+1)); rec "p$i" "$v" "$h" "$w" "$OUT/p$i.raw" done - # turn2 right after long-2048: the door restores the snapshot it took at long-2048's answer header. + # turn2 right after long-2048: the door restores the snapshot it took at long-2048's answer header; the + # server log lines written during the turn2 request must show it (single and batch door wording). + SLOG=${DRA65_SERVER_LOG:-} for name in long-256 long-8192 long-2048 turn2; do c=$(jq -c --arg n "$name" '.prompts[] | select(.name == $n)' "$LONG"); w=$(jq -c .golden_ids <<<"$c"); m=$(jq -r .max_tokens <<<"$c") if [ "$name" = turn2 ]; then msg=$(jq -c . "$REPO/$(jq -r .messages <<<"$c")"); else msg=$(user "$(cat "$REPO/$(jq -r .file <<<"$c")")"); fi - h=$(ask "$msg" "$m" "$OUT/$name.raw"); v=$(judge "$h" "$OUT/$name.raw" "$w"); n[$v]=$((n[$v]+1)); rec "$name" "$v" "$h" "$w" "$OUT/$name.raw" + before=0; [ -n "$SLOG" ] && before=$(wc -l < "$SLOG") + h=$(ask "$msg" "$m" "$OUT/$name.raw"); v=$(judge "$h" "$OUT/$name.raw" "$w"); sn= + if [ "$name" = turn2 ]; then + [ -n "$SLOG" ] && sn=$(tail -n "+$((before + 1))" "$SLOG" | grep -E 'reuse Snapshot\(|tok \(snapshot, row' | tail -n 1) + [ -n "$sn" ] || { sn="(none: ${SLOG:-no DRA65_SERVER_LOG})"; [ "$v" = NO_IDS ] || v=NO_SNAP; } + fi + n[$v]=$((n[$v]+1)); rec "$name" "$v" "$h" "$w" "$OUT/$name.raw" "$sn" done if [ "$EXPECT" = red ]; then - if [ $((n[NO_IDS] + n[SHORT])) -gt 0 ]; then verdict=INCONCLUSIVE; rc=2 + if [ $((n[NO_IDS] + n[SHORT] + n[NO_SNAP])) -gt 0 ]; then verdict=INCONCLUSIVE; rc=2 elif [ "${n[DIFF]}" -gt 0 ]; then verdict=PASS; rc=0; else verdict=FAIL; rc=1; fi else if [ "${n[NO_IDS]}" -gt 0 ]; then verdict=INCONCLUSIVE; rc=2 elif [ "${n[SAME]}" -eq 36 ]; then verdict=PASS; rc=0; else verdict=FAIL; rc=1; fi fi jq -cn --arg e "$EXPECT" --arg v $verdict --arg b "$BIN" --arg l "$LABEL" --argjson s "${n[SAME]}" --argjson d "${n[DIFF]}" \ - --argjson sh "${n[SHORT]}" --argjson x "${n[NO_IDS]}" --arg port "$PORT" --arg at "$(date -u +%FT%TZ)" --arg win "$WIN" \ - '{case:"golden", expect:$e, verdict:$v, bin_sha256:$b, label:$l, window:$win, same:$s, diff:$d, short:$sh, no_ids:$x, of:36, port:$port, at:$at}' \ + --argjson sh "${n[SHORT]}" --argjson x "${n[NO_IDS]}" --argjson ns "${n[NO_SNAP]}" --arg port "$PORT" --arg at "$(date -u +%FT%TZ)" --arg win "$WIN" \ + '{case:"golden", expect:$e, verdict:$v, bin_sha256:$b, label:$l, window:$win, same:$s, diff:$d, short:$sh, no_ids:$x, no_snap:$ns, of:36, port:$port, at:$at}' \ | tee "$OUT/golden-receipt.json" exit $rc ;; time) @@ -243,11 +336,13 @@ time) f=$HERE/$name.txt; [ -f "$f" ] || f=$REPO/evidence/merge-train/l369/$name.txt for run in 1 2 3; do o=$OUT/$name-r$run; : > "$o.sse"; t0=$(date +%s.%N); first="" - while IFS= read -r line; do - [ -z "$first" ] && [[ $line =~ ^data:.*\"content\":\ *\"[^\"] ]] && first=$(date +%s.%N) - printf '%s\n' "$line" >> "$o.sse" - done < <(curl -s -N -m 1800 -w '\nHTTP %{http_code}\n' "$URL/v1/chat/completions" -H 'Content-Type: application/json' \ - -d "$(req "$(user "$(cat "$f")")" 256 true)") + if m=$(left_s 1800); then + while IFS= read -r line; do + [ -z "$first" ] && [[ $line =~ ^data:.*\"content\":\ *\"[^\"] ]] && first=$(date +%s.%N) + printf '%s\n' "$line" >> "$o.sse" + done < <(curl -s -N -m "$m" -w '\nHTTP %{http_code}\n' "$URL/v1/chat/completions" -H 'Content-Type: application/json' \ + -d "$(req "$(user "$(cat "$f")")" 256 true)") + fi t1=$(date +%s.%N) code=$(grep -o '^HTTP [0-9]*' "$o.sse" | tail -n 1 | cut -c6-) usage=$(grep '^data: {' "$o.sse" | sed 's/^data: //' | jq -c 'select(.usage != null) | .usage' 2>/dev/null | tail -n 1) From 9addd622aea797524e3672959a1e70a00ca0f46f Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Sat, 31 Oct 2026 09:01:32 -0500 Subject: [PATCH 6/8] DRA-65: queue slices for window-dra65.sh: bounded lock wait, TERM ends flock(1), DRA65_CAP_S deadline, refuse windows holding the chip lock --- evidence/dra65-prefill-20261031/README.md | 39 +++++++++++++------ .../hosttest/runtests.sh | 20 ++++++++++ .../dra65-prefill-20261031/window-dra65.sh | 39 ++++++++++++++----- 3 files changed, 78 insertions(+), 20 deletions(-) diff --git a/evidence/dra65-prefill-20261031/README.md b/evidence/dra65-prefill-20261031/README.md index a39da3ea..71d5662c 100644 --- a/evidence/dra65-prefill-20261031/README.md +++ b/evidence/dra65-prefill-20261031/README.md @@ -94,8 +94,13 @@ Green probe without `DRA65_SERVER_LOG`: turn 2 NO_SNAP, FAIL rc 1; door that nev Lease 45 s with a 30 s/request door: step INCONCLUSIVE rc 2 at 46 s ("probe stopped at the lease deadline"), `lease_expired: true`, lock free. `expired` created mid-step: INCONCLUSIVE rc 2. SIGKILL of the run shell mid-step: the watchdog TERMed the server group, server gone, lock free. TERM of the flock(1) holder: the -watchdog stopped the server group and the run shell, lock free. Not host-testable: the real server, the -nvidia-smi/model/18091 checks and the chip. +watchdog stopped the server group and the run shell, lock free. Queue-slice additions (T10-T13, log of the full +run `/tmp/dra65mock/runtests-slices.log`): lock held 8 s elsewhere: no wait NOT_RUN rc 3 at once, +`DRA65_LOCK_WAIT=3` NOT_RUN rc 3 after 3 s, `DRA65_LOCK_WAIT=10` with a holder leaving after 3 s: rc 0, step 1 +PASS. TERM of the script itself mid-step (the runner's cap): rc 143 at once, the watchdog TERMed the server group +and the run shell, server gone, lock free, nothing left. `DRA65_CAP_S=40` under a 20-min lease: INCONCLUSIVE rc 2 +after 41 s, `lease_expired: true`. `$SPARK_WINDOW_DIR/gb10` = exclusive with `DRA65_LOCK_WAIT=60`: NOT_RUN rc 3 +after 0 s, no OUT written. Not host-testable: the real server, the nvidia-smi/model/18091 checks and the chip. Mutant 4 wiring (source, omega 474197e4f): `AIEN_Q36_TEST_MUTANT=4` -> `moe.rs` `graph_mutant()` -> `test_set_mutant` on the main graph and (`rows.rs` wire) every row and stroke graph; in C mutant 4 swaps K_CN for @@ -108,24 +113,34 @@ never reads it, and with `AIEN_Q36_PREFILL_CHUNK=0` the single door runs no chip ## Window (Main; chip gates NOT_RUN until then) -Main opens a quiet exclusive window without the chip lock (marker, `spark-window open ... --gb10 none --quiet -exclusive --lease 20`), stops 18091 and Flint, and runs one lease's steps: -`spark-window run bash evidence/dra65-prefill-20261031/window-dra65.sh run BIN OUT STEP ...`, BIN = the server -binary built from this branch, OUT = one receipt root for every lease (step N writes `OUT/N/`). The 35B server's +The single chip queue runs it: `~/handoffs/pdra4-hive/chip/DRA-65/s01-golden.sh` (steps 1 2 3 4 5), +`s02-time-single.sh` (6a 6b), `s03-time-batch.sh` (6c 6d), library `dra65-lib.sh`, budgets in `PLAN.md`. Each +slice carries the header `# pdra4-gb10: none`, so `chip/run-queue.sh` opens `spark-window open ... --gb10 none +--quiet exclusive --lease 20` after its preflight (18091 and Flint down) and the slice runs +`window-dra65.sh run BIN OUT STEP ...` from a pinned worktree of this branch, BIN = the server +binary built from this branch (`~/handoffs/pdra4-hive/bin/DRA-65/`), OUT = the slice's receipt directory +(`receipts/DRA-65//`, step N writes `OUT/N/`), and writes one `VERDICT` line from the script's exit code +and step receipts (0 PASS, 1 FAIL, 2 INCONCLUSIVE, 3 NOT_RUN, any other INCONCLUSIVE). s02 and s03 are NOT_RUN +unless s01 PASSed with the same binary sha256. The 35B server's chip reservation (`crates/aien-serve-http/src/chip_reservation.rs` L88-95) accepts `/tmp/aien-gb10.lock` only -when one of its ancestors holds it, and spark-window's holder never is; so the script takes `flock -n -o` on the +when one of its ancestors holds it, and spark-window's holder never is; so the script takes `flock -o` on the lock itself (flock(1) holds it and runs the script as its child; `-o` closes the fd before the exec, so no descendant inherits the lock), checks in `/proc/locks` that the exclusive holder is its ancestor, and starts each server as its own child, in its own session (`setsid`, pid file `OUT/.server..pid`), with `AIEN_GB10_LOCK_HELD=1` and the affinity reset of the live start scripts (`taskset -c` over every online CPU, so a core5/nice19 parent does not pin the 35B to one core; `nice` is inherited and cannot be lowered: do not start -`run` under `nice`). Exit 3 (NOT_RUN, chip untouched): no `SPARK_WINDOW`; the lock held by anyone else; a listener +`run` under `nice`). The slices wait for the lock at most `DRA65_LOCK_WAIT=90` s (default 0: no wait); a +TERM/INT/HUP to the script (the runner's 1140 s cap) ends flock(1), so the lock is released and the watchdog stops +the server group and the run. Exit 3 (NOT_RUN, chip untouched): no `SPARK_WINDOW`; a window that holds the chip +lock itself (`$SPARK_WINDOW_DIR/gb10` exclusive or shared: the server would refuse, so no wait either); the lock +held by anyone else after the wait; a listener on 18091, 18300, 18310 or the test port 18192; a compute app on the chip; BIN or the model missing; a green step (3-5) not preceded by both red steps in the same run and without their passing step receipts in `OUT/1`, `OUT/2` (rc 0, same bin_sha256, a lock holder, lease not expired); `$SPARK_WINDOW_DIR/expired` present; or the steps' estimates longer than the lease has left. -Lease: deadline = `held` + `lease` x `SPARK_LEASE_UNIT_S` (default 60). The server wait (at most 300 s), each probe +Lease: deadline = `held` + `lease` x `SPARK_LEASE_UNIT_S` (default 60), or `held` + `DRA65_CAP_S` when sooner (the +slices: 1060 s, so deadline + 20 s server stop + 40 s run-shell grace = 1120 s < the runner's 1140 s). The server wait (at most 300 s), each probe (`timeout` to the deadline) and every request (`curl -m` = min(1800 s, time left); none sent when no time is left) are bounded by it. A watchdog in its own session stops the server's process group (TERM, KILL after 20 s) and then the run shell at the deadline, or as soon as the run shell or the flock(1) holder dies (SIGKILL included); @@ -148,8 +163,10 @@ golden chunked `dec*(756 + 49 + 876) + 365/250. + 2486/250. + 8210/196.8` = 86.9 golden all-stepped (step 3) `dec*(756 + 365 + 2486 + 8210 + 49 + 876)` = 256.1 s -> 289 s; time chunked `3*(512/250. + 8210/196.8) + 6*256*dec` = 162.2 s -> 195 s; time all-stepped `dec*(3*(512 + 8210) + 6*256)` = 556.8 s -> 590 s (756 = the set's prompt tokens, 876 = its decode tokens 798 + 3*24 + 6; 49 = turn 2 past the -snapshot; 512 = planning size of long-512). 20-min leases: L1 = `run BIN OUT 1 2 3 4 5` -(`4*119.91 + 289.11` = 769 s), L2 = `6a 6b` (785 s), L3 = `6c 6d` (390 s). +snapshot; 512 = planning size of long-512). Queue slices: s01-golden = `run BIN OUT 1 2 3 4 5` +(`4*119.91 + 289.11` = 769 s), s02-time-single = `6a 6b` (785 s), s03-time-batch = `6c 6d` (390 s); with the +1060 s cap less a 120 s q36-extra slot wait and a 90 s lock wait, `1060 - 120 - 90` = 850 s is left for steps, +margins `850 - {769, 785, 390}` = {81, 65, 460} s (WolframLanguageEvaluator, chip/DRA-65/PLAN.md). | step | door | server env | probe | expect | est_s | |---|---|---|---|---|---| diff --git a/evidence/dra65-prefill-20261031/hosttest/runtests.sh b/evidence/dra65-prefill-20261031/hosttest/runtests.sh index 65810a14..54468c72 100755 --- a/evidence/dra65-prefill-20261031/hosttest/runtests.sh +++ b/evidence/dra65-prefill-20261031/hosttest/runtests.sh @@ -58,3 +58,23 @@ t "T9 TERM the flock holder mid-step (slow door)"; win 20 60 MOCK_M=slow bash "$S" run "$B" "$T/o9" 1 > /dev/null 2>&1 & sleep 6 fl=$(pgrep -x flock | while read -r p; do grep -q "o9" "/proc/$p/cmdline" && echo "$p"; done); echo "flock=$fl"; kill -TERM "$fl"; sleep 25 sleep 2; lockfree; echo "leftover=$(left)"; cat "$T/o9/watch.log"; wait + +t "T10 lock held elsewhere (8 s): DRA65_LOCK_WAIT unset, then 3 s; then 10 s with a holder leaving at 3 s"; win 20 60 +flock "$DRA65_TEST_LOCK" sleep 8 & hp=$!; sleep 0.5 +bash "$S" run "$B" "$T/o10" 1 2>&1 >/dev/null | tail -n 1; echo "rc=${PIPESTATUS[0]}" +s0=$(date +%s); DRA65_LOCK_WAIT=3 bash "$S" run "$B" "$T/o10" 1 2>&1 >/dev/null | tail -n 1; echo "rc=${PIPESTATUS[0]} after $(( $(date +%s) - s0 )) s" +wait $hp; flock "$DRA65_TEST_LOCK" sleep 3 & hp=$!; sleep 0.5 +s0=$(date +%s); DRA65_LOCK_WAIT=10 bash "$S" run "$B" "$T/o10" 1 > /dev/null 2>&1; echo "rc=$? after $(( $(date +%s) - s0 )) s"; sr "$T/o10/1"; wait $hp + +t "T11 TERM the script itself mid-step (the queue runner's cap; slow door)"; win 20 60 +MOCK_M=slow bash "$S" run "$B" "$T/o11" 1 > /dev/null 2>&1 & op=$!; sleep 6 +sp=$(cat $T/o11/.server.*.pid 2>/dev/null); echo "server=$sp"; s0=$(date +%s); kill -TERM $op; wait $op; echo "rc=$? after $(( $(date +%s) - s0 )) s" +sleep 2; echo "server alive: $(kill -0 -- "-$sp" 2>/dev/null && echo yes || echo no)"; lockfree; echo "leftover=$(left)"; cat "$T/o11/watch.log" + +t "T12 DRA65_CAP_S=40 under a 20-min lease (slow door), step 4"; win 20 60 +s0=$(date +%s); DRA65_CAP_S=40 MOCK_M=slow bash "$S" run "$B" "$T/o1" 4 > /dev/null 2>&1; echo "rc=$? after $(( $(date +%s) - s0 )) s" +sr "$T/o1/4"; sleep 2; lockfree; echo "leftover=$(left)" + +t "T13 window holding the chip lock (gb10 exclusive): refused before any wait"; win 20 60; echo exclusive > "$T/win/gb10" +s0=$(date +%s); DRA65_LOCK_WAIT=60 bash "$S" run "$B" "$T/o13" 1 2>&1 >/dev/null | tail -n 1; echo "rc=${PIPESTATUS[0]} after $(( $(date +%s) - s0 )) s" +rm -f "$T/win/gb10"; ls "$T/o13" 2>/dev/null | wc -l diff --git a/evidence/dra65-prefill-20261031/window-dra65.sh b/evidence/dra65-prefill-20261031/window-dra65.sh index 3d22cdb9..f6480f3e 100755 --- a/evidence/dra65-prefill-20261031/window-dra65.sh +++ b/evidence/dra65-prefill-20261031/window-dra65.sh @@ -1,18 +1,24 @@ #!/usr/bin/env bash # SPDX-License-Identifier: Apache-2.0 -# DRA-65 chip window. Main opens `spark-window open ... --gb10 none --quiet exclusive --lease 20`, stops 18091 and -# Flint, then runs one lease's steps as +# DRA-65 chip window. The single chip queue (~/handoffs/pdra4-hive/chip/run-queue.sh) runs it through the slices +# chip/DRA-65/s01-golden.sh (steps 1-5), s02-time-single.sh (6a 6b), s03-time-batch.sh (6c 6d); each carries +# the header `# pdra4-gb10: none`, so the runner opens `spark-window open ... --gb10 none --quiet exclusive +# --lease 20` (18091 and Flint stopped by the runner's preflight) and the slice runs # spark-window run bash window-dra65.sh run BIN OUT STEP [STEP ...] # BIN = the server binary built from this branch, OUT = a receipt root shared by every lease (step N writes # OUT/N/). The server's chip reservation (aien-serve-http chip_reservation.rs) only accepts /tmp/aien-gb10.lock -# held by one of its ancestors, so this script takes `flock -n -o` on it itself (the lock stays in flock(1), an +# held by one of its ancestors, so this script takes `flock -o` on it itself (the lock stays in flock(1), an # ancestor; no descendant inherits the fd) and starts every server as its child, in its own session # (setsid, pid file OUT/.server..pid), with AIEN_GB10_LOCK_HELD=1 and the affinity reset of the live start scripts. -# Exit 3 = NOT_RUN, chip untouched: no SPARK_WINDOW, the lock held by someone else, a listener on +# DRA65_LOCK_WAIT=N: wait at most N s for the lock (default 0: no wait). A TERM/INT/HUP to this script ends +# flock(1): the lock is released and the watchdog stops the server group and the run. +# Exit 3 = NOT_RUN, chip untouched: no SPARK_WINDOW, a window that holds the chip lock itself +# (SPARK_WINDOW_DIR/gb10 exclusive|shared), the lock held by someone else, a listener on # 18091/18300/18310 or the test port, a compute app on the chip, the binary or model missing, a green step # without passing red steps (listed before it, or their step receipts in OUT/1 and OUT/2), or the steps' # estimated time longer than the lease has left. -# Lease: deadline = SPARK_WINDOW_DIR/held + lease * SPARK_LEASE_UNIT_S (default 60). Every server wait and +# Lease: deadline = SPARK_WINDOW_DIR/held + lease * SPARK_LEASE_UNIT_S (default 60), or held + DRA65_CAP_S when +# that is sooner (queue slices: 1060, under the runner's 1140 s). Every server wait and # probe is bounded by the time left (timeout, curl -m). A watchdog in its own session stops the server group # at the deadline (and this script if it has not ended 40 s later), or at once when this script or the lock # holder dies; the lock is then released. @@ -80,7 +86,7 @@ plan) step_def $s; printf '%-4s %-7s %-55s %-24s %s\n' $s $DOOR "${ENVS[*]:--}" "$PROBE" $EST done echo "Steps 1-2 (red) come first; 3-5 need them earlier in the same run or their step receipts in OUT/1 and OUT/2." - echo "20-min leases: L1 = run BIN OUT 1 2 3 4 5 (769 s), L2 = 6a 6b (785 s), L3 = 6c 6d (390 s)." + echo "Queue slices (chip/DRA-65, cap 1060 s each): s01-golden = 1 2 3 4 5 (769 s), s02-time-single = 6a 6b (785 s), s03-time-batch = 6c 6d (390 s)." exit 0 ;; _watch) # _watch MAIN HOLDER DEADLINE PIDFILE (own session; started by run) M=$2; H=$3; DL=$4; PF=$5 @@ -104,11 +110,22 @@ run) # DRA65_TEST_LOCK (host check only): another lock file; the binary must be a script (a mock door, never the # ELF server), the chip and live-port checks are skipped and board lines go to OUT/board.log. LOCK=${DRA65_TEST_LOCK:-/tmp/aien-gb10.lock}; TEST=${DRA65_TEST_LOCK:+1} + # A window that holds the chip lock itself (--gb10 exclusive|shared): its holder is never our ancestor, so the + # server would refuse; and we would wait on the lock until the window closes. Refuse before any wait. + g=$(cat "${SPARK_WINDOW_DIR:-/nonexistent}/gb10" 2>/dev/null) + case $g in exclusive|shared) not_run "window $SPARK_WINDOW holds the chip lock (gb10 $g): open it with --gb10 none (queue slice header '# pdra4-gb10: none')" ;; esac if [ "${DRA65_LOCKED:-}" != "$SPARK_WINDOW" ]; then # flock(1) holds the lock in its own process (-o: closed before exec, so no descendant inherits it) and # runs us as its child: the holder is an ancestor of this shell and of every server it starts. - DRA65_LOCKED=$SPARK_WINDOW flock -n -o -E 75 "$LOCK" bash "$SELF" "$@"; rc=$? - [ $rc = 75 ] && not_run "$LOCK is held by another process; this script takes it itself (open the window with --gb10 none)" + # DRA65_LOCK_WAIT=N (seconds, queue slices): wait at most N s for the lock; unset or 0: do not wait. + lw=${DRA65_LOCK_WAIT:-0}; case $lw in ''|*[!0-9]*) die "DRA65_LOCK_WAIT=$lw: whole seconds" ;; esac + wflag=(-n); [ "$lw" -gt 0 ] && wflag=(-w "$lw") + # A signal to this shell (the queue runner's timeout) ends flock(1): the lock is released and the + # watchdog, seeing its holder gone, stops the server group and the run shell. + DRA65_LOCKED=$SPARK_WINDOW flock "${wflag[@]}" -o -E 75 "$LOCK" bash "$SELF" "$@" & FL=$! + trap 'kill -TERM $FL 2>/dev/null' INT TERM HUP + while :; do wait $FL; rc=$?; kill -0 $FL 2>/dev/null || break; done + [ $rc = 75 ] && not_run "$LOCK is held by another process (waited $lw s); this script takes it itself (open the window with --gb10 none)" exit $rc fi BIN=$(readlink -f "$2"); OUT=$(readlink -m "$3"); shift 3; STEPS=("$@") @@ -143,7 +160,11 @@ run) [ -n "$lease" ] && [ -n "$held" ] || not_run "no lease/held in SPARK_WINDOW_DIR='${SPARK_WINDOW_DIR:-}'" [ -e "$SPARK_WINDOW_DIR/expired" ] && not_run "the lease has expired ($SPARK_WINDOW_DIR/expired)" heldt=$(date -d "$held" +%s) || not_run "cannot read held time '$held'" - DEADLINE=$(( heldt + lease * ${SPARK_LEASE_UNIT_S:-60} )); export DRA65_DEADLINE=$DEADLINE + DEADLINE=$(( heldt + lease * ${SPARK_LEASE_UNIT_S:-60} )) + # DRA65_CAP_S=N (queue slices): also end N s after `held`, before the queue runner's own cap stops the slice. + cap=${DRA65_CAP_S:-}; case $cap in '') ;; *[!0-9]*) die "DRA65_CAP_S=$cap: whole seconds" ;; + *) [ $((heldt + cap)) -ge "$DEADLINE" ] || DEADLINE=$((heldt + cap)) ;; esac + export DRA65_DEADLINE=$DEADLINE left=$(( DEADLINE - $(date +%s) )) [ "$total" -le "$left" ] || not_run "steps ${STEPS[*]} estimate $total s, the lease has $left s left" # 4. Live 35B, Flint and the chip idle; model, port, tools there. From 458b8e68f394e19b6a3ac16f75b1165c73a94495 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Sun, 1 Nov 2026 07:21:50 -0600 Subject: [PATCH 7/8] DRA-65 window: export a per-run bearer token to the server and probes aien-serve-http refuses to start without AIEN_SERVE_HTTP_BEARER_TOKEN since the bearer cutover (58ac0e44, contained in the pinned binary a109ca70), so the 2026-11-01 02:15Z chip run of s01-golden ended NOT_RUN 'server did not come up'. run) now generates a 32-hex throwaway token when none is set and exports it; probes refuse without one and pass it to curl via -H @<(auth), keeping it out of argv. hosttest/mock2.py enforces the bearer like the real door (refuses to start without it, 401 on a wrong header). runtests.sh T4d: wrong token -> INCONCLUSIVE rc 2, no token -> refused rc 2. Host test: patched 7 PASS lines, rc 0; negative control (this mock, window script at 9addd622) reproduces 'server did not come up' NOT_RUN, 0 PASS. --- evidence/dra65-prefill-20261031/hosttest/mock2.py | 4 ++++ .../dra65-prefill-20261031/hosttest/runtests.sh | 10 +++++++--- evidence/dra65-prefill-20261031/window-dra65.sh | 13 +++++++++++-- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/evidence/dra65-prefill-20261031/hosttest/mock2.py b/evidence/dra65-prefill-20261031/hosttest/mock2.py index 8bc52ecf..560c8bf5 100644 --- a/evidence/dra65-prefill-20261031/hosttest/mock2.py +++ b/evidence/dra65-prefill-20261031/hosttest/mock2.py @@ -1,6 +1,9 @@ # dra65 mock door (host check of window-dra65.sh only): serves set32 goldens; M=exact|mut|nosnap|slow|slow1 import json, os, sys, time, http.server R=sys.argv[1]; D=R+'/evidence/dra65-prefill-20261031'; M=os.environ.get('M','exact') +# as aien-serve-http main.rs:231 / server.rs check_headers: no token, no start; chat needs exactly one matching Bearer +T=os.environ.get('AIEN_SERVE_HTTP_BEARER_TOKEN','') +if not T: sys.exit('AIEN_SERVE_HTTP_BEARER_TOKEN must be set to a nonempty private credential') g={p['user']:p['golden_ids'] for p in json.load(open(D+'/set32.json'))['prompts']} for p in json.load(open(D+'/long-goldens.json'))['prompts']: if 'file' in p: g[open(R+'/'+p['file']).read()]=p['golden_ids'] @@ -12,6 +15,7 @@ class H(http.server.BaseHTTPRequestHandler): def do_GET(s): s.out(200,json.dumps({'data':[{'id':'mock'}]}).encode()) def do_POST(s): q=json.loads(s.rfile.read(int(s.headers['Content-Length']))) + if s.headers.get_all('Authorization')!=['Bearer '+T]: return s.out(401,b'{"error":"unauthorized"}') if M=='500': return s.out(500,b'{"error":"x"}') msgs=q['messages']; key='TURN2' if len(msgs)==3 else msgs[0]['content']; ids=list(g.get(key,[1,2,3])) if M=='slow': time.sleep(30) diff --git a/evidence/dra65-prefill-20261031/hosttest/runtests.sh b/evidence/dra65-prefill-20261031/hosttest/runtests.sh index 54468c72..27fcef86 100755 --- a/evidence/dra65-prefill-20261031/hosttest/runtests.sh +++ b/evidence/dra65-prefill-20261031/hosttest/runtests.sh @@ -30,11 +30,15 @@ t "T4 golden receipts without step receipts (o4): run 4" mkdir -p "$T/o4/1" "$T/o4/2"; cp "$T/o1/1/golden-receipt.json" "$T/o4/1/"; cp "$T/o1/2/golden-receipt.json" "$T/o4/2/" bash "$S" run "$B" "$T/o4" 4 2>&1 >/dev/null | tail -n 1 t "T4b probe green directly with those receipts (mock up on 18979)" -M=exact python3 "$H/mock2.py" "$REPO" 18979 2>/dev/null & mp=$!; sleep 1 +K=$(od -An -tx1 -N16 /dev/urandom | tr -d ' \n') # direct mock + probes share a token, as `run` exports one to server and probes +AIEN_SERVE_HTTP_BEARER_TOKEN=$K M=exact python3 "$H/mock2.py" "$REPO" 18979 2>/dev/null & mp=$!; sleep 1 SHA=$(sha256sum < "$B" | cut -c1-64) -bash "$S" golden 18979 "$T/o4/g" green "$SHA" x "$T/o4/1/golden-receipt.json" "$T/o4/2/golden-receipt.json" > /dev/null 2> "$T/t4b.err"; echo "rc=$?"; cat "$T/t4b.err" +AIEN_SERVE_HTTP_BEARER_TOKEN=$K bash "$S" golden 18979 "$T/o4/g" green "$SHA" x "$T/o4/1/golden-receipt.json" "$T/o4/2/golden-receipt.json" > /dev/null 2> "$T/t4b.err"; echo "rc=$?"; cat "$T/t4b.err" t "T4c same probe with o1's receipts (step receipts present) but no DRA65_SERVER_LOG -> turn2 NO_SNAP -> FAIL" -bash "$S" golden 18979 "$T/o4/g2" green "$SHA" x "$T/o1/1/golden-receipt.json" "$T/o1/2/golden-receipt.json" | jq -c '{verdict, same, no_snap}'; echo "rc=${PIPESTATUS[0]}" +AIEN_SERVE_HTTP_BEARER_TOKEN=$K bash "$S" golden 18979 "$T/o4/g2" green "$SHA" x "$T/o1/1/golden-receipt.json" "$T/o1/2/golden-receipt.json" | jq -c '{verdict, same, no_snap}'; echo "rc=${PIPESTATUS[0]}" +t "T4d bearer controls: probe with a wrong token (door answers 401) -> no PASS; probe with no token -> refused" +AIEN_SERVE_HTTP_BEARER_TOKEN=wrong-$K bash "$S" golden 18979 "$T/o4/g3" green "$SHA" x "$T/o1/1/golden-receipt.json" "$T/o1/2/golden-receipt.json" 2> "$T/t4d.err" | jq -c '{verdict, same}'; echo "rc=${PIPESTATUS[0]}"; tail -n 1 "$T/t4d.err" +env -u AIEN_SERVE_HTTP_BEARER_TOKEN bash "$S" golden 18979 "$T/o4/g4" green "$SHA" x "$T/o1/1/golden-receipt.json" "$T/o1/2/golden-receipt.json" 2>&1 >/dev/null | tail -n 1; echo "rc=${PIPESTATUS[0]}" kill $mp t "T5 nosnap door, step 4 on o1"; win 20 60 diff --git a/evidence/dra65-prefill-20261031/window-dra65.sh b/evidence/dra65-prefill-20261031/window-dra65.sh index f6480f3e..6dccc1aa 100755 --- a/evidence/dra65-prefill-20261031/window-dra65.sh +++ b/evidence/dra65-prefill-20261031/window-dra65.sh @@ -106,6 +106,13 @@ _watch) # _watch MAIN HOLDER DEADLINE PIDFILE (own session; started by run) exit 0 ;; run) [ -n "${SPARK_WINDOW:-}" ] || not_run "no SPARK_WINDOW: run as 'spark-window run bash $0 run ...' inside a --quiet exclusive window" + # aien-serve-http refuses to start without AIEN_SERVE_HTTP_BEARER_TOKEN (main.rs:231, since 58ac0e44) and answers + # /v1/chat/completions 401 without `Authorization: Bearer `. A throwaway per-run token, exported: every server + # and probe below inherits it; the probes hand it to curl through a pipe, never on a command line. + [ -n "${AIEN_SERVE_HTTP_BEARER_TOKEN:-}" ] || { + AIEN_SERVE_HTTP_BEARER_TOKEN=$(od -An -tx1 -N16 /dev/urandom | tr -d ' \n') && [ ${#AIEN_SERVE_HTTP_BEARER_TOKEN} = 32 ] || + not_run "cannot draw a bearer token from /dev/urandom"; } + export AIEN_SERVE_HTTP_BEARER_TOKEN [ $# -ge 4 ] || die "usage: run BIN OUT STEP [STEP ...]" # DRA65_TEST_LOCK (host check only): another lock file; the binary must be a script (a mock door, never the # ELF server), the chip and live-port checks are skipped and board lines go to OUT/board.log. @@ -273,6 +280,8 @@ URL=http://127.0.0.1:$PORT mkdir -p "$OUT" MODEL=$(curl -s -m 10 "$URL/v1/models" | jq -r '.data[0].id // empty' 2>/dev/null) [ -n "$MODEL" ] || die "no model on $URL" +[ -n "${AIEN_SERVE_HTTP_BEARER_TOKEN:-}" ] || die "AIEN_SERVE_HTTP_BEARER_TOKEN unset: the server answers 401 ('run' exports one)" +auth() { printf 'Authorization: Bearer %s\n' "$AIEN_SERVE_HTTP_BEARER_TOKEN"; } # curl -H @<(auth): not in argv DEF=$(jq -c .defaults "$HERE/set32.json") SET=$HERE/set32.json; LONG=$HERE/long-goldens.json req() { # [stream] @@ -283,7 +292,7 @@ user() { jq -cn --arg u "$1" '[{role:"user",content:$u}]'; } # ask : prints the HTTP code (000 without lease time left) ask() { local m; m=$(left_s 1800) || { : > "$3"; echo 000; return; } - curl -s -m "$m" -o "$3" -w '%{http_code}' "$URL/v1/chat/completions" -H 'Content-Type: application/json' -d "$(req "$1" "$2")" + curl -s -m "$m" -o "$3" -w '%{http_code}' "$URL/v1/chat/completions" -H @<(auth) -H 'Content-Type: application/json' -d "$(req "$1" "$2")" } judge() { # : prints SAME|DIFF|SHORT|NO_IDS local got; [ "$1" = 200 ] || { echo NO_IDS; return; } @@ -361,7 +370,7 @@ time) while IFS= read -r line; do [ -z "$first" ] && [[ $line =~ ^data:.*\"content\":\ *\"[^\"] ]] && first=$(date +%s.%N) printf '%s\n' "$line" >> "$o.sse" - done < <(curl -s -N -m "$m" -w '\nHTTP %{http_code}\n' "$URL/v1/chat/completions" -H 'Content-Type: application/json' \ + done < <(curl -s -N -m "$m" -w '\nHTTP %{http_code}\n' "$URL/v1/chat/completions" -H @<(auth) -H 'Content-Type: application/json' \ -d "$(req "$(user "$(cat "$f")")" 256 true)") fi t1=$(date +%s.%N) From 661375370cc3fd3ca8368159994c219ee978202f Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Sun, 1 Nov 2026 07:43:48 -0600 Subject: [PATCH 8/8] dra65: count an EOS-proven empty or short reply as DIFF; pin golden receipts to the script sha The 2026-11-01 window's pf2 red step came back INCONCLUSIVE: 10 replies were HTTP 200, finish stop, ids [], completion_tokens 0, greedy_tokens 1, i.e. the mutant's first token was EOS, which the door samples but does not emit. judge() now classes a strict prefix (including []) as DIFF only with that proof (stop, completion = ids, greedy, greedy = ids + 1); anything else stays SHORT/NO_IDS. A green run that ends early on EOS is FAIL, so the change cannot fail open. Golden receipts carry script_sha256 and green counts only reds judged by the same script. Host: T14 probes (2 positives, 5 non-proofs, green FAIL, sha refusal) as expected; real step 1/2 replies re-judged 36/36 DIFF. --- evidence/dra65-prefill-20261031/README.md | 28 +++++++++-- .../dra65-prefill-20261031/hosttest/mock2.py | 15 +++++- .../hosttest/runtests.sh | 24 +++++++++ .../dra65-prefill-20261031/window-dra65.sh | 49 ++++++++++++------- 4 files changed, 90 insertions(+), 26 deletions(-) diff --git a/evidence/dra65-prefill-20261031/README.md b/evidence/dra65-prefill-20261031/README.md index 71d5662c..0697598a 100644 --- a/evidence/dra65-prefill-20261031/README.md +++ b/evidence/dra65-prefill-20261031/README.md @@ -47,10 +47,21 @@ text and sha256 (it names bin-16b0e6f8). `SHA256SUMS` pins every committed input one changed. Judge: exact id identity (the door returns no logit margins, so the 0.1-logit band cannot be judged through it). -Per case SAME / DIFF (a flip inside the common length, or more ids than the golden) / SHORT (a strict prefix: no -flip shown) / NO_IDS (HTTP error, missing or empty ids). Red PASS needs a DIFF and no SHORT/NO_IDS (else -INCONCLUSIVE); green PASS needs 36 SAME (NO_IDS -> INCONCLUSIVE, else FAIL). Green refuses to run without two red -PASS receipts with distinct labels for the same server binary sha256. +Per case SAME / DIFF (a flip inside the common length, more ids than the golden, or a strict prefix that the door +proves ended on EOS) / SHORT (any other strict prefix: no flip shown) / NO_IDS (HTTP error, missing or non-array +ids, or `[]` without the EOS proof). EOS proof: `finish_reason` stop, `completion_tokens` = number of ids, greedy +sampling with `greedy_tokens` = ids + 1. The door samples EOS and stops before emitting it (`qwen38_engine.rs` +single door, `qwen36_batch.rs` batch door), so an EOS stop draws one token more than it returns; a cancel, stop +string or constraint stop does not. Such rows show `got: []` or a short `got` in golden.jsonl with verdict DIFF. +Red PASS needs a DIFF and no SHORT/NO_IDS (else INCONCLUSIVE); green PASS needs 36 SAME (NO_IDS -> INCONCLUSIVE, +else FAIL). Green refuses to run without two red PASS receipts with distinct labels for the same server binary +sha256, judged by the same script (`script_sha256` in every golden receipt). + +Window 2026-11-01 (20261101T132245Z-82858b, bin 4a0368d4): step 2 (pf2) came back INCONCLUSIVE under the old +judge, same 0 / diff 26 / no_ids 10. All 10 NO_IDS rows were HTTP 200, `finish_reason` stop, ids `[]`, +`completion_tokens` 0, `greedy_tokens` 1: the mutant's first token was EOS. Across all 72 replies of steps 1 and 2, +every `stop` row had `greedy_tokens` = ids + 1 and every `length` row `greedy_tokens` = ids. Those receipts were +judged by the old script and are void for green. ## Host evidence (EXERCISED on host, not chip) @@ -100,7 +111,14 @@ run `/tmp/dra65mock/runtests-slices.log`): lock held 8 s elsewhere: no wait NOT_ PASS. TERM of the script itself mid-step (the runner's cap): rc 143 at once, the watchdog TERMed the server group and the run shell, server gone, lock free, nothing left. `DRA65_CAP_S=40` under a 20-min lease: INCONCLUSIVE rc 2 after 41 s, `lease_expired: true`. `$SPARK_WINDOW_DIR/gb10` = exclusive with `DRA65_LOCK_WAIT=60`: NOT_RUN rc 3 -after 0 s, no OUT written. Not host-testable: the real server, the nvidia-smi/model/18091 checks and the chip. +after 0 s, no OUT written. Reply-end judge (T14, 2026-11-01, `taskset -c 5`, direct probes with the mock's log as +`DRA65_SERVER_LOG`, the mock sending `completion_tokens` and `aien_sampling` as server.rs does): exact door green +PASS rc 0; EOS-proven `[]` and EOS-proven prefix red: 36 DIFF, PASS rc 0; `[]` with EOS proof on green: FAIL rc 1; +no proof (`[]` with no sampler record, greedy = ids, finish length, completion_tokens = ids + 1, a sampled token) +red: INCONCLUSIVE rc 2 (36 NO_IDS or 36 SHORT); `[]` without proof on green: INCONCLUSIVE rc 2. Green with red +receipts carrying another or no `script_sha256`: refused rc 2. The real window replies of 2026-11-01 re-judged on +host: step 1 36 DIFF (unchanged), step 2 36 DIFF (was 26 DIFF + 10 NO_IDS). Not host-testable: the real server, +the nvidia-smi/model/18091 checks and the chip. Mutant 4 wiring (source, omega 474197e4f): `AIEN_Q36_TEST_MUTANT=4` -> `moe.rs` `graph_mutant()` -> `test_set_mutant` on the main graph and (`rows.rs` wire) every row and stroke graph; in C mutant 4 swaps K_CN for diff --git a/evidence/dra65-prefill-20261031/hosttest/mock2.py b/evidence/dra65-prefill-20261031/hosttest/mock2.py index 560c8bf5..57043a18 100644 --- a/evidence/dra65-prefill-20261031/hosttest/mock2.py +++ b/evidence/dra65-prefill-20261031/hosttest/mock2.py @@ -1,4 +1,6 @@ -# dra65 mock door (host check of window-dra65.sh only): serves set32 goldens; M=exact|mut|nosnap|slow|slow1 +# dra65 mock door (host check of window-dra65.sh only): serves set32 goldens; M=exact|mut|nosnap|slow|slow1|empty|short|500 +# and reply-end shapes with full usage (completion_tokens, aien_sampling as server.rs): eos0 eosmid (EOS proof: +# stop, completion = ids, greedy = ids + 1) and the non-proofs cancel0 cutmid lenmid ctmismatch sampled. import json, os, sys, time, http.server R=sys.argv[1]; D=R+'/evidence/dra65-prefill-20261031'; M=os.environ.get('M','exact') # as aien-serve-http main.rs:231 / server.rs check_headers: no token, no start; chat needs exactly one matching Bearer @@ -29,5 +31,14 @@ class H(http.server.BaseHTTPRequestHandler): if M!='nousage': ev.append({'choices':[],'usage':{'prompt_tokens':9,'completion_tokens':len(ids)}}) b=''.join('data: '+json.dumps(e)+'\n\n' for e in ev)+'data: [DONE]\n\n' return s.out(200,b.encode(),'text/event-stream') - s.out(200,json.dumps({'choices':[{'message':{'content':'x'},'finish_reason':'stop'}],'usage':{'aien_token_ids':ids}}).encode()) + # (ids, finish, completion_tokens, sampling); None sampling = a cancel that drew no token through the sampler + n=len(ids)-1; shape={'eos0':([],'stop',0,('greedy',1,0)), 'eosmid':(ids[:-1],'stop',n,('greedy',n+1,0)), + 'cancel0':([],'stop',0,None), 'cutmid':(ids[:-1],'stop',n,('greedy',n,0)), + 'lenmid':(ids[:-1],'length',n,('greedy',n+1,0)), 'ctmismatch':(ids[:-1],'stop',n+1,('greedy',n+1,0)), + 'sampled':(ids[:-1],'stop',n,('mixed',n,1))}.get(M) + usage={'aien_token_ids':ids}; fin='stop' + if shape: + ids,fin,ct,sm=shape; usage={'aien_token_ids':ids,'completion_tokens':ct} + if sm: usage['aien_sampling']={'mode':sm[0],'greedy_tokens':sm[1],'sampled_tokens':sm[2]} + s.out(200,json.dumps({'choices':[{'message':{'content':'x'},'finish_reason':fin}],'usage':usage}).encode()) http.server.ThreadingHTTPServer(('127.0.0.1',int(sys.argv[2])),H).serve_forever() diff --git a/evidence/dra65-prefill-20261031/hosttest/runtests.sh b/evidence/dra65-prefill-20261031/hosttest/runtests.sh index 27fcef86..997c7570 100755 --- a/evidence/dra65-prefill-20261031/hosttest/runtests.sh +++ b/evidence/dra65-prefill-20261031/hosttest/runtests.sh @@ -41,6 +41,30 @@ AIEN_SERVE_HTTP_BEARER_TOKEN=wrong-$K bash "$S" golden 18979 "$T/o4/g3" green "$ env -u AIEN_SERVE_HTTP_BEARER_TOKEN bash "$S" golden 18979 "$T/o4/g4" green "$SHA" x "$T/o1/1/golden-receipt.json" "$T/o1/2/golden-receipt.json" 2>&1 >/dev/null | tail -n 1; echo "rc=${PIPESTATUS[0]}" kill $mp +t "T14 reply-end judge: direct probes on 18979 with the door log (DRA65_SERVER_LOG), o1's reds as green's receipts" +R1=$T/o1/1/golden-receipt.json; R2=$T/o1/2/golden-receipt.json +pr() { # MODE EXPECT [receipts...]: one probe against a fresh mock in MODE; prints the verdict line and rc + local m=$1 e=$2; shift 2 + AIEN_SERVE_HTTP_BEARER_TOKEN=$K M=$m python3 "$H/mock2.py" "$REPO" 18979 2> "$T/m14-$m.log" & local p=$!; sleep 1 + AIEN_SERVE_HTTP_BEARER_TOKEN=$K DRA65_SERVER_LOG=$T/m14-$m.log bash "$S" golden 18979 "$T/o14/$m-$e" "$e" "$SHA" "t14-$m" "$@" 2> "$T/t14-$m-$e.err" \ + | jq -c --arg m "$m" --arg e "$e" '{m: $m, e: $e, verdict, same, diff, short, no_ids, no_snap}'; local rc=${PIPESTATUS[0]} + echo "rc=$rc"; [ "$rc" = 2 ] && tail -n 1 "$T/t14-$m-$e.err"; kill $p; wait $p 2>/dev/null +} +pr exact green "$R1" "$R2" # positive control: same door, log present -> PASS rc 0 +for m in eos0 eosmid; do pr $m red; done # EOS-proven early stops -> DIFF -> PASS rc 0 +pr eos0 green "$R1" "$R2" # an early EOS on green -> FAIL rc 1 (cannot fail open) +for m in cancel0 cutmid lenmid ctmismatch sampled; do pr $m red; done # no EOS proof -> INCONCLUSIVE rc 2 +pr cancel0 green "$R1" "$R2" # [] without proof on green -> INCONCLUSIVE rc 2 +jq -c 'select(.id == "p2") | {id, verdict, got}' "$T/o14/eos0-red/golden.jsonl" +t "T14b green with reds judged by another script (script_sha256 differs) -> refused rc 2" +for s in 1 2; do mkdir -p "$T/o14x/$s" + jq '.script_sha256 = ("0" * 64)' "$T/o1/$s/golden-receipt.json" > "$T/o14x/$s/golden-receipt.json" + jq '.result.script_sha256 = ("0" * 64)' "$T/o1/$s/step-receipt.json" > "$T/o14x/$s/step-receipt.json"; done +pr exact green "$T/o14x/1/golden-receipt.json" "$T/o14x/2/golden-receipt.json" +for s in 1 2; do jq 'del(.script_sha256)' "$T/o1/$s/golden-receipt.json" > "$T/o14x/$s/golden-receipt.json" + jq 'del(.result.script_sha256)' "$T/o1/$s/step-receipt.json" > "$T/o14x/$s/step-receipt.json"; done +pr exact green "$T/o14x/1/golden-receipt.json" "$T/o14x/2/golden-receipt.json" # receipts from before the pin -> refused rc 2 + t "T5 nosnap door, step 4 on o1"; win 20 60 MOCK_M=nosnap bash "$S" run "$B" "$T/o1" 4 > /dev/null 2>&1; echo "rc=$?"; sr "$T/o1/4" jq -c 'select(.id=="turn2") | {id, verdict, snapshot_log}' "$T/o1/4/golden.jsonl" diff --git a/evidence/dra65-prefill-20261031/window-dra65.sh b/evidence/dra65-prefill-20261031/window-dra65.sh index 6dccc1aa..c27d3c81 100755 --- a/evidence/dra65-prefill-20261031/window-dra65.sh +++ b/evidence/dra65-prefill-20261031/window-dra65.sh @@ -37,16 +37,21 @@ # request (single: `reuse Snapshot(`, qwen38_engine.rs; batch: `tok (snapshot, row`, qwen36_batch.rs). # window-dra65.sh time PORT OUT BIN_SHA256 LABEL # TTFT and end-to-end tok/s, ~512 and 8210-token prompts, 3 runs each. -# Per case: SAME (ids equal), DIFF (a flip inside the common length, or more ids than the golden), -# SHORT (a strict prefix of the golden: no flip shown), NO_IDS (HTTP error, missing or empty ids), +# Per case: SAME (ids equal), DIFF (a flip inside the common length, more ids than the golden, or a strict prefix +# of the golden, [] included, that the door proves ended on EOS: finish_reason stop, completion_tokens = ids, +# greedy with greedy_tokens = ids + 1, because the door samples EOS without emitting it, qwen38_engine.rs and +# qwen36_batch.rs; a cancel, stop string or constraint stop draws no extra token), SHORT (any other strict +# prefix: no flip shown), NO_IDS (HTTP error, missing or non-array ids, or [] without that EOS proof), # NO_SNAP (turn2 without the snapshot-restore log line). # golden red: PASS = at least one DIFF and no NO_IDS/SHORT/NO_SNAP; those -> INCONCLUSIVE; else FAIL. -# golden green: PASS = all SAME; any NO_IDS -> INCONCLUSIVE; else (NO_SNAP included) FAIL. +# golden green: PASS = all SAME; any NO_IDS -> INCONCLUSIVE; else (NO_SNAP included) FAIL. Golden receipts carry +# this script's sha256 (script_sha256); green counts only red receipts judged by the same script. # Exit 0 = PASS, 1 = FAIL, 2 = INCONCLUSIVE or refused, 3 = NOT_RUN, 4 = interrupted. time: 0 only if every run # has HTTP 200, a first content delta and usage with completion_tokens > 0; else 2. `run` stops at the first # step that does not exit 0 and returns its code. set -uo pipefail HERE=$(cd "$(dirname "$0")" && pwd); REPO=$(cd "$HERE/../.." && pwd); SELF=$HERE/$(basename "$0") +SELF_SHA=$(sha256sum < "$SELF" | cut -c1-64) die() { echo "window-dra65: $*" >&2; exit 2; } not_run() { echo "window-dra65: NOT_RUN: $*" >&2; exit 3; } # left_s [CAP]: seconds to DRA65_DEADLINE (unset: CAP), at most CAP; returns 1 when none are left. @@ -73,10 +78,10 @@ step_def() { *) return 1 ;; esac } -# red_ok OUT STEP SHA: that red step's run receipt passed for this binary inside the lease. +# red_ok OUT STEP SHA: that red step's run receipt passed for this binary inside the lease, judged by this script. red_ok() { - jq -e --arg b "$3" '.rc == 0 and .bin_sha256 == $b and (.lock_holder | length) > 0 and .lease_expired == false - and .result.case == "golden" and .result.expect == "red" and .result.verdict == "PASS"' "$1/$2/step-receipt.json" > /dev/null 2>&1 + jq -e --arg b "$3" --arg s "$SELF_SHA" '.rc == 0 and .bin_sha256 == $b and (.lock_holder | length) > 0 and .lease_expired == false + and .result.case == "golden" and .result.expect == "red" and .result.verdict == "PASS" and .result.script_sha256 == $s' "$1/$2/step-receipt.json" > /dev/null 2>&1 } case ${1:-} in @@ -295,15 +300,21 @@ ask() { curl -s -m "$m" -o "$3" -w '%{http_code}' "$URL/v1/chat/completions" -H @<(auth) -H 'Content-Type: application/json' -d "$(req "$1" "$2")" } judge() { # : prints SAME|DIFF|SHORT|NO_IDS - local got; [ "$1" = 200 ] || { echo NO_IDS; return; } - got=$(jq -c '.usage.aien_token_ids | select(type == "array" and length > 0)' "$2" 2>/dev/null) - [ -n "$got" ] || { echo NO_IDS; return; } - jq -rn --argjson g "$got" --argjson w "$3" ' - ([$g, $w] | map(length) | min) as $m - | if $g == $w then "SAME" - elif ([range(0; $m) | select($g[.] != $w[.])] | length) > 0 then "DIFF" - elif ($g | length) > ($w | length) then "DIFF" - else "SHORT" end' + [ "$1" = 200 ] || { echo NO_IDS; return; } + jq -r --argjson w "$3" ' + .usage.aien_token_ids as $g + | if ($g | type) != "array" then "NO_IDS" else + ($g | length) as $n | ([$n, ($w | length)] | min) as $m + | (.choices[0].finish_reason == "stop" and .usage.completion_tokens == $n + and .usage.aien_sampling.mode == "greedy" and .usage.aien_sampling.sampled_tokens == 0 + and .usage.aien_sampling.greedy_tokens == $n + 1) as $eos + | if $g == $w then "SAME" + elif ([range(0; $m) | select($g[.] != $w[.])] | length) > 0 then "DIFF" + elif $n > ($w | length) then "DIFF" + elif $eos then "DIFF" + elif $n == 0 then "NO_IDS" + else "SHORT" end + end' "$2" 2>/dev/null || echo NO_IDS } case $MODE in @@ -316,9 +327,9 @@ golden) # A red receipt counts only next to run's step receipt for it: rc 0, same binary, lock held, lease not expired. shift 6; reds=$(for r in "$@"; do d=$(dirname "$r"); red_ok "$(dirname "$d")" "$(basename "$d")" "$BIN" || continue - jq -r --arg b "$BIN" 'select(.case == "golden" and .expect == "red" and .verdict == "PASS" and .bin_sha256 == $b) | .label' "$r" 2>/dev/null + jq -r --arg b "$BIN" --arg s "$SELF_SHA" 'select(.case == "golden" and .expect == "red" and .verdict == "PASS" and .bin_sha256 == $b and .script_sha256 == $s) | .label' "$r" 2>/dev/null done | sort -u | wc -l) - [ "$reds" -ge 2 ] || die "green refused: needs >= 2 red PASS receipts (distinct labels) for binary $BIN, each with a passing step-receipt.json of 'run', got $reds" + [ "$reds" -ge 2 ] || die "green refused: needs >= 2 red PASS receipts (distinct labels) for binary $BIN judged by this script ($SELF_SHA), each with a passing step-receipt.json of 'run', got $reds" fi : > "$OUT/golden.jsonl"; declare -A n=([SAME]=0 [DIFF]=0 [SHORT]=0 [NO_IDS]=0 [NO_SNAP]=0) rec() { jq -cn --arg id "$1" --arg v "$2" --arg h "$3" --argjson w "$4" --arg win "$WIN" --arg b "$BIN" --arg sn "${6:-}" \ @@ -351,8 +362,8 @@ golden) elif [ "${n[SAME]}" -eq 36 ]; then verdict=PASS; rc=0; else verdict=FAIL; rc=1; fi fi jq -cn --arg e "$EXPECT" --arg v $verdict --arg b "$BIN" --arg l "$LABEL" --argjson s "${n[SAME]}" --argjson d "${n[DIFF]}" \ - --argjson sh "${n[SHORT]}" --argjson x "${n[NO_IDS]}" --argjson ns "${n[NO_SNAP]}" --arg port "$PORT" --arg at "$(date -u +%FT%TZ)" --arg win "$WIN" \ - '{case:"golden", expect:$e, verdict:$v, bin_sha256:$b, label:$l, window:$win, same:$s, diff:$d, short:$sh, no_ids:$x, no_snap:$ns, of:36, port:$port, at:$at}' \ + --argjson sh "${n[SHORT]}" --argjson x "${n[NO_IDS]}" --argjson ns "${n[NO_SNAP]}" --arg port "$PORT" --arg at "$(date -u +%FT%TZ)" --arg win "$WIN" --arg ss "$SELF_SHA" \ + '{case:"golden", expect:$e, verdict:$v, bin_sha256:$b, script_sha256:$ss, label:$l, window:$win, same:$s, diff:$d, short:$sh, no_ids:$x, no_snap:$ns, of:36, port:$port, at:$at}' \ | tee "$OUT/golden-receipt.json" exit $rc ;; time)