Skip to content

feat(orchestration): record the image digest on the task Job, as §6.2 specifies - #541

Merged
athvin merged 1 commit into
mainfrom
bm/bluegreen-p13-task-cutover
Nov 5, 2026
Merged

athvin merged 1 commit into
mainfrom
bm/bluegreen-p13-task-cutover

Conversation

@athvin

@athvin athvin commented Nov 5, 2026

Copy link
Copy Markdown
Owner

batch-orchestration-design.md §6.2's Job spec lists er.dupezero.com/image-digest among the annotations. Nothing implemented it — the renderer had no such placeholder, the chart template rendered six labels and four annotations without it, and the digest lived only on the jobs and task_instances rows ("so a deploy mid-run is legible", but only to someone with a database connection).

It matters more now that a cutover is real. With two colours, kubectl get jobs -o custom-columns over this annotation answers "which colour's image is this in-flight attempt running" without opening Postgres — which is the question during a deploy.

An annotation, and that isn't a style choice

sha256: plus 64 hex is 71 characters; a label value caps at 63. The obvious reading — "add the image-digest label" — produces an object the API server rejects. So the test asserts both halves: the value is longer than 63, and no such label exists.

Not an adoption input

§6.2 is explicit that "an image-digest-only difference is adopted because the contract is the fingerprint". Nothing reads this to decide anything; it exists to be read by a person.

The hazard that made this more than a template edit

A template placeholder the renderer doesn't substitute is a launch-time refusal — RenderError::Unsubstituted, because "any surviving ${ER_ is a launch-time refusal". Adding the annotation to the chart alone would have failed every launch.

So the change spans three files: RenderAttempt gains the field, render_job substitutes it, and the executor passes ExecutorConfig::image_digest — which is an Option, because the chart only sets ER_IMAGE_DIGEST {{- with .Values.images.api.digest }}. A tag-based install (kind, make dev-up TAG=…) has none, so it renders empty rather than being omitted: an empty annotation value is legal and reads as "not deployed by digest", where an unsubstituted placeholder would be a refusal.

The check worth keeping

I compared the two sets rather than reading them — every ${ER_…} the chart template emits against every one render_job substitutes:

chart needs:               12 placeholders
renderer substitutes:      12 placeholders
chart placeholders the renderer does NOT substitute:  (none)

That comparison is the durable part. The chart is "the deployed authority" and REFERENCE_TEMPLATE is the in-code fallback, and nothing else makes them agree.

Verification

  • make check green; 22 er-k8s unit tests; charts-check clean.
  • Two new tests: the digest lands as an annotation and not a label (with the >63-character assertion that forces the choice), and an absent digest still substitutes.

