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/chatty-stream-otter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add experimental Stream calls for clients and Activities, with client interceptors for each operation.
1 change: 1 addition & 0 deletions changelog/fixed/unchanced-alfredia.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Core skips Local Activities when replay ends in an unfinished Workflow Task. Local Activity heartbeats preserve the Workflow versioning behavior.
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
2 changes: 1 addition & 1 deletion temporalio/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class Info:
apart. Zero if Core couldn't read it."""

_local_activity_origin: tuple[int, str] | None = None
"""Workflow Task id and Activity id of the first schedule of this Local Activity.
"""Command seq and Activity id of the first schedule of this Local Activity.
Retries keep them, so that every attempt writes to a Stream as the same Producer."""

@property
Expand Down
8 changes: 4 additions & 4 deletions temporalio/api/enums/v1/stream_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class _StreamIdConflictPolicyEnumTypeWrapper(
STREAM_ID_CONFLICT_POLICY_FAIL: _StreamIdConflictPolicy.ValueType # 1
"""The create fails with `ALREADY_EXISTS`."""
STREAM_ID_CONFLICT_POLICY_USE_EXISTING: _StreamIdConflictPolicy.ValueType # 2
"""The create returns the existing Stream without changing its expiry."""
"""The create returns `created` false for the existing Stream."""

class StreamIdConflictPolicy(
_StreamIdConflictPolicy, metaclass=_StreamIdConflictPolicyEnumTypeWrapper
Expand All @@ -45,7 +45,7 @@ STREAM_ID_CONFLICT_POLICY_UNSPECIFIED: StreamIdConflictPolicy.ValueType # 0
STREAM_ID_CONFLICT_POLICY_FAIL: StreamIdConflictPolicy.ValueType # 1
"""The create fails with `ALREADY_EXISTS`."""
STREAM_ID_CONFLICT_POLICY_USE_EXISTING: StreamIdConflictPolicy.ValueType # 2
"""The create returns the existing Stream without changing its expiry."""
"""The create returns `created` false for the existing Stream."""
global___StreamIdConflictPolicy = StreamIdConflictPolicy

class _StreamErrorReason:
Expand All @@ -63,7 +63,7 @@ class _StreamErrorReasonEnumTypeWrapper(
STREAM_ERROR_REASON_NOT_FOUND: _StreamErrorReason.ValueType # 1
"""The Stream was never created (`NOT_FOUND`)."""
STREAM_ERROR_REASON_EXPIRED: _StreamErrorReason.ValueType # 2
"""Retention has passed since create or the last append of a new batch (`NOT_FOUND`)."""
"""The Store's retention policy removed the Records (`NOT_FOUND`)."""
STREAM_ERROR_REASON_FENCED: _StreamErrorReason.ValueType # 3
"""A later attempt of this Producer has written, and fencing is enabled (`FAILED_PRECONDITION`)."""
STREAM_ERROR_REASON_FORMAT_TOO_NEW: _StreamErrorReason.ValueType # 4
Expand Down Expand Up @@ -96,7 +96,7 @@ STREAM_ERROR_REASON_UNSPECIFIED: StreamErrorReason.ValueType # 0
STREAM_ERROR_REASON_NOT_FOUND: StreamErrorReason.ValueType # 1
"""The Stream was never created (`NOT_FOUND`)."""
STREAM_ERROR_REASON_EXPIRED: StreamErrorReason.ValueType # 2
"""Retention has passed since create or the last append of a new batch (`NOT_FOUND`)."""
"""The Store's retention policy removed the Records (`NOT_FOUND`)."""
STREAM_ERROR_REASON_FENCED: StreamErrorReason.ValueType # 3
"""A later attempt of this Producer has written, and fencing is enabled (`FAILED_PRECONDITION`)."""
STREAM_ERROR_REASON_FORMAT_TOO_NEW: StreamErrorReason.ValueType # 4
Expand Down
32 changes: 16 additions & 16 deletions temporalio/api/stream/v1/message_pb2.py

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

