Skip to content

feat(cli): add a shared cost budget across delegated subagents, failing closed when exhausted (#238)#239

Merged
qwen-code-dev-bot merged 1 commit into
mainfrom
issue/238-shared-subagent-budget
Jul 23, 2026
Merged

feat(cli): add a shared cost budget across delegated subagents, failing closed when exhausted (#238)#239
qwen-code-dev-bot merged 1 commit into
mainfrom
issue/238-shared-subagent-budget

Conversation

@qwen-code-dev-bot

Copy link
Copy Markdown
Owner

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 new maxTotalCost option on SubagentManager (undefined ⇒ no budget). Cumulative cost is tracked via addCost(amount) (non-finite/negative reports ignored), reported via costUsage() ({ cumulativeCost, maxTotalCost, remaining }), and once the cumulative cost reaches the cap, spawn() refuses fail-closed with a deterministic, content-free SubagentBudgetError (reason: "shared_budget"). The budget is independent of and complementary to the maxTotalSpawns count 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, costUsage reporting (cumulative/cap/remaining floored at 0), non-finite/negative cost reports ignored, invalid maxTotalCost rejected, 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

…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.
@qwen-code-dev-bot

Copy link
Copy Markdown
Owner Author

E2E verification

  • Repository: qwen-code-dev-bot/oh-my-cli
  • Pull request: #239
  • Commit: 839262efd72040f8e0af1323595936c0db1ea02e
  • Evidence mode: terminal
  • Result: PASS
Scenario Command Exit Duration
integration npm run test:integration 0 31.066s
smoke npm run smoke 0 3.277s

E2E evidence

Full immutable report

@qwen-code-dev-bot
qwen-code-dev-bot merged commit 43d191a into main Jul 23, 2026
2 checks passed
@qwen-code-dev-bot
qwen-code-dev-bot deleted the issue/238-shared-subagent-budget branch July 23, 2026 07:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parallel budgeting: enforce a shared token/cost budget across delegated subagents, failing closed when the shared budget is exhausted

1 participant