Follows the colour stack (#461, #468, #472), all merged.

🤖 Generated with Claude Code

… specifies

`batch-orchestration-design.md` §6.2's Job spec lists
`er.dupezero.com/image-digest` among the annotations. Nothing implemented it:
the renderer had no such placeholder, the chart template rendered six labels
and four annotations without it, and the digest lived only on the `jobs` and
`task_instances` rows — "so a deploy mid-run is legible", but only to someone
with a database connection.

It matters more now that a cutover is a real thing. With two colours, a
`kubectl get jobs -o custom-columns` over this annotation answers "which
colour's image is this in-flight attempt running" without opening Postgres —
which is the question during a deploy.

**An ANNOTATION, and that is not a style choice.** `sha256:` plus 64 hex is 71
characters; a label VALUE caps at 63. The obvious reading of "add the
image-digest label" produces an object the API server rejects, so the test
asserts the value is longer than 63 AND that no such label exists.

**Not an adoption input.** §6.2 is explicit that "an image-digest-only
difference is adopted because the contract is the fingerprint". Nothing reads
this to decide anything; it exists to be read by a person.

**The hazard that made this more than a one-line template edit.** A template
placeholder the renderer does not substitute is a LAUNCH-TIME REFUSAL
(`RenderError::Unsubstituted` — "any surviving `${ER_` is a launch-time
refusal"). Adding the annotation to the chart alone would have failed EVERY
launch. So `RenderAttempt` gains the field, `render_job` substitutes it, and
the executor passes `ExecutorConfig::image_digest` — which is `Option`, because
the chart only sets `ER_IMAGE_DIGEST` `{{- with .Values.images.api.digest }}`.
A tag-based install (kind, `make dev-up TAG=…`) has none, so it renders empty
rather than being omitted: an empty annotation value is legal and reads as "not
deployed by digest", where an unsubstituted placeholder would be a refusal.

Verified by comparing the two sets rather than reading them — every `${ER_…}`
the CHART template emits against every one `render_job` substitutes, exact
match, 12 each. That comparison is the thing worth keeping: the chart is "the
deployed authority" and `REFERENCE_TEMPLATE` is the in-code fallback, and
nothing else makes them agree.

Two tests: the digest lands as an annotation and not a label (with the
>63-character assertion that forces the choice), and an absent digest still
substitutes.

Verified: `make check` green, 22 `er-k8s` unit tests, `charts-check` clean.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@athvin
athvin merged commit 0a4c226 into main Nov 5, 2026
58 of 61 checks passed
athvin pushed a commit that referenced this pull request Nov 5, 2026
… left out)

PR13 (#541) shipped the legibility half of "task pods survive a cutover" — the
`er.dupezero.com/image-digest` annotation that makes a mid-deploy run legible —
but not the proof half. This is the assertion the plan actually asked for.

A task pod's ONLY route to the control plane is `svc/er-api` (`ER_SERVER_URL`
in the task template is `http://er-api.<ns>.svc.cluster.local:8000`), so a
cutover moves its heartbeats, claim renewals and finish call onto a different
er-server process than the one that launched it. If that were visible to a
running attempt, a deploy would fail paying work: a data-path failure caused by
a serving-path deploy.

Phase 6 flips `color.active` with a task in `running` and asserts the attempt
did not notice: settles succeeded, `launches == 1`, and no termination_reason.

`exec-task` has TWO unreachability windows, and getting the assertion right
meant reading which one this phase can actually reach:

  step 1, work order   6 ticks x 10s = 60s, then control_plane_unreachable,
                       exit 3, charged to the launch budget. A task already
                       running is PAST this; a sibling that launches after the
                       flip is not.
  heartbeat thread     posts every 30s, fences after 3 consecutive transport
                       misses (~90s). Step 6 then refuses to post a verdict and
                       writes `fenced` — the work completed and the result is
                       discarded, which is the expensive one.

So the assertion is `termination_reason is None`, not a single named reason.
Asserting only `!= "control_plane_unreachable"` would have been decoration: it
is unreachable in the window this phase creates, so the guard could not have
fired no matter what the cutover did. `is None` covers fenced, sigterm,
stale_start, structural_mismatch and control_plane_unreachable together, and a
succeeded task carries no reason — every writer of the field in er-server
(`skipped`, `control_error`, `config`, `heartbeat_timeout`,
`no_terminal_record`, `DeadlineExceeded`, `build_skew`) is a failure path.

Distinct from phase 2 in what it exercises. The dispatcher is not coloured and
does not restart here, so adoption is not involved; what is proved is that the
attempt's callback path is stateless across the two pods.

Three things done so the phase cannot pass having proved nothing:

- **It refuses a pre-colour chart.** An empty `er.dupezero.com/color` selector
  on `svc/er-api` fails the phase outright, rather than flipping nothing and
  asserting a task succeeded. Observed firing against the stale local kind
  release, which is still on a pre-PR9 chart.
- **It asserts the selector actually moved** after the flip, so a no-op upgrade
  is a failure rather than a pass.
- **`termination_reason` is read by subscript, not `.get()`**, so a renamed or
  dropped field raises KeyError instead of passing on a `None` that only means
  "no such key".

It restores the release afterwards (flip back, then retire — the reverse order
would blackhole the Service for the length of the scale-down), so the probe
stays re-runnable and a later `kind_env.sh up` does not inherit a surprising
active colour.

Note the probe's own port-forward is unaffected and that is not a gap:
`kubectl port-forward svc/...` resolves to one pod when the stream opens and
does not re-resolve, so its reads keep landing on the old colour — which still
runs, because retiring it is the deploy's third phase. Both colours read the
same Postgres. The flip is proved by the selector assertion, not by where curl
lands.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
athvin pushed a commit that referenced this pull request Nov 5, 2026
… left out)

