diff --git a/crates/vetta-infer-gw/src/serve.rs b/crates/vetta-infer-gw/src/serve.rs index d7898be..a6e6bbb 100644 --- a/crates/vetta-infer-gw/src/serve.rs +++ b/crates/vetta-infer-gw/src/serve.rs @@ -299,6 +299,16 @@ pub fn serve_gen( } if std::env::var("VETTA_DBG_PREFIX").is_ok() { eprintln!("[prefix] prompt_len={n_prompt} restored={start}"); + if start == 0 { + // No match: show each cached checkpoint's length and how many leading + // tokens it shares with this prompt, to pinpoint a token divergence + // (common < len => the re-rendered prompt differs at that position). + let p = eng.prefix.borrow(); + for (i, ck) in p.pool.iter().enumerate() { + let common = ck.tokens.iter().zip(g.ids.iter()).take_while(|(a, b)| a == b).count(); + eprintln!("[prefix] ck[{i}] len={} common_prefix={common}", ck.tokens.len()); + } + } } // Weights are resident in eng.cache (loaded once at boot, reused across all @@ -342,6 +352,18 @@ pub fn serve_gen( history.extend_from_slice(toks); pos += take as i32; done += take; + // Multi-level checkpoint grid (strata --auto-ckpt): save an intermediate + // checkpoint every 512 tokens so the next turn can restore a stable prefix + // even when the prompt's trailing turn-tag tokens re-render differently + // (strata-ctl serializes the turn boundary differently once turn 1 becomes + // history). best_match then picks the longest 512-grid checkpoint that is a + // full prefix, instead of discarding everything over a 2-token tail mismatch. + if std::env::var("VETTA_NO_PREFIX_CACHE").is_err() && pos > 0 && pos % 512 == 0 { + let _ = eng.prefix.borrow_mut().save(&history[..pos as usize], &states, &eng.d); + if std::env::var("VETTA_DBG_PREFIX").is_ok() { + eprintln!("[prefix] grid save seq={pos}"); + } + } let ms = t0.elapsed().as_secs_f64() * 1000.0; if let Ok(pp) = sess.on_prefill_chunk((start + done) as u32, n_prompt as u32, ms) { emit_all(emit, pp);