Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
9bccb27
Added the generated code of the Streams API.
moetemp Nov 14, 2026
c65cf7a
Regenerated the Streams API with append and close on the Workflow Str…
moetemp Nov 14, 2026
6635c70
Regenerated the Streams API with the new names of a polled read.
moetemp Nov 18, 2026
e0ba191
Regenerate the Streams API from the API's attempt names
moetemp Nov 20, 2026
17c637e
Regenerate the Streams API with a request id and Stream ids
moetemp Nov 21, 2026
983611e
Regenerate the Streams API with ids in each Producer kind
moetemp Nov 21, 2026
5b5bf8b
Regenerate the Streams API with the API's comments on a Store's rules
moetemp Nov 21, 2026
bd9690c
Leave the generated Stream code out of mypy
moetemp Nov 22, 2026
cfad2eb
Regenerate the bridge protos and the payload visitor
moetemp Nov 22, 2026
7f855d6
Regenerate the Streams API with no `producer` in Workflow code
moetemp Nov 23, 2026
2407868
Regenerate the API protos with refs in the Stream requests
moetemp Nov 24, 2026
bfaca8f
Regenerate the Streams API with refs in the requests
moetemp Nov 24, 2026
41b14e7
Regenerate the bridge protos from Core's Stream ledger
moetemp Nov 24, 2026
16be05f
Pin Core with the Stream protos and the Stream WIT
moetemp Nov 24, 2026
eb3b474
Regenerate the protos and the Streams API at the pinned Core
moetemp Nov 24, 2026
cf85123
Pin Core at the SDK and Store sets of the Stream protos
moetemp Nov 25, 2026
10dcd0e
Regenerate the protos and the Streams API with no close
moetemp Nov 25, 2026
523848f
Generate the Nexus system API with nexgen 0.2.14
moetemp Nov 26, 2026
3574894
Pin Core to the Streams protos with the read doc of api#895
moetemp Nov 26, 2026
2054714
Merge branch 'codex/review-1127-python-info' into codex/review-1127-p…
moetemp Nov 27, 2026
f89671d
Pin reviewed Stream contracts and the client poll generator
moetemp Nov 27, 2026
839a3e4
Clarify generated read limits and pin the final generator
moetemp Nov 27, 2026
5c8be99
Remove the temporary generator comment
moetemp Nov 27, 2026
4aaf5e6
Merge the reviewed Local Activity info
moetemp Nov 28, 2026
844bd0f
Regenerate Streams with reviewed creation and polling rules
moetemp Nov 28, 2026
207b339
Include the generated Stream binding helpers
moetemp Nov 28, 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
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,15 @@ exclude = [
# Ignore generated code
'temporalio/api',
'temporalio/bridge/proto',
'temporalio/nexus/system/stream_service',
'temporalio/nexus/system/workflow_service',
]

[[tool.mypy.overrides]]
module = "temporalio.nexus.system.workflow_service.*"
module = [
"temporalio.nexus.system.stream_service.*",
"temporalio.nexus.system.workflow_service.*",
]
ignore_errors = true

[tool.pydocstyle]
Expand Down
72 changes: 48 additions & 24 deletions scripts/gen_nexus_system_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
wit_deps_dir = wit_input_dir / "deps"
workflow_output_dir = base_dir / "temporalio" / "nexus" / "system" / "workflow_service"
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_VERSION = "0.2.13"
NEX_GEN_REVISION = "5983b56b047cea94acbdb4760ca76f145f5a55d7"
proto_files = [
gen_protos.api_proto_dir
/ "temporal"
Expand All @@ -39,31 +40,40 @@
/ "notificationservice"
/ "v1"
/ "request_response.proto",
gen_protos.api_proto_dir
/ "temporal"
/ "api"
/ "streamservice"
/ "v1"
/ "request_response.proto",
gen_protos.api_proto_dir / "temporal" / "api" / "sdk" / "v1" / "stream.proto",
]


