Does a workflow query function need to be deterministic?

I’d like to have query function status() that returns the progress of a running workflow. The only catch is that I’d like to return the current long-running activity progress as well. I can indicate the progress of the long-running activity using a heartbeat, but is it ok to use that heartbeat information in the status() query function?
In general, is it ok for a query function to use external resources, making it a non-deterministic function that could return different results in the same state?

Hi @semekh

Ideally a query should return the internal workflow state (workflow variable or something similar) ,without performing any IO operations (that you should pace in activities)

from docs
A Query must never mutate the state of the Workflow Execution—that is, Queries are read-only and cannot contain any blocking code. This means, for example, that Query handling logic cannot schedule Activity Executions.

I can indicate the progress of the long-running activity using a heartbeat, but is it ok to use that heartbeat information in the status() query function?

I would expose a signal method and , from your activity, you can report progress back to the workflow through the signal method and store the value that status can returns

Antonio

1 Like

Longer term we want to allow running local activities from the query handler to support your use case better.

1 Like