[ABI][LD][Proofs][Docs] M1 groundwork: arena-safety proof + .vbundle contract; embedder lane (M1.5) accepted

- proofs/arena_plan.lean: memory.vplan arena safety (8 theorems + 4
  computational examples, 0 sorryAx): no overlap, checked index bounds,
  no use-before-write, overlap-rejection completeness.
- abi::arena: validator mirroring the proof, checked offset arithmetic
  (invariant #2), explicit error per violation class; 8 tests.
- abi::bundle: .vbundle manifest (ABI_VERSION=1, source+packer fingerprints,
  backend target; incompatible ABI rejected explicitly), checked
  memory.vplan/graph.vplan parsing, arena-validated compile(); 7 tests.
- ld::bundle: read-only load_bundle_plans(dir) over manifest + plan/*.vplan;
  3 tests (good bundle, missing file, ABI mismatch).
- abi::vplan: encoder-lane opcodes (layer_norm, flash_full_attn, gelu_erf,
  mean_pool_l2norm) + wire name mapping for all 22 opcodes, roundtrip test.
- Docs: utility-encoder scope carve-out (dense decoder LMs out, small
  fully-resident encoders in), embedder-lane wire proposal + characteristic
  parity vs vetta-semantics (cosine vs oracle, internal bit-exact goldens),
  16-primitive kernel set, M1.5 milestone; README/AGENTS aligned
  (65 tests, 42 theorems across 4 proof files).
- review/: tandem exchange with the strata-ctl coder (their request +
  observations, our formal reply: embedder accepted, M0 dir cleanup done).

Verified live: RUSTFLAGS="-D warnings" cargo test --workspace = 65/65 PASS;
lean proofs/{slab_ring_dma,bus_lifecycle,serve_session,arena_plan}.lean green,
standard axioms only.
This commit is contained in:
adm committed 2026-11-30 15:22:00 +01:00
1 parent 7b50f1c07c
commit fb92662106
13 files changed
+1235 -16

No files matched your search

+75
View File
@@ -0,0 +1,75 @@
//! Read-only `.vbundle` plan loading — the file-IO side of `abi::bundle`
//! (docs/ARCHITECTURE.md §3). Reads `manifest.json` + `plan/*.vplan` and
//! lowers them through the arena-validated compile. Weights (`weights/*.vbin`)
//! are mapped by the M1 packer/reload path; plans are validated before any
//! GPU launch, never after.
use std::path::Path;
use vetta_infer_abi::bundle::{compile, BundleError, CompiledPlans};
/// Load and validate the declarative plans of a `.vbundle` directory.
/// All reads are plain `O_RDONLY` (write-once cache invariant #3).
pub fn load_bundle_plans(dir: impl AsRef<Path>) -> Result<CompiledPlans, BundleError> {
let dir = dir.as_ref();
let read = |rel: &str| -> Result<String, BundleError> {
std::fs::read_to_string(dir.join(rel)).map_err(|e| BundleError::Io(format!("{rel}: {e}")))
};
let manifest = read("manifest.json")?;
let memory = read("plan/memory.vplan")?;
let graph = read("plan/graph.vplan")?;
compile(&manifest, &memory, &graph)
}
#[cfg(test)]
mod tests {
use super::*;
use std::sync::atomic::{AtomicU64, Ordering};
static SEQ: AtomicU64 = AtomicU64::new(0);
fn tmp_bundle(tag: &str) -> std::path::PathBuf {
let n = SEQ.fetch_add(1, Ordering::Relaxed);
let dir = std::env::temp_dir().join(format!("vetta-bundle-{}-{n}-{tag}", std::process::id()));
std::fs::create_dir_all(dir.join("plan")).unwrap();
dir
}
const MANIFEST: &str = r#"{"model_id":"inkling-2-mini","source_fingerprint":1,
"packer_fingerprint":2,"abi_version":1,"backend_target":"gfx1150"}"#;
const MEMORY: &str = r#"{"decls":[{"arena":0,"off":0,"len":64},
{"arena":0,"off":64,"len":32}],"inputs":[0]}"#;
const GRAPH: &str = r#"{"ops":[{"op":"embed_bf16","reads":[0],"writes":[1]}]}"#;
fn write_plans(dir: &Path, manifest: &str) {
std::fs::write(dir.join("manifest.json"), manifest).unwrap();
std::fs::write(dir.join("plan/memory.vplan"), MEMORY).unwrap();
std::fs::write(dir.join("plan/graph.vplan"), GRAPH).unwrap();
}
#[test]
fn load_good_bundle() {
let dir = tmp_bundle("ok");
write_plans(&dir, MANIFEST);
let c = load_bundle_plans(&dir).unwrap();
assert_eq!(c.manifest.model_id, "inkling-2-mini");
assert_eq!(c.graph.len(), 1);
std::fs::remove_dir_all(&dir).unwrap();
}
#[test]
fn missing_plan_file_is_io_error() {
let dir = tmp_bundle("missing");
std::fs::write(dir.join("manifest.json"), MANIFEST).unwrap();
assert!(matches!(load_bundle_plans(&dir), Err(BundleError::Io(_))));
std::fs::remove_dir_all(&dir).unwrap();
}
#[test]
fn incompatible_abi_rejected_on_load() {
let dir = tmp_bundle("abi");
write_plans(&dir, &MANIFEST.replace("\"abi_version\":1", "\"abi_version\":99"));
assert!(matches!(load_bundle_plans(&dir), Err(BundleError::AbiMismatch { found: 99, .. })));
std::fs::remove_dir_all(&dir).unwrap();
}
}
+2
View File
@@ -8,6 +8,8 @@
//! Eliminates audit-05 F-02 (shard bounds, u64 slice overflow, missing
//! index.json) and F-05 (PID-isolated atomic commit) by construction.
pub mod bundle;
use std::collections::{BTreeSet, HashMap};
use std::fs::{self, File, OpenOptions};
use std::os::unix::fs::FileExt;