Skip to main content

ContextTracker

Struct ContextTracker 

Source
pub struct ContextTracker { /* private fields */ }
Expand description

The size series for one conversation. In memory only; nothing is stored.

Implementations§

Source§

impl ContextTracker

Source

pub fn new() -> ContextTracker

Source

pub fn carry_into(&mut self, surface: u64)

Carry the series into a new run, or start clean if the request shape changed underneath it.

The series lives on the Conversation rather than on the run, for the reason taint does: it is a fact about the messages, and bundling it with them makes the right thing the default. It matters because in mecha chat and the TUI one submission is one run — so a per-run tracker started empty on every user turn, and the first request of each turn went out unpredicted however heavy the transcript was.

The reset is the other half. An anchor is a measurement under one model, one system prompt and one tool surface; /model replaces all three and would leave the next prediction extrapolating from a tokenizer that is no longer answering. Discarding is the only safe response — there is nothing to convert it to — and it costs one unpredicted turn, which is exactly what every run cost before.

Not fixed by this: a session resumed from disk starts unanchored, because a transcript records what runs cost in total and never what the last request weighed. It predicts from its second turn on.

Source

pub fn observe(&mut self, tokens: u64, bytes: usize)

Record what the provider charged for a list of a known size.

Source

pub fn invalidate(&mut self)

The transcript was rewritten under the last reading, so it is no longer a reading of it. See the module docs — this is the one thing here that can move a decision later, and it does so by discarding a number about a message list that no longer exists rather than by overriding a live one.

Source

pub fn reported(&self) -> Option<u64>

The last measured prompt size, or None when there is not one that describes the current transcript.

Source

pub fn peak_tokens(&self) -> u64

The largest prompt this run ever actually sent. A measurement throughout — never a prediction — because it is recorded, and a recorded estimate is indistinguishable from a recorded fact later.

Source

pub fn predict(&self, bytes: usize) -> Option<u64>

What a request carrying bytes of messages would cost.

None before the first response: with no anchor there is no measurement to extrapolate from, and a guess made entirely of constants would be a tuned parameter wearing a prediction’s clothes.

Source

pub fn over(&self, limit: u64, bytes: usize) -> bool

Is a transcript of this size due a compaction?

reported || predicted, in that order and never the prediction alone. That spelling is the monotonicity guarantee in one line: whatever this type believes, it can only ever add a reason to compact.

Source

pub fn affordable_output_bytes( &self, limit: u64, current_bytes: usize, ) -> Option<usize>

How many bytes of tool output the next turn can take before the transcript crosses limit.

The other half of §4.4’s cliff-to-gradient: the compaction threshold decides when to summarise, and this decides how much a single turn is allowed to add in the first place. They serve one constraint — resolved_output_budget’s docstring already states it — that “one turn’s results must not leap the gap between the threshold and the window itself”. That budget sizes the gap from the window, once, at startup. This sizes it from where the transcript actually is.

Converted at the measured rate rather than the floor, which is the conservative direction: a higher rate buys fewer bytes.

None before the first response, where there is no anchor and so no claim worth making.

Source

pub fn forecast(&self, limit: u64, current_bytes: usize) -> Option<Forecast>

What the model is shown when it looks at its plan.

None before the first response — with no anchor there is no reading, and inventing one would put a guess where the whole point is that every number is measured.

The pace is the mean growth across the recent window, not the last turn’s: a run alternates cheap turns and expensive ones, and the model is deciding between plan steps, which is exactly where one turn is least representative of the next.

Source

pub fn peak_pressure(&self, window: Option<u64>) -> Option<f32>

Share of the window the largest request used, for the record.

Trait Implementations§

Source§

impl Clone for ContextTracker

Source§

fn clone(&self) -> ContextTracker

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ContextTracker

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ContextTracker

Source§

fn default() -> ContextTracker

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more