Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
2ed0e67
feat(workflow): add reason to TerminateRequest descriptor
ep0ll Nov 14, 2026
2e4428a
feat(workflow): add terminationReason to WorkflowState descriptor
ep0ll Nov 14, 2026
965a517
feat(workflow): add reason to ExecutionTerminatedEvent descriptor
ep0ll Nov 14, 2026
ec86e7b
feat(workflow): add terminationReason to WorkflowMetadata descriptor
ep0ll Nov 14, 2026
58c73f2
feat(workflow): sync termination reason proto sources
ep0ll Nov 14, 2026
83aed17
feat(workflow): sync termination reason proto sources
ep0ll Nov 14, 2026
c737f26
fix(workflow): place termination reason on TerminateRequest
ep0ll Nov 14, 2026
5c6ecf9
fix(workflow): place termination reason on TerminateRequest
ep0ll Nov 14, 2026
bbd2e14
feat(workflow): sync termination reason proto definitions
ep0ll Nov 14, 2026
cadb2bd
feat(workflow): sync termination reason proto definitions
ep0ll Nov 14, 2026
0200905
feat(workflow): sync termination reason proto definitions
ep0ll Nov 14, 2026
77ef58f
feat(workflow): sync termination reason proto definitions
ep0ll Nov 14, 2026
969c1f2
feat(workflow): sync termination reason backend metadata
ep0ll Nov 14, 2026
2a36fef
feat(workflow): sync termination reason backend metadata
ep0ll Nov 14, 2026
32d73df
feat(workflow): expose durable termination reason in client
ep0ll Nov 14, 2026
c450ce9
feat(workflow): expose durable termination reason in client
ep0ll Nov 14, 2026
00ebb22
feat(workflow): expose durable termination reason in client
ep0ll Nov 14, 2026
0c276c4
feat(workflow): type reason protobuf field
ep0ll Nov 14, 2026
b264ebf
feat(workflow): type terminationReason protobuf field
ep0ll Nov 14, 2026
c4220b8
feat(workflow): type reason protobuf field
ep0ll Nov 14, 2026
730cfb2
feat(workflow): type terminationReason protobuf field
ep0ll Nov 14, 2026
03cafaa
feat(workflow): add termination reason to runtime request descriptor
ep0ll Nov 14, 2026
0dd08bd
feat(workflow): add termination reason to runtime request descriptor
ep0ll Nov 14, 2026
ac48bc2
feat(workflow): sync runtime termination reason proto
ep0ll Nov 14, 2026
226ef79
feat(workflow): sync runtime termination reason proto
ep0ll Nov 14, 2026
d98832d
feat(workflow): type runtime termination reason field
ep0ll Nov 14, 2026
852c081
feat(workflow): add optional termination reason to client interface
ep0ll Nov 14, 2026
f729338
feat(workflow): send termination reason over HTTP
ep0ll Nov 14, 2026
61c8a4e
chore(workflow): keep grpc workflow interface aligned
ep0ll Nov 14, 2026
2061bca
docs(workflow): document termination reason access
ep0ll Nov 15, 2026
72bc02a
fix(workflow): send HTTP termination reason in query
ep0ll Nov 16, 2026
dde1925
test(workflow): cover termination reason client API
ep0ll Nov 16, 2026
a6f3fcb
test(workflow): cover HTTP termination reason query
ep0ll Nov 16, 2026
da3a31e
test(workflow): cover termination reason state
ep0ll Nov 16, 2026
afb0067
chore(workflow): trim generated API documentation
ep0ll Nov 16, 2026
5f5cde5
chore(workflow): trim generated API documentation
ep0ll Nov 16, 2026
5e3a02b
chore(workflow): remove redundant proto comments
ep0ll Nov 16, 2026
e48cccb
chore(workflow): remove redundant proto comments
ep0ll Nov 16, 2026
20d4708
chore(workflow): remove redundant proto comments
ep0ll Nov 16, 2026
2244193
chore(workflow): remove redundant proto comments
ep0ll Nov 16, 2026
57d3bd2
chore(workflow): trim duplicate proto comments
ep0ll Nov 16, 2026
b110015
chore(workflow): trim duplicate proto comments
ep0ll Nov 16, 2026
deaa1a2
chore(workflow): trim duplicate proto comments
ep0ll Nov 16, 2026
dced688
chore(workflow): trim duplicate proto comments
ep0ll Nov 16, 2026
5c40470
refactor(workflow): reuse termination input payload
ep0ll Nov 18, 2026
c2bbbc7
refactor(workflow): rely on custom status for termination reason
ep0ll Nov 18, 2026
0bd20a2
refactor(workflow): map reason to existing termination input
ep0ll Nov 18, 2026
cb20a43
test(workflow): remove redundant termination reason state
ep0ll Nov 18, 2026
5887a56
test(workflow): cover termination input mapping
ep0ll Nov 18, 2026
735535e
refactor(workflow): use existing durabletask protocol fields
ep0ll Nov 18, 2026
2a85ab4
refactor(workflow): use existing durabletask protocol fields
ep0ll Nov 18, 2026
0559267
refactor(workflow): use existing durabletask protocol fields
ep0ll Nov 18, 2026
ed4fed5
refactor(workflow): use existing durabletask protocol fields
ep0ll Nov 18, 2026
57cb91c
refactor(workflow): use existing durabletask protocol fields
ep0ll Nov 18, 2026
0485400
refactor(workflow): use existing durabletask protocol fields
ep0ll Nov 18, 2026
e2d6aa8
refactor(workflow): use existing durabletask protocol fields
ep0ll Nov 18, 2026
1c6072f
refactor(workflow): use existing durabletask protocol fields
ep0ll Nov 18, 2026
dffde69
refactor(workflow): use existing durabletask protocol fields
ep0ll Nov 18, 2026
f79e5fb
refactor(workflow): use existing durabletask protocol fields
ep0ll Nov 18, 2026
a007026
refactor(workflow): use existing durabletask protocol fields
ep0ll Nov 18, 2026
716085d
refactor(workflow): use existing durabletask protocol fields
ep0ll Nov 18, 2026
1b22ace
refactor(workflow): use existing durabletask protocol fields
ep0ll Nov 18, 2026
cfa8ba6
refactor(workflow): use existing durabletask protocol fields
ep0ll Nov 18, 2026
fce709b
refactor(workflow): use existing durabletask protocol fields
ep0ll Nov 18, 2026
d3e63c0
refactor(workflow): use existing durabletask protocol fields
ep0ll Nov 18, 2026
abe814c
feat(workflow): name public termination reason explicitly
ep0ll Nov 18, 2026
2b83e69
feat(workflow): name public termination reason explicitly
ep0ll Nov 18, 2026
4d085da
feat(workflow): align generated terminate reason type
ep0ll Nov 18, 2026
b558540
feat(workflow): align runtime proto descriptor field name
ep0ll Nov 18, 2026
2010cb5
fix(workflow): allow reason without a separate output
ep0ll Nov 18, 2026
217a02b
fix(workflow): pass termination reason as the reason argument
ep0ll Nov 18, 2026
f0d2433
test(workflow): verify reason uses dedicated option argument
ep0ll Nov 18, 2026
97f5dc6
fix(workflow): align optional field descriptor oneof name
ep0ll Nov 18, 2026
dfdbecf
fix(workflow): reject explicitly supplied output with a reason
ep0ll Nov 18, 2026
2ad88ac
fix(workflow): omit output when sending a termination reason
ep0ll Nov 18, 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
1 change: 1 addition & 0 deletions dapr/proto/runtime/v1/workflow.proto
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ message TerminateWorkflowRequest {
// Defaults to the local app. Must be in the same namespace; the target
// app's WorkflowAccessPolicy governs whether the call is permitted.
optional string app_id = 3 [json_name = "appID"];
optional string terminate_reason = 4 [json_name = "terminateReason"];
}

