fix(deploy): #1111 review — Applied wins over a late Failed

Since #1111 a node re-applies a deployment only after its own Failed (the re-send retry), so
two acks from one node for one deployment can differ, and the ORIGINAL Failed can still land
after the retry's Applied (GrpcApplyAckSender's endpoint walk: a timed-out call may have been
delivered). ConfigPublishCoordinator.HandleAck now discards a Failed from a node whose Applied
(clean or degraded) for the current deployment has arrived — counted, persisting, parked behind
a write, or held for a persist retry — before the row write, so neither the count nor the
NodeDeploymentState row flips back. A stale unpersisted Failed is dropped with it so the deadline
never waits on a retry the guard always discards. Applied after a counted Failed still wins.

Residual, documented in docs/Redundancy.md (not corrected after the fact): a late Failed that
CLOSES the deployment before the retry's Applied arrives — re-opening or late-sealing a terminal
deployment would break write-once terminal outcomes (L8) and latest-sealed ordering.

Tests: late Failed after a persisted Applied (clean + degraded), back-to-back Failed racing the
in-flight Applied write (all three fail with the guard disabled), and an Applied-after-Failed
positive control.
This commit is contained in:
Joseph Doherty
2026-12-05 00:52:44 -05:00
parent 9be85f5a94
commit 2fcaffd2ed
4 changed files with 133 additions and 1 deletions
+19
View File
@@ -844,6 +844,25 @@ dial was dropped — either way the deployment sat until the 120 s deadline and
that deployment is still the node's **latest** answer with no other apply's ack held — a stale re-send of an older
failed deployment after a newer one was applied replays `Failed` rather than rolling the node back. `Applied` and
`Applied`+degraded acks keep the replay, so #601's "no repeated re-apply of a degraded revision on re-sends" holds.
- **Central: Applied wins over a late Failed (#1111 review).** Because the node re-applies only after its own `Failed`,
two acks from one node for one deployment can now differ — and the ORIGINAL `Failed` can still arrive after the
retry's `Applied` (`GrpcApplyAckSender` walks the central endpoints, and a call that timed out may still have
landed). Within one deployment `ConfigPublishCoordinator` therefore never lets a `Failed` overwrite that node's
`Applied` (clean or degraded) once the Applied has **arrived** — counted, being persisted, parked behind a write, or
held for a persist retry. The late `Failed` is discarded before its row write (logged at Info), so neither the count
nor the node's `NodeDeploymentState` row flips back. The reverse is unchanged: an `Applied` arriving after a counted
`Failed` still replaces it, as long as the deployment is open.
- **Residual: a late `Failed` that CLOSES the deployment first.** If the stale `Failed` reaches central before the
retry's `Applied` and it completes the expected set (a one-node cluster, or the peer already acked), the deployment is
marked `PartiallyFailed` at once and the retry's `Applied` is then discarded as a stale ack ("Discarding stale ApplyAck").
The node runs the new revision, but central's `Deployment` row reads `PartiallyFailed` and that node's
`NodeDeploymentState` row reads `Failed` (on a fused `Direct` node the node's own row write races central's, so it may
read either). Deliberately NOT corrected after the fact: re-opening a terminal deployment would break
"a terminal outcome is written once" (review L8), sealing it late would give an older deployment a newer
`SealedAtUtc` than one dispatched since — and "latest sealed" drives drift detection and the publish fallback — and
the coordinator keeps no per-deployment state past closure to judge it with. It needs a re-send to reach the node
after its `Failed` was delivered-but-unacknowledged, so it is narrow; it heals on the next deploy (a dispatch of the
same revision short-circuits to `Applied` on a node whose address space is confirmed, and re-applies otherwise).
- **A re-send carries what is left of the deadline (#1111).** `DispatchDeployment.DeadlineRemaining` (proto
`optional int64 deadline_remaining_ms = 5`, additive) is set on every re-send — a RELATIVE duration, so central's
and the node's clocks need not agree — and left unset on the original. A node whose apply was started by such a