Skip to content

promoter: fail closed (webhook required with --apply, unreachable API, re-posts, one writer per environment) - #77

Draft
Savid wants to merge 2 commits into
masterfrom
promoter-fail-closed
Draft

Savid wants to merge 2 commits into
masterfrom
promoter-fail-closed

Conversation

@Savid

@Savid Savid commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

The promoter could fail quietly in several ways. This makes each one fail closed, in today's GitHub Actions setup and for any other caller that runs it on a timer.

  • No webhook, no --apply. An applying run or action refuses to start without ROLLOUT_DISCORD_WEBHOOK, before it reads anything. Before, notify() skipped posting when it was empty, so hosts moved and nobody heard. Dry runs and gate are unchanged.
  • Missing deploy branches fail the run. Before, a run whose hosts had no branches said "no host of this environment runs NixOS yet" and exited 0, and a host whose branch was gone was skipped while the rest converged and staged a commit it never ran.
    • The plan now carries installed for each host: true or false from lib.mkFleet's host.json, null for any other host.
    • A host that's installed has its branch, because fleet install pushes it first. When it's missing, the run fails and names it, even when its siblings have theirs.
    • A host the plan can't tell about may not be migrated yet. The run fails only when none of them has its branch: the wrong remote, or a token that can't read them.
    • A lib.mkFleet environment whose hosts all wait to be installed stays a quiet no-op. That matters because the scheduled matrix runs every promoter environment once any one has an installed host.
  • A cluster API that doesn't answer (kubectl exits non-zero) counts as the host in flight not being back yet. It keeps its last flight state, on that state's clock and budget, then halts and posts. Before, load_cluster raised before the run decided anything, so a single server that didn't come back after its reboot made every run error, and none halted or posted.
    • With nothing in flight, the run fails without moving anything.
    • An answer that doesn't parse is still an error.
  • Halts and long waits post again every budgets.repost minutes (default 240), recorded as halted.postedAt and wait.notifiedAt. Before, each posted once.
  • One writer per environment. write_state stops without pushing when the environment's own state file changed since the run read it, which means a second run of the same environment wrote it. A change to another environment's file is still rebuilt on top. Before, it rebuilt on top in both cases and dropped the other run's move.
  • Batched evaluation. Fingerprints are evaluated --eval-batch hosts per nix eval (default 10), so a large fleet isn't one big process.
  • The caller picks the notices' link: ROLLOUT_RUN_URL, with the GitHub Actions run as the fallback.
  • New plan setting approveEvery (default [ ]). The listed later environments take only a commit approved with --action approve, the newest such one, which brings the commits before it. The plan refuses an environment that isn't after the first.

Tested: new tests in test_logic.py and test_promote.py for each point. Each fails on the previous code; the controls pass on both. The rollout-plan check covers the new keys and the settings it refuses. promoter (120 tests), rollout-plan, formatting, fleet-example, fleet-scripts, fleet-rules, workflows and ci pass.

A fleet will notice on its next lock bump:

  • applying runs fail without the webhook secret;
  • halts and long waits post again every 4 hours;
  • a second run of the same environment fails instead of overwriting the first one's state;
  • an unreachable API with a host in flight waits, then halts and posts;
  • environments with more than 10 hosts make more, smaller nix eval calls.

The plan JSON gains installed, approveEvery and budgets.repost. That's fine for lib.rolloutPlan, which comes from the same lock as the promoter; a hand-written plan needs the last two.

Worth reviewing:

  • using the last flight state's budget for an unreachable API (logic.plan_step);
  • treating any non-zero kubectl exit as unreachable, since a restarting server can answer with an error rather than refuse the connection;
  • the blob comparison in Repo.write_state;
  • promote_target's approval walk.

Not verified: real kubectl error texts, and nix eval's memory at the default batch of 10.

…, re-posts, one writer per environment)

- --apply (a run or any action) refuses to start without
  ROLLOUT_DISCORD_WEBHOOK, before it reads anything.
- A run fails when none of the environment's installed hosts in the plan
  has its deploy branch on the remote. The plan now says whether each
  host is installed: lib.mkFleet's host.json, and true for any other host.
- A cluster API that doesn't answer counts as the host in flight not
  being back yet, on its last state's budget, then halts and posts; with
  nothing in flight the run fails without moving anything.
- Halts and long waits post again every budgets.repost minutes (240).
- write_state stops without pushing when the environment's own state file
  changed since the run read it; another environment's change is still
  rebuilt on top.