// PauseWorkflowRequest is the request for PauseWorkflowBeta1.
Expand Down
2 changes: 1 addition & 1 deletion src/implementation/Client/GRPCClient/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default class GRPCClientWorkflow implements IClientWorkflow {
throw new GRPCNotSupportedError();
}

terminate(_instanceId: string): Promise<any> {
terminate(_instanceId: string, _reason?: string): Promise<any> {
throw new GRPCNotSupportedError();
}

Expand Down
5 changes: 3 additions & 2 deletions src/implementation/Client/HTTPClient/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,9 @@ export default class HTTPClientWorkflow implements IClientWorkflow {
}
}

async terminate(instanceId: string): Promise<void> {
await this._invokeMethod(instanceId, "terminate");
async terminate(instanceId: string, reason?: string): Promise<void> {
const method = reason === undefined ? "terminate" : `terminate?reason=${encodeURIComponent(reason)}`;
await this._invokeMethod(instanceId, method);
}

async pause(instanceId: string): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/Client/IClientWorkflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default interface IClientWorkflow {
*
* @see https://docs.dapr.io/reference/api/workflow_api/
*/
terminate(instanceId: string): Promise<void>;
terminate(instanceId: string, reason?: string): Promise<void>;

/**
* Pauses a running workflow instance.
Expand Down
1 change: 1 addition & 0 deletions src/proto/dapr/proto/runtime/v1/workflow.proto
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ message TerminateWorkflowRequest {
// Defaults to the local app. Must be in the same namespace; the target
// app's WorkflowAccessPolicy governs whether the call is permitted.
optional string app_id = 3 [json_name = "appID"];
optional string terminate_reason = 4 [json_name = "terminateReason"];
}

// PauseWorkflowRequest is the request for PauseWorkflowBeta1.
Expand Down
7 changes: 7 additions & 0 deletions src/proto/dapr/proto/runtime/v1/workflow_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,13 @@ export declare type TerminateWorkflowRequest = Message<"dapr.proto.runtime.v1.Te
* @generated from field: optional string app_id = 3 [json_name = "appID"];
*/
appId?: string | undefined;

/**
* Optional reason describing why the workflow is being terminated.
*
* @generated from field: optional string terminate_reason = 4 [json_name = "terminateReason"];
*/
terminateReason?: string | undefined;
};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/proto/dapr/proto/runtime/v1/workflow_pb.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const { file_google_protobuf_timestamp } = require("@bufbuild/protobuf/wkt");
* Describes the file dapr/proto/runtime/v1/workflow.proto.
*/
const file_dapr_proto_runtime_v1_workflow = /*@__PURE__*/
fileDesc("CiRkYXByL3Byb3RvL3J1bnRpbWUvdjEvd29ya2Zsb3cucHJvdG8SFWRhcHIucHJvdG8ucnVudGltZS52MSJ4ChJHZXRXb3JrZmxvd1JlcXVlc3QSHwoLaW5zdGFuY2VfaWQYASABKAlSCmluc3RhbmNlSUQSGgoSd29ya2Zsb3dfY29tcG9uZW50GAIgASgJEhoKBmFwcF9pZBgDIAEoCUgAUgVhcHBJRIgBAUIJCgdfYXBwX2lkIs0CChNHZXRXb3JrZmxvd1Jlc3BvbnNlEh8KC2luc3RhbmNlX2lkGAEgASgJUgppbnN0YW5jZUlEEhUKDXdvcmtmbG93X25hbWUYAiABKAkSLgoKY3JlYXRlZF9hdBgDIAEoCzIaLmdvb2dsZS5wcm90b2J1Zi5UaW1lc3RhbXASMwoPbGFzdF91cGRhdGVkX2F0GAQgASgLMhouZ29vZ2xlLnByb3RvY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jpWMWIGcHJvdG8z", [file_google_protobuf_timestamp]);

/**
* Describes the message dapr.proto.runtime.v1.GetWorkflowRequest.
Expand Down
18 changes: 18 additions & 0 deletions src/workflow/client/DaprWorkflowClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,24 @@ export default class DaprWorkflowClient {
await this._innerClient.terminateOrchestration(workflowInstanceId, output, signal);
}

/**
* Terminates a workflow with a durable, retrievable reason.
*
* The reason is stored as the existing termination input and exposed through
* {@link WorkflowState.customStatus}. It cannot be combined with an output.
*/
public async terminateWorkflowWithReason(
workflowInstanceId: string,
reason: string,
output?: unknown,
signal?: AbortSignal,
): Promise<void> {
if (output !== undefined) {
throw new TypeError("output and reason cannot be supplied together");
}
await this._innerClient.terminateOrchestration(workflowInstanceId, undefined, signal, reason);
}

/**
* Gets a snapshot of the current workflow state, or undefined if the instance does not exist.
* Compare runtimeStatus with WorkflowRuntimeStatus members, not hard-coded numbers or strings.
Expand Down
15 changes: 13 additions & 2 deletions src/workflow/engine/transport/TaskHubClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,13 +302,24 @@ export class TaskHubClient {
await this.client.raiseEvent(req, this.callOptions(signal));
}

async terminateOrchestration(instanceId: string, output: unknown = null, signal?: AbortSignal): Promise<void> {
async terminateOrchestration(
instanceId: string,
output: unknown = null,
signal?: AbortSignal,
reason?: string,
): Promise<void> {
const req = create(TerminateRequestSchema, {
instanceId,
recursive: true,
});

if (output !== undefined) {
if (output !== undefined && reason !== undefined) {
throw new TypeError("output and reason cannot be supplied together");
}

if (reason !== undefined) {
req.output = reason;
} else if (output !== undefined) {
req.output = await this.encodePayload(output, { kind: PayloadKind.WorkflowOutput, instanceId }, signal);
}

Expand Down
51 changes: 51 additions & 0 deletions test/unit/protocols/http/workflow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,55 @@ describe("workflow", () => {
it("should throw PropertyRequiredError when eventName variable is not provided in raiseEvent method", async () => {
await expect(workflow.raiseEvent(randomUUID(), "")).rejects.toThrow(PropertyRequiredError);
});
describe("terminate", () => {
it("sends a termination reason as a query parameter", async () => {
const reason = "operator requested & confirmed";
const execute = jest.spyOn(client, "executeWithApiVersion").mockResolvedValue({});

try {
await workflow.terminate("instance-1", reason);

expect(execute).toHaveBeenCalledWith(
"v1.0-beta1",
`/workflows/dapr/instance-1/terminate?reason=${encodeURIComponent(reason)}`,
{ method: "POST" },
);
} finally {
execute.mockRestore();
}
});

it("preserves an explicitly empty termination reason", async () => {
const execute = jest.spyOn(client, "executeWithApiVersion").mockResolvedValue({});

try {
await workflow.terminate("instance-1", "");

expect(execute).toHaveBeenCalledWith(
"v1.0-beta1",
"/workflows/dapr/instance-1/terminate?reason=",
{ method: "POST" },
);
} finally {
execute.mockRestore();
}
});

it("omits the termination reason when it is undefined", async () => {
const execute = jest.spyOn(client, "executeWithApiVersion").mockResolvedValue({});

try {
await workflow.terminate("instance-1");

expect(execute).toHaveBeenCalledWith(
"v1.0-beta1",
"/workflows/dapr/instance-1/terminate",
{ method: "POST" },
);
} finally {
execute.mockRestore();
}
});
});

});
21 changes: 21 additions & 0 deletions test/unit/workflow/workflowClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,27 @@ describe("DaprWorkflowClient", () => {
});
});

describe("terminateWorkflowWithReason", () => {
it("maps the reason to the existing termination input", async () => {
mockTerminateOrchestration.mockResolvedValue(undefined);

await client.terminateWorkflowWithReason("instance-1", "operator requested");

expect(mockTerminateOrchestration).toHaveBeenCalledWith(
"instance-1",
null,
undefined,
"operator requested",
);
});

it("rejects separate output and reason values", async () => {
await expect(
client.terminateWorkflowWithReason("instance-1", "operator requested", { result: "cancelled" }),
).rejects.toThrow("output and reason cannot be supplied together");
});
});

describe("raiseEvent", () => {
it("should raise an event with payload", async () => {
mockRaiseOrchestrationEvent.mockResolvedValue(undefined);
Expand Down