PR13 (#541) shipped the legibility half of "task pods survive a cutover" — the
`er.dupezero.com/image-digest` annotation that makes a mid-deploy run legible —
but not the proof half. This is the assertion the plan actually asked for.

A task pod's ONLY route to the control plane is `svc/er-api` (`ER_SERVER_URL`
in the task template is `http://er-api.<ns>.svc.cluster.local:8000`), so a
cutover moves its heartbeats, claim renewals and finish call onto a different
er-server process than the one that launched it. If that were visible to a
running attempt, a deploy would fail paying work: a data-path failure caused by
a serving-path deploy.

Phase 6 flips `color.active` with a task in `running` and asserts the attempt
did not notice: settles succeeded, `launches == 1`, and no termination_reason.

`exec-task` has TWO unreachability windows, and getting the assertion right
meant reading which one this phase can actually reach:

  step 1, work order   6 ticks x 10s = 60s, then control_plane_unreachable,
                       exit 3, charged to the launch budget. A task already
                       running is PAST this; a sibling that launches after the
                       flip is not.
  heartbeat thread     posts every 30s, fences after 3 consecutive transport
                       misses (~90s). Step 6 then refuses to post a verdict and
                       writes `fenced` — the work completed and the result is
                       discarded, which is the expensive one.

So the assertion is `termination_reason is None`, not a single named reason.
Asserting only `!= "control_plane_unreachable"` would have been decoration: it
is unreachable in the window this phase creates, so the guard could not have
fired no matter what the cutover did. `is None` covers fenced, sigterm,
stale_start, structural_mismatch and control_plane_unreachable together, and a
succeeded task carries no reason — every writer of the field in er-server
(`skipped`, `control_error`, `config`, `heartbeat_timeout`,
`no_terminal_record`, `DeadlineExceeded`, `build_skew`) is a failure path.

Distinct from phase 2 in what it exercises. The dispatcher is not coloured and
does not restart here, so adoption is not involved; what is proved is that the
attempt's callback path is stateless across the two pods.

Three things done so the phase cannot pass having proved nothing:

- **It refuses a pre-colour chart.** An empty `er.dupezero.com/color` selector
  on `svc/er-api` fails the phase outright, rather than flipping nothing and
  asserting a task succeeded. Observed firing against the stale local kind
  release, which is still on a pre-PR9 chart.
- **It asserts the selector actually moved** after the flip, so a no-op upgrade
  is a failure rather than a pass.
- **`termination_reason` is read by subscript, not `.get()`**, so a renamed or
  dropped field raises KeyError instead of passing on a `None` that only means
  "no such key".

It restores the release afterwards (flip back, then retire — the reverse order
would blackhole the Service for the length of the scale-down), so the probe
stays re-runnable and a later `kind_env.sh up` does not inherit a surprising
active colour.

Note the probe's own port-forward is unaffected and that is not a gap:
`kubectl port-forward svc/...` resolves to one pod when the stream opens and
does not re-resolve, so its reads keep landing on the old colour — which still
runs, because retiring it is the deploy's third phase. Both colours read the
same Postgres. The flip is proved by the selector assertion, not by where curl
lands.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
athvin pushed a commit that referenced this pull request Nov 5, 2026
… left out)

PR13 (#541) shipped the legibility half of "task pods survive a cutover" — the
`er.dupezero.com/image-digest` annotation that makes a mid-deploy run legible —
but not the proof half. This is the assertion the plan actually asked for.

A task pod's ONLY route to the control plane is `svc/er-api` (`ER_SERVER_URL`
in the task template is `http://er-api.<ns>.svc.cluster.local:8000`), so a
cutover moves its heartbeats, claim renewals and finish call onto a different
er-server process than the one that launched it. If that were visible to a
running attempt, a deploy would fail paying work: a data-path failure caused by
a serving-path deploy.

Phase 6 flips `color.active` with a task in `running` and asserts the attempt
did not notice: settles succeeded, `launches == 1`, and no termination_reason.

`exec-task` has TWO unreachability windows, and getting the assertion right
meant reading which one this phase can actually reach:

  step 1, work order   6 ticks x 10s = 60s, then control_plane_unreachable,
                       exit 3, charged to the launch budget. A task already
                       running is PAST this; a sibling that launches after the
                       flip is not.
  heartbeat thread     posts every 30s, fences after 3 consecutive transport
                       misses (~90s). Step 6 then refuses to post a verdict and
                       writes `fenced` — the work completed and the result is
                       discarded, which is the expensive one.

