I believe I found the answer – and that is that I should use the @Internal annotation. The naming was what had thrown me off originally. I never looked into it because my assumption was that Internal would change the accessibility - however it seems that this annotation is merely to mark a property as one where the output isn’t considered towards up-to-date-ness.
Yes, @Internal has nothing to do with accessibility, but only with up-to-dateness and cache key calculation.
But if consumers of your task depend on invokeResult being filled properly, you should probably make your task always out-of-date anyway.
Because if the inputs you define are the same as when you last run the task and the outputs after the last run were not touched, the task is up-to-date and thus will not run.
That means that your field will not be set.