Workflow status confusion

I’m very confused about the state of the workflow after execution. When I have executed cancellation of the samples-go, I find that the status of workflow is ‘completed’, instead of ‘cancelled’. And the workflow status is still completed, even though activity has timed out. So what is the most important factor affecting the status after workflow execution

Do you mean the sample workflow at samples-go/workflow.go at main · temporalio/samples-go · GitHub? If so, that doesn’t bubble the cancellation error from the context so it is successfully completing when a cancellation is triggered. Most workflows will return errors they get from activities which means the cancel error will bubble showing the workflow as cancelled. Workflow can react to cancellation and still complete successfully if they want.

I’m confused about this sentence. I would like to know when the workflow will return the canceledErr history event, instead of completed event. At least so far all I’m getting are completed and failed events. In other words, what triggered the cancellation error returned by the workflow at the end?

If you returned ctx.Err() or an error from a downstream call (e.g. sleep) upon cancel, the workflow will show cancelled.

If you are using the workflow I linked, that swallows errors. Don’t swallow or affect the error, just return it.

I may be misunderstanding the question, but the cancellation is triggered by a user or timeout.