So the assertion is `termination_reason is None`, not a single named reason.
Asserting only `!= "control_plane_unreachable"` would have been decoration: it
is unreachable in the window this phase creates, so the guard could not have
fired no matter what the cutover did. `is None` covers fenced, sigterm,
stale_start, structural_mismatch and control_plane_unreachable together, and a
succeeded task carries no reason — every writer of the field in er-server
(`skipped`, `control_error`, `config`, `heartbeat_timeout`,
`no_terminal_record`, `DeadlineExceeded`, `build_skew`) is a failure path.

Distinct from phase 2 in what it exercises. The dispatcher is not coloured and
does not restart here, so adoption is not involved; what is proved is that the
attempt's callback path is stateless across the two pods.

Three things done so the phase cannot pass having proved nothing:

- **It refuses a pre-colour chart.** An empty `er.dupezero.com/color` selector
  on `svc/er-api` fails the phase outright, rather than flipping nothing and
  asserting a task succeeded. Observed firing against the stale local kind
  release, which is still on a pre-PR9 chart.
- **It asserts the selector actually moved** after the flip, so a no-op upgrade
  is a failure rather than a pass.
- **`termination_reason` is read by subscript, not `.get()`**, so a renamed or
  dropped field raises KeyError instead of passing on a `None` that only means
  "no such key".

It restores the release afterwards (flip back, then retire — the reverse order
would blackhole the Service for the length of the scale-down), so the probe
stays re-runnable and a later `kind_env.sh up` does not inherit a surprising
active colour.

Note the probe's own port-forward is unaffected and that is not a gap:
`kubectl port-forward svc/...` resolves to one pod when the stream opens and
does not re-resolve, so its reads keep landing on the old colour — which still
runs, because retiring it is the deploy's third phase. Both colours read the
same Postgres. The flip is proved by the selector assertion, not by where curl
lands.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
athvin pushed a commit that referenced this pull request Nov 5, 2026
… left out)

PR13 (#541) shipped the legibility half of "task pods survive a cutover" — the
`er.dupezero.com/image-digest` annotation that makes a mid-deploy run legible —
but not the proof half. This is the assertion the plan actually asked for.

A task pod's ONLY route to the control plane is `svc/er-api` (`ER_SERVER_URL`
in the task template is `http://er-api.<ns>.svc.cluster.local:8000`), so a
cutover moves its heartbeats, claim renewals and finish call onto a different
er-server process than the one that launched it. If that were visible to a
running attempt, a deploy would fail paying work: a data-path failure caused by
a serving-path deploy.

Phase 6 flips `color.active` with a task in `running` and asserts the attempt
did not notice: settles succeeded, `launches == 1`, and no termination_reason.

`exec-task` has TWO unreachability windows, and getting the assertion right
meant reading which one this phase can actually reach:

  step 1, work order   6 ticks x 10s = 60s, then control_plane_unreachable,
                       exit 3, charged to the launch budget. A task already
                       running is PAST this; a sibling that launches after the
                       flip is not.
  heartbeat thread     posts every 30s, fences after 3 consecutive transport
                       misses (~90s). Step 6 then refuses to post a verdict and
                       writes `fenced` — the work completed and the result is
                       discarded, which is the expensive one.

So the assertion is `termination_reason is None`, not a single named reason.
Asserting only `!= "control_plane_unreachable"` would have been decoration: it
is unreachable in the window this phase creates, so the guard could not have
fired no matter what the cutover did. `is None` covers fenced, sigterm,
stale_start, structural_mismatch and control_plane_unreachable together, and a
succeeded task carries no reason — every writer of the field in er-server
(`skipped`, `control_error`, `config`, `heartbeat_timeout`,
`no_terminal_record`, `DeadlineExceeded`, `build_skew`) is a failure path.

Distinct from phase 2 in what it exercises. The dispatcher is not coloured and
does not restart here, so adoption is not involved; what is proved is that the
attempt's callback path is stateless across the two pods.

Three things done so the phase cannot pass having proved nothing:

- **It refuses a pre-colour chart.** An empty `er.dupezero.com/color` selector
  on `svc/er-api` fails the phase outright, rather than flipping nothing and
  asserting a task succeeded. Observed firing against the stale local kind
  release, which is still on a pre-PR9 chart.
- **It asserts the selector actually moved** after the flip, so a no-op upgrade
  is a failure rather than a pass.
