pub struct Budget { /* private fields */ }Expand description
Mutable per-execution counters for one script run.
Implementations§
Source§impl Budget
impl Budget
Sourcepub fn charge_step(&mut self) -> Result<(), LimitExceeded>
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.
Sourcepub fn charge_value_bytes(&mut self, bytes: u64) -> Result<(), LimitExceeded>
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.
Sourcepub fn check_deadline(&self) -> Result<(), LimitExceeded>
pub fn check_deadline(&self) -> Result<(), LimitExceeded>
Re-reads the wall clock immediately.
Sourcepub fn enter_call(&mut self) -> Result<(), LimitExceeded>
pub fn enter_call(&mut self) -> Result<(), LimitExceeded>
Enters one shell-function frame.
Sourcepub fn leave_call(&mut self)
pub fn leave_call(&mut self)
Leaves one shell-function frame.
Sourcepub fn charge_capability_call(&mut self) -> Result<(), LimitExceeded>
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.
Sourcepub fn capability_calls(&self) -> u32
pub fn capability_calls(&self) -> u32
Returns the number of capability invocations charged so far.
Sourcepub fn value_bytes(&self) -> u64
pub fn value_bytes(&self) -> u64
Returns the value bytes charged so far.