Skip to content

Every budgeted part collapses by its levels instead of refusing: hands, framing, grounding as consumers in one searched allocation - #5814

Merged
joelteply merged 7 commits into
canaryfrom
fable/every-claim-collapses
Nov 7, 2026
Merged

joelteply merged 7 commits into
canaryfrom
fable/every-claim-collapses

Conversation

@joelteply

@joelteply joelteply commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Serves the residents directly: on a small window their turns were refused and their grounding suppressed, because her hands, her framing and her RAG sat outside the one codec. Advances goal 7 (one budget) and order-of-work line 2 (prefix reuse: the tools head churned at "the window could not hold her tool set").

Joel, 2026-11-07: "The rag budgeting should collapse rather than crap out and positron ought to flexbox not kill." "Rejection should be rare. Constants never. Each rag budget consumer ... might be asked to reduce." "It's an optimizer too. It sort of searches to fit."

The contract (one owner: continuum-context)

  • ladder: every budget consumer is a Leveled list of items, each with Rungs (its levels, most detail first, measured from the rendered item; the last rung is its hard limit). reduce(target) = the most it can show within a target, by the view's own rule (most important item first, an older item never more whole than a newer one, an item with no summary is its own summary). The floor is derived from the items, never declared.
  • allocation::search: which level each leveled consumer shows, searched together. Value = priority × ln(1 + tokens) (its continuous optimum is the flexbox's proportional grow, so "like flexbox"); first guess = the flexbox with each grant rounded down to a level; then a ballpark DP over options (unit derived from the instance: span / option count) and an exact exchange climb. Never worse than the first guess.
  • allocation::allocate: ActClaims members are Leveled (framing, required, newest, tools, grounding, last move) or continuous (history, reply, view sources). The turn is short only when every hard limit together does not fit, and IrreducibleShortfall names the binding part. The receipt's floor for a leveled part is its hard limit.

Each section: levels, hard limit, priority

Section Levels (generated from) Hard limit (measured where) Priority
tools per verb: whole / summary (codec summary of its description, every parameter typed, no parameter docs) / pointer (name, every parameter name with any value, the commands/help(name=…) handle) (tool_surface/levels.rs) every verb at its pointer; an Always verb (nothing expands it) at its summary 7
framing identity + turn contract + tools intro (one item, whole) and each menu category expanded / collapsed to its commands/list --filter handle (prompt/framing.rs, persona_tools::menu_lines) the irreducible blocks + every category collapsed; the whole prices the system message exactly, a collapse never under-counts 10
grounding per contribution: whole / unit prefixes (lists) or levels::summarize Output ladder (indivisible) / its handle, else it leaves (prompt/grounding.rs) 0 (enrichment leaves before a turn is refused) 6
newest result its existing summary chain (newest_result.rs) its coarsest level, chosen before the search (never cut for optional parts) 10
required input whole its whole (input she must read) 10
last move whole its whole (goal 7) 10
history continuous (whole messages, oldest first) 0 5
reply continuous her measured need (reply_claim) the turn's
view sources the view's own levels/folds (view::floor) the view's floor each source's

Her head (tools + menu) is held per epoch of her head (ToolsEpoch, now holding levels): kept while the window holds it; re-chosen loudly (delib.tools.epoch_level_lost) when it cannot; a rise (both ways) or a held card's new set is adopted only at a view start that funds its growth (fit_view's head_growth). Her head's levels are searched with the reply at its measured need (a pass and the act after it choose the same head); the grounding, which rides the tail, is searched again beside the reply's real priority.

Deviation from the brief, stated: the summary keeps every parameter (typed), not only the required ones, and the pointer keeps every parameter's name. The served engine builds its tool-call grammar and parser over the head's schemas and skips a tail tool whose name is in the head (vendor/llama.cpp common/chat.cpp, common_chat_templates_apply), so a level that dropped a parameter would make it uncallable until her head's next epoch.

Measured

