fix(deploy): #949 ask timeout on the deploy trigger is OutcomeUnknown (202 + pre-allocated id), not a failure; slow-compose phase timings

The id is allocated before the ask and travels in StartDeployment, so a timed-out
caller can name and poll the deployment that may still go ahead. REST answers 202
OutcomeUnknown with a Location; the AdminUI shows 'could not be confirmed, may still
be created'; a retry during a running compose gets 409 naming the same id. The actor
logs per-phase timings for composes slower than 3 s.
This commit is contained in:
Joseph Doherty
2026-12-01 19:27:13 -05:00
parent 6b60845931
commit 88c9766ab5
14 changed files with 333 additions and 15 deletions
@@ -233,7 +233,9 @@ public sealed class AdminOperationsActor : ReceiveActor
{
replyTo.Tell(new StartDeploymentResult(
StartDeploymentOutcome.AnotherDeploymentInFlight,
DeploymentId: null,
// The in-flight request's pre-allocated id (#949): a caller retrying after an ask timeout
// learns which deployment is going ahead instead of getting a bare refusal.
DeploymentId: inFlightRequest.DeploymentId,
RevisionHash: null,
Message: $"A deployment requested by {inFlightRequest.CreatedBy} is still being composed.",
msg.CorrelationId));
@@ -373,6 +375,33 @@ public sealed class AdminOperationsActor : ReceiveActor
msg.Request.CorrelationId));
}
/// <summary>Per-phase wall-clock of one deploy compose; logs only when the compose is slow (lmxopcua#949).</summary>
private sealed class ComposePhaseTimer
{
/// <summary>A compose slower than this is logged with its phase breakdown (normal ones take 60-630 ms).</summary>
private static readonly TimeSpan SlowThreshold = TimeSpan.FromSeconds(3);
private readonly System.Diagnostics.Stopwatch _total = System.Diagnostics.Stopwatch.StartNew();
private readonly List<(string Phase, TimeSpan Elapsed)> _phases = new();
private TimeSpan _last = TimeSpan.Zero;
internal void Mark(string phase)
{
var now = _total.Elapsed;
_phases.Add((phase, now - _last));
_last = now;
}
internal void LogIfSlow(Akka.Event.ILoggingAdapter log, StartDeployment msg, string outcome)
{
if (_total.Elapsed < SlowThreshold) return;
log.Warning(
"StartDeployment compose was slow ({Total:F1}s, {Outcome}) for {CreatedBy} (correlation {CorrelationId}, deployment {DeploymentId}); phases: {Phases}",
_total.Elapsed.TotalSeconds, outcome, msg.CreatedBy, msg.CorrelationId, msg.DeploymentId?.ToString() ?? "(unallocated)",
string.Join(", ", _phases.Select(p => $"{p.Phase}={p.Elapsed.TotalMilliseconds:F0}ms")));
}
}
/// <summary>Outcome of the off-actor compose: the reply to send, and the dispatch to issue when Accepted.</summary>
private sealed record ComposeOutcome(StartDeploymentResult Result, DispatchDeployment? Dispatch);
@@ -389,6 +418,11 @@ public sealed class AdminOperationsActor : ReceiveActor
/// </summary>
private async Task<ComposeOutcome> ComposeDeploymentAsync(StartDeployment msg, string sourceNode)
{
// lmxopcua#949: phase timings, logged only when the compose is slow. The one observed 10.5 s compose
// (H4 gate, 2026-11-28) was never explained — the Deployment row's CreatedAtUtc is stamped AFTER the
// snapshot read, so the time went into the lock / read / validate / compose phases, not the insert —
// and nothing recorded which. A repeat now names the phase.
var phases = new ComposePhaseTimer();
await using var db = await _dbFactory.CreateDbContextAsync();
// The singleton update obtains a write lock BEFORE reading the draft. The revision and
// deployment row remain in this same transaction until the sealed artifact is committed.
@@ -401,6 +435,7 @@ public sealed class AdminOperationsActor : ReceiveActor
var locked = await db.Database.ExecuteSqlRawAsync("UPDATE DataConnectionScopeState SET ScopeVersion = ScopeVersion WHERE Id = 1");
if (locked != 1) throw new InvalidOperationException("Authoritative data scope state is unavailable.");
scopeState = await db.DataConnectionScopeStates.SingleAsync(x => x.Id == 1);
phases.Mark("serializable-begin+scope-lock");
}
else
{
@@ -420,6 +455,7 @@ public sealed class AdminOperationsActor : ReceiveActor
// committed/visible when the snapshot is read — operators seeing a spurious one should
// check ExternalIdReservation state before re-submitting.
var draft = await DraftSnapshotFactory.FromConfigDbAsync(db);
phases.Mark("snapshot-read");
var errors = DraftValidator.Validate(draft).ToList();
// Cluster-topology guard. The SQL
@@ -493,8 +529,10 @@ public sealed class AdminOperationsActor : ReceiveActor
foreach (var w in DataConnectionValidator.DeployWarnings(draft))
_log.Warning("StartDeployment: data-connection warning (non-blocking): {Warning}", w);
phases.Mark("validate");
if (errors.Count > 0)
{
phases.LogIfSlow(_log, msg, outcome: "rejected");
var summary = string.Join("; ", errors.Select(e => $"[{e.Code}] {e.Message}"));
_log.Warning("StartDeployment rejected ({Count} validation error(s)): {Summary}",
errors.Count, summary);
@@ -550,7 +588,8 @@ public sealed class AdminOperationsActor : ReceiveActor
scopeState.Fingerprint = scope.Fingerprint;
draft.DataConnectionScopeVersion = scope.Version;
var artifact = ConfigComposer.Compose(draft);
var deploymentId = DeploymentId.NewId();
phases.Mark("compose");
var deploymentId = msg.DeploymentId ?? DeploymentId.NewId();
var revHash = RevisionHash.Parse(artifact.RevisionHash);
db.Deployments.Add(new Deployment
@@ -574,6 +613,8 @@ public sealed class AdminOperationsActor : ReceiveActor
await db.SaveChangesAsync();
if (transaction is not null) await transaction.CommitAsync();
phases.Mark("save+commit");
phases.LogIfSlow(_log, msg, outcome: "accepted");
// Accepted message = the compile-cost advisory (if any) + any Warn-mode TagConfig warnings, so
// the operator sees the non-blocking strictness findings on a successful deploy.