Session lifetime for retries

Working on file processing, I’ve looked at the file processing example. If I create the session as follows - will the defer close the session on any error even a retriable one?

sessionCtx, err := workflow.CreateSession(ctx, &so)
if err != nil {
	return nil, err
}
defer workflow.CompleteSession(sessionCtx)

The behavior I want is to keep the session and file for retries, and clean them up on completion, non retryable error etc. How could I achieve that?

I realized this is easier than it seems, activity retries are handled transparently before returning control flow to the workflow.