Please have a look at the fetchHistoricActivityInstances method of the ActivityInstanceFetcher class.
- Current Timestamp is 1.
- the last page of historic activity instances is fetched using the finishedAfter 1 query
- afterwards, to import other entities that might have been missed due to pagination, a second query is performed, importing all instances with the same endtime of the last imported instance (still 1)
- later, the timestamp is increased by one millisecond for the next page
- If an entity is added to the engine database after the second query is performed, but before the millisecond is over (so it also has the timestamp 1), it is not found, because the next query will only find entities with a timestamp >=2
- Instead of having the non-paginated query after the paginated request, we should have it before, using the non-incremented timestamp of the last found entity
- Then, we perform the paginated request with the timestamp increased by one ms, but only update the timestamp of the last found entity if this request returns one.