Skip to main content

ContextBudgetSnapshot

Struct ContextBudgetSnapshot 

Source
pub struct ContextBudgetSnapshot {
    pub context_window_tokens: usize,
    pub overhead_tokens: usize,
    pub overhead_cap_tokens: usize,
    pub working_context_pct: u8,
    pub overhead_pct: u8,
    pub within_budget: bool,
    pub compaction_fired: bool,
    pub compaction_rounds: usize,
    pub lifetime_compaction_alarm_count: u64,
    pub working_context_pct_low_water_mark: Option<u8>,
    pub working_context_pct_sample_count: usize,
    pub lifetime_cadence_floor_breach_count: u64,
}
Expand description

A cached snapshot of the Event::ContextBudget payload (issue #3015 — session.get_context_budget query RPC; surfaced by PR #3014’s GUI status bar, which renders “budget: unavailable” waiting for exactly this API).

Why: Event::ContextBudget above is a per-turn STREAM value, not a queryable one — a client that attaches (or reconnects) between turns has no way to ask “what is the working-context budget right now”; it can only ever see events that arrive while it happens to be subscribed. This is the field-for-field twin of Event::ContextBudget’s payload (deliberately excluding session_id, contextual to the cache slot it lives in) so SessionRegistry can cache the last-recorded measurement per session and session.get_context_budget can hand it back verbatim to a late-attaching client — mirrors IndexReadinessSnapshot exactly. What: every field name and type matches the corresponding field on Event::ContextBudget exactly. SessionRegistry::record_context_budget builds one of these first and derives the Event::ContextBudget it publishes from it, so the two can never disagree. All-Copy (unlike IndexReadinessSnapshot) since every field is a primitive. Test: session::registry_tests::record_context_budget_caches_snapshot_for_late_query, session::protocol_budget::tests::get_context_budget_returns_recorded_snapshot_after_recording.

(issue #3868) lifetime_compaction_alarm_count is additive and, unlike every other field here, has NO twin on Event::ContextBudget — it is deliberately absent from the per-turn stream. Why: the stream event is derived once, at the moment a turn’s cadence measurement lands, from values the caller already computed; the alarm count instead needs a File::open + line-scan of agent_loop::telemetry’s durable, cross-session alarm log, which is too expensive to pay on the EVERY-TURN write path (record_context_budget, called once per cadence tick). It is therefore read fresh only in SessionRegistry::get_context_budget — the actual RPC query path, called once per client poll — which overwrites the field on the cached snapshot right before returning it; the copy record_context_budget stores is a 0 placeholder never observed by a caller. This also means a session that never fires threshold compaction still gets an accurate count reflecting fires from ANY session on this machine, not a stale per-session value baked in at some earlier turn. It answers “has threshold compaction EVER fired under cadence, cumulative across every session on this machine” — a fact with no natural single-turn “stream” moment to attach to.

Fields§

§context_window_tokens: usize§overhead_tokens: usize§overhead_cap_tokens: usize§working_context_pct: u8§overhead_pct: u8§within_budget: bool§compaction_fired: bool§compaction_rounds: usize§lifetime_compaction_alarm_count: u64

(#3868) Lifetime, cross-session count of cadence: Some(_) threshold-compaction fires — epic #2343’s never-event alarm, made durable and reachable from the ONE RPC that’s already the front door for budget state (session.get_context_budget) instead of requiring a second session.get_transcript call.

§working_context_pct_low_water_mark: Option<u8>

(issues #3912, #3948) This SESSION’s lowest working_context_pct across every cadence measurement SessionRegistry has recorded for it — None until the first measurement lands. It exists because the load-realistic compression soak (epic #3866) proved the single most-recent snapshot above (working_context_pct) can read 98-99% while the same session dipped to 48-60% moments earlier; a coarse poll reliably misses the turn where the floor was lowest.

(#3948) Unlike lifetime_compaction_alarm_count above, this is NOT read fresh from a durable log at query time. It is folded in incrementally by SessionRegistry::record_context_budget and lives as long as the session does, which means the value is scoped to the running daemon: a restart drops the session itself, so the RPC answers session_not_found rather than a reset floor. Offline history stays in compression.jsonl, readable via agent_loop::telemetry::session_working_context_floor; that reader aggregates a different sample set (only turns that did compaction work, plus threshold fires), so its floor and this one can differ.

§working_context_pct_sample_count: usize

(issues #3912, #3948) How many cadence measurements working_context_pct_low_water_mark was computed over for this session — lets a consumer distinguish “no samples yet” (None above) from “exactly one, possibly unrepresentative, sample”. Counts live measurements, not durable JSONL rows.

§lifetime_cadence_floor_breach_count: u64

(issue #3911) Lifetime, cross-session count of a cadence-level 60%-floor breach (CadenceOutcome::within_budget == false after cadence::enforce_budget exhausted every eligible entry) — the backstop’s own alarm, mirroring lifetime_compaction_alarm_count exactly but keyed to the cadence mechanism’s OWN floor guarantee rather than the mechanically-independent threshold compactor’s separate 75%-of-window trigger (see agent_loop::telemetry::record_cadence_floor_breach’s docs for why the two alarms cannot be the same counter). Same “placeholder 0 on the write path, real read on the query path” pattern.

Trait Implementations§

Source§

impl Clone for ContextBudgetSnapshot

Source§

fn clone(&self) -> ContextBudgetSnapshot

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 Copy for ContextBudgetSnapshot

Source§

impl Debug for ContextBudgetSnapshot

Source§

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

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

impl<'de> Deserialize<'de> for ContextBudgetSnapshot

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for ContextBudgetSnapshot

Source§

fn eq(&self, other: &ContextBudgetSnapshot) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for ContextBudgetSnapshot

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for ContextBudgetSnapshot

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> AsOut<T> for T
where T: Copy,

Source§

fn as_out(&mut self) -> Out<'_, T>

Returns an out reference to self.
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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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> Same for T

Source§

type Output = T

Should always be Self
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