Skip to main content

Budget

Struct Budget 

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

Mutable per-execution counters for one script run.

Implementations§

Source§

impl Budget

Source

pub fn start(limits: Limits) -> Self

Starts a fresh budget and its wall clock.

Source

pub fn charge_step(&mut self) -> Result<(), LimitExceeded>

Charges one evaluation step and re-checks the deadline.

This is the only backstop against while true; do :; done. The deadline is re-read on every step rather than every Nth: a script can spend minutes in very few steps (a handful of slow capability calls, one enormous string concatenation), so a sampled clock leaves the exact workloads that most need bounding unbounded. Reading a monotonic clock costs tens of nanoseconds against a tree-walking step that costs far more.

Source

pub fn charge_value_bytes(&mut self, bytes: u64) -> Result<(), LimitExceeded>

Charges value bytes a script materialized into a variable, buffer, or capture.

This counter is deliberately cumulative rather than retained: it bounds how many bytes a script may bring into existence over its whole run, not how many it holds at one instant. Retained memory is always at most the cumulative total, so a cheap bound on the total is a sound bound on the peak, and it needs no release path that a missed call could silently corrupt. Without it, x="$x$x" repeated twenty-six times reaches gigabytes in a few hundred steps — every other ceiling here counts operations, and none of them counts bytes.

Source

pub fn check_deadline(&self) -> Result<(), LimitExceeded>

Re-reads the wall clock immediately.

Source

pub fn remaining(&self) -> Duration

Returns the time left before the deadline trips.

Source

pub fn enter_call(&mut self) -> Result<(), LimitExceeded>

Enters one shell-function frame.

Source

pub fn leave_call(&mut self)

Leaves one shell-function frame.

Source

pub fn charge_capability_call(&mut self) -> Result<(), LimitExceeded>

Charges one capability invocation.

This counter is deliberately independent of the step budget: a single script can loop and drive many capability calls where one model tool call drives exactly one today, so the amplification vector needs its own ceiling.

Source

pub fn capability_calls(&self) -> u32

Returns the number of capability invocations charged so far.

Source

pub fn steps(&self) -> u64

Returns the number of steps charged so far.

Source

pub fn value_bytes(&self) -> u64

Returns the value bytes charged so far.

Trait Implementations§

Source§

impl Debug for Budget

Source§

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

Formats the value using the given formatter. 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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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