Repository navigation
Conversation
Unaccepted polls aborted with WorkflowNotReadyFailure during continue-as-new are retried instead of ending the subscription. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
|
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
I ran the deterministic loopback reproduction from #2170 against main Replayed with Codex assistance. |
|
Thanks for running the deterministic loopback reproduction on both main and this PR — great to see the PR delivers the expected greeting where the official SDK loses the subscriber, and that the collision path was still exercised. Appreciate the independent verification. |
ptimizeroracle
left a comment
There was a problem hiding this comment.
i filed #2170 and had a patch with the same branch, so no need for mine. i did not run the pr branch: i applied gh pr diff 2172 onto main at ce8cd48, python 3.12, bridge from the 1.37.0 wheel.
the tests here are mocks and you say the dev server ones were not run, so i ran this one on the dev server: a publish signal lands while the continue-as-new task is open. on main it fails with the RPCError from the issue, with the diff it passes (n=3). all 90 tests in tests/contrib/workflow_streams pass with it, and the accepted case test fails (timeout) if i drop the polled_run_id is None check.
the retry has no limit, same as the StreamDraining one. fine for me, a maintainer may want a cap.
here is the dev server test if you want to add it, it applies on ce8cd48:
test diff
diff --git a/tests/contrib/workflow_streams/test_workflow_streams.py b/tests/contrib/workflow_streams/test_workflow_streams.py
index a61db95..12956c8 100644
--- a/tests/contrib/workflow_streams/test_workflow_streams.py
+++ b/tests/contrib/workflow_streams/test_workflow_streams.py
@@ -3,6 +3,7 @@
from __future__ import annotations
import asyncio
+import threading
import uuid
from asyncio import timeout as _async_timeout
from collections.abc import Sequence
@@ -47,7 +48,11 @@ from temporalio.nexus import WorkflowRunOperationContext, workflow_run_operation
from temporalio.service import RPCError, RPCStatusCode
from temporalio.testing import WorkflowEnvironment
from temporalio.worker import Worker
-from tests.helpers import assert_eq_eventually, new_worker
+from tests.helpers import (
+ assert_eq_eventually,
+ assert_task_fail_eventually,
+ new_worker,
+)
from tests.helpers.nexus import make_nexus_endpoint_name
@@ -2289,6 +2294,74 @@ async def test_subscribe_retries_while_draining(client: Client) -> None:
await new_handle.signal(DrainingGateWorkflow.close)
+continue_as_new_reached = threading.Event()
+publish_signal_sent = threading.Event()
+
+
+@workflow.defn(sandboxed=False)
+class ContinueAsNewRacesPublishWorkflow:
+ """Continues-as-new in the workflow task that delivers the first poll, and
+ holds that task open until the test has sent a publish signal."""
+
+ @workflow.init
+ def __init__(self, input: CANWorkflowInputTyped) -> None:
+ self.stream = WorkflowStream(prior_state=input.stream_state)
+ self._closed = False
+
+ @workflow.signal
+ def close(self) -> None:
+ self._closed = True
+
+ @workflow.run
+ async def run(self, _input: CANWorkflowInputTyped) -> None:
+ del _input
+ await workflow.wait_condition(
+ lambda: self._closed or not workflow.all_handlers_finished()
+ )
+ if not self._closed:
+ await self.stream.continue_as_new(self._build_args)
+
+ def _build_args(self, state: WorkflowStreamState) -> list[CANWorkflowInputTyped]:
+ if not continue_as_new_reached.is_set():
+ continue_as_new_reached.set()
+ publish_signal_sent.wait(1)
+ return [CANWorkflowInputTyped(stream_state=state)]
+
+
+@pytest.mark.asyncio
+async def test_subscribe_survives_continue_as_new_racing_publish(
+ client: Client,
+) -> None:
+ """A publish signal that lands during the continue-as-new workflow task makes
+ the server fail that task and abort the poll it delivered. The poll was
+ never accepted, so the subscription must resend it instead of raising."""
+ continue_as_new_reached.clear()
+ publish_signal_sent.clear()
+ async with new_worker(client, ContinueAsNewRacesPublishWorkflow) as worker:
+ handle = await client.start_workflow(
+ ContinueAsNewRacesPublishWorkflow.run,
+ CANWorkflowInputTyped(),
+ id=f"workflow-stream-can-races-publish-{uuid.uuid4()}",
+ task_queue=worker.task_queue,
+ )
+ first_run = client.get_workflow_handle(handle.id, run_id=handle.result_run_id)
+
+ collect = asyncio.create_task(
+ collect_items(client, handle, None, 0, 1, result_type=str)
+ )
+ assert await asyncio.to_thread(continue_as_new_reached.wait, 10)
+ stream = WorkflowStreamClient.create(client, handle.id)
+ stream.topic("events", type=str).publish("item-0")
+ await stream.flush()
+ publish_signal_sent.set()
+
+ assert [i.data for i in await collect] == ["item-0"]
+ await assert_task_fail_eventually(first_run)
+
+ await handle.signal(ContinueAsNewRacesPublishWorkflow.close)
+ await handle.result()
+
+
# ---------------------------------------------------------------------------
# Cross-workflow workflow stream (Scenario 1)
# ---------------------------------------------------------------------------(ai-assisted, checked by me)
|
@ptimizeroracle Thanks for running the dev-server test — good to see the fix holds against a real publish signal racing a continue-as-new task, and that dropping the |
What was changed
WorkflowStreamClient.subscribe()now retries a poll aborted before acceptance withFAILED_PRECONDITIONand aWorkflowNotReadyFailuredetail. That is the error the server produces when a publish lands in the workflow task that emits continue-as-new. The retry is limited to the unaccepted case: accepted-run errors, generic RPC errors, cancellation, and terminal handling are unchanged.The public docstring now states that unaccepted polls aborted with
WorkflowNotReadyFailureare retried. Achangelog/fixed/fragment is included. The fix uses only local per-attempt state; it adds no cache, client, connection, loop, timer, or retained global state.Why?
Issue #2170 reports that a healthy token-stream subscriber dies because
subscribe()describes the run, seesRUNNING, and re-raises the aborted poll error. The method already retries unaccepted polls forStreamDrainingand promises to follow continue-as-new chains. A stress reproduction lost 6 of 20 subscribers at rollover under publish load.Checklist
Closes [Bug] workflow_streams: subscribe() raises RPCError when a publish signal lands during the continue-as-new workflow task #2170
How was this tested:
ce8cd48149423e005302ae0b4ea5f5488d90a4f3+ new tests: 1 failed, 1 passed. The retry test failed with the reportedRPCError.ruff check --select Iandruff format --checkpass on both changed Python files;git diff --checkpasses.uvdev install timed out downloading the unrelatedcibuildwheelpackage, so tests ran with the local Python 3.11 environment and the installed native bridge shim. Integration tests requiring a Temporal dev server were not run.Any docs updates needed?
subscribe()docstring and added achangelog/fixed/fragment. No docs.temporal.io update is needed.🤖 Generated with Claude Code