Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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 changelog/added/steady-stream-heron.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add experimental Streams for clients, Activities, and Workflows, with configurable Stores, buffered appends, client interceptor hooks, and replay support.
1 change: 1 addition & 0 deletions changelog/changed/juggling-jellyfish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Route client and Activity Stream calls through operation-specific outbound interceptor hooks using typed Nexus input envelopes and operation handles, without invoking generic Nexus start or result hooks. Preserve request IDs and call options across interceptor retries.
2 changes: 1 addition & 1 deletion scripts/gen_nexus_system_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
notification_output_dir = base_dir / "temporalio" / "nexus" / "notifications"
stream_output_dir = base_dir / "temporalio" / "nexus" / "system" / "stream_service"
workflow_init_path = base_dir / "temporalio" / "workflow" / "__init__.py"
NEX_GEN_REVISION = "38c39883e78980a864b1b838aa8f6ff91561bb9f"
NEX_GEN_REVISION = "db48bf91ace1f2669022c26ca3d00f1ae6889056"
proto_files = [
gen_protos.api_proto_dir
/ "temporal"
Expand Down
43 changes: 30 additions & 13 deletions scripts/gen_payload_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,38 @@
from temporalio.converter._payload_converter import _get_transfer_type_converter


def discover_system_nexus_roots() -> list[Descriptor]:
module_path = base_dir / "temporalio" / "nexus" / "system" / "workflow_service"
spec = spec_from_file_location(
"temporalio_nexus_system_workflow_service",
module_path / "__init__.py",
submodule_search_locations=[str(module_path)],
)
if spec is None or spec.loader is None:
raise RuntimeError(f"Cannot load generated system service from {module_path}")
module = module_from_spec(spec)
sys.modules[spec.name] = module
spec.loader.exec_module(module)
def discover_system_nexus_services() -> list[type]:
services: list[type] = []
system_dir = base_dir / "temporalio" / "nexus" / "system"
for module_path in sorted(path.parent for path in system_dir.glob("*/services.py")):
spec = spec_from_file_location(
f"temporalio_nexus_system_{module_path.name}",
module_path / "__init__.py",
submodule_search_locations=[str(module_path)],
)
if spec is None or spec.loader is None:
raise RuntimeError(
f"Cannot load generated system service from {module_path}"
)
module = module_from_spec(spec)
sys.modules[spec.name] = module
spec.loader.exec_module(module)
services.extend(
value
for value in vars(module.services).values()
if isinstance(value, type) and nexusrpc.get_service_definition(value)
)
return services


def discover_system_nexus_roots() -> list[Descriptor]:
roots: list[Descriptor] = []
for annotation in get_type_hints(module._services.WorkflowService).values():
annotations = [
annotation
for service in discover_system_nexus_services()
for annotation in get_type_hints(service).values()
]
for annotation in annotations:
if get_origin(annotation) is not nexusrpc.Operation:
continue
for operation_type in get_args(annotation):
Expand Down
76 changes: 76 additions & 0 deletions temporalio/bridge/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions temporalio/bridge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ temporalio-sdk-core = { version = "0.12.0", path = "./sdk-core/crates/sdk-core",
"ephemeral-server",
"envconfig",
"prometheus",
# Replay must retain the result groups of Stream create and describe Local Activities.
"disable_workflow_task_chunking",
] }
temporalio-streams = { version = "0.1.0", path = "./sdk-core/crates/streams" }
tokio = "1.26"
# Matches the sdk-core client crate's rustls stack; used to build the custom
# server certificate verifier for TLSConfig.verification_server_name.
Expand Down
91 changes: 91 additions & 0 deletions temporalio/bridge/_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,32 @@ async def _visit_coresdk_workflow_activation_ResolveNexusOperation(
if o.HasField("result"):
await self._visit_coresdk_nexus_NexusOperationResult(fs, o.result)

async def _visit_coresdk_workflow_activation_ResolveStreamAppend(
self, fs: VisitorFunctions, o: Any
):
if o.HasField("failed"):
await self._visit_temporal_api_failure_v1_Failure(fs, o.failed)

async def _visit_temporal_api_stream_v1_StreamRecord(
self, fs: VisitorFunctions, o: Any
):
if o.HasField("body"):
await self._visit_temporal_api_common_v1_Payload(fs, o.body)

async def _visit_coresdk_workflow_activation_StreamPage(
self, fs: VisitorFunctions, o: Any
):
for v in o.records:
await self._visit_temporal_api_stream_v1_StreamRecord(fs, v)

async def _visit_coresdk_workflow_activation_ResolveStreamRead(
self, fs: VisitorFunctions, o: Any
):
if o.HasField("page"):
await self._visit_coresdk_workflow_activation_StreamPage(fs, o.page)
elif o.HasField("failed"):
await self._visit_temporal_api_failure_v1_Failure(fs, o.failed)

async def _visit_coresdk_workflow_activation_WorkflowActivationJob(
self, fs: VisitorFunctions, o: Any
):
Expand Down Expand Up @@ -353,6 +379,14 @@ async def _visit_coresdk_workflow_activation_WorkflowActivationJob(
await self._visit_coresdk_workflow_activation_ResolveNexusOperation(
fs, o.resolve_nexus_operation
)
elif o.HasField("resolve_stream_append"):
await self._visit_coresdk_workflow_activation_ResolveStreamAppend(
fs, o.resolve_stream_append
)
elif o.HasField("resolve_stream_read"):
await self._visit_coresdk_workflow_activation_ResolveStreamRead(
fs, o.resolve_stream_read
)

async def _visit_coresdk_workflow_activation_WorkflowActivation(
self, fs: VisitorFunctions, o: Any
Expand Down Expand Up @@ -492,6 +526,11 @@ async def _visit_coresdk_workflow_commands_ScheduleNexusOperation(
if o.HasField("input"):
await self._visit_nexus_operation_input_payload(fs, o.input)

async def _visit_coresdk_workflow_commands_AppendToStream(
self, fs: VisitorFunctions, o: Any
):
await self._visit_payload_container(fs, o.bodies)

async def _visit_coresdk_workflow_commands_WorkflowCommand(
self, fs: VisitorFunctions, o: Any
):
Expand Down Expand Up @@ -551,6 +590,10 @@ async def _visit_coresdk_workflow_commands_WorkflowCommand(
await self._visit_coresdk_workflow_commands_ScheduleNexusOperation(
fs, o.schedule_nexus_operation
)
elif o.HasField("append_to_stream"):
await self._visit_coresdk_workflow_commands_AppendToStream(
fs, o.append_to_stream
)

async def _visit_coresdk_workflow_completion_Success(
self, fs: VisitorFunctions, o: Any
Expand Down Expand Up @@ -639,6 +682,54 @@ async def _visit_temporal_api_notificationservice_v1_OnCompleteResponse(
) -> None:
pass

async def _visit_temporal_api_sdk_v1_CreateStreamRequest(
self, fs: VisitorFunctions, o: Any
) -> None:
pass

async def _visit_temporal_api_sdk_v1_CreateStreamResponse(
self, fs: VisitorFunctions, o: Any
) -> None:
pass

async def _visit_temporal_api_stream_v1_AppendRecord(
self, fs: VisitorFunctions, o: Any
):
if o.HasField("body"):
await self._visit_temporal_api_common_v1_Payload(fs, o.body)

async def _visit_temporal_api_sdk_v1_AppendRecordsRequest(
self, fs: VisitorFunctions, o: Any
):
for v in o.records:
await self._visit_temporal_api_stream_v1_AppendRecord(fs, v)

async def _visit_temporal_api_streamservice_v1_AppendRecordsResponse(
self, fs: VisitorFunctions, o: Any
) -> None:
pass

async def _visit_temporal_api_sdk_v1_ReadRecordsRequest(
self, fs: VisitorFunctions, o: Any
) -> None:
pass

async def _visit_temporal_api_streamservice_v1_ReadRecordsResponse(
self, fs: VisitorFunctions, o: Any
):
for v in o.records:
await self._visit_temporal_api_stream_v1_StreamRecord(fs, v)

async def _visit_temporal_api_sdk_v1_DescribeStreamRequest(
self, fs: VisitorFunctions, o: Any
) -> None:
pass

async def _visit_temporal_api_streamservice_v1_DescribeStreamResponse(
self, fs: VisitorFunctions, o: Any
) -> None:
pass

async def _visit_temporal_api_common_v1_Header(self, fs: VisitorFunctions, o: Any):
for v in o.fields.values():
await self._visit_temporal_api_common_v1_Payload(fs, v)
Expand Down
Loading
Loading