The activityInstanceId should be set on a HistoricVariableUpdate when a variable is updated.
Eg. When a 'runtimeService.setVariables(executionId, variableMap)' is called, the corresponding HistoricVariableUpdates should have their activityInstanceId set to the active activity in the execution. The same goos for variables set from inside for example a service-task (execution.setVariable("name", "value")), this way a more fine-grained view is available on the variable updates.
When a process-instance is started, the activityInstanceId of the start-event should be used, to be able to determine what variables were passed when the process was started.