Validator: continuum-core test_env::mind_integration::registry::deliberation::every_claim_collapses (the live registry's 52 verbs, real schemas), Aiko's window 30,566 (per_slot_window, fe91c2b, 2026-11-07), her act's reply need derived from the act's own receipt (puts her parts with her hands whole past her window by half of what her hands' levels give back). Built and run on this branch's head 382a5ac, 2026-11-07, M5 (serving live, nice -n 19):

window 30566; her hands whole 16508 tokens, at their pointers 4144 (52 verbs); her act's reply need 18357
          | framing |  tools | newest | history | grounding |   view | reply | refused
canary   |    1377 |  16508 |    200 |      22 |         0 |    232 | 12117 | 36806 of 30566 needed (binding reply)
collapse |    1377 |   4144 |   1456 |      22 |      2207 |   2893 | 18357 |

"canary" = this act's parts priced with no levels (hands and framing whole-or-refuse, grounding whole-or-nothing), run through the same allocation; "collapse" = the real prompt_view. Every verb is still sent (names equal), each whole, at its summary or at its pointer; her newest result is whole; the standing board reaches her.

Search cost per act (allocation::search tests): act-sized instance (384 options), 35,484 cells, 1.78 ms release / 14.4 ms debug per search; an act runs it at most 3 times (head, grounding, unheld rise). Matches the exhaustive optimum on 196 of 200 random instances, never below its first guess. Live: delib.window.flex now carries allocation_us, searched_cells, search_refined, tools_limit. The live 15-minute read (reuse, refusals, delib.context.render levels) is owed after deploy: Fable, before this card closes.

Tests (head 382a5ac): continuum-context 98 lib + 21 replay; continuum-cognition --lib --features test-fixtures,metal 964 passed; continuum-core --lib --features metal,test-fixtures 1,185 passed; cargo check --tests of continuum-academy, continuum-mind, continuum-vitals clean; oversized-edits and source-hygiene --bin ratchets against canary a071f9f: green.

Deleted (non-test: +1,982 / -1,271; total +2,607 / -1,452)

  • The tools' hand-built claim (ToolsClaim floor/level/want) and its refusal ("a window that cannot hold those refuses the turn"); ToolSurface::select_granted's grant path, claim_tokens, claim_with_head; the learned head's budget reserve (SelectedSurface::reserving) and over-grant fallback.
  • GroundingPlan (minimum / within_budget shedding / expand_within / its always-empty trailing half), the Fitted enum, the salience walk in render_assembled_context_within and the delib.context.salience_inversion sensor (a more salient block can no longer be shown less whole than a lesser one), the zero-budget "assembled context suppressed" path.
  • PromptMessages::grounding_tokens and RequiredParts::grounding (always 0).
  • fit.rs leaves clean (Fable, its owner): PER_MESSAGE_TEMPLATE_TOKENS = 5 is gone (the engine counts the templated prompt and the estimate counts text, so her measured density, whose bound prices the next prompt, carries the template's tokens; unmeasured, the estimate stands alone and the engine's exact count before generation refits a denser prompt, refusing nothing); FRONT_DROP_QUANTUM_DIVISOR = 8 and its 512 floor are gone (the quantized front drop kept the conversation's front byte-stable across acts, which her view's epoch owns now; the fit sees this act's fresh tail or its refused prompt, never the next act's prefix, and drops whole messages oldest first, each step the oldest message's own size), with FitReceipt::quantum and the quanta test.
  • Ratchets: prompt_messages_outside_the_view 8 -> 7; collapse_outside_the_view 0, hand_churn_labels 3, modules_in_cycles 26, unjustified_unwraps 1,824: unchanged.

Not done: a scenario in the codec's replay example (it is capture-driven and has no tool registry; the validator runs on the real registry in core instead); re-read hazard as a value weight in the act-level search (it already drives history's collapse depth at a view start, depth::choose; weighting the search needs per-claim weights in allocation::search): card 4e97192b, owner Fable.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

joelteply and others added 3 commits November 7, 2026 03:00
…searches its levels

The ladder (one contract: each item's levels, most detail first, its last the hard limit;
reduce = the most it can show within a target, newest/most important first, never an older
item above a newer), the search (a multiple-choice knapsack over the leveled parts' options,
value = priority x ln(1 + tokens), the flexbox's proportional grow as its continuous optimum;
first guess = flexbox + round down, then a ballpark table and an exact exchange climb), and
ActClaims made of Leveled parts whose floors are derived, never declared. Refusal only when
every hard limit together does not fit, naming the binding one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
… levels instead of refusing

Every budgeted part of an act is a leveled consumer in the one allocation (continuum-context
ladder + search): each verb whole / summary (first sentence, every parameter typed, no parameter
docs) / pointer (name, parameter names, the commands/help handle); each tool-menu category
expanded / collapsed to its commands/list handle; each grounding contribution whole / unit
prefixes or shape summaries / its handle, else it leaves the turn. Floors are the items' hard
limits, derived, never declared; the turn is short only when every hard limit together does not
fit, and the shortfall names the binding part. Her head (tools + menu) keeps its levels per epoch
of her head, re-chooses them loudly when the window cannot hold them, and rises at the next view
start that funds the growth.

Deleted: the tools' hand-built floor/level/want claim and its refusal, select_granted's grant
path and the learned head's budget reserve, GroundingPlan (within_budget shedding, expand_within,
the always-empty trailing half), the salience walk and its inversion sensor (structurally
impossible now), PromptMessages::grounding_tokens / RequiredParts::grounding (always 0).

Validator (continuum-core test_env, the live registry's 52 verbs): Aiko's act on her 30,566
window, priced as canary priced it, needs 36,877 (binding: her reply need); leveled, it fits with
her hands at 4,001 of 16,508, grounding 2,212 instead of 0, her view 2,970 instead of 242.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…he allocation's flexbox run

The search nests under the allocation (its top-level name collided with continuum-perception's
`search` module in the module-cycle ratchet, 26 -> 28), and the flexbox first guess moves into
the allocation, the one caller of the allocator. A verb's summary takes its description's codec
summary (`levels::summarize`), never a first-line head cut. The search sees the reply at its
measured need for her head's levels (a pass and the act after it choose the same head), and the
grounding, which rides the tail, is searched again beside the reply's real priority. Added test
unwraps justified; the receipt names each leveled part's hard limit as its floor.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
joelteply and others added 2 commits November 7, 2026 03:26
…y; the fit drops whole messages, oldest first, exactly as many as it must

PER_MESSAGE_TEMPLATE_TOKENS (5) is gone: the engine counts the templated prompt and the estimate
counts text, so her density (delib.prompt.density, its bound the next prompt's price) carries the
chat template's tokens around each message; unmeasured, the estimate stands alone and the engine's
exact count before generation refits a denser prompt, refusing nothing.

FRONT_DROP_QUANTUM_DIVISOR (8) and its 512 floor are gone: the quantized front drop kept the
conversation's front byte-stable across acts, which her view's epoch owns now; what the fit sees
(this act's fresh tail, or this act's refused prompt) is never the next act's prefix. It drops whole
messages, oldest first, each step the oldest message's own size. FitReceipt::quantum deleted; the
quanta test becomes "whole oldest messages, exactly as many as the budget needs".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
… that could price a real item at 0

Rungs::kept(whole, tag, smaller) builds an item's rungs from its whole down and returns one tag per
rung, aligned; it cannot fail (the whole is always a level). Every producer builds through it: a
verb's levels (VerbLevels::rungs), a grounding contribution's levels (its `None` tag is leaving the
turn, a real level, not a default), a menu category's, and her newest result's (view.rs's hand-built
dedup and map migrated). The per-rung lookups index the aligned tags directly: the
`Rungs::new(..).unwrap_or_else(|| Rungs::whole(0))` and `map.get(rung).unwrap_or(0)` fallbacks, which
would have charged a real schema at 0 tokens, and the render's clamp are gone (Cormac on #5814).
Framing's held levels read the category's rungs, never its byte lengths.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
joelteply added a commit that referenced this pull request Nov 7, 2026
…er allocation estimate

#5814 removed PER_MESSAGE_TEMPLATE_TOKENS (no constant) but nothing measured in its place, so an
"ok" turn cost 0 and a start priced by text alone kept twenty of them against a 32-token grant
(Codex's 100 > 32).

Engine (llama_server/template_overhead.rs): the serving lane's template is measured once per engine
process and model, from the reconcile that already reads its build (observe_template beside
observe_served_engine). Probe messages per kind (system, user, assistant, native tool result, native
tool call with 0-3 parameters) are rendered in the middle of a conversation through /apply-template
on the request wire (request_body::wire_messages) and counted by /tokenize (HTTP-thread calls, no
slot, no decode); each records the tokens it added. MessageShape is the one owner of how a message is
classified (kind, calls or results, parameters). TemplateMeasurement::Unmeasured is a type; the
adapter seam reports it (AIProviderAdapter::template_overhead, OpenAI adapter for the serving lane,
the placement switch forwards). Probe: serving.template_overhead.

Cognition (prompt/template.rs): TemplateEstimate derives each kind's share against her own text
estimate (message_cost) at its HIGHEST observation, a call's as the least-overcharging line over its
parameters on or above every observation, so the estimate errs high on every observation and states
its spread. PromptCalibration carries it (fit_within, from the adapter); estimate(message) =
message_cost + its kind's share (unmeasured: text alone, density carries the template, probed on
delib.prompt.density); estimated_prompt_tokens counts it, so density calibrates the rest.

The view's oracle is renamed for what it is: AllocationEstimate (cognition) over
continuum_context::cost::Estimate (the trait, was Cost). Its docs say it decides what to keep, errs
high, claims no exact count or token prefix; dispatch still rests on the engine's exact quote.

Measured on the M5 engine (Qwen3.6-35B-A3B-Q4_K_M, build b11017-444f386cf, 2026-11-07T11:38Z),
tokens each probe added: plain turns 6/12/10/7/11 for every role, tool results 10/16/14/11/15,
calls 17/31/43/57 (0/1/2/3 parameters). Beyond her text estimate: system/user/assistant highest 9,
lowest 1 (spread 8); tool result 13, lowest 5 (spread 8); call line 17 + 8 per parameter
(base lowest 14, spread 3).

Tests: Codex's regression stays byte-identical but for the View::start cost argument, and stays
green (its "ok" turns are priced by message_cost, which counts text). The template's red/green is
a_view_start_keeps_its_token_grant_with_the_measured_template_overhead on his conversation: priced
by text alone the start keeps 20 "ok" turns, 120 tokens as the recorded engine counts them (6 each)
against 32; priced by the allocation estimate it keeps within every grant 32..512, and the recorded
engine count is under the estimate. the_allocation_estimate_errs_high_on_the_recorded_engine: every
probe is estimated at or above the engine's count, and a six-message multi-role conversation counted
at 97 (92 without the 5-token generation suffix) is estimated at 118.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
joelteply and others added 2 commits November 7, 2026 07:54
… rise is funded like a tools rise

NextHead.growth counted only the tool surface's tokens, so a held collapsed menu that the allocation
raised (tools unchanged) reported 0 while the system message grew 19 tokens (Codex's red test,
ef78cfb, now green). The next head's parts are built first (her changed moves' set or her held
set risen, her menu risen or as held), then its growth is measured in one place for every head
consumer: the head it renders (system message at its menu plus its tool surface) against this
act's, in the allocation's unit, the unit fit_view funds a start's reserve in (it was raw tokens).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
joelteply added a commit that referenced this pull request Nov 7, 2026
… as the final prompt prices it

Codex's defect: View::start converted a source's TOKEN grant into characters at the source's
AVERAGE tokens per character (start_grants: share * full_chars / requested_max), so a source of
cheap long old turns and dear short new ones bought characters enough for new turns whose own
cost overran the grant.

continuum-context::cost::Cost<T> is the caller's price of a block (block, stored), with Chars for
callers whose grants are characters and cost::whole as the one owner of an item's whole price
(source::whole_chars deleted). View::start / turn_over / start_would_restore / readmit, view::claims,
view::floor, the allotment (allot, fold_of) and depth::collapsible all price by it; Claim's sizes
(floor, full, newest, logged), depth's Collapsible (whole, saves) and Growing (base, logged) are in
the oracle's unit, and Growing::per_char is gone. Motion's order stays in characters.

Cognition's oracle is ViewCost(calibration): each block at calibration.charge(message_cost), the
function the final prompt is charged with (charged per block it errs high by under a token a block,
never low). view_claims prices the plan's claims by the same oracle through view::claims (its own
floor/whole pricing removed, view.rs no longer re-charges them); start_grants hands back token
shares (the share itself, or the claim's full when granted all), takes one act's growth in tokens
from fit_view's next_act_tokens, and reads Claim::newest directly; admit_view hands readmit its
token budget.

Removed char conversions: start_grants' grant mapping and its newest_of and wanted_tokens/
wanted_chars ratio; depth's per_char (claims[i].growing(share, requested_max / full_chars));
admit_view's budget * view.chars() / view_tokens limit; view_claims' raw-then-charge path;
the fold decision in chars (fold_of now decides in the oracle the view allots by).

Tests: Codex's regression (previous commit) passes on this base before and after: #5814 removed
the per-message template tokens, so his short "ok" turns cost nothing here.
a_view_start_keeps_its_token_grant_when_her_newest_turns_are_denser is the same defect on this
base (CJK newest turns: a byte-counted estimate makes them three times as dense per char): red
before (36 tokens in 3 messages against 32), green after. a_view_start_with_uniform_message_sizes_
keeps_what_it_kept: five newest turns before and after.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
joelteply added a commit that referenced this pull request Nov 7, 2026
…er allocation estimate

#5814 removed PER_MESSAGE_TEMPLATE_TOKENS (no constant) but nothing measured in its place, so an
"ok" turn cost 0 and a start priced by text alone kept twenty of them against a 32-token grant
(Codex's 100 > 32).

Engine (llama_server/template_overhead.rs): the serving lane's template is measured once per engine
process and model, from the reconcile that already reads its build (observe_template beside
observe_served_engine). Probe messages per kind (system, user, assistant, native tool result, native
tool call with 0-3 parameters) are rendered in the middle of a conversation through /apply-template
on the request wire (request_body::wire_messages) and counted by /tokenize (HTTP-thread calls, no
slot, no decode); each records the tokens it added. MessageShape is the one owner of how a message is
classified (kind, calls or results, parameters). TemplateMeasurement::Unmeasured is a type; the
adapter seam reports it (AIProviderAdapter::template_overhead, OpenAI adapter for the serving lane,
the placement switch forwards). Probe: serving.template_overhead.

Cognition (prompt/template.rs): TemplateEstimate derives each kind's share against her own text
estimate (message_cost) at its HIGHEST observation, a call's as the least-overcharging line over its
parameters on or above every observation, so the estimate errs high on every observation and states
its spread. PromptCalibration carries it (fit_within, from the adapter); estimate(message) =
message_cost + its kind's share (unmeasured: text alone, density carries the template, probed on
delib.prompt.density); estimated_prompt_tokens counts it, so density calibrates the rest.

The view's oracle is renamed for what it is: AllocationEstimate (cognition) over
continuum_context::cost::Estimate (the trait, was Cost). Its docs say it decides what to keep, errs
high, claims no exact count or token prefix; dispatch still rests on the engine's exact quote.

Measured on the M5 engine (Qwen3.6-35B-A3B-Q4_K_M, build b11017-444f386cf, 2026-11-07T11:38Z),
tokens each probe added: plain turns 6/12/10/7/11 for every role, tool results 10/16/14/11/15,
calls 17/31/43/57 (0/1/2/3 parameters). Beyond her text estimate: system/user/assistant highest 9,
lowest 1 (spread 8); tool result 13, lowest 5 (spread 8); call line 17 + 8 per parameter
(base lowest 14, spread 3).

Tests: Codex's regression stays byte-identical but for the View::start cost argument, and stays
green (its "ok" turns are priced by message_cost, which counts text). The template's red/green is
a_view_start_keeps_its_token_grant_with_the_measured_template_overhead on his conversation: priced
by text alone the start keeps 20 "ok" turns, 120 tokens as the recorded engine counts them (6 each)
against 32; priced by the allocation estimate it keeps within every grant 32..512, and the recorded
engine count is under the estimate. the_allocation_estimate_errs_high_on_the_recorded_engine: every
probe is estimated at or above the engine's count, and a six-message multi-role conversation counted
at 97 (92 without the 5-token generation suffix) is estimated at 118.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply
joelteply merged commit e5f57d9 into canary Nov 7, 2026
18 checks passed
@joelteply
joelteply deleted the fable/every-claim-collapses branch November 7, 2026 14:36
joelteply added a commit that referenced this pull request Nov 7, 2026
… as the final prompt prices it

Codex's defect: View::start converted a source's TOKEN grant into characters at the source's
AVERAGE tokens per character (start_grants: share * full_chars / requested_max), so a source of
cheap long old turns and dear short new ones bought characters enough for new turns whose own
cost overran the grant.

continuum-context::cost::Cost<T> is the caller's price of a block (block, stored), with Chars for
callers whose grants are characters and cost::whole as the one owner of an item's whole price
(source::whole_chars deleted). View::start / turn_over / start_would_restore / readmit, view::claims,
view::floor, the allotment (allot, fold_of) and depth::collapsible all price by it; Claim's sizes
(floor, full, newest, logged), depth's Collapsible (whole, saves) and Growing (base, logged) are in
the oracle's unit, and Growing::per_char is gone. Motion's order stays in characters.

Cognition's oracle is ViewCost(calibration): each block at calibration.charge(message_cost), the
function the final prompt is charged with (charged per block it errs high by under a token a block,
never low). view_claims prices the plan's claims by the same oracle through view::claims (its own
floor/whole pricing removed, view.rs no longer re-charges them); start_grants hands back token
shares (the share itself, or the claim's full when granted all), takes one act's growth in tokens
from fit_view's next_act_tokens, and reads Claim::newest directly; admit_view hands readmit its
token budget.

Removed char conversions: start_grants' grant mapping and its newest_of and wanted_tokens/
wanted_chars ratio; depth's per_char (claims[i].growing(share, requested_max / full_chars));
admit_view's budget * view.chars() / view_tokens limit; view_claims' raw-then-charge path;
the fold decision in chars (fold_of now decides in the oracle the view allots by).

Tests: Codex's regression (previous commit) passes on this base before and after: #5814 removed
the per-message template tokens, so his short "ok" turns cost nothing here.
a_view_start_keeps_its_token_grant_when_her_newest_turns_are_denser is the same defect on this
base (CJK newest turns: a byte-counted estimate makes them three times as dense per char): red
before (36 tokens in 3 messages against 32), green after. a_view_start_with_uniform_message_sizes_
keeps_what_it_kept: five newest turns before and after.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
joelteply added a commit that referenced this pull request Nov 7, 2026
…er allocation estimate

#5814 removed PER_MESSAGE_TEMPLATE_TOKENS (no constant) but nothing measured in its place, so an
"ok" turn cost 0 and a start priced by text alone kept twenty of them against a 32-token grant
(Codex's 100 > 32).

Engine (llama_server/template_overhead.rs): the serving lane's template is measured once per engine
process and model, from the reconcile that already reads its build (observe_template beside
observe_served_engine). Probe messages per kind (system, user, assistant, native tool result, native
tool call with 0-3 parameters) are rendered in the middle of a conversation through /apply-template
on the request wire (request_body::wire_messages) and counted by /tokenize (HTTP-thread calls, no
slot, no decode); each records the tokens it added. MessageShape is the one owner of how a message is
classified (kind, calls or results, parameters). TemplateMeasurement::Unmeasured is a type; the
adapter seam reports it (AIProviderAdapter::template_overhead, OpenAI adapter for the serving lane,
the placement switch forwards). Probe: serving.template_overhead.

Cognition (prompt/template.rs): TemplateEstimate derives each kind's share against her own text
estimate (message_cost) at its HIGHEST observation, a call's as the least-overcharging line over its
parameters on or above every observation, so the estimate errs high on every observation and states
its spread. PromptCalibration carries it (fit_within, from the adapter); estimate(message) =
message_cost + its kind's share (unmeasured: text alone, density carries the template, probed on
delib.prompt.density); estimated_prompt_tokens counts it, so density calibrates the rest.

The view's oracle is renamed for what it is: AllocationEstimate (cognition) over
continuum_context::cost::Estimate (the trait, was Cost). Its docs say it decides what to keep, errs
high, claims no exact count or token prefix; dispatch still rests on the engine's exact quote.

Measured on the M5 engine (Qwen3.6-35B-A3B-Q4_K_M, build b11017-444f386cf, 2026-11-07T11:38Z),
tokens each probe added: plain turns 6/12/10/7/11 for every role, tool results 10/16/14/11/15,
calls 17/31/43/57 (0/1/2/3 parameters). Beyond her text estimate: system/user/assistant highest 9,
lowest 1 (spread 8); tool result 13, lowest 5 (spread 8); call line 17 + 8 per parameter
(base lowest 14, spread 3).

Tests: Codex's regression stays byte-identical but for the View::start cost argument, and stays
green (its "ok" turns are priced by message_cost, which counts text). The template's red/green is
a_view_start_keeps_its_token_grant_with_the_measured_template_overhead on his conversation: priced
by text alone the start keeps 20 "ok" turns, 120 tokens as the recorded engine counts them (6 each)
against 32; priced by the allocation estimate it keeps within every grant 32..512, and the recorded
engine count is under the estimate. the_allocation_estimate_errs_high_on_the_recorded_engine: every
probe is estimated at or above the engine's count, and a six-message multi-role conversation counted
at 97 (92 without the 5-token generation suffix) is estimated at 118.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
joelteply added a commit that referenced this pull request Nov 7, 2026
… as the final prompt prices it (#5819)

* test: reproduce view start exceeding its token grant with uneven message sizes

* The view starts by the caller's token oracle: a start keeps its grant as the final prompt prices it

Codex's defect: View::start converted a source's TOKEN grant into characters at the source's
AVERAGE tokens per character (start_grants: share * full_chars / requested_max), so a source of
cheap long old turns and dear short new ones bought characters enough for new turns whose own
cost overran the grant.

continuum-context::cost::Cost<T> is the caller's price of a block (block, stored), with Chars for
callers whose grants are characters and cost::whole as the one owner of an item's whole price
(source::whole_chars deleted). View::start / turn_over / start_would_restore / readmit, view::claims,
view::floor, the allotment (allot, fold_of) and depth::collapsible all price by it; Claim's sizes
(floor, full, newest, logged), depth's Collapsible (whole, saves) and Growing (base, logged) are in
the oracle's unit, and Growing::per_char is gone. Motion's order stays in characters.

Cognition's oracle is ViewCost(calibration): each block at calibration.charge(message_cost), the
function the final prompt is charged with (charged per block it errs high by under a token a block,
never low). view_claims prices the plan's claims by the same oracle through view::claims (its own
floor/whole pricing removed, view.rs no longer re-charges them); start_grants hands back token
shares (the share itself, or the claim's full when granted all), takes one act's growth in tokens
from fit_view's next_act_tokens, and reads Claim::newest directly; admit_view hands readmit its
token budget.

Removed char conversions: start_grants' grant mapping and its newest_of and wanted_tokens/
wanted_chars ratio; depth's per_char (claims[i].growing(share, requested_max / full_chars));
admit_view's budget * view.chars() / view_tokens limit; view_claims' raw-then-charge path;
the fold decision in chars (fold_of now decides in the oracle the view allots by).

Tests: Codex's regression (previous commit) passes on this base before and after: #5814 removed
the per-message template tokens, so his short "ok" turns cost nothing here.
a_view_start_keeps_its_token_grant_when_her_newest_turns_are_denser is the same defect on this
base (CJK newest turns: a byte-counted estimate makes them three times as dense per char): red
before (36 tokens in 3 messages against 32), green after. a_view_start_with_uniform_message_sizes_
keeps_what_it_kept: five newest turns before and after.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

* The template's share is measured per kind from the engine and joins her allocation estimate

#5814 removed PER_MESSAGE_TEMPLATE_TOKENS (no constant) but nothing measured in its place, so an
"ok" turn cost 0 and a start priced by text alone kept twenty of them against a 32-token grant
(Codex's 100 > 32).

Engine (llama_server/template_overhead.rs): the serving lane's template is measured once per engine
process and model, from the reconcile that already reads its build (observe_template beside
observe_served_engine). Probe messages per kind (system, user, assistant, native tool result, native
tool call with 0-3 parameters) are rendered in the middle of a conversation through /apply-template
on the request wire (request_body::wire_messages) and counted by /tokenize (HTTP-thread calls, no
slot, no decode); each records the tokens it added. MessageShape is the one owner of how a message is
classified (kind, calls or results, parameters). TemplateMeasurement::Unmeasured is a type; the
adapter seam reports it (AIProviderAdapter::template_overhead, OpenAI adapter for the serving lane,
the placement switch forwards). Probe: serving.template_overhead.

Cognition (prompt/template.rs): TemplateEstimate derives each kind's share against her own text
estimate (message_cost) at its HIGHEST observation, a call's as the least-overcharging line over its
parameters on or above every observation, so the estimate errs high on every observation and states
its spread. PromptCalibration carries it (fit_within, from the adapter); estimate(message) =
message_cost + its kind's share (unmeasured: text alone, density carries the template, probed on
delib.prompt.density); estimated_prompt_tokens counts it, so density calibrates the rest.

The view's oracle is renamed for what it is: AllocationEstimate (cognition) over
continuum_context::cost::Estimate (the trait, was Cost). Its docs say it decides what to keep, errs
high, claims no exact count or token prefix; dispatch still rests on the engine's exact quote.

Measured on the M5 engine (Qwen3.6-35B-A3B-Q4_K_M, build b11017-444f386cf, 2026-11-07T11:38Z),
tokens each probe added: plain turns 6/12/10/7/11 for every role, tool results 10/16/14/11/15,
calls 17/31/43/57 (0/1/2/3 parameters). Beyond her text estimate: system/user/assistant highest 9,
lowest 1 (spread 8); tool result 13, lowest 5 (spread 8); call line 17 + 8 per parameter
(base lowest 14, spread 3).

Tests: Codex's regression stays byte-identical but for the View::start cost argument, and stays
green (its "ok" turns are priced by message_cost, which counts text). The template's red/green is
a_view_start_keeps_its_token_grant_with_the_measured_template_overhead on his conversation: priced
by text alone the start keeps 20 "ok" turns, 120 tokens as the recorded engine counts them (6 each)
against 32; priced by the allocation estimate it keeps within every grant 32..512, and the recorded
engine count is under the estimate. the_allocation_estimate_errs_high_on_the_recorded_engine: every
probe is estimated at or above the engine's count, and a six-message multi-role conversation counted
at 97 (92 without the 5-token generation suffix) is estimated at 118.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

* One price for a message: the view's start, the final fit and a refusal's refit all estimate through PromptCalibration::estimate

The view's start priced each block by her allocation estimate (text plus the measured template
share) while the final fit and a refusal's refit priced text alone (LlmDeliberationFaculty::
messages_cost): two pricing paths for one fact. Now PromptCalibration::estimate / estimate_all is
the one owner, and every prompt-assembly reader goes through it:

- PromptMessages carries its pricing (set by its one builder from the faculty's binding, and by
  the act's view build to that act's calibration); required_parts, tokens, recent_move_evidence,
  fit_messages (each message and the quiet-tick minimum) and the newest result's levels price with it.
- DeliberationPromptView carries the pricing its messages were estimated with; refit_rejected_prompt
  reprices and rebuilds with it.
- The view build (view tokens, the quiet minimum, the tail budget, the sent sample, the assembled
  context's used tokens), fit_view (view and admitted tokens) and the budget ledger
  (estimate_system for the system message) price through it.

Removed: LlmDeliberationFaculty::messages_cost (no production caller left; tests use
PromptCalibration::default().estimate_all, numerically the same text-only estimate when unmeasured).
message_cost stays as the text part estimate builds on, documented as never a price by itself.
PromptCalibration derives Debug (the view snapshot carries it).

Codex's regression changes one more call for the removal: messages_cost(&rendered) ->
PromptCalibration::default().estimate_all(&rendered) (same number; his test stays green).

Test: the_final_fit_and_a_view_start_price_a_multi_role_sequence_identically: a user turn, a native
call, its result, an assistant turn and a CJK user turn, priced at the recorded engine's template:
the view's start (AllocationEstimate per block) and the final fit (its receipt's history_tokens)
give the same number, and a budget of that number keeps all of it.

The engine's exact quote of the finalized body before generation stays the authority for dispatch.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

* Canary's new view callers price by the caller's oracle: the shed and board tests start and turn over at a cost

Rebasing onto canary (7b7d277) brought tests written against the
character-unit view API (#5815 shed, #5827 collapsed navigation). They
now pass the cost the API requires and read Claim::full. The rebase's
conflict in context_streams/tests.rs had dropped this branch's own
updates to that file; they are re-applied, minus the tally test #5827
moved into blocks.rs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant