diff --git a/openapi/openapiv2.json b/openapi/openapiv2.json index e546e8a59..ba3e98e4b 100644 --- a/openapi/openapiv2.json +++ b/openapi/openapiv2.json @@ -14180,6 +14180,17 @@ } } }, + "v1ActivitySessionOptions": { + "type": "object", + "properties": { + "workflowSession": { + "type": "object", + "properties": {}, + "description": "Run in the workflow's current session (on its sticky queue).\nCurrently requires the activity's task queue to be the workflow's,\nand the workflow's worker to service sessions." + } + }, + "description": "EXPERIMENTAL. Subject to redesign or removal.\nResolved activity placement. Unset = normal task-queue routing." + }, "v1ActivityTaskCancelRequestedEventAttributes": { "type": "object", "properties": { @@ -14350,6 +14361,10 @@ "priority": { "$ref": "#/definitions/v1Priority", "description": "Priority metadata. If this message is not present, or any fields are not\npresent, they inherit the values from the workflow." + }, + "sessionOptions": { + "$ref": "#/definitions/v1ActivitySessionOptions", + "description": "Preserves the scheduling command's session routing options so activity state\ncan be reconstructed from history." } } }, @@ -17403,6 +17418,10 @@ }, "title": "Metadata relevant for metering purposes" }, + "v1MultiSessionOptions": { + "type": "object", + "description": "EXPERIMENTAL. Subject to redesign or removal.\nService any number of sessions concurrently. Future admission knobs (e.g.\nsession slots) belong here." + }, "v1NamespaceConfig": { "type": "object", "properties": { @@ -19973,6 +19992,20 @@ } } }, + "v1SessionInfo": { + "type": "object", + "properties": { + "exclusiveWorker": { + "type": "boolean", + "description": "True when the workflow is bound to a single-session worker. Such a\nbinding never moves to another worker." + }, + "workerQueue": { + "type": "string", + "description": "The sticky queue of the worker the workflow is bound to: the stable\nidentity of a single-session worker, or the worker instance key of a\nmulti-session worker. History has no other record of it, so the server\nneeds it to restore the binding when it rebuilds the workflow from\nhistory. Always set." + } + }, + "description": "EXPERIMENTAL. Subject to redesign or removal.\nHow a workflow is bound to a worker." + }, "v1SetCurrentDeploymentResponse": { "type": "object", "properties": { @@ -20162,6 +20195,16 @@ } } }, + "v1SingleSessionOptions": { + "type": "object", + "properties": { + "stableIdentity": { + "type": "string", + "description": "Identity the binding is stored under. Required; must be non-empty.\nReuse it across restarts of the same session, not across concurrently\nrunning workers. If multiple workers poll with the same stable_identity\nconcurrently, the server treats them as pollers of a single worker and\nprocess affinity is lost.\n\nNote: this is the name of the worker's sticky queue, specified by the user.\nNote: we are currently unsure how this will evolve. May be deprecated as\nthe session model develops." + } + }, + "description": "EXPERIMENTAL. Subject to redesign or removal.\nService exactly one session for the worker's lifetime, including across\nprocess restarts with the same stable_identity. The first workflow this\nworker picks up is bound to it, and from then on the worker only receives\nthat workflow's tasks, even after the workflow completes." + }, "v1StartActivityExecutionResponse": { "type": "object", "properties": { @@ -21574,6 +21617,10 @@ "environment": { "$ref": "#/definitions/v1EnvironmentInfo", "description": "Information about the environment this SDK is running in." + }, + "sessionOptions": { + "$ref": "#/definitions/v1WorkerSessionOptions", + "description": "The worker's session options, as sent on its polls. Lets the server recognize a multi-session worker that has\nstopped, so it can move the workflows bound to it to other workers. Unset for a worker without sessions.\nNot used in the case of single-session workers." } }, "description": "Worker info message, contains information about the worker and its current state.\nAll information is provided by the worker itself." @@ -21712,6 +21759,20 @@ }, "description": "This is used to send commands to a specific worker or a group of workers.\nRight now, it is used to send commands to a specific worker instance.\nWill be extended to be able to send command to multiple workers." }, + "v1WorkerSessionOptions": { + "type": "object", + "properties": { + "singleSession": { + "$ref": "#/definitions/v1SingleSessionOptions", + "description": "If specified, the worker only polls for work belonging to its session." + }, + "multiSession": { + "$ref": "#/definitions/v1MultiSessionOptions", + "description": "If specified, the worker can service multiple sessions at once." + } + }, + "description": "EXPERIMENTAL. Subject to redesign or removal.\nSent on workflow and activity polls. Presence means this worker can service\nsessions. Currently, the only supported Session type is Workflow Session\n(aka Workflow-as-Session). A Workflow that is bound to a worker servicing sessions\ncan receive both workflow tasks and activity tasks of an execution.\n\nThe server routes a session's work to the worker's sticky queue, so the\nsticky queue name depends on the admission mode:\n * single_session: the worker polls only its sticky queue, named after\n SingleSessionOptions.stable_identity.\n * multi_session: the worker polls the normal queue and its sticky queue,\n named after the poll's worker_instance_key.\nThe server rejects sticky polls whose name does not follow this rule." + }, "v1WorkerSlotsInfo": { "type": "object", "properties": { @@ -22431,6 +22492,10 @@ "propagatedNexusSerializationContext": { "$ref": "#/definitions/v1PropagatedSerializationContext", "description": "Serialization context propagated from the Nexus caller that started this workflow." + }, + "inheritedSessionInfo": { + "$ref": "#/definitions/v1SessionInfo", + "description": "Session info this run inherited from the previous run (continue-as-new or retry), so the server\ncan rebuild it from history. Nil when the previous run was not bound or this run is on a different\ntask queue. Child workflows never inherit it.\nUsed internally by the server; SDKs should not read or interpret this field.\nEXPERIMENTAL. Subject to redesign or removal." } }, "title": "Always the first event in workflow history" @@ -22908,10 +22973,11 @@ "WORKFLOW_TASK_FAILED_CAUSE_PAYLOADS_TOO_LARGE", "WORKFLOW_TASK_FAILED_CAUSE_EXTERNAL_STORAGE_FAILURE", "WORKFLOW_TASK_FAILED_CAUSE_WORKFLOW_PAUSE_REQUESTED_BEFORE_TASK_STARTED", - "WORKFLOW_TASK_FAILED_CAUSE_REQUEST_TOO_LARGE" + "WORKFLOW_TASK_FAILED_CAUSE_REQUEST_TOO_LARGE", + "WORKFLOW_TASK_FAILED_CAUSE_SESSION_WORKER_REQUIRED" ], "default": "WORKFLOW_TASK_FAILED_CAUSE_UNSPECIFIED", - "description": "Workflow tasks can fail for various reasons. Note that some of these reasons can only originate\nfrom the server, and some of them can only originate from the SDK/worker.\n\n - WORKFLOW_TASK_FAILED_CAUSE_UNHANDLED_COMMAND: Between starting and completing the workflow task (with a workflow completion command), some\nnew command (like a signal) was processed into workflow history. The outstanding task will be\nfailed with this reason, and a worker must pick up a new task.\n - WORKFLOW_TASK_FAILED_CAUSE_RESET_STICKY_TASK_QUEUE: The worker wishes to fail the task and have the next one be generated on a normal, not sticky\nqueue. Generally workers should prefer to use the explicit `ResetStickyTaskQueue` RPC call.\n - WORKFLOW_TASK_FAILED_CAUSE_NON_DETERMINISTIC_ERROR: The worker encountered a mismatch while replaying history between what was expected, and\nwhat the workflow code actually did.\n - WORKFLOW_TASK_FAILED_CAUSE_PENDING_CHILD_WORKFLOWS_LIMIT_EXCEEDED: We send the below error codes to users when their requests would violate a size constraint\nof their workflow. We do this to ensure that the state of their workflow does not become too\nlarge because that can cause severe performance degradation. You can modify the thresholds for\neach of these errors within your dynamic config.\n\nSpawning a new child workflow would cause this workflow to exceed its limit of pending child\nworkflows.\n - WORKFLOW_TASK_FAILED_CAUSE_PENDING_ACTIVITIES_LIMIT_EXCEEDED: Starting a new activity would cause this workflow to exceed its limit of pending activities\nthat we track.\n - WORKFLOW_TASK_FAILED_CAUSE_PENDING_SIGNALS_LIMIT_EXCEEDED: A workflow has a buffer of signals that have not yet reached their destination. We return this\nerror when sending a new signal would exceed the capacity of this buffer.\n - WORKFLOW_TASK_FAILED_CAUSE_PENDING_REQUEST_CANCEL_LIMIT_EXCEEDED: Similarly, we have a buffer of pending requests to cancel other workflows. We return this error\nwhen our capacity for pending cancel requests is already reached.\n - WORKFLOW_TASK_FAILED_CAUSE_BAD_UPDATE_WORKFLOW_EXECUTION_MESSAGE: Workflow execution update message (update.Acceptance, update.Rejection, or update.Response)\nhas wrong format, or missing required fields.\n - WORKFLOW_TASK_FAILED_CAUSE_UNHANDLED_UPDATE: Similar to WORKFLOW_TASK_FAILED_CAUSE_UNHANDLED_COMMAND, but for updates.\n - WORKFLOW_TASK_FAILED_CAUSE_BAD_SCHEDULE_NEXUS_OPERATION_ATTRIBUTES: A workflow task completed with an invalid ScheduleNexusOperation command.\n - WORKFLOW_TASK_FAILED_CAUSE_PENDING_NEXUS_OPERATIONS_LIMIT_EXCEEDED: A workflow task completed requesting to schedule a Nexus Operation exceeding the server configured limit.\n - WORKFLOW_TASK_FAILED_CAUSE_BAD_REQUEST_CANCEL_NEXUS_OPERATION_ATTRIBUTES: A workflow task completed with an invalid RequestCancelNexusOperation command.\n - WORKFLOW_TASK_FAILED_CAUSE_FEATURE_DISABLED: A workflow task completed requesting a feature that's disabled on the server (either system wide or - typically -\nfor the workflow's namespace).\nCheck the workflow task failure message for more information.\n - WORKFLOW_TASK_FAILED_CAUSE_GRPC_MESSAGE_TOO_LARGE: A workflow task failed because a grpc message was too large.\n - WORKFLOW_TASK_FAILED_CAUSE_PAYLOADS_TOO_LARGE: A workflow task failed because payloads were too large.\n - WORKFLOW_TASK_FAILED_CAUSE_EXTERNAL_STORAGE_FAILURE: A workflow task failed because an external storage operation failed.\nCheck the workflow task failure message for more information.\n - WORKFLOW_TASK_FAILED_CAUSE_WORKFLOW_PAUSE_REQUESTED_BEFORE_TASK_STARTED: A workflow task is failed because the workflow is paused before the task is started.\n - WORKFLOW_TASK_FAILED_CAUSE_REQUEST_TOO_LARGE: A workflow task failed because the request exceeded a size limit." + "description": "Workflow tasks can fail for various reasons. Note that some of these reasons can only originate\nfrom the server, and some of them can only originate from the SDK/worker.\n\n - WORKFLOW_TASK_FAILED_CAUSE_UNHANDLED_COMMAND: Between starting and completing the workflow task (with a workflow completion command), some\nnew command (like a signal) was processed into workflow history. The outstanding task will be\nfailed with this reason, and a worker must pick up a new task.\n - WORKFLOW_TASK_FAILED_CAUSE_RESET_STICKY_TASK_QUEUE: The worker wishes to fail the task and have the next one be generated on a normal, not sticky\nqueue. Generally workers should prefer to use the explicit `ResetStickyTaskQueue` RPC call.\n - WORKFLOW_TASK_FAILED_CAUSE_NON_DETERMINISTIC_ERROR: The worker encountered a mismatch while replaying history between what was expected, and\nwhat the workflow code actually did.\n - WORKFLOW_TASK_FAILED_CAUSE_PENDING_CHILD_WORKFLOWS_LIMIT_EXCEEDED: We send the below error codes to users when their requests would violate a size constraint\nof their workflow. We do this to ensure that the state of their workflow does not become too\nlarge because that can cause severe performance degradation. You can modify the thresholds for\neach of these errors within your dynamic config.\n\nSpawning a new child workflow would cause this workflow to exceed its limit of pending child\nworkflows.\n - WORKFLOW_TASK_FAILED_CAUSE_PENDING_ACTIVITIES_LIMIT_EXCEEDED: Starting a new activity would cause this workflow to exceed its limit of pending activities\nthat we track.\n - WORKFLOW_TASK_FAILED_CAUSE_PENDING_SIGNALS_LIMIT_EXCEEDED: A workflow has a buffer of signals that have not yet reached their destination. We return this\nerror when sending a new signal would exceed the capacity of this buffer.\n - WORKFLOW_TASK_FAILED_CAUSE_PENDING_REQUEST_CANCEL_LIMIT_EXCEEDED: Similarly, we have a buffer of pending requests to cancel other workflows. We return this error\nwhen our capacity for pending cancel requests is already reached.\n - WORKFLOW_TASK_FAILED_CAUSE_BAD_UPDATE_WORKFLOW_EXECUTION_MESSAGE: Workflow execution update message (update.Acceptance, update.Rejection, or update.Response)\nhas wrong format, or missing required fields.\n - WORKFLOW_TASK_FAILED_CAUSE_UNHANDLED_UPDATE: Similar to WORKFLOW_TASK_FAILED_CAUSE_UNHANDLED_COMMAND, but for updates.\n - WORKFLOW_TASK_FAILED_CAUSE_BAD_SCHEDULE_NEXUS_OPERATION_ATTRIBUTES: A workflow task completed with an invalid ScheduleNexusOperation command.\n - WORKFLOW_TASK_FAILED_CAUSE_PENDING_NEXUS_OPERATIONS_LIMIT_EXCEEDED: A workflow task completed requesting to schedule a Nexus Operation exceeding the server configured limit.\n - WORKFLOW_TASK_FAILED_CAUSE_BAD_REQUEST_CANCEL_NEXUS_OPERATION_ATTRIBUTES: A workflow task completed with an invalid RequestCancelNexusOperation command.\n - WORKFLOW_TASK_FAILED_CAUSE_FEATURE_DISABLED: A workflow task completed requesting a feature that's disabled on the server (either system wide or - typically -\nfor the workflow's namespace).\nCheck the workflow task failure message for more information.\n - WORKFLOW_TASK_FAILED_CAUSE_GRPC_MESSAGE_TOO_LARGE: A workflow task failed because a grpc message was too large.\n - WORKFLOW_TASK_FAILED_CAUSE_PAYLOADS_TOO_LARGE: A workflow task failed because payloads were too large.\n - WORKFLOW_TASK_FAILED_CAUSE_EXTERNAL_STORAGE_FAILURE: A workflow task failed because an external storage operation failed.\nCheck the workflow task failure message for more information.\n - WORKFLOW_TASK_FAILED_CAUSE_WORKFLOW_PAUSE_REQUESTED_BEFORE_TASK_STARTED: A workflow task is failed because the workflow is paused before the task is started.\n - WORKFLOW_TASK_FAILED_CAUSE_REQUEST_TOO_LARGE: A workflow task failed because the request exceeded a size limit.\n - WORKFLOW_TASK_FAILED_CAUSE_SESSION_WORKER_REQUIRED: A workflow task was completed by a worker that does not service sessions while the workflow has session\nactivities waiting for a session worker. Only a worker servicing sessions can complete the workflow's tasks\nuntil one binds the workflow. The task is retried; check the workflow task failure message for more information." }, "v1WorkflowTaskFailedEventAttributes": { "type": "object", @@ -23022,6 +23088,10 @@ "type": "string", "format": "int64", "title": "Used by server internally to properly reapply build ID redirects to an execution\nwhen rebuilding it from events.\nDeprecated. This field should be cleaned up when versioning-2 API is removed. [cleanup-experimental-wv]" + }, + "sessionInfo": { + "$ref": "#/definitions/v1SessionInfo", + "description": "Session info of this workflow as of this task start, so the server can rebuild it from history (for\nexample on reset). Nil when the workflow is not bound to a worker.\nUsed internally by the server; SDKs should not read or interpret this field.\nEXPERIMENTAL. Subject to redesign or removal." } } }, diff --git a/openapi/openapiv3.yaml b/openapi/openapiv3.yaml index 22e107bc5..3bf8d3332 100644 --- a/openapi/openapiv3.yaml +++ b/openapi/openapiv3.yaml @@ -10138,6 +10138,12 @@ components: description: |- If set, update the retry policy of the activity, replacing it with the specified one. The number of attempts at the activity is preserved. + ActivitySessionOptions: + type: object + properties: {} + description: |- + EXPERIMENTAL. Subject to redesign or removal. + Resolved activity placement. Unset = normal task-queue routing. ActivityTaskCancelRequestedEventAttributes: type: object properties: @@ -10309,6 +10315,12 @@ components: description: |- Priority metadata. If this message is not present, or any fields are not present, they inherit the values from the workflow. + sessionOptions: + allOf: + - $ref: '#/components/schemas/ActivitySessionOptions' + description: |- + Preserves the scheduling command's session routing options so activity state + can be reconstructed from history. ActivityTaskStartedEventAttributes: type: object properties: @@ -13619,6 +13631,13 @@ components: aip.dev/not-precedent: Negative values make no sense to represent. --) format: uint32 description: Metadata relevant for metering purposes + MultiSessionOptions: + type: object + properties: {} + description: |- + EXPERIMENTAL. Subject to redesign or removal. + Service any number of sessions concurrently. Future admission knobs (e.g. + session slots) belong here. NamespaceConfig: type: object properties: @@ -16847,6 +16866,25 @@ components: properties: nonRetryable: type: boolean + SessionInfo: + type: object + properties: + exclusiveWorker: + type: boolean + description: |- + True when the workflow is bound to a single-session worker. Such a + binding never moves to another worker. + workerQueue: + type: string + description: |- + The sticky queue of the worker the workflow is bound to: the stable + identity of a single-session worker, or the worker instance key of a + multi-session worker. History has no other record of it, so the server + needs it to restore the binding when it rebuilds the workflow from + history. Always set. + description: |- + EXPERIMENTAL. Subject to redesign or removal. + How a workflow is bound to a worker. SetCurrentDeploymentRequest: type: object properties: @@ -17330,6 +17368,27 @@ components: Link to be associated with the WorkflowExecutionSignaled event. Added on the response to propagate the backlink. Available from Temporal server 1.31 and up. + SingleSessionOptions: + type: object + properties: + stableIdentity: + type: string + description: |- + Identity the binding is stored under. Required; must be non-empty. + Reuse it across restarts of the same session, not across concurrently + running workers. If multiple workers poll with the same stable_identity + concurrently, the server treats them as pollers of a single worker and + process affinity is lost. + + Note: this is the name of the worker's sticky queue, specified by the user. + Note: we are currently unsure how this will evolve. May be deprecated as + the session model develops. + description: |- + EXPERIMENTAL. Subject to redesign or removal. + Service exactly one session for the worker's lifetime, including across + process restarts with the same stable_identity. The first workflow this + worker picks up is bound to it, and from then on the worker only receives + that workflow's tasks, even after the workflow completes. StartActivityExecutionRequest: type: object properties: @@ -20007,6 +20066,13 @@ components: allOf: - $ref: '#/components/schemas/EnvironmentInfo' description: Information about the environment this SDK is running in. + sessionOptions: + allOf: + - $ref: '#/components/schemas/WorkerSessionOptions' + description: |- + The worker's session options, as sent on its polls. Lets the server recognize a multi-session worker that has + stopped, so it can move the workflows bound to it to other workers. Unset for a worker without sessions. + Not used in the case of single-session workers. description: |- Worker info message, contains information about the worker and its current state. All information is provided by the worker itself. @@ -20141,6 +20207,31 @@ components: This is used to send commands to a specific worker or a group of workers. Right now, it is used to send commands to a specific worker instance. Will be extended to be able to send command to multiple workers. + WorkerSessionOptions: + type: object + properties: + singleSession: + allOf: + - $ref: '#/components/schemas/SingleSessionOptions' + description: If specified, the worker only polls for work belonging to its session. + multiSession: + allOf: + - $ref: '#/components/schemas/MultiSessionOptions' + description: If specified, the worker can service multiple sessions at once. + description: |- + EXPERIMENTAL. Subject to redesign or removal. + Sent on workflow and activity polls. Presence means this worker can service + sessions. Currently, the only supported Session type is Workflow Session + (aka Workflow-as-Session). A Workflow that is bound to a worker servicing sessions + can receive both workflow tasks and activity tasks of an execution. + + The server routes a session's work to the worker's sticky queue, so the + sticky queue name depends on the admission mode: + * single_session: the worker polls only its sticky queue, named after + SingleSessionOptions.stable_identity. + * multi_session: the worker polls the normal queue and its sticky queue, + named after the poll's worker_instance_key. + The server rejects sticky polls whose name does not follow this rule. WorkerSlotsInfo: type: object properties: @@ -21101,6 +21192,15 @@ components: allOf: - $ref: '#/components/schemas/PropagatedSerializationContext' description: Serialization context propagated from the Nexus caller that started this workflow. + inheritedSessionInfo: + allOf: + - $ref: '#/components/schemas/SessionInfo' + description: |- + Session info this run inherited from the previous run (continue-as-new or retry), so the server + can rebuild it from history. Nil when the previous run was not bound or this run is on a different + task queue. Child workflows never inherit it. + Used internally by the server; SDKs should not read or interpret this field. + EXPERIMENTAL. Subject to redesign or removal. description: Always the first event in workflow history WorkflowExecutionTerminatedEventAttributes: type: object @@ -21669,6 +21769,7 @@ components: - WORKFLOW_TASK_FAILED_CAUSE_EXTERNAL_STORAGE_FAILURE - WORKFLOW_TASK_FAILED_CAUSE_WORKFLOW_PAUSE_REQUESTED_BEFORE_TASK_STARTED - WORKFLOW_TASK_FAILED_CAUSE_REQUEST_TOO_LARGE + - WORKFLOW_TASK_FAILED_CAUSE_SESSION_WORKER_REQUIRED type: string format: enum failure: @@ -21781,6 +21882,14 @@ components: Used by server internally to properly reapply build ID redirects to an execution when rebuilding it from events. Deprecated. This field should be cleaned up when versioning-2 API is removed. [cleanup-experimental-wv] + sessionInfo: + allOf: + - $ref: '#/components/schemas/SessionInfo' + description: |- + Session info of this workflow as of this task start, so the server can rebuild it from history (for + example on reset). Nil when the workflow is not bound to a worker. + Used internally by the server; SDKs should not read or interpret this field. + EXPERIMENTAL. Subject to redesign or removal. WorkflowTaskTimedOutEventAttributes: type: object properties: diff --git a/temporal/api/command/v1/message.proto b/temporal/api/command/v1/message.proto index ee839115b..b8be64315 100644 --- a/temporal/api/command/v1/message.proto +++ b/temporal/api/command/v1/message.proto @@ -16,6 +16,7 @@ import "temporal/api/enums/v1/command_type.proto"; import "temporal/api/common/v1/message.proto"; import "temporal/api/failure/v1/message.proto"; import "temporal/api/taskqueue/v1/message.proto"; +import "temporal/api/session/v1/message.proto"; import "temporal/api/workflow/v1/message.proto"; import "temporal/api/sdk/v1/user_metadata.proto"; import "temporal/api/sdk/v1/event_group_marker.proto"; @@ -68,6 +69,8 @@ message ScheduleActivityTaskCommandAttributes { // Priority metadata. If this message is not present, or any fields are not // present, they inherit the values from the workflow. temporal.api.common.v1.Priority priority = 14; + + temporal.api.session.v1.ActivitySessionOptions session_options = 15; } message RequestCancelActivityTaskCommandAttributes { diff --git a/temporal/api/enums/v1/failed_cause.proto b/temporal/api/enums/v1/failed_cause.proto index ba0d74273..a1e004de8 100644 --- a/temporal/api/enums/v1/failed_cause.proto +++ b/temporal/api/enums/v1/failed_cause.proto @@ -90,6 +90,10 @@ enum WorkflowTaskFailedCause { WORKFLOW_TASK_FAILED_CAUSE_WORKFLOW_PAUSE_REQUESTED_BEFORE_TASK_STARTED = 39; // A workflow task failed because the request exceeded a size limit. WORKFLOW_TASK_FAILED_CAUSE_REQUEST_TOO_LARGE = 40; + // A workflow task was completed by a worker that does not service sessions while the workflow has session + // activities waiting for a session worker. Only a worker servicing sessions can complete the workflow's tasks + // until one binds the workflow. The task is retried; check the workflow task failure message for more information. + WORKFLOW_TASK_FAILED_CAUSE_SESSION_WORKER_REQUIRED = 41; } // Activity tasks can fail for various reasons. Note that some of these reasons can only originate diff --git a/temporal/api/history/v1/message.proto b/temporal/api/history/v1/message.proto index aeeb334f2..5f9a29759 100644 --- a/temporal/api/history/v1/message.proto +++ b/temporal/api/history/v1/message.proto @@ -20,6 +20,7 @@ import "temporal/api/common/v1/message.proto"; import "temporal/api/deployment/v1/message.proto"; import "temporal/api/failure/v1/message.proto"; import "temporal/api/nexus/v1/message.proto"; +import "temporal/api/session/v1/message.proto"; import "temporal/api/taskqueue/v1/message.proto"; import "temporal/api/update/v1/message.proto"; import "temporal/api/workflow/v1/message.proto"; @@ -218,6 +219,13 @@ message WorkflowExecutionStartedEventAttributes { // Serialization context propagated from the Nexus caller that started this workflow. temporal.api.nexus.v1.PropagatedSerializationContext propagated_nexus_serialization_context = 44; + + // Session info this run inherited from the previous run (continue-as-new or retry), so the server + // can rebuild it from history. Nil when the previous run was not bound or this run is on a different + // task queue. Child workflows never inherit it. + // Used internally by the server; SDKs should not read or interpret this field. + // EXPERIMENTAL. Subject to redesign or removal. + temporal.api.session.v1.SessionInfo inherited_session_info = 45; } @@ -341,6 +349,11 @@ message WorkflowTaskStartedEventAttributes { // when rebuilding it from events. // Deprecated. This field should be cleaned up when versioning-2 API is removed. [cleanup-experimental-wv] int64 build_id_redirect_counter = 7 [deprecated = true]; + // Session info of this workflow as of this task start, so the server can rebuild it from history (for + // example on reset). Nil when the workflow is not bound to a worker. + // Used internally by the server; SDKs should not read or interpret this field. + // EXPERIMENTAL. Subject to redesign or removal. + temporal.api.session.v1.SessionInfo session_info = 10; } message WorkflowTaskCompletedEventAttributes { @@ -467,6 +480,9 @@ message ActivityTaskScheduledEventAttributes { // Priority metadata. If this message is not present, or any fields are not // present, they inherit the values from the workflow. temporal.api.common.v1.Priority priority = 14; + // Preserves the scheduling command's session routing options so activity state + // can be reconstructed from history. + temporal.api.session.v1.ActivitySessionOptions session_options = 15; } message ActivityTaskStartedEventAttributes { diff --git a/temporal/api/session/v1/message.proto b/temporal/api/session/v1/message.proto new file mode 100644 index 000000000..5331a0941 --- /dev/null +++ b/temporal/api/session/v1/message.proto @@ -0,0 +1,87 @@ +syntax = "proto3"; + +package temporal.api.session.v1; + +option go_package = "go.temporal.io/api/session/v1;session"; +option java_package = "io.temporal.api.session.v1"; +option java_multiple_files = true; +option java_outer_classname = "MessageProto"; +option ruby_package = "Temporalio::Api::Session::V1"; +option csharp_namespace = "Temporalio.Api.Session.V1"; + +import "google/protobuf/empty.proto"; + +// EXPERIMENTAL. Subject to redesign or removal. +// Sent on workflow and activity polls. Presence means this worker can service +// sessions. Currently, the only supported Session type is Workflow Session +// (aka Workflow-as-Session). A Workflow that is bound to a worker servicing sessions +// can receive both workflow tasks and activity tasks of an execution. +// +// The server routes a session's work to the worker's sticky queue, so the +// sticky queue name depends on the admission mode: +// * single_session: the worker polls only its sticky queue, named after +// SingleSessionOptions.stable_identity. +// * multi_session: the worker polls the normal queue and its sticky queue, +// named after the poll's worker_instance_key. +// The server rejects sticky polls whose name does not follow this rule. +message WorkerSessionOptions { + // Admission control. Required: exactly one mode must be set, and the + // server rejects session options with neither. + oneof admission { + // If specified, the worker only polls for work belonging to its session. + SingleSessionOptions single_session = 1; + // If specified, the worker can service multiple sessions at once. + MultiSessionOptions multi_session = 2; + } +} + +// EXPERIMENTAL. Subject to redesign or removal. +// Service exactly one session for the worker's lifetime, including across +// process restarts with the same stable_identity. The first workflow this +// worker picks up is bound to it, and from then on the worker only receives +// that workflow's tasks, even after the workflow completes. +message SingleSessionOptions { + // Identity the binding is stored under. Required; must be non-empty. + // Reuse it across restarts of the same session, not across concurrently + // running workers. If multiple workers poll with the same stable_identity + // concurrently, the server treats them as pollers of a single worker and + // process affinity is lost. + // + // Note: this is the name of the worker's sticky queue, specified by the user. + // Note: we are currently unsure how this will evolve. May be deprecated as + // the session model develops. + string stable_identity = 1; +} + +// EXPERIMENTAL. Subject to redesign or removal. +// Service any number of sessions concurrently. Future admission knobs (e.g. +// session slots) belong here. +message MultiSessionOptions { +} + +// EXPERIMENTAL. Subject to redesign or removal. +// Resolved activity placement. Unset = normal task-queue routing. +message ActivitySessionOptions { + oneof placement { + // Run in the workflow's current session (on its sticky queue). + // Currently requires the activity's task queue to be the workflow's, + // and the workflow's worker to service sessions. + google.protobuf.Empty workflow_session = 1; + + // Future: references to other types of sessions. + } +} + +// EXPERIMENTAL. Subject to redesign or removal. +// How a workflow is bound to a worker. +message SessionInfo { + // True when the workflow is bound to a single-session worker. Such a + // binding never moves to another worker. + bool exclusive_worker = 1; + // The sticky queue of the worker the workflow is bound to: the stable + // identity of a single-session worker, or the worker instance key of a + // multi-session worker. History has no other record of it, so the server + // needs it to restore the binding when it rebuilds the workflow from + // history. Always set. + string worker_queue = 2; +} diff --git a/temporal/api/worker/v1/message.proto b/temporal/api/worker/v1/message.proto index 470b5b66c..ec29e7dd4 100644 --- a/temporal/api/worker/v1/message.proto +++ b/temporal/api/worker/v1/message.proto @@ -14,6 +14,7 @@ import "google/protobuf/timestamp.proto"; import "temporal/api/common/v1/message.proto"; import "temporal/api/deployment/v1/message.proto"; import "temporal/api/enums/v1/common.proto"; +import "temporal/api/session/v1/message.proto"; message WorkerPollerInfo { // Number of polling RPCs that are currently in flight. @@ -138,6 +139,11 @@ message WorkerHeartbeat { // Information about the environment this SDK is running in. EnvironmentInfo environment = 25; + + // The worker's session options, as sent on its polls. Lets the server recognize a multi-session worker that has + // stopped, so it can move the workflows bound to it to other workers. Unset for a worker without sessions. + // Not used in the case of single-session workers. + temporal.api.session.v1.WorkerSessionOptions session_options = 26; } // Detailed worker information. diff --git a/temporal/api/workflowservice/v1/request_response.proto b/temporal/api/workflowservice/v1/request_response.proto index 5786e0f75..a44066c07 100644 --- a/temporal/api/workflowservice/v1/request_response.proto +++ b/temporal/api/workflowservice/v1/request_response.proto @@ -38,6 +38,7 @@ import "temporal/api/replication/v1/message.proto"; import "temporal/api/rules/v1/message.proto"; import "temporal/api/sdk/v1/worker_config.proto"; import "temporal/api/schedule/v1/message.proto"; +import "temporal/api/session/v1/message.proto"; import "temporal/api/taskqueue/v1/message.proto"; import "temporal/api/update/v1/message.proto"; import "temporal/api/version/v1/message.proto"; @@ -317,6 +318,7 @@ message PollWorkflowTaskQueueRequest { string identity = 3; // A unique key for this worker instance, used for tracking worker lifecycle. // This is guaranteed to be unique, whereas identity is not guaranteed to be unique. + // A multi-session worker's sticky queue is named after it (see WorkerSessionOptions). string worker_instance_key = 8; // A dedicated per-worker Nexus task queue on which the server sends control @@ -347,6 +349,12 @@ message PollWorkflowTaskQueueRequest { // Removed in 1.55.0; was temporal.api.worker.v1.WorkerHeartbeat worker_heartbeat reserved 7; reserved "worker_heartbeat"; + + // EXPERIMENTAL. Subject to redesign or removal. The worker's session options. + // A single-session worker sends them on sticky polls only; a multi-session + // worker sends them on normal and sticky polls. Unset for a worker without + // sessions. + temporal.api.session.v1.WorkerSessionOptions session_options = 13; } message PollWorkflowTaskQueueResponse { @@ -560,6 +568,7 @@ message PollActivityTaskQueueRequest { string identity = 3; // A unique key for this worker instance, used for tracking worker lifecycle. // This is guaranteed to be unique, whereas identity is not guaranteed to be unique. + // A multi-session worker's sticky queue is named after it (see WorkerSessionOptions). string worker_instance_key = 8; // A dedicated per-worker Nexus task queue on which the server sends control @@ -580,6 +589,12 @@ message PollActivityTaskQueueRequest { // Removed in 1.55.0; was temporal.api.worker.v1.WorkerHeartbeat worker_heartbeat reserved 7; reserved "worker_heartbeat"; + + // EXPERIMENTAL. Subject to redesign or removal. The worker's session options. + // A single-session worker sends them on sticky polls only; a multi-session + // worker sends them on normal and sticky polls. Unset for a worker without + // sessions. + temporal.api.session.v1.WorkerSessionOptions session_options = 13; } message PollActivityTaskQueueResponse {