- **`termination_reason` is read by subscript, not `.get()`**, so a renamed or
  dropped field raises KeyError instead of passing on a `None` that only means
  "no such key".

It restores the release afterwards (flip back, then retire — the reverse order
would blackhole the Service for the length of the scale-down), so the probe
stays re-runnable and a later `kind_env.sh up` does not inherit a surprising
active colour.

Note the probe's own port-forward is unaffected and that is not a gap:
`kubectl port-forward svc/...` resolves to one pod when the stream opens and
does not re-resolve, so its reads keep landing on the old colour — which still
runs, because retiring it is the deploy's third phase. Both colours read the
same Postgres. The flip is proved by the selector assertion, not by where curl
lands.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
athvin pushed a commit that referenced this pull request Nov 5, 2026
… left out)

PR13 (#541) shipped the legibility half of "task pods survive a cutover" — the
`er.dupezero.com/image-digest` annotation that makes a mid-deploy run legible —
but not the proof half. This is the assertion the plan actually asked for.

A task pod's ONLY route to the control plane is `svc/er-api` (`ER_SERVER_URL`
in the task template is `http://er-api.<ns>.svc.cluster.local:8000`), so a
cutover moves its heartbeats, claim renewals and finish call onto a different
er-server process than the one that launched it. If that were visible to a
running attempt, a deploy would fail paying work: a data-path failure caused by
a serving-path deploy.

Phase 6 flips `color.active` with a task in `running` and asserts the attempt
did not notice: settles succeeded, `launches == 1`, and no termination_reason.

`exec-task` has TWO unreachability windows, and getting the assertion right
meant reading which one this phase can actually reach:

  step 1, work order   6 ticks x 10s = 60s, then control_plane_unreachable,
                       exit 3, charged to the launch budget. A task already
                       running is PAST this; a sibling that launches after the
                       flip is not.
  heartbeat thread     posts every 30s, fences after 3 consecutive transport
                       misses (~90s). Step 6 then refuses to post a verdict and
                       writes `fenced` — the work completed and the result is
                       discarded, which is the expensive one.

So the assertion is `termination_reason is None`, not a single named reason.
Asserting only `!= "control_plane_unreachable"` would have been decoration: it
is unreachable in the window this phase creates, so the guard could not have
fired no matter what the cutover did. `is None` covers fenced, sigterm,
stale_start, structural_mismatch and control_plane_unreachable together, and a
succeeded task carries no reason — every writer of the field in er-server
(`skipped`, `control_error`, `config`, `heartbeat_timeout`,
`no_terminal_record`, `DeadlineExceeded`, `build_skew`) is a failure path.

Distinct from phase 2 in what it exercises. The dispatcher is not coloured and
does not restart here, so adoption is not involved; what is proved is that the
attempt's callback path is stateless across the two pods.

Three things done so the phase cannot pass having proved nothing:

- **It refuses a pre-colour chart.** An empty `er.dupezero.com/color` selector
  on `svc/er-api` fails the phase outright, rather than flipping nothing and
  asserting a task succeeded. Observed firing against the stale local kind
  release, which is still on a pre-PR9 chart.
- **It asserts the selector actually moved** after the flip, so a no-op upgrade
  is a failure rather than a pass.
- **`termination_reason` is read by subscript, not `.get()`**, so a renamed or
  dropped field raises KeyError instead of passing on a `None` that only means
  "no such key".

It restores the release afterwards (flip back, then retire — the reverse order
would blackhole the Service for the length of the scale-down), so the probe
stays re-runnable and a later `kind_env.sh up` does not inherit a surprising
active colour.

Note the probe's own port-forward is unaffected and that is not a gap:
`kubectl port-forward svc/...` resolves to one pod when the stream opens and
does not re-resolve, so its reads keep landing on the old colour — which still
runs, because retiring it is the deploy's third phase. Both colours read the
same Postgres. The flip is proved by the selector assertion, not by where curl
lands.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
athvin pushed a commit that referenced this pull request Nov 6, 2026
… left out)

PR13 (#541) shipped the legibility half of "task pods survive a cutover" — the
`er.dupezero.com/image-digest` annotation that makes a mid-deploy run legible —
but not the proof half. This is the assertion the plan actually asked for.

A task pod's ONLY route to the control plane is `svc/er-api` (`ER_SERVER_URL`
in the task template is `http://er-api.<ns>.svc.cluster.local:8000`), so a
cutover moves its heartbeats, claim renewals and finish call onto a different
er-server process than the one that launched it. If that were visible to a
running attempt, a deploy would fail paying work: a data-path failure caused by
a serving-path deploy.

