Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,38 @@ A `Migration` section is added to any release that bumps `schema_version`.

## [Unreleased]

### Added

- **generate:** `retries` now applies to promote deploys (#626). A promote
deploy that declares `inputs` and `retries` replaces its matrix with one job
per promotion target (`deploy-<name>-to-<env>`, every declared environment
except the first), each gated on preflight's new `deploy_<name>_envs` output
and each reading its resolved inputs from the new
`deploy_<name>_inputs_<env>` outputs, so a retry re-invokes the callback for
only the environment whose attempt failed. A promote deploy without declared
inputs, and the prod deployment job, are already single-environment and get
plain retry ladders, emitted through the same shared shim writer the
orchestrate generator uses. Every promote result sink now judges the
effective result across environments and attempts: the rollback gate fires
only when some environment's ladder is exhausted (never when a retry rescued
it), `DEPLOY_RESULT_<NAME>` stays a single aggregate value
(`failure`/`success`/`skipped`) that drives `cascade promote finalize`'s
pointer gate exactly as the per-job result did, and the GitHub Deployments
status reflects each ladder's effective result. Manifests that do not use
`retries` keep byte-identical promote output, including the matrix form and
its `rollout` handling (`fail_fast`/`max_parallel` do not apply to a deploy
while `retries` fans it out). Two behavior notes for manifests that adopt
`retries` on an inputs deploy: the publish marker (the prerelease → release
advance) is a metadata step, so the fan-out runs no deploy leg for it where
the matrix previously invoked the callback once with
`environment="release"` — no recorded state ever depended on that invocation
(finalize skips the marker for per-deploy rows and preflight plans no
deploys for it); and a single-environment component (an `environments:`
override) has no promotion target, so its inputs deploy keeps the matrix
form there. `run_policy` and `on_failure` remain
orchestrate-only: promote has no dependency skips to bind `run_policy` to,
and the `force` dispatch input is promote's continue-past-failure control.

### Fixed

- **generate:** The promote workflow's rollback jobs no longer thread
Expand Down
6 changes: 4 additions & 2 deletions docs/src/content/docs/guides/promote.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ With `rollback_on_failure: true` (the default), a promotion is all-or-nothing. P

Either way, finalize holds the environment's recorded pointer (`state.<env>.sha` and `state.<env>.version`) at its prior value when any in-scope deploy failed or was cancelled, so recorded state matches what the environment is actually running. The per-deployable rows for the deploys that did succeed are still recorded, so a re-run re-plans and retries only the failed deploy. The environment pointer advances only when every in-scope deploy succeeds.

This is a different knob from `rollout.fail_fast` and `rollout.max_parallel` on a `deploys[].rollout` entry in the manifest. Those two control the GitHub Actions `strategy:` block on that one deploy's matrix job (whether one failed matrix leg cancels the rest, and how many legs run in parallel); `rollback_on_failure` controls what promote does across deploys after a failure. See [the deploy strategy block](/cascade/reference/generated-workflows/#the-deploy-strategy-block) for the manifest-to-YAML mapping. Everything else under `rollout` (`type`, `canary`, `blue_green`) is reserved and has no effect on generated output.
This is a different knob from `rollout.fail_fast` and `rollout.max_parallel` on a `deploys[].rollout` entry in the manifest. Those two control the GitHub Actions `strategy:` block on that one deploy's matrix job (whether one failed matrix leg cancels the rest, and how many legs run in parallel); `rollback_on_failure` controls what promote does across deploys after a failure. A deploy that declares `retries` has no matrix job to tune: it fans out to one job per environment instead, so `fail_fast` and `max_parallel` do not apply to it. See [the deploy strategy block](/cascade/reference/generated-workflows/#the-deploy-strategy-block) for the manifest-to-YAML mapping. Everything else under `rollout` (`type`, `canary`, `blue_green`) is reserved and has no effect on generated output.

A deploy that declares `retries` is retried per environment inside the same run: each per-environment job carries its own retry ladder, and a ladder that rescues an environment does not fire the rollback — only an exhausted ladder does. Finalize still holds the environment pointer when any ladder is exhausted.

## Selective deploys

Expand All @@ -64,7 +66,7 @@ For the release stage, version is the latest semver tag auto-incremented from co
## What to watch

- **Preflight** fails fast on a bad source/target pair, a non-ancestor SHA, or the breaking-change gate; the run log names which one.
- **Deploy jobs** run as a matrix; check each deployable's own job for its callback's output, not just the aggregate status.
- **Deploy jobs** run as a matrix (or, when the deploy declares `retries`, as one job per environment, each with its own retry ladder); check each deployable's own job for its callback's output, not just the aggregate status.
- **Rollback jobs** only appear when `rollback_on_failure: true` and a deploy actually failed; their presence in the run means something needed reverting.
- **Finalize** is where state, changelog, and release actually get written. A promotion that finishes deploy but fails finalize has redeployed without updating recorded state; rerun finalize rather than the whole promotion.

