Calling Query Method on a Terminated Workflow Throws Exception

I have a method that gets the details of a workflow. In order to do that I’m calling a query method. But when I call a query method on a terminated workflow, it throws IllegalArgumentException. On completed workflows it works fine. Is it expected that I cannot call query methods on terminated workflows?

When I checked the code, it’s the handleNonStatefulEvent method in WorkflowStateMachines.java that’s throwing the error when event type is EVENT_TYPE_WORKFLOW_EXECUTION_TERMINATED.

I’m using temporal-sdk:1.2.0

hello @Jerome_John

I think it is an issue in the SDK, I am able to reproduce it with 1.18.1 and 1.18.2

Let me double-check it and create an issue

This is by design. Terminate is a hard stop of a workflow without any guarantees. So running query against a terminated workflow is not safe. Use cancellation if you need to query workflows after the completion.

I added a feature request to support querying workflows at the last valid point.