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
@@ -994,11 +994,41 @@ public sealed class ConfigPublishCoordinator : ReceiveActor, IWithTimers, IWithU
return;
}
// #1111 review: within one deployment an Applied (clean or degraded) ack from a node is never overwritten by a
// later Failed from that node. A node re-applies a deployment only after its OWN Failed (the re-send retry), so a
// Failed arriving after that node's Applied can only be a stale or duplicate delivery of the earlier Failed (the
// gRPC ack sender walks endpoints, and a timed-out call may still have landed). Discarded BEFORE the persist, so
// the row is not flipped back to Failed either.
if (msg.Outcome == ApplyAckOutcome.Failed && HasAppliedAckFrom(msg.NodeId))
{
_log.Info(
"Discarding a late Failed ApplyAck from {Node} for {Id}: that node's Applied ack for this deployment " +
"already arrived (a Failed after Applied is a stale/duplicate delivery of the ack the re-send retry replaced)",
msg.NodeId, msg.DeploymentId);
// The stale Failed may itself be the node's unpersisted entry (its write failed and is on a retry tick that
// re-enters here): drop it, or the deadline would wait on a retry this guard now always discards.
if (_unpersisted.TryGetValue(msg.NodeId, out var parked) && parked.Ack.Outcome == ApplyAckOutcome.Failed)
DropUnpersisted(msg.NodeId);
return;
}
// Persist FIRST: the row is the system of record (driver-only nodes never write their own, and nodes do not
// resend). A throw here used to restart the actor and drop the ack; it is re-queued instead.
StartAckPersist(msg);
}
/// <summary>
/// #1111 review: whether an Applied (clean or degraded) ack of the CURRENT deployment from <paramref name="node"/>
/// has arrived — counted, held for a persist retry, being persisted, or parked behind a write.
/// </summary>
private bool HasAppliedAckFrom(NodeId node) =>
(_acks.TryGetValue(node, out var counted) && counted == ApplyAckOutcome.Applied)
|| (_unpersisted.TryGetValue(node, out var held) && IsAppliedForCurrent(held.Ack))
|| (_persisting.TryGetValue(node, out var inflight) && IsAppliedForCurrent(inflight))
|| (_pendingBehind.TryGetValue(node, out var behind) && IsAppliedForCurrent(behind));
private bool IsAppliedForCurrent(ApplyAck ack) => ack.Outcome == ApplyAckOutcome.Applied && IsForCurrent(ack);
/// <summary>
/// lmxopcua#996 (review H-6): the ack write runs OFF the actor thread and its outcome comes back as
/// <see cref="AckPersisted"/>. The write used to be a blocking <c>SaveChanges</c> in the handler, so with the