Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
439df34
feat(workflows): add Python RaiseError client and replay support
ep0ll Nov 14, 2026
db9ee49
build(workflows): update generated Python protobuf descriptors
ep0ll Nov 14, 2026
9fccda8
fix(workflows): distinguish unset event failure metadata
ep0ll Nov 14, 2026
db53dff
test(workflows): cover sync raised error client
ep0ll Nov 17, 2026
d8c3dff
test(workflows): cover async raised error client
ep0ll Nov 17, 2026
2f5eb07
test(workflows): cover sync and async raised error staging
ep0ll Nov 17, 2026
9590da4
test(workflows): add cross-app error wait fixture
ep0ll Nov 17, 2026
5b125c7
test(workflows): cover cross-app raised error integration
ep0ll Nov 17, 2026
ff862e8
refactor(workflows): reuse RaiseEvent for failures
ep0ll Nov 19, 2026
2f8f1af
refactor(workflows): reuse RaiseEvent for failures
ep0ll Nov 19, 2026
eda7a1d
proto: remove redundant RaiseError gRPC method
ep0ll Nov 19, 2026
7a6bf20
feat(workflows): expose nested task failure details
ep0ll Nov 19, 2026
27fc73f
proto: remove redundant RaiseError service descriptor
ep0ll Nov 19, 2026
0abc6af
test(workflows): verify nested Python failure details
ep0ll Nov 19, 2026
5791415
test(workflows): use RaiseEvent for staged error requests
ep0ll Nov 19, 2026
c21d926
test(workflows): use orchestration failure protobuf types
ep0ll Nov 19, 2026
1383824
feat(workflows): add Python is_caused_by helper
ep0ll Nov 19, 2026
117aadf
test(workflows): cover Python cause inspection
ep0ll Nov 19, 2026
bf2eed3
test(workflows): verify raised Python exception causes
ep0ll Nov 19, 2026
f773309
feat(workflows): export task failure types from async SDK
ep0ll Nov 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions dapr/ext/workflow/_durabletask/aio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,37 @@ async def raise_orchestration_event_with_result(
self._logger.info(f"Raising event '{event_name}' for instance '{instance_id}'.")
return await self._get_stub().RaiseEvent(req)

async def raise_orchestration_error(
self,
instance_id: str,
event_name: str,
error: Exception,
*,
app_id: Optional[str] = None,
) -> None:
await self.raise_orchestration_error_with_result(
instance_id, event_name, error, app_id=app_id
)

async def raise_orchestration_error_with_result(
self,
instance_id: str,
event_name: str,
error: Exception,
*,
app_id: Optional[str] = None,
) -> pb.RaiseEventResponse:
if not isinstance(error, Exception):
raise TypeError('error must be an Exception')
req = pb.RaiseEventRequest(
instanceId=instance_id,
name=event_name,
failureDetails=helpers.new_failure_details(error),
router=new_task_router(app_id),
)
self._logger.info(f"Raising error for event '{event_name}' on instance '{instance_id}'.")
return await self._get_stub().RaiseEvent(req)

async def terminate_orchestration(
self,
instance_id: str,
Expand Down
31 changes: 31 additions & 0 deletions dapr/ext/workflow/_durabletask/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,37 @@ def raise_orchestration_event_with_result(
self._logger.info(f"Raising event '{event_name}' for instance '{instance_id}'.")
return self._stub.RaiseEvent(req)

def raise_orchestration_error(
self,
instance_id: str,
event_name: str,
error: Exception,
*,
app_id: Optional[str] = None,
) -> None:
self.raise_orchestration_error_with_result(
instance_id, event_name, error, app_id=app_id
)

def raise_orchestration_error_with_result(
self,
instance_id: str,
event_name: str,
error: Exception,
*,
app_id: Optional[str] = None,
) -> pb.RaiseEventResponse:
if not isinstance(error, Exception):
raise TypeError('error must be an Exception')
req = pb.RaiseEventRequest(
instanceId=instance_id,
name=event_name,
failureDetails=helpers.new_failure_details(error),
router=new_task_router(app_id),
)
self._logger.info(f"Raising error for event '{event_name}' on instance '{instance_id}'.")
return self._stub.RaiseEvent(req)

def terminate_orchestration(
self,
instance_id: str,
Expand Down
36 changes: 32 additions & 4 deletions dapr/ext/workflow/_durabletask/internal/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,47 @@ def new_child_workflow_failed_event(event_id: int, ex: Exception) -> pb.HistoryE
)


def new_failure_details(ex: Exception) -> pb.TaskFailureDetails:
def new_failure_details(ex: Exception, _seen: Optional[set[int]] = None) -> pb.TaskFailureDetails:
existing = getattr(ex, 'failure_details', None)
if isinstance(existing, pb.TaskFailureDetails):
return existing

if _seen is None:
_seen = set()
if id(ex) in _seen:
return pb.TaskFailureDetails(
errorType=f'{type(ex).__module__}.{type(ex).__qualname__}',
errorMessage=str(ex),
)
_seen.add(id(ex))

inner = ex.__cause__ or ex.__context__
inner_failure = (
new_failure_details(inner, _seen)
if isinstance(inner, Exception)
else None
)
return pb.TaskFailureDetails(
errorType=type(ex).__name__,
errorType=f'{type(ex).__module__}.{type(ex).__qualname__}',
errorMessage=str(ex),
stackTrace=wrappers_pb2.StringValue(value=''.join(traceback.format_tb(ex.__traceback__))),
innerFailure=inner_failure,
)


def new_event_raised_event(name: str, encoded_input: Optional[str] = None) -> pb.HistoryEvent:
def new_event_raised_event(
name: str,
encoded_input: Optional[str] = None,
failure_details: Optional[pb.TaskFailureDetails] = None,
) -> pb.HistoryEvent:
return pb.HistoryEvent(
eventId=-1,
timestamp=timestamp_pb2.Timestamp(),
eventRaised=pb.EventRaisedEvent(name=name, input=get_string_value(encoded_input)),
eventRaised=pb.EventRaisedEvent(
name=name,
input=get_string_value(encoded_input),
failureDetails=failure_details,
),
)


Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def RaiseEvent(self, request, context):
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')


def TerminateInstance(self, request, context):
"""Terminates a running workflow instance.
Expand Down
86 changes: 79 additions & 7 deletions dapr/ext/workflow/_durabletask/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,21 @@ def get_propagated_history(self) -> Optional[PropagatedHistory]:


class FailureDetails:
def __init__(self, message: str, error_type: str, stack_trace: Optional[str]):
"""Python-friendly view of a workflow task failure and its nested causes."""

def __init__(
self,
message: str,
error_type: str,
stack_trace: Optional[str],
inner_failure: Optional[FailureDetails] = None,
is_non_retriable: bool = False,
):
self._message = message
self._error_type = error_type
self._stack_trace = stack_trace
self._inner_failure = inner_failure
self._is_non_retriable = is_non_retriable

@property
def message(self) -> str:
Expand All @@ -284,22 +295,83 @@ def error_type(self) -> str:
def stack_trace(self) -> Optional[str]:
return self._stack_trace

@property
def inner_failure(self) -> Optional[FailureDetails]:
"""Gets the nested cause, if one was supplied by the raising process."""
return self._inner_failure

@property
def is_non_retriable(self) -> bool:
return self._is_non_retriable

def is_caused_by(self, error_type: str) -> bool:
"""Checks the current failure and its nested causes by their source type name."""
if not error_type:
return False
current: Optional[FailureDetails] = self
while current is not None:
if current.error_type == error_type:
return True
current = current.inner_failure
return False


def _map_failure_details(details: pb.TaskFailureDetails) -> FailureDetails:
inner = (
_map_failure_details(details.innerFailure)
if details.HasField('innerFailure')
else None
)
return FailureDetails(
details.errorMessage,
details.errorType,
details.stackTrace.value if not pbh.is_empty(details.stackTrace) else None,
inner,
details.isNonRetriable,
)


class TaskFailedError(Exception):
"""Exception type for all orchestration task failures."""
"""Raised when an activity, child workflow, or external-event wait fails.

The details property offers a Python-friendly recursive view. The
failure_details property retains the complete protobuf payload.
"""

def __init__(self, message: str, details: pb.TaskFailureDetails):
super().__init__(message)
self._details = FailureDetails(
details.errorMessage,
details.errorType,
details.stackTrace.value if not pbh.is_empty(details.stackTrace) else None,
)
self._failure_details = details
self._details = _map_failure_details(details)

@property
def details(self) -> FailureDetails:
return self._details

@property
def error_type(self) -> str:
return self._details.error_type

@property
def error_message(self) -> str:
return self._details.message

@property
def stack_trace(self) -> Optional[str]:
return self._details.stack_trace

@property
def inner_failure(self) -> Optional[FailureDetails]:
return self._details.inner_failure

@property
def failure_details(self) -> pb.TaskFailureDetails:
"""Gets the structured protobuf failure, including nested causes."""
return self._failure_details

def is_caused_by(self, error_type: str) -> bool:
"""Checks the source error type across the full cause chain."""
return self._details.is_caused_by(error_type)


class NonDeterminismError(Exception):
pass
Expand Down
58 changes: 46 additions & 12 deletions dapr/ext/workflow/_durabletask/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1512,6 +1512,12 @@ async def _execute_activity_async(
)


class _BufferedExternalEventFailure:
def __init__(self, event_name: str, failure_details: pb.TaskFailureDetails):
self.event_name = event_name
self.failure_details = failure_details


class _RuntimeOrchestrationContext(
task.OrchestrationContext, deterministic.DeterministicContextMixin
):
Expand Down Expand Up @@ -1656,10 +1662,18 @@ def get_actions(self) -> list[pb.WorkflowAction]:
# replayed when the new instance starts.
for event_name, values in self._received_events.items():
for event_value in values:
encoded_value = shared.to_json(event_value) if event_value else None
carryover_events.append(
ph.new_event_raised_event(event_name, encoded_value)
)
if isinstance(event_value, _BufferedExternalEventFailure):
carryover_events.append(
ph.new_event_raised_event(
event_name,
failure_details=event_value.failure_details,
)
)
else:
encoded_value = shared.to_json(event_value) if event_value else None
carryover_events.append(
ph.new_event_raised_event(event_name, encoded_value)
)
action = ph.new_complete_workflow_action(
self.next_sequence_number(),
pb.ORCHESTRATION_STATUS_CONTINUED_AS_NEW,
Expand Down Expand Up @@ -1923,7 +1937,14 @@ def wait_for_external_event(
event_data = event_list.pop(0)
if not event_list:
del self._received_events[event_name]
external_event_task.complete(event_data)
if isinstance(event_data, _BufferedExternalEventFailure):
details = event_data.failure_details
external_event_task.fail(
f"External event '{event_data.event_name}' failed: {details.errorMessage}",
details,
)
else:
external_event_task.complete(event_data)
else:
task_list = self._pending_events.get(event_name, None)
if not task_list:
Expand Down Expand Up @@ -2411,24 +2432,37 @@ def process_event(self, ctx: _RuntimeOrchestrationContext, event: pb.HistoryEven
if not ctx.is_replaying:
self._logger.info(f'{ctx.instance_id} Event raised: {event_name}')
task_list = ctx._pending_events.get(event_name, None)
has_failure_details = event.eventRaised.HasField('failureDetails')
failure_details = event.eventRaised.failureDetails if has_failure_details else None
decoded_result: Optional[Any] = None
if task_list:
event_task = task_list.pop(0)
if not ph.is_empty(event.eventRaised.input):
decoded_result = shared.from_json(event.eventRaised.input.value)
event_task.complete(decoded_result)
if has_failure_details:
event_task.fail(
f"External event '{event.eventRaised.name}' failed: {failure_details.errorMessage}",
failure_details,
)
else:
if not ph.is_empty(event.eventRaised.input):
decoded_result = shared.from_json(event.eventRaised.input.value)
event_task.complete(decoded_result)
if not task_list:
del ctx._pending_events[event_name]
ctx.resume()
else:
# buffer the event
# Buffer the event without mixing failure metadata into user payloads.
event_list = ctx._received_events.get(event_name, None)
if not event_list:
event_list = []
ctx._received_events[event_name] = event_list
if not ph.is_empty(event.eventRaised.input):
decoded_result = shared.from_json(event.eventRaised.input.value)
event_list.append(decoded_result)
if has_failure_details:
event_list.append(
_BufferedExternalEventFailure(event.eventRaised.name, failure_details)
)
else:
if not ph.is_empty(event.eventRaised.input):
decoded_result = shared.from_json(event.eventRaised.input.value)
event_list.append(decoded_result)
if not ctx.is_replaying:
self._logger.info(
f"{ctx.instance_id}: Event '{event_name}' has been buffered as there are no tasks waiting for it."
Expand Down
3 changes: 3 additions & 0 deletions dapr/ext/workflow/aio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@

# Re-export MCPToolDef so async users don't need to import from the sync module.
from dapr.ext.workflow.mcp import MCPToolDef
from dapr.ext.workflow import FailureDetails, TaskFailedError

from .dapr_workflow_client import DaprWorkflowClient
from .mcp import DaprMCPClient

__all__ = [
'DaprWorkflowClient',
'TaskFailedError',
'FailureDetails',
'DaprMCPClient',
'MCPToolDef',
]
27 changes: 27 additions & 0 deletions dapr/ext/workflow/aio/dapr_workflow_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,33 @@ async def raise_workflow_event(
instance_id, event_name, data=data, app_id=app_id
)

async def raise_workflow_error(
self,
instance_id: str,
event_name: str,
error: Exception,
*,
app_id: Optional[str] = None,
) -> None:
"""Raises a failure for the oldest matching external-event wait."""
return await self.__obj.raise_orchestration_error(
instance_id, event_name, error, app_id=app_id
)

async def raise_workflow_error_with_result(
self,
instance_id: str,
event_name: str,
error: Exception,
*,
app_id: Optional[str] = None,
) -> WorkflowOperationResult:
"""Raises a workflow error and reports whether the sidecar staged it."""
res = await self.__obj.raise_orchestration_error_with_result(
instance_id, event_name, error, app_id=app_id
)
return WorkflowOperationResult(staged=res.staged)

async def raise_workflow_event_with_result(
self,
instance_id: str,
Expand Down
Loading