fix(communication): fail a site command over within the call when the stopped node never received it (#136)

The first mutation (instance deploy) to a site pair whose sticky node was down
returned OUTCOME_UNKNOWN: SitePairChannelProvider.ExecuteAsync treated every
Unavailable on a non-retry-safe command as possibly-applied unless the server
sent the not-dispatched trailer, flipped stickiness, and threw. The retry then
succeeded on the live peer.

A connect-phase failure provably never sent the request, so it is now treated
like the pre-dispatch rejection: GrpcRetrySafety.WasNeverSent recognises
Grpc.Net.Client's subchannel connect failure ("Error connecting to subchannel."
with a SocketException cause) and an HttpRequestException name-resolution /
connection error with a connect-only socket error. Anything that may have been
delivered (reset, premature end, GOAWAY, server Unavailable) stays
OUTCOME_UNKNOWN and is not replayed. The site->central reconcile path uses the
same ProvablyNotApplied rule.

Claude-Session: https://claude.ai/code/session_01GT67ACmpMR7b9LGRPLijMi
This commit is contained in:
Joseph Doherty
2026-11-13 00:22:54 -05:00
parent d7fa31f0b8
commit fd80aeab57
5 changed files with 244 additions and 9 deletions
@@ -35,7 +35,8 @@ public sealed class SiteChannelUnavailableException(string siteId)
/// <remarks>
/// <para>
/// <b>Retry safety.</b> Unavailable can mean a lost response after application. Only explicitly
/// retry-safe operations or a server-owned not-started trailer permit replay on the peer.
/// retry-safe operations, a server-owned not-started trailer, or a connect-phase failure that
/// provably never sent the request (<see cref="GrpcRetrySafety.WasNeverSent"/>) permit replay on the peer.
/// Ambiguous mutations fail with Aborted / OUTCOME_UNKNOWN; the next independent call uses the
/// peer. Deadlines are never replayed. Readiness rejection remains safe before actor dispatch.
/// </para>
@@ -324,16 +325,20 @@ public sealed class SitePairChannelProvider : IDisposable
catch (RpcException ex) when (ex.StatusCode == StatusCode.Unavailable)
{
if (secondary is not null) FlipTo(pair, toIsA: !primaryIsA);
if (!retrySafe && !GrpcRetrySafety.WasNotDispatched(ex))
// ScadaBridge#136: a connect-phase failure (refused / unresolvable — the stopped node of
// a pair) provably never sent the request, so a mutation fails over within this call
// just like an explicit pre-dispatch rejection. Anything that may have been delivered
// stays OUTCOME_UNKNOWN and is never replayed.
if (!retrySafe && !GrpcRetrySafety.ProvablyNotApplied(ex))
throw GrpcRetrySafety.OutcomeUnknown(ex);
if (secondary is null) throw;
// Only reads/idempotent operations or an explicit pre-dispatch rejection may replay.
// Only reads/idempotent operations or a provably unapplied request may replay.
_logger.LogWarning(
"Site {SiteId} node {FromNode} unavailable; failing over to node {ToNode}",
siteId, primaryIsA ? "A" : "B", primaryIsA ? "B" : "A");
try { return await call(secondary, ct).ConfigureAwait(false); }
catch (RpcException retryError) when (retryError.StatusCode == StatusCode.Unavailable
&& !retrySafe && !GrpcRetrySafety.WasNotDispatched(retryError))
&& !retrySafe && !GrpcRetrySafety.ProvablyNotApplied(retryError))
{
throw GrpcRetrySafety.OutcomeUnknown(retryError);
}