def nex_gen_command() -> list[str]:
if bin_path := os.environ.get("NEX_GEN_BIN"):
return [bin_path]
if (
shutil.which("nexgen") is None
or subprocess.check_output(["nexgen", "--version"], text=True).strip()
!= f"nexgen {NEX_GEN_VERSION}"
):
install_dir = base_dir / "build" / "nexgen" / NEX_GEN_REVISION
binary = install_dir / "bin" / ("nexgen.exe" if os.name == "nt" else "nexgen")
if not binary.is_file():
subprocess.check_call(
[
"cargo",
"install",
"--locked",
"nexgen",
"--version",
NEX_GEN_VERSION,
"--git",
"https://github.com/temporalio/nexgen.git",
"--rev",
NEX_GEN_REVISION,
"--root",
str(install_dir),
"--features",
"advanced",
"--force",
]
)
return ["nexgen"]
return [str(binary)]


def build_descriptor_set(descriptor_path: Path) -> None:
Expand All @@ -85,11 +95,11 @@ def generate_package(
output_dir: Path,
descriptor_path: Path,
*,
native_api: bool,
targets: str | None,
) -> None:
args = [*command, "python", str(wit_input_dir / wit_name), str(wit_deps_dir)]
if native_api:
args.extend(["--targets", "workflow"])
if targets:
args.extend(["--targets", targets])
subprocess.check_call(
[
*args,
Expand Down Expand Up @@ -132,17 +142,28 @@ def replace_marker_block(


def generate_workflow_exports() -> None:
exports = generated_exports(workflow_output_dir / "__init__.py")
import_block = [
"# BEGIN GENERATED NEXUS SYSTEM EXPORTS\n",
"from temporalio.nexus.system.workflow_service import (\n",
*[f" {export},\n" for export in exports],
")\n",
"# END GENERATED NEXUS SYSTEM EXPORTS\n",
packages = [
(
"temporalio.nexus.system.stream_service.workflow",
stream_output_dir / "workflow" / "__init__.py",
),
(
"temporalio.nexus.system.workflow_service",
workflow_output_dir / "__init__.py",
),
]
exports = [(module, generated_exports(path)) for module, path in packages]
import_block = ["# BEGIN GENERATED NEXUS SYSTEM EXPORTS\n"]
for module, names in exports:
import_block += [
f"from {module} import (\n",
*[f" {name},\n" for name in names],
")\n",
]
import_block.append("# END GENERATED NEXUS SYSTEM EXPORTS\n")
all_block = [
" # BEGIN GENERATED NEXUS SYSTEM __ALL__\n",
*[f' "{export}",\n' for export in exports],
*[f' "{name}",\n' for _, names in exports for name in names],
" # END GENERATED NEXUS SYSTEM __ALL__\n",
]
content = workflow_init_path.read_text()
Expand All @@ -163,6 +184,7 @@ def generate_nexus_system_api() -> None:
required_paths = [
wit_input_dir / "workflow-service.wit",
wit_input_dir / "notification-service.wit",
wit_input_dir / "stream-service.wit",
wit_deps_dir,
*proto_files,
]
Expand All @@ -173,9 +195,10 @@ def generate_nexus_system_api() -> None:
descriptor_path = Path(temp_dir) / "temporal_api.bin"
build_descriptor_set(descriptor_path)
command = nex_gen_command()
for wit_name, output_dir, native_api in (
("workflow-service.wit", workflow_output_dir, True),
("notification-service.wit", notification_output_dir, False),
for wit_name, output_dir, targets in (
("workflow-service.wit", workflow_output_dir, "workflow"),
("notification-service.wit", notification_output_dir, None),
("stream-service.wit", stream_output_dir, "workflow,client"),
):
shutil.rmtree(output_dir, ignore_errors=True)
output_dir.parent.mkdir(parents=True, exist_ok=True)
Expand All @@ -184,13 +207,14 @@ def generate_nexus_system_api() -> None:
wit_name,
output_dir,
descriptor_path,
native_api=native_api,
targets=targets,
)
workflow_output_dir.parent.joinpath("__init__.py").touch()
generate_workflow_exports()
format_paths = [
str(workflow_output_dir),
str(notification_output_dir),
str(stream_output_dir),
str(workflow_init_path),
]
subprocess.check_call(
Expand Down
9 changes: 8 additions & 1 deletion temporalio/_workflow_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,16 @@ class _WorkflowLogicFlag(IntEnum):
# Remove the explicit overrides for this flag from tests/worker/test_workflow_flags.py
# when enabling it. Then remove this reminder.
DECODE_DATETIME_PROXIES = 3
USE_LAST_STREAM_RECORD_OFFSET = 4
REPORT_EXISTING_STREAM_AS_FALSE = 5


_DEFAULT_ENABLED_WORKFLOW_LOGIC_FLAGS: frozenset[_WorkflowLogicFlag] = frozenset()
_DEFAULT_ENABLED_WORKFLOW_LOGIC_FLAGS: frozenset[_WorkflowLogicFlag] = frozenset(
{
_WorkflowLogicFlag.USE_LAST_STREAM_RECORD_OFFSET,
_WorkflowLogicFlag.REPORT_EXISTING_STREAM_AS_FALSE,
}
)


@dataclass(frozen=True)
Expand Down
3 changes: 3 additions & 0 deletions temporalio/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ class Info:
This API is experimental and unstable.
"""

_scheduled_event_id: int = 0
"""Allow Stream writes when the task token has no scheduling event ID."""

@property
def in_workflow(self) -> bool:
"""Was this activity started by a workflow?"""
Expand Down
3 changes: 3 additions & 0 deletions temporalio/api/enums/v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
from .query_pb2 import QueryRejectCondition, QueryResultType
from .reset_pb2 import ResetReapplyExcludeType, ResetReapplyType, ResetType
from .schedule_pb2 import ScheduleOverlapPolicy
from .stream_pb2 import StreamErrorReason, StreamIdConflictPolicy
from .task_queue_pb2 import (
BuildIdTaskReachability,
DescribeTaskQueueMode,
Expand Down Expand Up @@ -126,6 +127,8 @@
"Severity",
"SignalExternalWorkflowExecutionFailedCause",
"StartChildWorkflowExecutionFailedCause",
"StreamErrorReason",
"StreamIdConflictPolicy",
"SuggestContinueAsNewReason",
"TaskQueueKind",
"TaskQueueType",
Expand Down
29 changes: 29 additions & 0 deletions temporalio/api/enums/v1/stream_pb2.py

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

120 changes: 120 additions & 0 deletions temporalio/api/enums/v1/stream_pb2.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
"""
@generated by mypy-protobuf. Do not edit manually!
isort:skip_file
"""

import builtins
import sys
import typing

import google.protobuf.descriptor
import google.protobuf.internal.enum_type_wrapper

if sys.version_info >= (3, 10):
import typing as typing_extensions
else:
import typing_extensions

DESCRIPTOR: google.protobuf.descriptor.FileDescriptor

class _StreamIdConflictPolicy:
ValueType = typing.NewType("ValueType", builtins.int)
V: typing_extensions.TypeAlias = ValueType

class _StreamIdConflictPolicyEnumTypeWrapper(
google.protobuf.internal.enum_type_wrapper._EnumTypeWrapper[
_StreamIdConflictPolicy.ValueType
],
builtins.type,
):
DESCRIPTOR: google.protobuf.descriptor.EnumDescriptor
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."""

class StreamIdConflictPolicy(
_StreamIdConflictPolicy, metaclass=_StreamIdConflictPolicyEnumTypeWrapper
):
"""Experimental. Might change in the future.
The conflict policy for an existing Stream. Unspecified means `FAIL`.
"""

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."""
global___StreamIdConflictPolicy = StreamIdConflictPolicy

class _StreamErrorReason:
ValueType = typing.NewType("ValueType", builtins.int)
V: typing_extensions.TypeAlias = ValueType

class _StreamErrorReasonEnumTypeWrapper(
google.protobuf.internal.enum_type_wrapper._EnumTypeWrapper[
_StreamErrorReason.ValueType
],
builtins.type,
):
DESCRIPTOR: google.protobuf.descriptor.EnumDescriptor
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`)."""
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
"""The Stream has a newer format than this caller knows (`FAILED_PRECONDITION`)."""
STREAM_ERROR_REASON_OFFSET_TOO_HIGH: _StreamErrorReason.ValueType # 5
"""The offset is past the newest one, for example after a failover lost the newest Records. A
read from it works again once the Stream has Records up to that offset (`OUT_OF_RANGE`).
"""
STREAM_ERROR_REASON_TOO_LARGE: _StreamErrorReason.ValueType # 6
"""A Record or a batch is larger than the Store allows (`INVALID_ARGUMENT`)."""
STREAM_ERROR_REASON_INVALID_ARGUMENT: _StreamErrorReason.ValueType # 7
"""The request is malformed (`INVALID_ARGUMENT`)."""
STREAM_ERROR_REASON_STORE_UNAVAILABLE: _StreamErrorReason.ValueType # 8
"""The Store failed or did not respond. A retry can succeed (`UNAVAILABLE`)."""
STREAM_ERROR_REASON_UNSUPPORTED: _StreamErrorReason.ValueType # 9
"""The Store doesn't support something that the call needs (`UNIMPLEMENTED`)."""
STREAM_ERROR_REASON_ALREADY_EXISTS: _StreamErrorReason.ValueType # 10
"""A create with the `FAIL` policy found that the Stream already exists (`ALREADY_EXISTS`)."""
STREAM_ERROR_REASON_STORE_CORRUPT: _StreamErrorReason.ValueType # 11
"""Stored data is invalid. Retrying cannot repair it (`DATA_LOSS`)."""

class StreamErrorReason(
_StreamErrorReason, metaclass=_StreamErrorReasonEnumTypeWrapper
):
"""Experimental. Might change in the future.
Several reasons share a gRPC status code. Callers must check the reason to distinguish them.
"""

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`)."""
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
"""The Stream has a newer format than this caller knows (`FAILED_PRECONDITION`)."""
STREAM_ERROR_REASON_OFFSET_TOO_HIGH: StreamErrorReason.ValueType # 5
"""The offset is past the newest one, for example after a failover lost the newest Records. A
read from it works again once the Stream has Records up to that offset (`OUT_OF_RANGE`).
"""
STREAM_ERROR_REASON_TOO_LARGE: StreamErrorReason.ValueType # 6
"""A Record or a batch is larger than the Store allows (`INVALID_ARGUMENT`)."""
STREAM_ERROR_REASON_INVALID_ARGUMENT: StreamErrorReason.ValueType # 7
"""The request is malformed (`INVALID_ARGUMENT`)."""
STREAM_ERROR_REASON_STORE_UNAVAILABLE: StreamErrorReason.ValueType # 8
"""The Store failed or did not respond. A retry can succeed (`UNAVAILABLE`)."""
STREAM_ERROR_REASON_UNSUPPORTED: StreamErrorReason.ValueType # 9
"""The Store doesn't support something that the call needs (`UNIMPLEMENTED`)."""
STREAM_ERROR_REASON_ALREADY_EXISTS: StreamErrorReason.ValueType # 10
"""A create with the `FAIL` policy found that the Stream already exists (`ALREADY_EXISTS`)."""
STREAM_ERROR_REASON_STORE_CORRUPT: StreamErrorReason.ValueType # 11
"""Stored data is invalid. Retrying cannot repair it (`DATA_LOSS`)."""
global___StreamErrorReason = StreamErrorReason
14 changes: 14 additions & 0 deletions temporalio/api/sdk/v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
)
from .event_group_marker_pb2 import EventGroupMarker
from .external_storage_pb2 import ExternalStorageReference
from .stream_pb2 import (
AppendRecordsRequest,
CreateStreamRequest,
CreateStreamResponse,
DescribeStreamRequest,
ReadRecordsRequest,
StreamRef,
)
from .task_complete_metadata_pb2 import WorkflowTaskCompletedMetadata
from .user_metadata_pb2 import UserMetadata
from .worker_config_pb2 import WorkerConfig
Expand All @@ -17,13 +25,19 @@
)

__all__ = [
"AppendRecordsRequest",
"CreateStreamRequest",
"CreateStreamResponse",
"DescribeStreamRequest",
"EnhancedStackTrace",
"EventGroupMarker",
"ExternalStorageReference",
"ReadRecordsRequest",
"StackTrace",
"StackTraceFileLocation",
"StackTraceFileSlice",
"StackTraceSDKInfo",
"StreamRef",
"UserMetadata",
"WorkerConfig",
"WorkflowDefinition",
Expand Down
Loading
Loading