diff --git a/docs/architecture/ONE-BUDGET.md b/docs/architecture/ONE-BUDGET.md index 42c226dc95..8af72b9ec1 100644 --- a/docs/architecture/ONE-BUDGET.md +++ b/docs/architecture/ONE-BUDGET.md @@ -155,7 +155,12 @@ types for network grants and must stay separately capable, so the crate depends (ts-rs behind a feature), the same "bubble down" rule as `airc_core::shown_id`. Its home (settled by Cormac in review): its own crate in the airc workspace, `crates/flex`, package `cambrian-flex`, named for the pattern and neutral to both repos, not inside `airc-core` (which keeps its one job). Continuum depends on it through its existing airc pin; -airc's NETWORK-AUTHORITY consumes it. Slice 1's code therefore lands as an airc PR. Pure: no I/O, no clock, no randomness (THE-PROVING-GROUND P8). Generic over a unit type each +airc's NETWORK-AUTHORITY consumes it. Slice 1's code therefore lands as an airc PR. The cost of that home +(Cormac on #5723): a solver change is an airc PR plus a continuum pin bump, not an edit beside the caller. It is +paid once per API change, not per memory-policy change: policy (values, levels, claims) lives in continuum and calls +the solver; only the solver's own types and clearing live in airc. While a solver change is being developed, a +local `[patch]` in the developer's `.cargo/config.toml` points continuum at their airc checkout, so the edit is +checked in seconds and the pin moves only when the airc PR merges. Pure: no I/O, no clock, no randomness (THE-PROVING-GROUND P8). Generic over a unit type each consumer defines (`Tokens`, `Bytes`, `LaneSeconds`, bytes in flight); continuum-only pieces (where values come from, the behaviour model, ts-rs bindings) stay out of it. @@ -395,6 +400,127 @@ with fast decode), replaying captured traces under each: a read stays whole acro has room; no turnover while unclaimed window remains; prefix reuse per act reported. A new machine is covered by its own measured profile, never by a list of boxes. Then one deploy per node and a 15-minute read: reads per edit, writes per hour, act time. +### Slice 3b in detail: a mind's memory in the engine, granted by level and valued by prediction (2026-11-03) + +Joel, 2026-11-03: "One slot grows in context and the other shrinks and same for genome sizes. The goal here is +dynamic allocation"; "Every part of prompts and these kinds of caches need to comply or the whole shebang doesn't +work, plus it's less code and easier"; "it lets you do really advanced prediction when inputs and outputs to LLMs +(or world models) are entirely under the same systems"; "You can then prioritize both caching and collapsing, +expansion, in the flexbox or any of your memory constraints." + +**What the engine holds, by its own report** (fork `resident_state`, CambrianTech/llama.cpp#91, read live on the M5 +2026-11-03 12:51Z, Qwen3.6-35B-A3B at 2 x 128,768): target weights 20.69 GB, target KV and recurrent state 2.14 GB +(8,317 B/token as one figure; it is two holders, below), one compute graph 1.87 GB, the draft model 3.15 GB, the projector 0.90 GB, one checkpoint 94.6 MB +(x 32 per slot at today's `--ctx-checkpoints` = 3.0 GB per mind). Before #91 the plan saw only the first three and +inferred the rest from the process footprint as a per-lane term that read 2.8 to 4.5 GB a minute apart. + +**The claims, on the node's device tier** (one pool on unified memory, normalized per part 2's pool rule): + +| Holder | Claim on `cambrian-flex` | +|---|---| +| Weights, graph, draft, projector of the serving model | `Floor::Required`, the engine's reported bytes | +| A mind's context, resident | `Floor::Required` = what her in-flight turn holds (a grant never shrinks under a running turn); then one indivisible increment per block of her context, valued as below. On a hybrid model the attention cells are per token and may be shared (`seq_cp`); the recurrent state is per sequence and is never shared, so each owner pays her own. The two are separate claims, and the fork's report gives each its own bytes (today it reports one 8,317 B/token figure; the split is a field #91 adds) | +| Her checkpoint | one indivisible increment of its reported bytes, at her predicted divergence point | +| Prompt cache | divisible increments, valued by measured restore hits | +| Her genes | one indivisible increment per adapter her focus selects; an adapter shared by several minds is ONE claim | + +**A page's level depends on its genes** (Cormac on #5723). Since fork #90, a paged-out KV page restores only when +every adapter ACTIVE on it (scale != 0) is attached at the same file revision; otherwise the engine refuses it and +she re-prefills cold (IntelMac 2026-11-03, task 519: 1,139 s for 13,144 tokens after a refused restore). So her +page at a resident or paged level and its active genes are one bundle for the restore: the solver may keep the page +paged only while those genes are held at a level that can attach them before the page-in, and the page-in's +`switch_cost` includes attaching any that are not. A page whose genes are lowered below that is valued as what it +then is, a re-prefill, never as the page-in it can no longer be. This is a dependency between claims, the joint form +of `cambrian-flex` part 2 (airc#1632), not a rule inside either owner. + +**Caching, collapsing, expanding are one decision.** Each item has levels: on the GPU, paged to RAM, paged to disk, +rebuilt from her prompt. A level is an increment on that tier's clearing (the GPU tier, the RAM tier, the disk tier), +with its bytes as width, its value as below and its move (a page-in, a page-out, a re-prefill) as `switch_cost`. +Caching is a level held; collapsing is a grant lowered (a `ShrinkRequested` the holder reports when done); +expanding is a grant raised, which a prediction may raise early (prefetch). No owner has its own victim rule. + +**Values come from prediction, because her inputs and the engine's memory are one system.** The core writes her +prompt and holds the memory it lands in, so the next prompt is mostly known before it is sent: +- *who acts next*: her activity temperature, her tool calls in flight, an unread turn in her room. The value of her + context resident on the GPU is that chance times the prefill seconds a resident page-in saves; +- *where her next prompt diverges*: `Motion` (continuum-context) and her view's stable end. Her checkpoint goes + there, valued by the tokens a resume from it saves; the engine reports each request's actual divergence (`lcp`), so + a miss is measured and names the defect at its source (a live value in a stable block, an unstable tool surface); +- *how much she appends*: `appended_per_act`, so her grant grows ahead of her and a turnover is scheduled when cheap; +- *what minds share*: identical runs of attention cells across sequences are held once (`seq_cp`), one claim with + several owners. The recurrent state at the end of a shared run is per sequence: copied, not shared, and each owner's + own claim. +A value without its measurement is the population's for the activity, marked so (provenance), and an unmeasured +claim is granted only its floor. + +**What this deletes:** `window_within`, `lanes_that_fit`, `ModelFootprint::pool_within`, +`window_allocator::allocate`, the process-footprint inference (`lane_footprint`, `fixed_per_lane_bytes`), +`host_prompt_cache_mib`'s own affordable figure, the `--ctx-checkpoints` / `--checkpoint-min-step` derivation, +`gene_residency::victims`, the slots' page victim logic, `coordinator.rs evict_under_pressure`, the persona +allocator's GPU tiers. The fork keeps checkpoints only where the core names them (the boundary rule, fork branch +`fable/boundary-checkpoints`). + +**Order** (each lands before the next, each deletes its sizers): +1. Slice 1's migration: continuum's airc pin moves to include `cambrian-flex` (38a22ab09, 3 commits past the current + pin); the turn's allocation, the view's start grants, the reply claim and grounding claim from it with measured + values; `flex_allocate` and its priorities are deleted. Proven on the proving ground's T0 first. +2. The engine tier: serving's claims above, from the fork's report, as a child tier of the `ResourceDaemon`'s device + tier (slice 2's shape; until slice 2 lands, the serving daemon clears its own grant from the plan's budget). +3. Pages and genes on the same levels; their victim rules deleted. +4. The zero gate: `allocators_outside_the_flexbox` (a sizer outside the solver) at 0, failing on any new one. + +**Her own actions' results are the causal floor** (Joel: "this should help prevent the causal loops too ... anything +where the inference needs to see a state of results from its own actions"). Her newest act, its result, a reply she is +waiting on, and the state her action changed are `Floor::Required` claims at every tier: reserved before anything is +traded, never shrunk, and `Infeasible` (named, refused) when they cannot all fit, never cut. An oversized newest result +claims its summary with its handle as the floor, the rest as an increment (MIND-CONTEXT invariant 2). Everything older +competes by value and collapses to a reopenable level. A loop needs her input to stop reflecting what she did; with the +causal edge in the claim's type, no source's own rule can drop it (Benchy's 125 identical acts, 10-20). + +**Infeasible is where the budgeter starts working, not where her turn stops** (Joel: "The budgeter must iterate on +things that while infeasible would break what she's doing or themselves entirely, till it hopefully finds a solution +that best fits. It's a bit like a bubble sort"). The solver's pure core still reports `Infeasible`; the tier around it +iterates: +1. **Repair.** Every required claim declares its ladder of viable levels, each with its measured damage (how often a + mind held at that level re-reads, faults or loops: the behaviour model's data): her newest result whole, at its + summary with its handle, at a pointer she opens; her recall at summary, at pointers; a cold mind's context on the + GPU, paged to RAM. While the required floors do not fit, the claim whose next rung costs the least damage steps + down one rung and the tier clears again. Each step strictly lowers demand on finite ladders, so it ends: feasible, + or at every claim's last rung. +2. **Exchange.** On a feasible clearing with indivisible levels the greedy order is a lower bound; passes over pairs + (one claim down a level, another up) keep a swap only when total value rises, until a pass changes nothing. + Value strictly rises on a finite set of states, so it ends, and each pass narrows the reported gap to the bound. +3. **Capacity beyond the tier,** before any refusal, in order of measured cost: page another mind's cold context out; + grant her a larger share of the shared pool for this turn (others' cold pages to RAM, back when her turn ends, a + temporary grant priced by its switch cost); move pages to RAM; split her turn (an oversized result read in pages); + serve her alone on the whole pool, every other mind paged out for one turn (the last rung, Joel: "or reduce to one + lane in worst case scenario"); grow the pool into free memory once the engine resizes live (SERVING-ENGINE S2); + and on the grid place her where the window is larger. Each exists only because every holder is a claim with levels, + a cost and custody: a fixed slot or a private cap anywhere is the one place the budgeter could not move (Joel: "If + we follow rich and strict architectural adherence we can always get ourselves out of a bind"). +4. Only then a refusal, naming what she needed and what was tried. + +Both loops are bounded by the claims and their rungs, never by an iteration count someone picked, and each step is in +the clearing's receipt, so the proving ground replays the exact sequence. + +**A small window is the same clearing at a lower capacity** (Joel: "even intelmacs severely limited context windows +should be doable within an intelligent budgeting flexbox"). A mind granted a small window (16,384 tokens, say: a capacity chosen +for the replay, not a node's measured grant; the IntelMac's "16,384 per mind" on 11-03 was a publication bug) holds +the causal floor whole, the stable head once, then the highest-valued increments: her card's files at summary, the room's last turns, +recall at pointers she expands on demand. The M5 at 128,768 clears the same claims to fuller levels. No per-node rule +exists; values are measured per node, so a small node learns which levels its residents reopen. + +**Acceptance cases** (proving ground, then each node's live read): (0) a scenario whose required floors exceed +capacity ends in a clearing (repaired) whose damage is no more than a brute-forced optimum's on small cases, never a +stalled turn; (a) across every captured act of the four residents, +her newest act and result are present whole or at their summary with a handle, at the M5's and the IntelMac's +capacities alike; (b) no two consecutive acts with identical calls and identical inputs (the loop signature) on the +replay; (c) at a chosen replay capacity of 16,384 tokens a resident completes a card's read-edit-test cycle on replay with no `Infeasible` clearing. + +**Validators:** replay the four residents' captures (`fixtures/prompt-captures`) against the fork's measured +holdings: every clearing fits the reported capacity, resumes land at the predicted divergence, and fewer tokens are +re-read than today's 1,244-resume baseline (80% within 8k, 10% past 25k). + ### Acceptance: the user's own load (Joel, 2026-10-30: "What if we start this and someone is playing a video game or starts one later? Or Photoshop") The product runs on someone's computer while they use it. Today (canary, `serving_daemon/reconcile.rs`): diff --git a/docs/architecture/SERVING-ENGINE.md b/docs/architecture/SERVING-ENGINE.md index e1f7dd3988..9b4986aab3 100644 --- a/docs/architecture/SERVING-ENGINE.md +++ b/docs/architecture/SERVING-ENGINE.md @@ -185,3 +185,108 @@ gives memory back to the user's app. - The IPC cost is one request per act plus 30-120 token frames a second over a unix socket: microseconds against a 60 s act. - MODULE-ARCHITECTURE §9.2 rule 2 asks for one protocol per seam, local or remote. - The in-process `ServingPort` implementation exists only for the validator and tests. + +## 7. Memory is conserved across minds, and the engine says what it holds (2026-11-03) + +Joel, 2026-11-03: "One slot grows in context and the other shrinks and same for genome sizes. The +goal here is dynamic allocation"; "think harder about conservation around multiple minds or sharing +what you need across api boundaries so that intelligence can manage"; "you just treat llama.cpp +like any other daemon and interface with it. It's fully under your control." The engine is our +daemon. Nothing about a mind's memory is fixed at launch and guessed: the engine reports what it +holds, the core tells it where her prompt's boundaries are, and the core's ledger decides. + +### 7.1 What the engine holds (fork `resident_state`, read live on the M5, 2026-11-03 12:51Z) + +Qwen3.6-35B-A3B, `-c 257214 --parallel 2 --ctx-checkpoints 32`, two 13.9k-token prompts in: + +| Holder | Bytes | Notes | +|---|---|---| +| Target weights | 20.69 GB | mmapped | +| Target KV + recurrent state | 2.14 GB | 8,317 B/token over 257,536 tokens, reported as one figure. Two holders: attention cells per token (shareable by `seq_cp`) and recurrent state per sequence (never shared); #91 reports them separately | +| Target compute graph | 1.87 GB | one graph for the shared pool | +| Draft (MTP) context | 3.15 GB | 1.34 weights, 0.53 KV, 1.29 compute: unreported before | +| Projector | 0.90 GB | unreported before | +| One checkpoint | 94.6 MB | x 32 per sequence = 3.03 GB per mind at the ceiling | + +`memory_breakdown` alone covered the first three. The rest was what the plan had been inferring from +the process footprint as a per-lane fixed term (2.8 to 4.5 GB a minute apart). + +### 7.2 Why a mind's prompt re-reads: measured, not assumed + +Engine log, 1,244 checkpoint resumes: 80% resumed within 8k tokens of the end (median 2,431 tokens +re-read, her changing tail). The other 20% fell back to her head-end checkpoint (~11k tokens). +The prompt captures of the four residents (`fixtures/prompt-captures`, 611 consecutive pairs) say why: + +| Where her next prompt first differs | Pairs | +|---|---| +| Her changing tail (the prompt only appended before it) | 435 | +| Identical | 62 | +| She moved to another room (activity); 52 of 59 keep her first 3 messages | 59 | +| A turnover: her view restarted, and an early block differs | 29 | +| Live state in an early block with no turnover (`room-kanban`'s "557 claimable" counter, `room-wall`, `workspace-map`, `recall`) | 11 | +| Tool surface changed | 9 | +| A turnover with only later messages different | 6 | + +Of the 40 turnovers, 26 came on the same core at the same window: her view filled its grant, the +codec's one designed re-read. 12 came across a core restart (the day's deploys and rollbacks): her +view is not carried over a restart, so a deploy starts every mind over. 2 came with a changed window +on the same core (one grown, one shrunk). + +Minds share only 6,177 chars of system prompt with each other (it diverges inside it). The +recurring 11,114-token checkpoint is each mind's own head end, not a shared one. + +So the blind every-4k checkpoints were covering defects upstream of the engine: a view that does not +survive a restart, live values in blocks meant to be stable, and an unstable tool surface (goal 10). +The fills themselves are by design, and one checkpoint at her stable end serves every act between them. + +### 7.3 The contract across the seam + +- **Core to engine, per request:** her prompt's boundaries as token positions: the head end, the + stable end (where her changing tail starts), and each activity's span. The request already + carries `view_messages` spans for this. The engine keeps a checkpoint exactly at the stable end + (one per mind per activity), never by a count or a step. +- **Engine to core, live (`/slots`, read on the server thread):** per sequence, the tokens it holds, + its checkpoints and their bytes, and what is shared with another sequence; on `/props`, every + fixed holder (7.1). A core never infers a holding from the process or the device. +- **The core's ledger, continuous:** weights and the graph are fixed claims; each mind's context is + her grant, growing with her and accommodated proportionally (Joel: "it might still be given less + than that, just try to accommodate"; her budget compresses to the grant); an in-flight turn's grant + never shrinks. Checkpoints and pages are held at their live bytes. Under pressure a cold mind's + unique state pages to RAM, then disk, by her activity temperature, before any grant shrinks. +- **Conservation:** what is identical across sequences is held once. Today that is the first 6k + chars; ordering the shared constitution and the stable tool surface ahead of her identity makes + the shared head the system prompt plus the tools, one KV run and one checkpoint for every mind + (`seq_cp` of the attention cells plus the head checkpoint, §1). Genes follow the same rule: one + copy per adapter, attached to every mind whose focus selects it. + +### 7.4 One solver for prompt and memory (ONE-BUDGET.md) + +Joel: "it's always collapsing flexbox style ... everywhere same base classes and interfaces." The base exists: +`cambrian-flex` (airc `crates/flex`, merged as airc#1630), ONE-BUDGET slice 1. Claims are cleared by measured value +per unit against a scarcity price; an item's levels are indivisible increments with their own value; a move between +levels carries its measured `switch_cost`; custody, provenance and generation fencing are in the type. A mind's prompt +and the engine's memory are two tiers of the same solver, and each keeps only its levels and how to move between them. +The engine-memory slice, with caching, collapsing and expansion as one decision valued by prediction, is ONE-BUDGET.md +"Slice 3b". The hand-rolled memory allocators (`window_within`, `lanes_that_fit`, `pool_within`, +`window_allocator::allocate`, the kernel `memory_manager` budgets, `gene_residency::victims`, the persona allocator's +tiers and the rest) converge on it and are deleted; the gate goes to zero. + +### 7.5 Order of work + +0. The base: the prompt's callers move to `cambrian-flex` and `flex_allocate` is deleted (ONE-BUDGET slice 1). +1. Her view survives a restart: the epoch (its start, its items' levels, its appends) is durable + state beside her KV page, so a deploy pages her back in where she was instead of starting her + over. Validator: replay the captures across the day's restarts; turnovers at a restart go to 0. +2. Mind side: no live value in a stable block. The kanban counter, the wall, the workspace map and + recall arrive as appended item versions (the keyed-item contract above), never as an in-place + rewrite; a ratchet refuses one. Validator: rerun 7.2 on fresh captures, in-place early changes + to 0. Her activities stay one view: a move between rooms appends. +3. Fork: the boundary checkpoint verb (keep one at the stable end the request names) replaces + `--ctx-checkpoints N` / `--checkpoint-min-step`; per-sequence holdings on `/slots` (`resident_state` + and slot `checkpoints`, fork #91, are the first part). +4. Core: serving's memory is claims and items on the base, fed by the engine's live holdings + (`ResidentReport`); every seated mind is a sequence; the hand-rolled allocators above and the + process-footprint inference (`lane_footprint`, `fixed_per_lane_bytes`) are deleted. `Motion` over + token runs, fed by the divergence point the engine reports per request, places checkpoints and + finds what minds share. +5. Shared head (S7): constitution and tools ahead of identity, one copy for all minds.