@@ -95,6 +95,7 @@ internal class WorkflowInstance : TaskScheduler, IWorkflowInstance, IWorkflowCon
9595 private bool workflowInitialized ;
9696 private bool applyModernEventLoopLogic ;
9797 private bool dynamicOptionsGetterInvoked ;
98+ private bool inQueryOrValidator ;
9899
99100 /// <summary>
100101 /// Initializes a new instance of the <see cref="WorkflowInstance"/> class.
@@ -352,6 +353,9 @@ public object Instance
352353 /// <inheritdoc />
353354 public bool IsReplaying { get ; private set ; }
354355
356+ /// <inheritdoc />
357+ public bool IsReplayingHistoryEvents => IsReplaying && ! inQueryOrValidator ;
358+
355359 /// <inheritdoc />
356360 public ILogger Logger => replaySafeLogger ;
357361
@@ -1188,12 +1192,20 @@ private Task ApplyDoUpdateAsync(DoUpdate update)
11881192 {
11891193 // Capture command count so we can ensure it is unchanged after call
11901194 var origCmdCount = completion ? . Successful ? . Commands ? . Count ?? 0 ;
1191- inbound . Value . ValidateUpdate ( new (
1192- Id : update . Id ,
1193- Update : update . Name ,
1194- Definition : updateDefn ,
1195- Args : DecodeUpdateArgs ( ) ,
1196- Headers : update . Headers ) ) ;
1195+ try
1196+ {
1197+ inQueryOrValidator = true ;
1198+ inbound . Value . ValidateUpdate ( new (
1199+ Id : update . Id ,
1200+ Update : update . Name ,
1201+ Definition : updateDefn ,
1202+ Args : DecodeUpdateArgs ( ) ,
1203+ Headers : update . Headers ) ) ;
1204+ }
1205+ finally
1206+ {
1207+ inQueryOrValidator = false ;
1208+ }
11971209 // If the command count changed, we need to issue a task failure
11981210 var newCmdCount = completion ? . Successful ? . Commands ? . Count ?? 0 ;
11991211 if ( origCmdCount != newCmdCount )
@@ -1367,6 +1379,7 @@ private void ApplyQueryWorkflow(QueryWorkflow query)
13671379 var origCmdCount = completion ? . Successful ? . Commands ? . Count ;
13681380 try
13691381 {
1382+ inQueryOrValidator = true ;
13701383 WorkflowQueryDefinition ? queryDefn ;
13711384 object ? resultObj ;
13721385
@@ -1437,6 +1450,10 @@ private void ApplyQueryWorkflow(QueryWorkflow query)
14371450 } ) ;
14381451 return Task . CompletedTask ;
14391452 }
1453+ finally
1454+ {
1455+ inQueryOrValidator = false ;
1456+ }
14401457 // Check for commands but don't include null counts in check since Successful is
14411458 // unset by other completion failures
14421459 var newCmdCount = completion ? . Successful ? . Commands ? . Count ;
0 commit comments