2929
3030@dataclasses .dataclass (frozen = True )
3131class StreamStoreCallOptions :
32- """Options of the Local Activity that calls a Stream Store for Workflow code.
32+ """Options of the Activity that calls a Stream Store for Workflow code.
3333
3434 Workflow code can't do I/O, so the default
35- :py:meth:`StreamStore.call_from_workflow` calls its Store from a Local Activity.
35+ :py:meth:`StreamStore.call_from_workflow` calls its Store from an Activity. A close
36+ runs it as a regular Activity, and every other operation runs it as a Local
37+ Activity. Both get these options.
3638
3739 A :py:class:`StreamConfig` holds them in
3840 :py:attr:`StreamConfig.workflow_call_options`, and every Store of that config
@@ -137,8 +139,9 @@ def worker_activities(self) -> Sequence[Callable[..., Any]]:
137139 """The Activities that a Worker registers for this Store when it runs Workflows.
138140
139141 The default is one Activity, named for this Store, that
140- :py:meth:`call_from_workflow` runs as a Local Activity. A Store that overrides
141- one of the two methods overrides the other to match.
142+ :py:meth:`call_from_workflow` runs as a Local Activity, or as a regular Activity
143+ for a close. A Store that overrides one of the two methods overrides the other to
144+ match.
142145 """
143146 return [_store_call_activity (self )]
144147
@@ -151,13 +154,15 @@ async def call_from_workflow(
151154 """Answer one Stream operation for Workflow code.
152155
153156 It runs in Workflow code, so it does no I/O itself. The default runs the
154- Activity of :py:meth:`worker_activities` as a Local Activity, with the timeouts
155- and the retry policy of ``options``. A replay takes the result from History and
156- calls no method of this Store.
157+ Activity of :py:meth:`worker_activities` with the timeouts and the retry policy
158+ of ``options``. A close runs it as a regular Activity on the Workflow's Task
159+ Queue, after the Workflow Task completes. Every other operation runs it as a
160+ Local Activity. A replay takes the result from History and calls no method of
161+ this Store.
157162
158163 Args:
159- operation: The Nexus operation name, ``CreateStream``, ``AppendRecords``
160- or ``DescribeStream`` in this release.
164+ operation: The Nexus operation name, ``CreateStream``, ``AppendRecords``,
165+ ``CloseStream`` or ``DescribeStream`` in this release.
161166 request: The request message of ``temporalio.api.streamservice.v1``.
162167 options: The :py:attr:`StreamConfig.workflow_call_options` of the config.
163168
@@ -167,14 +172,29 @@ async def call_from_workflow(
167172 stream_operation = _STREAM_OPERATIONS [operation ]
168173 # Workflow code runs no payload codec, so the Activity encodes the bodies of an
169174 # append before the Store gets them.
170- response = await temporalio .workflow .execute_local_activity (
171- _store_call_activity_name (self .name ),
172- args = [operation , request .SerializeToString ()],
173- result_type = bytes ,
174- schedule_to_close_timeout = options .schedule_to_close_timeout ,
175- start_to_close_timeout = options .start_to_close_timeout ,
176- retry_policy = options .retry_policy ,
177- )
175+ if operation == "CloseStream" :
176+ # A Local Activity reaches the Store before its Workflow Task completes. If
177+ # that task then failed, the Stream would stay closed and the retry of the
178+ # task could not append. The server schedules a regular Activity only when
179+ # the task completes.
180+ response = await temporalio .workflow .execute_activity (
181+ _store_call_activity_name (self .name ),
182+ args = [operation , request .SerializeToString ()],
183+ result_type = bytes ,
184+ task_queue = temporalio .workflow .info ().task_queue ,
185+ schedule_to_close_timeout = options .schedule_to_close_timeout ,
186+ start_to_close_timeout = options .start_to_close_timeout ,
187+ retry_policy = options .retry_policy ,
188+ )
189+ else :
190+ response = await temporalio .workflow .execute_local_activity (
191+ _store_call_activity_name (self .name ),
192+ args = [operation , request .SerializeToString ()],
193+ result_type = bytes ,
194+ schedule_to_close_timeout = options .schedule_to_close_timeout ,
195+ start_to_close_timeout = options .start_to_close_timeout ,
196+ retry_policy = options .retry_policy ,
197+ )
178198 return stream_operation .response_type .FromString (response )
179199
180200
@@ -315,10 +335,6 @@ def check_response(
315335 "close_stream" ,
316336 temporalio .api .streamservice .v1 .CloseStreamRequest ,
317337 temporalio .api .streamservice .v1 .CloseStreamResponse ,
318- workflow_refusal = (
319- "Workflow code can't close a Stream on a Store in this release. "
320- "Call an Activity that closes it through its client."
321- ),
322338 ),
323339 "DescribeStream" : _StreamOperation (
324340 "describe_stream" ,
@@ -411,6 +427,10 @@ class StreamConfig:
411427 Store of that name. A call whose ref names no Store, such as a create, goes to
412428 the one Store, or to the Store that :py:attr:`store_selector` returns.
413429
430+ A Worker with Workflows and this config polls for Activity Tasks, since a Workflow's
431+ close runs the Store's Activity as a regular Activity. With ``no_remote_activities``
432+ on that Worker, another Worker of the Task Queue must run the close.
433+
414434 .. warning::
415435 This API is experimental and subject to change.
416436 """
@@ -431,8 +451,8 @@ class StreamConfig:
431451 ``None`` and there is one Store, every new Stream goes to that Store.
432452
433453 For a call of Workflow code, the selector runs in Workflow code, also on a
434- replay. So it must give the same Store for the same context. The Local Activity
435- of the chosen Store is in History, and another answer on a replay is a
454+ replay. So it must give the same Store for the same context. The Activity of the
455+ chosen Store is in History, and another answer on a replay is a
436456 non-determinism error. A Stream that code builds from an id only goes through the
437457 selector on each call, so the selector must also give the same Store for the same
438458 id.
@@ -443,8 +463,9 @@ class StreamConfig:
443463 )
444464 """Options of a Store's call for Workflow code, for every Store of this config.
445465
446- :py:meth:`StreamStore.call_from_workflow` gets them. The default runs its Local
447- Activity with their timeouts and retry policy.
466+ :py:meth:`StreamStore.call_from_workflow` gets them. The default runs the Store's
467+ Activity with their timeouts and retry policy, as a Local Activity, or as a regular
468+ Activity for a close.
448469 """
449470
450471 _store_map : dict [str , StreamStore ] = dataclasses .field (
0 commit comments