Expand Down
2 changes: 1 addition & 1 deletion docs/src/content/docs/internals/coverage-matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ only under real installation tokens on the fleet, never in the token-free harnes
| Least-privilege permissions | `orchestrate/least-privilege-permissions`, `09-single-env-repo` | least-priv posture (callbacks); gen-time wiring (3env); single-env release posture (single-env) | `internal/generate` | Permissions are scoped to the job that needs them, not the top level |
| OIDC id-token propagation | `orchestrate/callback-permissions-oidc` | OIDC posture at callee (callbacks); gen-time `id-token: write` scoped (3env) | `internal/generate` | `id-token: write` propagates to the caller job without leaking workflow-wide |
| Callback dependency ordering (`depends_on`) | `11-job-timeouts-and-optional-deps` | needs ordering (callbacks); base to app order (3env gen-time) | `internal/generate` | A dependent callback starts only after its prerequisite concludes |
| Callback retry wrapper | `73-deploy-retries` | retry rescue and dependent-of-a-retried-deploy gating (retries); retry-wrapper jobs present (callbacks); retry shim jobs (3env gen-time) | `internal/generate` | The retry jobs are emitted and wired for `retries: N`, including a dependent deploy's `needs:` carrying its dependency's retry shims |
| Callback retry wrapper | `73-deploy-retries`, `promote/promote-retries-exhaustion` | retry rescue and dependent-of-a-retried-deploy gating (retries); retry-wrapper jobs present (callbacks); retry shim jobs (3env gen-time) | `internal/generate` | The retry jobs are emitted and wired for `retries: N`, including a dependent deploy's `needs:` carrying its dependency's retry shims; in promote, a retried deploy with inputs fans out per environment and its exhausted ladder holds the env pointer and arms rollback |
| Signed auto-commit identity (`auto_commits`) | `03-three-env-repo` | auto_commits author and message (3env) | `internal/promote/auto_commit_sha*.go` | The state commit carries the configured author and message |

See [the `auto_commits` field](/cascade/reference/manifest/) in the manifest reference for what a callback must do to trigger this capture.
Expand Down
2 changes: 1 addition & 1 deletion docs/src/content/docs/reference/callbacks.md
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ Callback failures are handled by the `on_failure` policy:

With `retries: N`, a failed callback is retried up to N times before it counts as a final failure. Each retry is a separate job that re-invokes the same reusable workflow, and the chain stops at the first attempt that succeeds. A callback that fails and is then rescued by a retry counts as a success: the run stays green and the deploy is recorded in state.

