feat(cli): add a shared cost budget across delegated subagents, failing closed when exhausted (#238)#239
Merged
Conversation
…ng closed when exhausted (#238) The spawn-count cap (#126) bounds how many subagents a session may spawn and the per-run spend budget (#58) bounds a single run, but nothing bounded the aggregate cost that delegated subagents collectively consume — a parent delegating many children could exhaust resources even within the count limit. Add an opt-in shared cost budget to SubagentManager (maxTotalCost): cumulative cost is tracked via addCost, reported via costUsage, and once the budget is exhausted further delegation is refused fail-closed with a deterministic, content-free SubagentBudgetError — independent of and complementary to the spawn-count cap.
Owner
Author
E2E verification
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an opt-in shared cost budget that bounds the aggregate cost delegated subagents collectively consume, decomposed from roadmap #39 (isolated parallel agents). This is the last slice of #39's roadmap outcome.
The spawn-count cap (#126) bounds how many subagents a session may spawn and the per-run spend budget (#58) bounds a single run, but nothing bounded the aggregate cost that delegated subagents collectively consume — a parent delegating many children could exhaust resources even within the count limit.
Design
src/subagents.ts: a newmaxTotalCostoption onSubagentManager(undefined ⇒ no budget). Cumulative cost is tracked viaaddCost(amount)(non-finite/negative reports ignored), reported viacostUsage()({ cumulativeCost, maxTotalCost, remaining }), and once the cumulative cost reaches the cap,spawn()refuses fail-closed with a deterministic, content-freeSubagentBudgetError(reason: "shared_budget"). The budget is independent of and complementary to themaxTotalSpawnscount cap.Testing
tests/unit/subagents.test.ts(+7 tests): spawns while under budget then refuses once exhausted, independence from the spawn-count cap, no budget when unconfigured,costUsagereporting (cumulative/cap/remaining floored at 0), non-finite/negative cost reports ignored, invalidmaxTotalCostrejected, and a deterministic content-free refusal (no secret/host/label leak).tests/integration/subagents.test.ts(+1 dogfood scenario): a parent delegates read-only research children that report cost; once the shared budget is exhausted the next delegation is refused fail-closed while the parent and completed children are unaffected.Gates: typecheck, build, unit (1674), integration (465 + desktop), smoke (51) all pass.
Closes #238