Reliable task duration in workflow

We want to log how long each step would take:

long start = Workflow.currentTimeMillis();
operation1();
long duration = Workflow.currentTimeMillis() - start;

My question is if the worker died when it runs operation1(), and temporal restores the workflow. What would happen to the start?
Will the start restored to the start timestamp on the first run? Or it will become actual timestamp on the second run (when restoring)?

I am asking this because in former case, the calculated duration would be too large: Duration(end of run 2 - start of run 1)
In the latter case, the duration would be too small, because in my understanding, all recorded activities will use the recorded results, so the time spent on run 2 will be shorter.

On restore, the start will contain the time of the first execution. So duration will be the actual duration of the operation.

So if the restoring happens after one day, then the final duration will be one day + actual time spent in operation?

Correct. But it assumes that the workflow worker has been down for a day. In a normal situation, the recovery will happen immediately after the operation’s completion.

I see. Thanks for confirming this. Do we have a way to know whether there was a recovery? e.g., an API in SDK to get current retry times

You can watch the workflow task queue schedule to start latency metric. If it starts growing then the workflow workers cannot keep up with the workflow update reate or down.