Skip to content

Workflow monitor throws "actor is closed" error during active DurableAgent execution #520

Open
dapr/python-sdk
#1357

Description

@Eileen-Yu

The workflow monitor raises an unhandled gRPC error while the workflow is still executing successfully. The error is non-fatal but noisy.

== APP - diagram-agent == INFO:durabletask-worker:231e8453401c4f8289df69b845e3e85f: Orchestrator yielded with 1 task(s) and 0 event(s) outstanding.
== APP - diagram-agent == ERROR:dapr_agents.workflow.runners.base:[agent-runner] 231e8453401c4f8289df69b845e3e85f: error while monitoring workflow outcome
== APP - diagram-agent == Traceback (most recent call last):
== APP - diagram-agent ==   File "/Users/eileenyu/programming/diagram-agent/.venv/lib/python3.12/site-packages/dapr_agents/workflow/runners/base.py", line 563, in _await_and_log_state
== APP - diagram-agent ==     state = await self._await_state(
== APP - diagram-agent ==             ^^^^^^^^^^^^^^^^^^^^^^^^
== APP - diagram-agent ==   File "/Users/eileenyu/programming/diagram-agent/.venv/lib/python3.12/site-packages/dapr_agents/workflow/runners/base.py", line 543, in _await_state
== APP - diagram-agent ==     return await asyncio.to_thread(_wait)
== APP - diagram-agent ==            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
== APP - diagram-agent ==   File "/opt/homebrew/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/threads.py", line 25, in to_thread
== APP - diagram-agent ==     return await loop.run_in_executor(None, func_call)
== APP - diagram-agent ==            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
== APP - diagram-agent ==   File "/opt/homebrew/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/concurrent/futures/thread.py", line 58, in run
== APP - diagram-agent ==     result = self.fn(*self.args, **self.kwargs)
== APP - diagram-agent ==              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
== APP - diagram-agent ==   File "/Users/eileenyu/programming/diagram-agent/.venv/lib/python3.12/site-packages/dapr_agents/workflow/runners/base.py", line 537, in _wait
== APP - diagram-agent ==     return self._wf_client.wait_for_workflow_completion(
== APP - diagram-agent ==            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
== APP - diagram-agent ==   File "/Users/eileenyu/programming/diagram-agent/.venv/lib/python3.12/site-packages/dapr/ext/workflow/dapr_workflow_client.py", line 199, in wait_for_workflow_completion
== APP - diagram-agent ==     state = self.__obj.wait_for_orchestration_completion(
== APP - diagram-agent ==             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
== APP - diagram-agent ==   File "/Users/eileenyu/programming/diagram-agent/.venv/lib/python3.12/site-packages/durabletask/client.py", line 224, in wait_for_orchestration_completion
== APP - diagram-agent ==     res: pb.GetInstanceResponse = self._stub.WaitForInstanceCompletion(
== APP - diagram-agent ==                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
== APP - diagram-agent ==   File "/Users/eileenyu/programming/diagram-agent/.venv/lib/python3.12/site-packages/grpc/_interceptor.py", line 276, in __call__
== APP - diagram-agent ==     response, ignored_call = self._with_call(
== APP - diagram-agent ==                              ^^^^^^^^^^^^^^^^
== APP - diagram-agent ==   File "/Users/eileenyu/programming/diagram-agent/.venv/lib/python3.12/site-packages/grpc/_interceptor.py", line 331, in _with_call
== APP - diagram-agent ==     return call.result(), call
== APP - diagram-agent ==            ^^^^^^^^^^^^^
== APP - diagram-agent ==   File "/Users/eileenyu/programming/diagram-agent/.venv/lib/python3.12/site-packages/grpc/_channel.py", line 438, in result
== APP - diagram-agent ==     raise self
== APP - diagram-agent ==   File "/Users/eileenyu/programming/diagram-agent/.venv/lib/python3.12/site-packages/grpc/_interceptor.py", line 314, in continuation
== APP - diagram-agent ==     response, call = self._thunk(new_method).with_call(
== APP - diagram-agent ==                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
== APP - diagram-agent ==   File "/Users/eileenyu/programming/diagram-agent/.venv/lib/python3.12/site-packages/opentelemetry/instrumentation/grpc/grpcext/_interceptor.py", line 92, in with_call
== APP - diagram-agent ==     return self._interceptor.intercept_unary(
== APP - diagram-agent ==            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
== APP - diagram-agent ==   File "/Users/eileenyu/programming/diagram-agent/.venv/lib/python3.12/site-packages/opentelemetry/instrumentation/grpc/_client.py", line 190, in intercept_unary
== APP - diagram-agent ==     return self._intercept(request, metadata, client_info, invoker)
== APP - diagram-agent ==            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
== APP - diagram-agent ==   File "/Users/eileenyu/programming/diagram-agent/.venv/lib/python3.12/site-packages/opentelemetry/instrumentation/grpc/_client.py", line 171, in _intercept
== APP - diagram-agent ==     raise exc
== APP - diagram-agent ==   File "/Users/eileenyu/programming/diagram-agent/.venv/lib/python3.12/site-packages/opentelemetry/instrumentation/grpc/_client.py", line 157, in _intercept
== APP - diagram-agent ==     result = invoker(request, metadata)
== APP - diagram-agent ==              ^^^^^^^^^^^^^^^^^^^^^^^^^^
== APP - diagram-agent ==   File "/Users/eileenyu/programming/diagram-agent/.venv/lib/python3.12/site-packages/opentelemetry/instrumentation/grpc/grpcext/_interceptor.py", line 82, in invoker
== APP - diagram-agent ==     return self._base_callable.with_call(
== APP - diagram-agent ==            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
== APP - diagram-agent ==   File "/Users/eileenyu/programming/diagram-agent/.venv/lib/python3.12/site-packages/grpc/_channel.py", line 1173, in with_call
== APP - diagram-agent ==     return _end_unary_response_blocking(state, call, True, None)
== APP - diagram-agent ==            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
== APP - diagram-agent ==   File "/Users/eileenyu/programming/diagram-agent/.venv/lib/python3.12/site-packages/grpc/_channel.py", line 990, in _end_unary_response_blocking
== APP - diagram-agent ==     raise _InactiveRpcError(state)  # pytype: disable=not-instantiable
== APP - diagram-agent ==     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
== APP - diagram-agent == grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
== APP - diagram-agent ==       status = StatusCode.UNKNOWN
== APP - diagram-agent ==       details = "actor is closed, cannot handle deactivated"
== APP - diagram-agent ==       debug_error_string = "UNKNOWN:Error received from peer ipv4:34.248.40.116:443 {grpc_message:"actor is closed, cannot handle deactivated", grpc_status:2}"
== APP - diagram-agent == >
== APP - diagram-agent == 2026-03-12 17:15:45.591 durabletask-worker INFO: 231e8453401c4f8289df69b845e3e85f: Orchestrator yielded with 1 task(s) and 0 event(s) outstanding.
== APP - diagram-agent == INFO:durabletask-worker:231e8453401c4f8289df69b845e3e85f: Orchestrator yielded with 1 task(s) and 0 event(s) outstanding.
== APP - diagram-agent == INFO:dapr_agents.llm.utils.request:Tools are available in the request.

Expected: Retry or gracefully handle the deactivation instead of raising.
Versions: dapr-agents 0.13.0 and 1.0.0rc1, dapr SDK 1.17.x, Python 3.12

Activity

  1. self-assigned this
    on Mar 13, 2026
  2. added
    enhancement
    good first issue
    help wanted
    on Mar 24, 2026
  3. JeffreyJPZ commented on Apr 3, 2026

    @JeffreyJPZ
    Member

    Hi, I'm not sure if this is supposed to be a bug, but I tried to do a little bit of digging into this.

    If we trace through the Python workflow SDK, waiting for workflow completion is a unary RPC (see the workflow client code here). Tracing through the workflow engine and workflow actor code, it looks like its handled by this method which eventually blocks if the workflow isn't complete:
    dapr/pkg/actors/targets/workflow/orchestrator/stream.go

    func (o *orchestrator) handleStream(ctx context.Context,
    	req *internalsv1pb.InternalInvokeRequest,
    	stream func(*internalsv1pb.InternalInvokeResponse) (bool, error),
    	unlock context.CancelFunc,
    ) (bool, error) {
    	if m := req.GetMessage().GetMethod(); m != todo.WaitForRuntimeStatus {
    		return false, fmt.Errorf("unsupported stream method: %s", m)
    	}
    
    	_, ometa, err := o.loadInternalState(ctx)
    	if err != nil {
    		return false, err
    	}
    
    	if ometa != nil {
    		var arstate *anypb.Any
    		arstate, err = anypb.New(ometa)
    		if err != nil {
    			return false, err
    		}
    
    		var ok bool
    		ok, err = stream(&internalsv1pb.InternalInvokeResponse{
    			Status:  &internalsv1pb.Status{Code: http.StatusOK},
    			Message: &commonv1pb.InvokeResponse{Data: arstate},
    		})
    		if err != nil || ok {
    			if api.OrchestrationMetadataIsComplete(ometa) {
    				o.factory.deactivate(o)
    			}
    			return false, err
    		}
    	}
    
    	idx := o.streamIDx
    	o.streamIDx++
    
    	sf := &streamFn{
    		fn:    stream,
    		errCh: make(chan error, 1),
    	}
    	defer sf.done.Store(true)
    
    	o.streamFns[idx] = sf
    
    	// unlock this orchestrator actor.
    	unlock()
    	
    	select {
    	case <-ctx.Done():
    		return true, ctx.Err()
    	case err = <-sf.errCh:
    		return true, err
    	}
    }

    The actual "deactivated" error seems to be caused by this Deactivate method in the workflow actor code:
    dapr/pkg/actors/targets/workflow/orchestrator/orchestrator.go

    // DeactivateActor implements actors.InternalActor
    func (o *orchestrator) Deactivate(ctx context.Context) error {
    	unlock, err := o.lock.ContextLock(ctx)
    	if err != nil {
    		return fmt.Errorf("failed to deactivate workflow '%s': %w", o.actorID, err)
    	}
    	defer unlock()
    
    	o.table.Delete(o.actorID)
    	o.state = nil
    	o.rstate = nil
    	o.ometa = nil
    	o.lock.Close()
    	for _, stream := range o.streamFns {
    		stream.errCh <- targeterrors.NewClosed("deactivated")
    	}
    	clear(o.streamFns)
    	o.wg.Wait()
    	orchestratorCache.Put(o)
    
    	return nil
    }

    If we look at all the references, this is called indirectly by HaltAll/HaltNonHosted and some lifecycle methods (purging workflows/cleanup on workflow completion):
    dapr/pkg/actors/targets/workflow/orchestrator/factory.go

    deactivateCh := make(chan *orchestrator, 100)
    go func() {
    	for orchestrator := range deactivateCh {
    		orchestrator.Deactivate(ctx)
    	}
    }()

    dapr/pkg/actors/targets/workflow/orchestrator/orchestrator.go

    func (f *factory) deactivate(orchestrator *orchestrator) {
    	if !orchestrator.closed.CompareAndSwap(false, true) {
    		return
    	}
    	f.deactivateCh <- orchestrator
    }

    The logs show that the workflow is definitely not complete, so my best guess is that its related somehow to actor deactivation (HaltAll/HaltNonHosted are used for actor placement rebalancing?). The docs also mention that idle workflow actors can be deactivated/unloaded from memory (e.g. after scheduling activities), so it could also be related to that (not sure exactly where that occurs though). If this is the case should the client swallow the error and just wait again here?

  4. praneshnikhar commented on Jul 29, 2026

    @praneshnikhar

    heyy i haved fixed the issue and created a PR

  5. added a commit that references this issue on Aug 5, 2026
    e43ce11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementgood first issuehelp wanted

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions