pub struct BudgetHandle { /* private fields */ }Expand description
Cheap, cloneable handle for budget checking from the Lua bridge.
Wraps the shared SessionStatus to expose only budget-related queries.
Passed to bridge::register_llm() where it gates every alc.llm()
and alc.llm_batch() call.
§Call site and threading
Both check() and remaining() are called exclusively from Lua
closures registered in bridge.rs, which run on the Lua OS thread.
They acquire std::sync::Mutex<SessionStatus> for a few microseconds
(read-only field comparisons). See SessionStatus doc for full
locking design.
§TOCTOU safety of Lua-side alc.budget_check()
The prelude’s alc.budget_check() calls remaining() then the
caller decides whether to call alc.llm() (which calls check()).
Between remaining() release and check() acquire, llm_calls
could theoretically change — but within a single session this is
structurally impossible: the Lua thread is the only writer path
(via observer callbacks), and observer callbacks only fire after
the Lua thread yields control through the mpsc channel. Lua is
single-threaded and does not yield between budget_check() and
alc.llm().
§Poison policy
check() propagates poison as Err — this surfaces as a Lua error,
which is the correct behavior since a poisoned mutex indicates an
unrecoverable state (OOM panic under lock). remaining() returns
Null on poison — it is observational and non-fatal.
Implementations§
Trait Implementations§
Source§impl Clone for BudgetHandle
impl Clone for BudgetHandle
Source§fn clone(&self) -> BudgetHandle
fn clone(&self) -> BudgetHandle
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more