Phase 6 flips `color.active` with a task in `running` and asserts the attempt
did not notice: settles succeeded, `launches == 1`, and no termination_reason.

`exec-task` has TWO unreachability windows, and getting the assertion right
meant reading which one this phase can actually reach:

  step 1, work order   6 ticks x 10s = 60s, then control_plane_unreachable,
                       exit 3, charged to the launch budget. A task already
                       running is PAST this; a sibling that launches after the
                       flip is not.
  heartbeat thread     posts every 30s, fences after 3 consecutive transport
                       misses (~90s). Step 6 then refuses to post a verdict and
                       writes `fenced` — the work completed and the result is
                       discarded, which is the expensive one.

So the assertion is `termination_reason is None`, not a single named reason.
Asserting only `!= "control_plane_unreachable"` would have been decoration: it
is unreachable in the window this phase creates, so the guard could not have
fired no matter what the cutover did. `is None` covers fenced, sigterm,
stale_start, structural_mismatch and control_plane_unreachable together, and a
succeeded task carries no reason — every writer of the field in er-server
(`skipped`, `control_error`, `config`, `heartbeat_timeout`,
`no_terminal_record`, `DeadlineExceeded`, `build_skew`) is a failure path.

Distinct from phase 2 in what it exercises. The dispatcher is not coloured and
does not restart here, so adoption is not involved; what is proved is that the
attempt's callback path is stateless across the two pods.

Three things done so the phase cannot pass having proved nothing:

- **It refuses a pre-colour chart.** An empty `er.dupezero.com/color` selector
  on `svc/er-api` fails the phase outright, rather than flipping nothing and
  asserting a task succeeded. Observed firing against the stale local kind
  release, which is still on a pre-PR9 chart.
- **It asserts the selector actually moved** after the flip, so a no-op upgrade
  is a failure rather than a pass.
- **`termination_reason` is read by subscript, not `.get()`**, so a renamed or
  dropped field raises KeyError instead of passing on a `None` that only means
  "no such key".

It restores the release afterwards (flip back, then retire — the reverse order
would blackhole the Service for the length of the scale-down), so the probe
stays re-runnable and a later `kind_env.sh up` does not inherit a surprising
active colour.

