Skip to main content

Module budget

Module budget 

Source
Expand description

Runtime cost-budget enforcement for composition execution.

BudgetedExecutor wraps any StageExecutor and tracks actual cost consumed by each stage using its declared Effect::Cost effects. The accounting uses an AtomicU64 so parallel branches are handled correctly without a mutex.

§Semantics

Cost is deducted before a stage runs. If adding a stage’s declared cost would push spent_cents past budget_cents, the call returns ExecutionError::BudgetExceeded immediately — the stage is never invoked. This is conservative: a stage that fails does not refund its cost.

Parallel branches that collectively exceed the budget will each see the up-to-date atomic counter. The first branch to cross the limit aborts; others may proceed transiently if they add their cost in the same microsecond, but the overall spent total accurately reflects reality.

§Usage

use noether_engine::executor::budget::{BudgetedExecutor, build_cost_map};
use noether_engine::executor::mock::MockExecutor;
use noether_engine::lagrange::CompositionNode;
use noether_store::MemoryStore;

let store = MemoryStore::new();
let cost_map = build_cost_map(&CompositionNode::Const { value: serde_json::Value::Null }, &store);
let inner = MockExecutor::new();
let budgeted = BudgetedExecutor::new(inner, cost_map, 100 /* cents */);

Structs§

BudgetedExecutor
An executor wrapper that enforces a runtime cost budget.

Functions§

build_cost_map
Walk a composition graph and build a map of StageId → declared_cents.