`run_policy`, `on_failure`, and `retries` apply to trunk runs (`orchestrate.yaml`). They are not emitted into `promote.yaml`; see [Policy fields](/reference/manifest/#policy-fields).
`run_policy` and `on_failure` apply to trunk runs (`orchestrate.yaml`) only; see [Policy fields](/reference/manifest/#policy-fields) for why a promotion has nothing to bind them to. `retries` applies to trunk runs and promotions alike: in a promotion, a deploy with declared inputs fans out to one job per environment so each retry is scoped to the one environment whose attempt failed.

## Migrating from inline `run:`/`shell:` callbacks

Expand Down
2 changes: 2 additions & 0 deletions docs/src/content/docs/reference/generated-workflows.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ jobs:

Only `fail_fast` and `max_parallel` reach this block. `rollout.type`, `rollout.canary`, and `rollout.blue_green` parse and validate but are reserved: they carry zero generator consumption today. See [Progressive rollout](/cascade/reference/versioning/#progressive-rollout) for the full reserved-field list.

A deploy that declares `retries` does not carry this block: with retries, the matrix is replaced by one `deploy-<name>-to-<env>` job per promotion target, each with its own retry ladder, so a retry re-invokes the callback for only the environment whose attempt failed (a matrix reports one aggregate result, and GitHub Actions cannot re-run only a dependency's failed legs). `fail_fast` and `max_parallel` apply to the matrix form only. See [Policy fields](/cascade/reference/manifest/#policy-fields).

### Publish

When the manifest has a `publish:` callback, promote adds a publish step that runs once per build at the prerelease-to-release boundary. It reads `artifact_id` from the source environment's build state and dispatches the publish workflow with `build_name`, `old_version`, `new_version`, `sha`, and `artifact_id`; the callback performs the registry operation (retag, copy, sign).
Expand Down
30 changes: 22 additions & 8 deletions docs/src/content/docs/reference/manifest.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ ci:
| `env_inputs` | emitted | map | {} | Per-environment input overrides. |
| `run_policy` | emitted | string | `default` | Execution policy. See [Policy fields](#policy-fields). |
| `on_failure` | emitted | string | `abort` | Failure handling. See [Policy fields](#policy-fields). |
| `retries` | emitted | int | 0 | Retry attempts (0-3). Trunk runs only. See [Policy fields](#policy-fields). |
| `retries` | emitted | int | 0 | Retry attempts (0-3). Trunk runs and promotions. See [Policy fields](#policy-fields). |

## builds

Expand Down Expand Up @@ -497,9 +497,9 @@ ci:
| `rollout` | partial | object | No | Deploy rollout strategy. See [rollout](#rollout). |
| `state_tags` | emitted (behavior) | list | No | State-capture tags recorded for this deploy. |
| `auto_commits` | emitted (behavior) | bool | No | Captures the advanced HEAD sha, as for builds. |
| `run_policy` | emitted | string | No | Execution policy. |
| `on_failure` | emitted | string | No | Failure handling. |
| `retries` | emitted | int | No | Retry attempts (0-3). |
| `run_policy` | emitted | string | No | Execution policy. Trunk runs only. |
| `on_failure` | emitted | string | No | Failure handling. Trunk runs only. |
| `retries` | emitted | int | No | Retry attempts (0-3). Trunk runs and promotions. See [Policy fields](#policy-fields). |
| `artifact_upload` | emitted | object | No | GitHub Actions artifact passthrough between jobs in one orchestrate run, as for builds (`upload`/`downloads`). |
| `runs_on` | validated-only | object | No | Parsed and validated, never emitted. |
| `concurrency` | validated-only | object | No | Parsed and validated, never emitted. |
Expand Down Expand Up @@ -1069,12 +1069,26 @@ versioning](/cascade/reference/versioning/#per-component-versioning).

`run_policy`, `on_failure`, and `retries` apply to `validate`, each `builds` entry, and each `deploys` entry.

:::caution[Trunk runs only]
These three fields shape `orchestrate.yaml`, the workflow that runs on a trunk merge. They are **not** emitted into `promote.yaml`, so a promotion runs each deploy once, with no retry and no `on_failure` handling.
`retries` applies to both trunk runs and promotions: a failed deploy callback is retried up to N times, each retry a separate job that re-invokes the same reusable workflow, and the chain stops at the first attempt that succeeds. A callback that fails and is then rescued by a retry counts as a success — the run stays green, the deploy is recorded in state, and a promotion's rollback does not fire for it.

:::caution[`run_policy` and `on_failure` shape trunk runs only]
`run_policy` and `on_failure` shape `orchestrate.yaml`, the workflow that runs on a trunk merge. They are **not** emitted into `promote.yaml`:

- `on_failure` supports only `abort` (see below), and a promotion already behaves exactly that way: a deploy failure fails the run and, with `rollback_on_failure`, reverts the deploys that succeeded.
- `run_policy` gates a callback on its dependencies' results, and a promote deploy has no dependency graph to bind the policy to. A promotion dispatches each in-scope deploy for the promotion's environments; the `force` dispatch input is promote's continue-past-failure control.
:::

:::note[How retries works in a promotion]
A promote deploy that declares `inputs` compiles to one job per environment it can be promoted into — every declared environment except the first, which is the promotion source — named `deploy-<name>-to-<env>`. Each job runs only when the promotion includes its environment, and each carries its own retry ladder, so a retry re-invokes the callback for **only the one environment whose attempt failed**. A deploy without declared inputs, and the prod deployment job, are already single-environment and carry plain ladders.

This per-environment shape is what makes caller-side retries sound: a matrix job reports one aggregate result (`failure` if any environment failed), and GitHub Actions offers no way for a calling workflow to re-run only the failed legs of a dependency's matrix, so a retry gated on that aggregate would redeploy the environments that already succeeded.

Every result the promote workflow consumes is judged on the effective result across environments and attempts: the rollback gate fires only when some environment's ladder is exhausted, `DEPLOY_RESULT_<NAME>` reports a single aggregate (`failure` when any ladder is exhausted, `success` when any environment succeeded, `skipped` when nothing ran) that `cascade promote finalize` reads to decide whether the environment pointer advances, and the GitHub Deployments status reflects each ladder's effective result.

`retries` is deliberately not emitted into `promote.yaml`. A promote deploy that declares `inputs` compiles to a matrix job fanned across environments, and a matrix job reports one aggregate result: `failure` if any environment failed. A retry gated on that aggregate would re-invoke the callback for **every** environment, redeploying the ones that already succeeded, and GitHub Actions offers no way for a calling workflow to re-run only the failed legs of a dependency's matrix. Retrying a healthy production environment because an unrelated environment failed is worse than not retrying, so a promote-side retry needs a design that retries per environment. Track it in [issue #626](https://github.com/stablekernel/cascade/issues/626).
Two consequences of the fan-out, stated plainly:

To make a promotion resilient to a transient failure, handle the retry inside the reusable workflow the deploy points at, where it can be scoped to the one environment that failed.
- The per-environment jobs are separate jobs, not matrix legs, so a deploy's [`rollout`](#rollout) settings (`fail_fast`, `max_parallel`) do not apply while `retries` fans it out. A retry-free deploy keeps the matrix form and its `rollout` handling unchanged.
- A promotion's publish marker (the prerelease → release advance) is a metadata step, not a deployable environment, so it runs no per-environment deploy legs.
:::

| `run_policy` | Behavior |
Expand Down
Loading