Relationships
#5093 Stagecraft: cycle budgets per way back (transition), not only per stage entry
Opened by jeremy_schulman · 11/25/2026
Type: feature Title: stagecraft: cycle budgets per way back (transition), not only per stage entry
Summary
maxCycles caps how many times a stage is entered, whoever sent the work there. When two reviews can each send work back to the same stage, there is no way to give each review its own budget. I'd like a cycle budget that can be attached to a way back (a transition, or a group of them). The engine would count it, a person could grant an override on it, and validate and the studio would understand it, just as they do for maxCycles.
Version: @swamp/stagecraft 2026.11.22.2 (swamp 20261123.160012.0).
The situation
A factory with two review stages in series, each able to send the work back to implement:
implement (maxCycles: 3) -> verify -> code-review -> test-review -> release
^ | |
+------- rework --------+--------------+The owner wants:
- code review's send-backs (plus failed checks) capped at 3 entries into
implement, as today; - test review's send-backs capped separately at 3;
- a test-review send-back never using up code review's budget.
Why it can't be expressed today
maxCyclescounts entries into the target stage, whoever sent the work there.cycleLimit()inrun_ops.tscomparesrun.entries[stage]withmaxCyclesplus granted overrides, so every way intoimplementdraws on one shared count.- A second "fix" stage with its own
maxCyclesdoesn't help. Only the declaring stage can record an artifact (run_ops.ts: "stage '…' does not declare artifact"), and artifact names are unique across the definition. The fix stage would need a second change-summary artifact. Every later CEL reference and everyreviews:freshness link would then have to choose the newer of the two. max-cyclesgates come closest, but only half fit. You can split a way back into several transitions that each test entry counts. For example, "code review may rework whileimplementhas been entered fewer than 3 + (test-review entries) times" becomes 4 near-copies of the same transition. That works, with two drawbacks:- Overrides don't reach it. A cycle override raises
maxCyclesand themax-cyclesgate doesn't see it. When the split route closes, a person can't grant one more round. They have to use a manual transition instead, so the normal "needs-cycle-override" flow and its record are lost. - It is hard to read. The studio and
validateshow 4 or more transitions instead of one rule.
- Overrides don't reach it. A cycle override raises
Proposal
A named budget on transitions:
transitions:
- name: rework
to: implement
budget: { id: code-review-sendbacks, max: 2 }- Each time a transition with that budget fires, the budget is spent once. Transitions that share an
idshare the budget (for example verifyfailedand code-reviewrework). - When the budget is used up, the transition behaves like a
maxCyclesrefusal: the run waits, the stage view says which budget closed it, and a person can grant an override (kind: budget, withbudget: <id>), recorded like today's cycle overrides. maxCyclesstays as it is and still applies as the hard ceiling on entries.- Budgets reset on a new era, as entry counts do.
validate: a loop bounded by a budget counts as bounded (no "default-cycle-bound" warning), and "needs-cycle-override" reports budget closures too.- Read-only CEL view (nice to have):
budgets["code-review-sendbacks"]→{ spent, max, granted }, so prompts can tell a reviewer which round it is.
Smaller alternatives that would also unblock this
Either of these would be enough, in order of preference:
- Overrides that apply to
max-cyclesgates (for example agrant_overridenaming the gate), so the split-transition workaround keeps the normal override flow. - A transition traversal count in CEL (for example
transitions["code-review.rework"].count), so a singlecelgate can express the budget. It would still need (1) for overrides.
Acceptance
- One transition per way back, each with its own budget. A send-back from one review never consumes another's budget.
- A used-up budget can be extended by a recorded human override, and the stage view and studio show which budget is closed.
validatetreats budget-bounded loops as bounded.- Existing definitions that use only
maxCyclesbehave exactly as before.
Open
No activity in this phase yet.
system commented 11/25/2026, 1:58:14 PM
Classified automatically when this issue was filed.
- Source: Extensions
If you feel this classification is incorrect, add a ripple to tell us so.
Sign in to post a ripple.