26 changes: 15 additions & 11 deletions temporalio/api/stream/v1/message_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -197,22 +197,25 @@ class LocalActivityProducer(google.protobuf.message.Message):
NAMESPACE_FIELD_NUMBER: builtins.int
WORKFLOW_ID_FIELD_NUMBER: builtins.int
RUN_ID_FIELD_NUMBER: builtins.int
WORKFLOW_TASK_ID_FIELD_NUMBER: builtins.int
ACTIVITY_ID_FIELD_NUMBER: builtins.int
ATTEMPT_FIELD_NUMBER: builtins.int
SEQ_FIELD_NUMBER: builtins.int
namespace: builtins.str
"""Required. The namespace of the Workflow that made the call."""
workflow_id: builtins.str
"""Required."""
run_id: builtins.str
"""Required."""
workflow_task_id: builtins.int
"""Retries retain the original scheduling task's id, including after a Workflow timer.
Zero identifies a Local Activity first scheduled in the run's first Workflow Task.
"""
activity_id: builtins.str
"""Required. The SDK keeps this id across retries so they share one Producer.
The id must distinguish Local Activities first scheduled in the same Workflow Task.
"""Required. The Activity id of the first schedule. It is part of the Producer identity,
so the SDK keeps it across retries.
"""
seq: builtins.int
"""The sequence number of the command that first scheduled the Local Activity. It identifies
the Local Activity in its Workflow run. Retries retain it, including after a Workflow timer.

(-- api-linter: core::0141::forbidden-types=disabled
aip.dev/not-precedent: Sequence numbers are never negative. --)
"""
@property
def attempt(self) -> global___LocalActivityAttempt:
Expand All @@ -224,9 +227,9 @@ class LocalActivityProducer(google.protobuf.message.Message):
namespace: builtins.str = ...,
workflow_id: builtins.str = ...,
run_id: builtins.str = ...,
workflow_task_id: builtins.int = ...,
activity_id: builtins.str = ...,
attempt: global___LocalActivityAttempt | None = ...,
seq: builtins.int = ...,
) -> None: ...
def HasField(
self, field_name: typing.Literal["attempt", b"attempt"]
Expand All @@ -242,10 +245,10 @@ class LocalActivityProducer(google.protobuf.message.Message):
b"namespace",
"run_id",
b"run_id",
"seq",
b"seq",
"workflow_id",
b"workflow_id",
"workflow_task_id",
b"workflow_task_id",
],
) -> None: ...

Expand Down Expand Up @@ -393,7 +396,8 @@ global___ClientProducer = ClientProducer
class Producer(google.protobuf.message.Message):
"""Experimental. Might change in the future.
The kind and ids identify a Producer. The attempt does not.
With fencing enabled, a write fails with `FENCED` after a later attempt of that Producer writes.
A Store can reject an older attempt with `FENCED` after a later attempt of that Producer writes.
A remembered resend still returns its original offsets.
Records retain their Producer and attempt so that readers can apply their own retry policy.
Attempts of different Producers have no order. A reset run cannot fence its base run.
"""
Expand Down
6 changes: 3 additions & 3 deletions temporalio/api/streamservice/v1/request_response_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class CreateStreamRequest(google.protobuf.message.Message):
A retry with the original create request id returns `created` true, even with `FAIL`.
Either policy returns `EXPIRED` while the Store remembers an expired Stream.

Retention is a Store setting. It starts at create and restarts when an append writes a new batch.
Reads and resends keep the existing expiry.
Retention is a Store policy. Keep Records for as long as a Workflow History can replay them,
including after a Workflow reset.
(-- api-linter: core::0133=disabled
aip.dev/not-precedent: The request identifies a Stream by its id. --)
"""
Expand Down Expand Up @@ -77,7 +77,7 @@ global___CreateStreamResponse = CreateStreamResponse
class AppendRecordsRequest(google.protobuf.message.Message):
"""Experimental. Might change in the future.
Retries must use the same Producer, attempt, request id and batch. A remembered request id
returns the original offsets without writing again. The Store sets its resend window per
returns the original offsets without duplicating Records. The Store sets its resend window per
Producer. An empty or forgotten request id permits a second write.
"""

Expand Down
13 changes: 13 additions & 0 deletions temporalio/bridge/Cargo.lock

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

1 change: 1 addition & 0 deletions temporalio/bridge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ temporalio-sdk-core = { version = "0.12.0", path = "./sdk-core/crates/sdk-core",
"envconfig",
"prometheus",
] }
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
Loading
Loading