Spotlight #06: Envelope cap enforcement
Source: examples/dogfood/fake/06-envelope-cap-rejection/
What it demonstrates
This spotlight exercises manifest-level budget cap enforcement with clean rejection semantics in a depth-2 dispatch.
Scenario: An operator sets max_sublead_budget_usd = 3.0 as a safety rail. A root lead attempts to spawn a sub-lead with budget_usd = 5.0 (either by bad design or runaway generation). The cap enforcement rejects the spawn cleanly — no partial state, no phantom reservation.
The spotlight proves four things:
-
Cap rejection is pre-state: When the envelope budget exceeds
max_sublead_budget_usd,spawn_subleadreturns an error before any state mutation. No half-spawned sub-lead is registered. -
Error message is actionable: The error names the cap (“exceeds per-sublead cap”), allowing Claude to understand the constraint and retry with a smaller budget.
-
Clean state after rejection: After a rejected spawn:
state.subleadsis empty (no partial registration)reserved_usd == 0(no phantom reservation)
-
Successful retry with compliant budget: Retrying with
budget_usd = 2.0(within the 3.0 cap) succeeds; the sub-lead is registered andreserved_usd = 2.0.
The manifest cap
[[lead]]
allow_subleads = true
max_sublead_budget_usd = 3.0
How to run
cargo test --test dogfood_fake_flows dogfood_envelope_cap_rejection
The test:
- Constructs a
DispatchStatewithmax_sublead_budget_usd = 3.0 - Attempts
spawn_sublead(budget_usd=5.0)→ expects MCP error - Verifies no partial state and no budget reserved
- Retries with
spawn_sublead(budget_usd=2.0)→ expects success
The run.sh script prints instructions pointing to this cargo invocation.
Why pre-state rejection matters
Failing before any state mutation keeps the dispatch state clean and predictable. A half-spawned sub-lead with a phantom budget reservation would be difficult to diagnose and could cause downstream spawn failures or incorrect budget accounting.
Key assertions
See expected-observables.md for the full expected behavior.
Related concepts
- Depth-2 sub-leads —
max_sublead_budget_usdand other manifest caps - Manifest schema —
[[lead]]field reference - Session control —
spawn_subleaderror conditions