The intermediate throw compensation event provides the activityRef attribute. The attribute allows to reference an activity which should be compensated. NOT the compensation handler.
This currently works fine if the activityRef references a scope activity (ie. embedded subprocess) but is broken for task activities (like Service tasks, User tasks etc.).
The problem is that the CompensationEventSubscription.getActivityId is used for resolving subscriptions. this is broken since this property references the id of the compensation handler and not the id of the scope to be compensated. the fact that the CompensationEventSubscription.getActivityId references the compensation handler is fine (for internal engine purposes), the bug occurs since we query with the id of the scope to be compensated.
See failing testcase
Spec page 294
For an End Event: The Activity to be compensated MAY be supplied. If an Activity is not supplied, then the compensation is broadcast to all completed Activities in the current Sub- Process (if present), or the entire Process instance (if at the global level).