A pay-per-event orchestrator started with maxTotalChargeUsd has no help keeping its children inside that budget. Each child accepts its own max_total_charge_usd, but splitting the parent's remaining budget across children, adjusting as earlier children finish under their cap, is left to the caller. The orchestrator skill (apify/agent-skills#90) lists this as a must-have, which means agents are currently writing it themselves.
Depends on #1127: the reservations live in the child run registry, and only the registry knows the children after a restart.
Proposal
Treat a child's cap as a reservation against the parent's budget:
- remaining = parent limit − parent's own charge so far − Σ caps of tracked children that are still running
- a named child started without an explicit
max_total_charge_usd gets remaining; an explicit value is capped at remaining. The cap is recorded in the registry when the child starts.
- when a child reaches a terminal state, release
cap − actual charge (from the run's usage_total_usd) back to the budget
Caps are known locally at start time, so the limit holds however many children start concurrently, and recursively for grandchildren since each child's subtree is bounded by its own cap. The delayed cost feed only affects the release step; being late there under-allocates for a while, which is the safe direction.
ChargingManager is the natural owner: it already knows the parent's own charge and limit.
Out of scope
A budget shared across unrelated runs (a "BudgetPool", see the discussion below). In the SDK it would race on a KVS record without compare-and-swap and depend on the delayed cost feed for every decision. The platform has authoritative usage per run, so that belongs there, next to the idempotency key on run start and the parent/child run link.
✍️ Drafted by Claude Code
A pay-per-event orchestrator started with
maxTotalChargeUsdhas no help keeping its children inside that budget. Each child accepts its ownmax_total_charge_usd, but splitting the parent's remaining budget across children, adjusting as earlier children finish under their cap, is left to the caller. The orchestrator skill (apify/agent-skills#90) lists this as a must-have, which means agents are currently writing it themselves.Depends on #1127: the reservations live in the child run registry, and only the registry knows the children after a restart.
Proposal
Treat a child's cap as a reservation against the parent's budget:
max_total_charge_usdgetsremaining; an explicit value is capped atremaining. The cap is recorded in the registry when the child starts.cap − actual charge(from the run'susage_total_usd) back to the budgetCaps are known locally at start time, so the limit holds however many children start concurrently, and recursively for grandchildren since each child's subtree is bounded by its own cap. The delayed cost feed only affects the release step; being late there under-allocates for a while, which is the safe direction.
ChargingManageris the natural owner: it already knows the parent's own charge and limit.Out of scope
A budget shared across unrelated runs (a "BudgetPool", see the discussion below). In the SDK it would race on a KVS record without compare-and-swap and depend on the delayed cost feed for every decision. The platform has authoritative usage per run, so that belongs there, next to the idempotency key on run start and the parent/child run link.
✍️ Drafted by Claude Code