Skip to content

Commit 225b5bc

Browse files
committed
Use Temporal Failures for Nexus APIs
Also add a failure representation of the Nexus SDK's OperationError.
1 parent 2e5751c commit 225b5bc

File tree

5 files changed

+62
-3
lines changed

5 files changed

+62
-3
lines changed

openapi/openapiv2.json

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9131,6 +9131,9 @@
91319131
},
91329132
"nexusHandlerFailureInfo": {
91339133
"$ref": "#/definitions/v1NexusHandlerFailureInfo"
9134+
},
9135+
"nexusSdkOperationFailureInfo": {
9136+
"$ref": "#/definitions/v1NexusSDKOperationFailureInfo"
91349137
}
91359138
}
91369139
},
@@ -9181,6 +9184,9 @@
91819184
"format": "date-time",
91829185
"description": "The timestamp when the request was scheduled in the frontend."
91839186
},
9187+
"capabilities": {
9188+
"$ref": "#/definitions/v1RequestCapabilities"
9189+
},
91849190
"startOperation": {
91859191
"$ref": "#/definitions/v1StartOperationRequest"
91869192
},
@@ -12579,7 +12585,8 @@
1257912585
"type": "string",
1258012586
"description": "Operation token - may be empty if the operation completed synchronously."
1258112587
}
12582-
}
12588+
},
12589+
"description": "Representation of the Temporal SDK NexusOperationError object that is returned to workflow callers."
1258312590
},
1258412591
"v1NexusOperationScheduledEventAttributes": {
1258512592
"type": "object",
@@ -12669,6 +12676,15 @@
1266912676
},
1267012677
"description": "Nexus operation timed out."
1267112678
},
12679+
"v1NexusSDKOperationFailureInfo": {
12680+
"type": "object",
12681+
"properties": {
12682+
"state": {
12683+
"type": "string"
12684+
}
12685+
},
12686+
"description": "Representation of the Nexus SDK OperationError object."
12687+
},
1267212688
"v1OnConflictOptions": {
1267312689
"type": "object",
1267412690
"properties": {
@@ -13635,6 +13651,15 @@
1363513651
"v1RequestCancelWorkflowExecutionResponse": {
1363613652
"type": "object"
1363713653
},
13654+
"v1RequestCapabilities": {
13655+
"type": "object",
13656+
"properties": {
13657+
"temporalFailureResponses": {
13658+
"type": "boolean",
13659+
"description": "If set, handlers may use temporal.api.failure.v1.Failure instances to return failures to the server.\nThis also allows handler and operation errors to have their own messages and stack traces."
13660+
}
13661+
}
13662+
},
1363813663
"v1RequestIdInfo": {
1363913664
"type": "object",
1364013665
"properties": {
@@ -14849,6 +14874,10 @@
1484914874
"operationError": {
1485014875
"$ref": "#/definitions/v1UnsuccessfulOperationError",
1485114876
"description": "The operation completed unsuccessfully (failed or canceled)."
14877+
},
14878+
"failure": {
14879+
"$ref": "#/definitions/apifailurev1Failure",
14880+
"description": "The operation completed unsuccessfully (failed or canceled).\nFailure object must contain a NexusSDKOperationFailureInfo object."
1485214881
}
1485314882
},
1485414883
"description": "Response variant for StartOperationRequest."

openapi/openapiv3.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8261,6 +8261,8 @@ components:
82618261
$ref: '#/components/schemas/NexusOperationFailureInfo'
82628262
nexusHandlerFailureInfo:
82638263
$ref: '#/components/schemas/NexusHandlerFailureInfo'
8264+
nexusSdkOperationFailureInfo:
8265+
$ref: '#/components/schemas/NexusSDKOperationFailureInfo'
82648266
FetchWorkerConfigRequest:
82658267
type: object
82668268
properties:
@@ -9383,6 +9385,7 @@ components:
93839385
operationToken:
93849386
type: string
93859387
description: Operation token - may be empty if the operation completed synchronously.
9388+
description: Representation of the Temporal SDK NexusOperationError object that is returned to workflow callers.
93869389
NexusOperationScheduledEventAttributes:
93879390
type: object
93889391
properties:
@@ -9474,6 +9477,12 @@ components:
94749477
type: string
94759478
description: The request ID allocated at schedule time.
94769479
description: Nexus operation timed out.
9480+
NexusSDKOperationFailureInfo:
9481+
type: object
9482+
properties:
9483+
state:
9484+
type: string
9485+
description: Representation of the Nexus SDK OperationError object.
94779486
OnConflictOptions:
94789487
type: object
94799488
properties:

temporal/api/failure/v1/message.proto

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ message ChildWorkflowExecutionFailureInfo {
6666
temporal.api.enums.v1.RetryState retry_state = 6;
6767
}
6868

69+
// Representation of the Temporal SDK NexusOperationError object that is returned to workflow callers.
6970
message NexusOperationFailureInfo {
7071
// The NexusOperationScheduled event ID.
7172
int64 scheduled_event_id = 1;
@@ -91,6 +92,11 @@ message NexusHandlerFailureInfo {
9192
temporal.api.enums.v1.NexusHandlerErrorRetryBehavior retry_behavior = 2;
9293
}
9394

95+
// Representation of the Nexus SDK OperationError object.
96+
message NexusSDKOperationFailureInfo {
97+
string state = 1;
98+
}
99+
94100
message Failure {
95101
string message = 1;
96102
// The source this Failure originated in, e.g. TypeScriptSDK / JavaSDK
@@ -125,6 +131,7 @@ message Failure {
125131
ChildWorkflowExecutionFailureInfo child_workflow_execution_failure_info = 12;
126132
NexusOperationFailureInfo nexus_operation_execution_failure_info = 13;
127133
NexusHandlerFailureInfo nexus_handler_failure_info = 14;
134+
NexusSDKOperationFailureInfo nexus_sdk_operation_failure_info = 15;
128135
}
129136
}
130137

temporal/api/nexus/v1/message.proto

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ option csharp_namespace = "Temporalio.Api.Nexus.V1";
1212
import "google/protobuf/timestamp.proto";
1313
import "temporal/api/common/v1/message.proto";
1414
import "temporal/api/enums/v1/nexus.proto";
15+
import "temporal/api/failure/v1/message.proto";
1516

1617
// A general purpose failure message.
1718
// See: https://github.com/nexus-rpc/api/blob/main/SPEC.md#failure
@@ -77,6 +78,12 @@ message CancelOperationRequest {
7778

7879
// A Nexus request.
7980
message Request {
81+
message Capabilities {
82+
// If set, handlers may use temporal.api.failure.v1.Failure instances to return failures to the server.
83+
// This also allows handler and operation errors to have their own messages and stack traces.
84+
bool temporal_failure_responses = 1;
85+
}
86+
8087
// Headers extracted from the original request in the Temporal frontend.
8188
// When using Nexus over HTTP, this includes the request's HTTP headers ignoring multiple values.
8289
map<string, string> header = 1;
@@ -86,6 +93,8 @@ message Request {
8693
// aip.dev/not-precedent: Not following linter rules. --)
8794
google.protobuf.Timestamp scheduled_time = 2;
8895

96+
Capabilities capabilities = 100;
97+
8998
oneof variant {
9099
StartOperationRequest start_operation = 3;
91100
CancelOperationRequest cancel_operation = 4;
@@ -114,6 +123,9 @@ message StartOperationResponse {
114123
Async async_success = 2;
115124
// The operation completed unsuccessfully (failed or canceled).
116125
UnsuccessfulOperationError operation_error = 3;
126+
// The operation completed unsuccessfully (failed or canceled).
127+
// Failure object must contain a NexusSDKOperationFailureInfo object.
128+
temporal.api.failure.v1.Failure failure = 4;
117129
}
118130
}
119131

temporal/api/workflowservice/v1/request_response.proto

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1834,8 +1834,10 @@ message RespondNexusTaskFailedRequest {
18341834
string identity = 2;
18351835
// A unique identifier for this task.
18361836
bytes task_token = 3;
1837-
// The error the handler failed with.
1837+
// The error the handler failed with (DEPRECATED, use the failure field instead).
18381838
temporal.api.nexus.v1.HandlerError error = 4;
1839+
// The error the handler failed with. Must contain a NexusHandlerFailureInfo object.
1840+
temporal.api.failure.v1.Failure failure = 5;
18391841
}
18401842

18411843
message RespondNexusTaskFailedResponse {
@@ -2550,4 +2552,4 @@ message DescribeWorkerRequest {
25502552

25512553
message DescribeWorkerResponse {
25522554
temporal.api.worker.v1.WorkerInfo worker_info = 1;
2553-
}
2555+
}

0 commit comments

Comments
 (0)