Steps to reproduce:
1) start a case instance
2) set a variable
3) execute a HistoricVariableInstanceQuery
The field activityInstanceId is always null.
The activityInstanceId is set. The activityInstanceId should be the id of the scope, in which the variable is available.
This is only related to cases.