Local activities aren't cancelled when I cancel the CancellationScope they are being called in

I have a bunch of local activities with retry options configured that are being ran inside a cancellation scope like so:

val result = Workflow.newPromise<SomeClass>()
val scope = Workflow.newCancellationScope { _ -> 
  activity1.execute()
  ....
  activityN.execute()
  result.complete(someValue)
}
Workflow.newTimer(Duration.ofSeconds(10))
  .thenApply { 
     scope.cancel()
     result.complete(someOtherValue) 
}

try {
  scope.run()
  result.get()
} catch (e: ActivityFailure) {
  handleError()
}

I expected that when scope.cancel() method is called that would close the scope with the running activities just as it works with normal activities.

Instead, it proceeds to retry local activities. What can I do about it? Thanks in advance!

Cancellation of local activities is currently not possible via Java SDK. This is something that will be added in the future.

This is because cancellation is delivered through heartbeats (see sample here) and local activities do not support heartbeating (more info in this post).

For your use case you would need to use regular activities and make sure they heartbeat to receive cancellation request.