- Fingerprints are evaluated --eval-batch hosts per nix eval (10).
- ROLLOUT_RUN_URL sets the notices' run link.
- approveEvery: listed later environments take only an approved commit.

@redpandabot redpandabot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

The promoter is hardened in several places: --apply now requires the Discord webhook, an unreachable cluster API becomes a wait/halt instead of an error, halts and long waits re-post, state writes are compare-and-swapped per environment, fingerprint evaluation is batched, and the plan gains approveEvery. The core logic and the new tests line up; I found two gaps in the new installed-host/deploy-branch handling.

Issues

  • 🟡 rollout/promoter/promote.py:699 — one installed host's deleted deploy branch still converges silently — see the thread on that line
  • 🟡 rollout/promoter/promote.py:698 — an environment with no installed hosts records a stale target, not a quiet no-op — An environment whose hosts are all installed: false skips this guard but then goes through choose_target → new_roll, which posts "Rolling …" and saves a target, so it is not the quiet no-op the change describes. When the hosts are later installed their deploy branches sit at the newer install commit, so the first real roll keeps that stale target and halts on provenance ("isn't a fast-forward of branch") until someone abandons it.

Reviewed @ b7b82390
Red pandas make a twittering "huff-quack" — the original microblogging.

# host lib.mkFleet hasn't installed yet has none, and a fleet's
# scheduled run covers its environments whose hosts all wait to be.
installed = [h for h in self.hosts if self.plan["hosts"][h].get("installed", True)]
if installed and not any(refs[h] for h in installed):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 one installed host's deleted deploy branch still converges silently

The guard fails the run only when none of the installed hosts has its deploy branch. If one installed host's branch is deleted (or unreadable) while its siblings' exist, logic.plan_step drops that host from migrated and the environment still converges with "every host runs the target" and stages the commit for the next environment, so production promotes a commit that host never ran — the same silent fail-open this change closes, for the partial case.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, fixed in 3428735. fleet install pushes a host's deploy branch before it installs it, so a host whose host.json says it's installed and that has no branch lost it, or the token can't read it. The run now fails and names it, even when its siblings have their branches.

The plan's installed is now true or false from lib.mkFleet's host.json, and null for a host outside lib.mkFleet. Such a host without its branch may just not be migrated yet, so it keeps the "none of them has one" rule.

Tests: test_an_installed_host_without_its_deploy_branch_fails_the_run (fails with the new check disabled) and test_a_host_the_plan_cant_tell_is_installed_may_lack_its_deploy_branch.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed by 3428735. The guard is no longer all-or-nothing: rollout/promoter/promote.py:703 collects every host whose plan entry is installed: True and has no branch, and step() fails naming it (704–707) before the earlier "none of them has one" rule at 709–716, so a deleted or unreadable branch on one installed host now stops the run even when its siblings' branches exist. That matches the fleet install ordering, and lib/rollout-plan.nix:122 now carries installed = ... or null so hosts outside lib.mkFleet aren't mistaken for installed. Both new tests cover the split (rollout/promoter/test_promote.py:543 for an installed host failing, :555 for a host the plan can't tell about), and the README was updated to separate the two cases.

The remaining behaviour for installed: null hosts (no branch → skipped, converge as before) is now an explicit, documented choice rather than an oversight, so my finding no longer holds.


@ 3428735f

lib.mkFleet's fleet install pushes a host's deploy branch before it
installs it, so a host host.json calls installed that has no branch lost
it, or the token can't read it, and converging without it would stage a
commit it never ran. The plan's installed is now true or false from
host.json and null for any other host, which may not be migrated yet:
those still fail the run only when none of them has its branch.

@redpandabot redpandabot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The promoter now fails closed: applying runs require a Discord webhook, an unreachable cluster API becomes a wait/halt rather than an early error, halts and long waits re-post, state writes detect a competing writer, fingerprints are batched, and approveEvery adds explicit approval for later environments. The new commit closes the remaining gap from the previous review: a lib.mkFleet host marked installed but missing its deploy branch now fails the run instead of converging silently. I found no new code defects; minor note: the PR body still says non-fleet hosts count as installed true, while the final code and README treat them as null (unknown).


Reviewed 9 changed file(s) @ 3428735f — no blocking issues found.
Red pandas make a twittering "huff-quack" — the original microblogging.

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.

1 participant