Note the probe's own port-forward is unaffected and that is not a gap:
`kubectl port-forward svc/...` resolves to one pod when the stream opens and
does not re-resolve, so its reads keep landing on the old colour — which still
runs, because retiring it is the deploy's third phase. Both colours read the
same Postgres. The flip is proved by the selector assertion, not by where curl
lands.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
athvin added a commit that referenced this pull request Nov 6, 2026
… left out) (#610)

* test(kind): prove a task pod survives a colour cutover (the half PR13 left out)

PR13 (#541) shipped the legibility half of "task pods survive a cutover" — the
`er.dupezero.com/image-digest` annotation that makes a mid-deploy run legible —
but not the proof half. This is the assertion the plan actually asked for.

A task pod's ONLY route to the control plane is `svc/er-api` (`ER_SERVER_URL`
in the task template is `http://er-api.<ns>.svc.cluster.local:8000`), so a
cutover moves its heartbeats, claim renewals and finish call onto a different
er-server process than the one that launched it. If that were visible to a
running attempt, a deploy would fail paying work: a data-path failure caused by
a serving-path deploy.

Phase 6 flips `color.active` with a task in `running` and asserts the attempt
did not notice: settles succeeded, `launches == 1`, and no termination_reason.

`exec-task` has TWO unreachability windows, and getting the assertion right
meant reading which one this phase can actually reach:

  step 1, work order   6 ticks x 10s = 60s, then control_plane_unreachable,
                       exit 3, charged to the launch budget. A task already
                       running is PAST this; a sibling that launches after the
                       flip is not.
  heartbeat thread     posts every 30s, fences after 3 consecutive transport
                       misses (~90s). Step 6 then refuses to post a verdict and
                       writes `fenced` — the work completed and the result is
                       discarded, which is the expensive one.

So the assertion is `termination_reason is None`, not a single named reason.
Asserting only `!= "control_plane_unreachable"` would have been decoration: it
is unreachable in the window this phase creates, so the guard could not have
fired no matter what the cutover did. `is None` covers fenced, sigterm,
stale_start, structural_mismatch and control_plane_unreachable together, and a
succeeded task carries no reason — every writer of the field in er-server
(`skipped`, `control_error`, `config`, `heartbeat_timeout`,
`no_terminal_record`, `DeadlineExceeded`, `build_skew`) is a failure path.

Distinct from phase 2 in what it exercises. The dispatcher is not coloured and
does not restart here, so adoption is not involved; what is proved is that the
attempt's callback path is stateless across the two pods.

Three things done so the phase cannot pass having proved nothing:

- **It refuses a pre-colour chart.** An empty `er.dupezero.com/color` selector
  on `svc/er-api` fails the phase outright, rather than flipping nothing and
  asserting a task succeeded. Observed firing against the stale local kind
  release, which is still on a pre-PR9 chart.
- **It asserts the selector actually moved** after the flip, so a no-op upgrade
  is a failure rather than a pass.
- **`termination_reason` is read by subscript, not `.get()`**, so a renamed or
  dropped field raises KeyError instead of passing on a `None` that only means
  "no such key".

It restores the release afterwards (flip back, then retire — the reverse order
would blackhole the Service for the length of the scale-down), so the probe
stays re-runnable and a later `kind_env.sh up` does not inherit a surprising
active colour.

Note the probe's own port-forward is unaffected and that is not a gap:
`kubectl port-forward svc/...` resolves to one pod when the stream opens and
does not re-resolve, so its reads keep landing on the old colour — which still
runs, because retiring it is the deploy's third phase. Both colours read the
same Postgres. The flip is proved by the selector assertion, not by where curl
lands.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* test(kind): mutation-test the probe's assertions on every PR that touches them

Phase 6 was nearly shipped with an assertion that could not fail, and the
two-hour nightly run would have reported green. This makes that class of
mistake catchable in about a second.

The assertion was `termination_reason != "control_plane_unreachable"` on a task
caught in `running`. Reading exec_task.rs afterwards: that reason is written at
exactly ONE site, the step-1 work-order loop, which a running task has already
passed. The reachable mid-run failure is `fenced`, from the heartbeat thread
after three missed posts. So the guard's precondition could not hold.

Why a per-PR test rather than trusting the nightly: **an assertion that can no
longer fail makes the probe GREENER, not redder**, so the nightly cannot detect
its own neutering. And the probe is the least-exercised correctness-critical
code here — a cluster, an image build and two hours, once a day.

`scripts/ci/kind-assertions-test.sh`, following the `tf-helpers-test.sh` /
`merge-bus-test.sh` pattern:

- Every embedded assertion block must compile. Cheap coverage for the phases
  this does not mutate, whose syntax errors would otherwise surface two hours
  in, after five phases of real work.
- Ten mutants of the phase 6 ledger — `fenced`, `control_plane_unreachable`,
  `sigterm`, `stale_start`, a relaunch, a non-succeeded state, a missing
  field, an empty live set, and one bad row among good ones. Each must be
  REFUSED; a mutant that still exits 0 is an assertion that cannot
  discriminate.
- The three bash guards must still be present (textual, deliberately: proving
  those work costs a cluster, but proving nobody deleted them is free).
- Exits 2 if it finds fewer than two blocks to examine — rename detection, so
  a changed heredoc shape cannot read as a pass.

The blocks are EXTRACTED from check_kind.sh, never transcribed; a copy would
be a second source of truth, and the drift would show up as this test passing
against code the probe no longer runs.

**The test was mutation-tested itself**, which is what found the one real gap.
Narrowing the assertion back to the unreachable reason, deleting a bash guard,
and breaking the heredoc shape were all caught. Deleting the
`"termination_reason" in t` guard was NOT: the subscript beside it raises
KeyError anyway, so it is a behaviourally equivalent mutant and no exit code
can distinguish it. What that guard actually buys is the diagnosis — a named
AssertionError about the ledger shape instead of a bare KeyError traceback
surfacing two hours into a nightly. So that case now asserts the message, not
just the refusal, and the mutant is caught.

Wiring: a `pull_request` trigger with a `paths:` filter, plus a new
`assertions` job; `probe` gains `if: github.event_name != 'pull_request'` so
the 2h run never fires on a PR. The `paths:` filter is safe ONLY because
nothing in this workflow is a required status check — on rust.yml or
frontend.yml the same filter would leave a required context permanently
unreported, which is why those use a `detect` job instead.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* test(kind): check the probe's routes against the router, per-PR

#622 fixed the probe calling `POST /v1/orgs/{org}/jobs`, a route that stopped
existing when the datasets work made every job route dataset-scoped on
2026-11-04. That PR noted the gate belonged here, in the file this PR
introduces, rather than duplicated alongside the fix. This is it.

The bug was as cheap to detect as bugs get — a path that is right there in the
router, or is not — and it survived two days because every instrument that
could have caught it was the wrong shape: kind.yml is nightly and not a
required check, two of its three runs were `steps_sum=0` outage no-starts, and
the one that did report surfaced a 404 as a bare JSONDecodeError naming neither
the request nor the status.

So: extract every `/v1` path the probe calls, normalise its shell
interpolations to the router's placeholder form, and require each one to be a
route `er-server` actually declares. No cluster, no network, ~instant.

Three properties that keep it from passing on nothing:

- **`SUBST` is explicit and unmapped variables FAIL.** A silent fallback would
  turn an interpolation nobody taught it about into a false pass, which is the
  failure mode this whole file exists to prevent.
- **Fewer than 20 routes parsed exits 2** — if the router's declaration shape
  changes, that is a broken extraction, not a clean bill of health.
- **Zero probe call sites found exits 2.** The probe cannot be calling nothing.

Observed failing against the real bug rather than a contrived one: regressing
that one path back to its pre-datasets form gives

    FAIL  the probe calls /v1/orgs/${ORG}/jobs, which normalises to
          /v1/orgs/{org}/jobs — no such route in er-server. It will 404.

and the clean tree reports `(checked 8 probe paths against 114 routes)`.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* test(kind): phase 6 needs three pods the CPU budget never counted

#624 made a task pod schedulable by dropping the executor classes from a full
CPU to 250m, against a steady state of 1.55 on a 2-vCPU runner. That is
sufficient for phases 1 to 5, which add exactly one pod. It is not sufficient
for phase 6, which is the only phase that adds three:

  the idle colour's web-api   scaled to replicas: 1 for the cutover
  a task pod                  caught mid-attempt, by design
  er-schema-migrate           a PRE-UPGRADE hook, so every `helm upgrade`
                              re-fires it — including the `color.active` flip
                              that happens while the task is in flight

At the old numbers that peaks at 2.15 of ~2.0, and the pod that loses is
whichever asks last. The symptom would have been a five-minute `helm --wait`
timeout or a 420s wait on a job whose pod never started — the same
misattribution that made #624 take three runs to find, since a Pending pod
reports as a timeout about a job rather than as a scheduling refusal.

Three changes, none of which raises the ceiling by guesswork:

`values-kind.yaml` trims the api and dispatcher CPU REQUESTS to 100m. That is
the lever rather than the executor classes because three pods carry it during
phase 6 and only one carries a class. Requests only — the limits stay at the
chart's `cpu: "1"`, so a 100m er-server still bursts to a full core and
`ensure_schema` is untouched. Verified by rendering the profile: requests
100m, limits 1, memory limits intact. Steady state 1.25, phase 6 peak 1.70.

`check_kind.sh` gains a `cpu_budget` helper and asserts the 450m phase 6 needs
BEFORE the phase runs, so an over-committed node fails with both figures in
one sentence instead of as a timeout several minutes later. It also logs the
budget unconditionally rather than only on failure: #624 added that diagnostic
under `if: failure()`, which means a green run never records allocatable CPU —
and the budget is precisely the number that has to be re-derived every time
this moves. Tested against a live kind cluster, where it reproduced the
`cpu 1550m` that `kubectl describe node` reports.

`kind-assertions-test.sh` adds the preflight to its list of textual guards.
Deleting that assertion does not make phase 6 fail; it makes phase 6 fail
later and about something else, so its removal is invisible to every other
check here. Observed failing against a mutant, with the substitution count
asserted so a regex that matched nothing could not pass.

er-db-migrate is deliberately absent from the sums: it is guarded by
`web.enabled`, off in this profile. Checked by rendering, not assumed.

---------

Co-authored-by: bmoore813 <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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.

2 participants