Skip to main content
← Back to list
01Issue
FeatureOpenExtensionsPublic
AssigneesNone

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

  1. maxCycles counts entries into the target stage, whoever sent the work there. cycleLimit() in run_ops.ts compares run.entries[stage] with maxCycles plus granted overrides, so every way into implement draws on one shared count.
  2. A second "fix" stage with its own maxCycles doesn'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 every reviews: freshness link would then have to choose the newer of the two.
  3. max-cycles gates 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 while implement has 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 maxCycles and the max-cycles gate 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 validate show 4 or more transitions instead of one rule.

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 id share the budget (for example verify failed and code-review rework).
  • When the budget is used up, the transition behaves like a maxCycles refusal: the run waits, the stage view says which budget closed it, and a person can grant an override (kind: budget, with budget: <id>), recorded like today's cycle overrides.
  • maxCycles stays 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:

  1. Overrides that apply to max-cycles gates (for example a grant_override naming the gate), so the split-transition workaround keeps the normal override flow.
  2. A transition traversal count in CEL (for example transitions["code-review.rework"].count), so a single cel gate 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.
  • validate treats budget-bounded loops as bounded.
  • Existing definitions that use only maxCycles behave exactly as before.
02Bog Flow
◉OPEN○TRIAGED○IN PROGRESS○SHIPPED

Open

11/25/2026, 1:58:14 PM

No activity in this phase yet.

03Sludge Pulse
Editable. Press Enter to edit.

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.