From cebe9e650cae8b31bc769c16e13dc83171186939 Mon Sep 17 00:00:00 2001 From: joelteply Date: Tue, 3 Nov 2026 09:06:37 -0600 Subject: [PATCH 1/2] continuum-proving-types: the engine's fixed holders, KV apart from recurrent state, and where an act resumed Fable's review of #5727, for ONE-BUDGET slice 3b: - ModelProfile.holders: every fixed holder the fork reports (weights, compute graph, draft, projector, prompt cache), each with its tier, from memory_breakdown and resident_state (llama.cpp#91). On the M5 the draft (3.15 GB), projector (0.90 GB) and graph (1.87 GB) were what the plan could not see. - kv_bytes_per_token and recurrent_bytes_per_sequence replace state_bytes_per_token: a hybrid model's recurrent state is fixed per sequence, so folding it into the per-token rate overstates long sequences and short-changes many short ones (card c8b2e1df). Unmeasured until the fork reports it apart. - ActReduction.resume: Joined, where the engine resumed the prompt from (slot prefix kept, a checkpoint at N, a page restored, a page refused with a typed class, cold). The tokens re-read stay Timing::prefill_tokens; nothing is recorded twice. Clearing waits on cambrian-flex reaching continuum's airc pin (Fable), and will carry flex's own Clearing type rather than a copy of it. Validation: cargo test -p continuum-proving-types 13/13, clippy --all-targets -D warnings clean. continuum card 950064f2 Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE --- core/continuum-proving-types/src/profile.rs | 71 ++++++++++++++++++- core/continuum-proving-types/src/reduction.rs | 23 ++++++ 2 files changed, 91 insertions(+), 3 deletions(-) diff --git a/core/continuum-proving-types/src/profile.rs b/core/continuum-proving-types/src/profile.rs index a877c0c6a3..9a00c0205d 100644 --- a/core/continuum-proving-types/src/profile.rs +++ b/core/continuum-proving-types/src/profile.rs @@ -66,14 +66,44 @@ pub struct PageCost { pub bytes_per_s: Measured, } +/// A fixed holder of engine memory. +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] +#[serde(rename_all = "snake_case")] +pub enum Holder { + Weights, + /// The compute graph: one for the shared pool under `--kv-unified`. + ComputeGraph, + /// The speculative draft model's whole context (its weights, KV and compute). + Draft, + /// The multimodal projector's weights and reserved compute. + Projector, + /// The host prompt cache's byte limit. + PromptCache, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] +pub struct HolderBytes { + pub holder: Holder, + pub tier: Tier, + pub bytes: Measured, +} + /// One model as served on this node. #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(deny_unknown_fields)] pub struct ModelProfile { pub model: ModelId, - pub weight_bytes: Measured, - /// KV plus recurrent state per token (the engine's `memory_breakdown`). - pub state_bytes_per_token: Measured, + /// Everything the engine holds whatever the minds do, each where it lives (the fork's + /// `memory_breakdown` and `resident_state`, llama.cpp#91). Before #91 the draft and the + /// projector were invisible, and the plan inferred them from the process footprint. + pub holders: Vec, + /// Attention KV per token of a sequence's context. + pub kv_bytes_per_token: Measured, + /// A hybrid model's recurrent state, fixed per sequence whatever its length. Folding it into the + /// per-token rate overstates long sequences and short-changes many short ones (card c8b2e1df). + /// `Unmeasured` until the fork reports it apart from the KV. + pub recurrent_bytes_per_sequence: Measured, pub prefill: RateCurve, pub decode: RateCurve, pub page: Vec, @@ -112,4 +142,39 @@ mod tests { assert_eq!(wire["memory"][0]["bytes"], serde_json::json!({ "state": "unmeasured" })); assert_eq!(serde_json::from_value::(wire).expect("de"), declared); } + + // what this catches: a model profile that cannot carry what the fork reports, which is how the + // plan went wrong on the M5 (it saw weights and KV, not the draft, the projector or the graph). + #[test] + fn a_model_profile_carries_every_fixed_holder_and_the_recurrent_split() { + use crate::provenance::{Source, Spread}; + let slug = |s: &str| Slug::try_from(s.to_string()).expect("slug"); + let measured = |value: u64| Measured::Measured { + value, + at_ms: 1_793_710_260_000, + source: Source { kind: slug("engine/resident-state"), node: slug("m5") }, + samples: 1, + error: Spread::NotYetMeasured, + }; + let holder = |holder, bytes| HolderBytes { holder, tier: Tier::Unified, bytes: measured(bytes) }; + let model = ModelProfile { + model: crate::closed::ModelId::try_from("continuum-ai/qwen3.6-35b-a3b-GGUF".to_string()).expect("model id"), + holders: vec![ + holder(Holder::Weights, 20_690_000_000), + holder(Holder::ComputeGraph, 1_870_000_000), + holder(Holder::Draft, 3_150_000_000), + holder(Holder::Projector, 900_000_000), + ], + kv_bytes_per_token: measured(8_317), + recurrent_bytes_per_sequence: Measured::Unmeasured {}, + prefill: RateCurve::Points { points: vec![] }, + decode: RateCurve::Points { points: vec![] }, + page: vec![], + checkpoint_bytes: measured(94_600_000), + slots: Measured::Unmeasured {}, + }; + let wire = serde_json::to_value(&model).expect("ser"); + assert_eq!(wire["recurrent_bytes_per_sequence"], serde_json::json!({ "state": "unmeasured" })); + assert_eq!(serde_json::from_value::(wire).expect("de"), model); + } } diff --git a/core/continuum-proving-types/src/reduction.rs b/core/continuum-proving-types/src/reduction.rs index b228213cce..6ca64f5e79 100644 --- a/core/continuum-proving-types/src/reduction.rs +++ b/core/continuum-proving-types/src/reduction.rs @@ -193,6 +193,24 @@ pub enum OutcomeKind { Unfulfilled, } +/// Where the engine resumed the act's prompt from (`llama-server`'s `lcp after reuse`, its checkpoint +/// restores, and the core's page probes). The tokens it then re-read are `Timing::prefill_tokens`. +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[serde(tag = "from", rename_all = "snake_case", deny_unknown_fields)] +pub enum Resume { + /// Her KV was resident in the slot, and the engine kept this many tokens of it. + SlotPrefix { kept: u32 }, + /// Rolled back to a context checkpoint ending at this token (a hybrid model resumes only there). + Checkpoint { at: u32 }, + /// Paged in from disk, and the engine kept this many tokens of the page. + PageRestored { kept: u32 }, + /// The page was refused, and the act prefilled cold. The class names why (`adapter_identity`, + /// `no_space`), never the engine's message. + PageRefused { class: Slug }, + /// Nothing was reusable. + Cold {}, +} + /// One act, with no words in it. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(deny_unknown_fields)] @@ -206,6 +224,9 @@ pub struct ActReduction { /// joins it from `delib.act.reasoning_budgeted` by persona and time. pub reasoning_budget: Joined, pub allocation: Joined, + /// Joined from the engine log and page probes by slot and time; going forward the capture binds + /// it by request id. + pub resume: Joined, /// Tokens of each view item, in order (count and size, no words). pub view_items: Vec, pub delivery: Delivery, @@ -245,6 +266,7 @@ mod tests { }}, "reasoning_budget": { "join": "ambiguous", "candidates": 2 }, "allocation": { "join": "unresolved" }, + "resume": { "join": "exact", "value": { "from": "page_refused", "class": "adapter_identity" } }, "view_items": [1200, 300], "delivery": { "outcome": "completed", "elapsed_ms": 125000, "attempts": 1 }, "outcomes": ["tool_error"] @@ -277,6 +299,7 @@ mod tests { &["request", "tools", "0", "name"], &["response", "value", "tool_calls", "0", "name"], &["response", "value", "tool_calls", "0", "args"], + &["resume", "value", "class"], ]; for path in slots { let mut v = reduction_json(); From 03ca729fbc2d2d479a48b6ffecc4b7bea77a5d58 Mon Sep 17 00:00:00 2001 From: joelteply Date: Tue, 3 Nov 2026 09:29:52 -0600 Subject: [PATCH 2/2] continuum-proving-types: the prompt cache is a claim, not a holder; the draft's KV is a per-token rate (Fable on #5732) Holder::PromptCache is gone: the prompt cache is a divisible claim that sheds first, cleared with the minds' claims, not a fixed holder. Holder::Draft is the draft's weights and compute only; its KV grows with the pool (0.53 GB at 257,536 tokens on the M5, ~2,048 B/token), so it is ModelProfile::draft_kv_bytes_per_token beside kv_bytes_per_token. continuum card 950064f2 Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE --- core/continuum-proving-types/src/profile.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/core/continuum-proving-types/src/profile.rs b/core/continuum-proving-types/src/profile.rs index 9a00c0205d..c1bcf3900c 100644 --- a/core/continuum-proving-types/src/profile.rs +++ b/core/continuum-proving-types/src/profile.rs @@ -73,12 +73,11 @@ pub enum Holder { Weights, /// The compute graph: one for the shared pool under `--kv-unified`. ComputeGraph, - /// The speculative draft model's whole context (its weights, KV and compute). + /// The speculative draft model's weights and compute. Its KV grows with the pool, so it is + /// `ModelProfile::draft_kv_bytes_per_token`, not here. Draft, /// The multimodal projector's weights and reserved compute. Projector, - /// The host prompt cache's byte limit. - PromptCache, } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] @@ -94,12 +93,16 @@ pub struct HolderBytes { #[serde(deny_unknown_fields)] pub struct ModelProfile { pub model: ModelId, - /// Everything the engine holds whatever the minds do, each where it lives (the fork's + /// Everything the engine holds whatever the minds do, each where it lives. The prompt cache is + /// not one: it is a divisible claim that sheds first, cleared with the minds' claims (the fork's /// `memory_breakdown` and `resident_state`, llama.cpp#91). Before #91 the draft and the /// projector were invisible, and the plan inferred them from the process footprint. pub holders: Vec, /// Attention KV per token of a sequence's context. pub kv_bytes_per_token: Measured, + /// The speculative draft's KV per token of the pool (0.53 GB at 257,536 tokens on the M5, + /// ~2,048 B/token); `Unmeasured` on a model served without a draft. + pub draft_kv_bytes_per_token: Measured, /// A hybrid model's recurrent state, fixed per sequence whatever its length. Folding it into the /// per-token rate overstates long sequences and short-changes many short ones (card c8b2e1df). /// `Unmeasured` until the fork reports it apart from the KV. @@ -162,10 +165,11 @@ mod tests { holders: vec![ holder(Holder::Weights, 20_690_000_000), holder(Holder::ComputeGraph, 1_870_000_000), - holder(Holder::Draft, 3_150_000_000), + holder(Holder::Draft, 2_630_000_000), // 1.34 weights + 1.29 compute; its KV is per token holder(Holder::Projector, 900_000_000), ], kv_bytes_per_token: measured(8_317), + draft_kv_bytes_per_token: measured(2_048), recurrent_bytes_per_sequence: Measured::Unmeasured {}, prefill: RateCurve::Points { points: vec![] }, decode: RateCurve::Points { points: vec![] },