Skip to content

Distribute the parent's maxTotalChargeUsd across child runs #1139

Description

@B4nan

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request.t-toolingIssues with this label are in the ownership of the tooling team.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions