sdk-python icon indicating copy to clipboard operation
sdk-python copied to clipboard

[Bug] `retry_policy` not set in `ativity.info()` despite being defined in the `workflow.execute_activity()` call

Open brent-cybrid opened this issue 1 year ago • 9 comments

What are you really trying to do?

We're trying to access the retry_policy from the activity.info from within an activity.

Describe the bug

retry_policy isn't set even though it's set on the workflow.execute_activity call.

Minimal Reproduction

#!/usr/bin/env python3
"""
Minimal reproducible example demonstrating Temporal SDK bug:
activity.info().retry_policy is None even when workflow specifies retry_policy

This script is standalone and only requires: pip install temporalio
"""
import asyncio
from datetime import timedelta
from temporalio import activity, workflow
from temporalio.common import RetryPolicy
from temporalio.testing import WorkflowEnvironment
from temporalio.worker import Worker


# Simple activity that captures what retry_policy information it receives
@activity.defn
async def check_retry_policy_activity() -> dict:
    """Activity that returns information about the retry_policy it receives."""
    info = activity.info()

    return {
        'has_retry_policy_attr': hasattr(info, 'retry_policy'),
        'rety_policy_is_set': info.retry_policy is not None if hasattr(info, 'retry_policy') else False,
        'non_retryable_error_types': (
            info.retry_policy.non_retryable_error_types
            if (
                hasattr(info, 'retry_policy')
                and hasattr(info.retry_policy, 'non_retryable_error_types')
            )
            else None
        )
    }


# Simple workflow that specifies retry_policy with non_retryable_error_types
@workflow.defn
class RetryPolicyTestWorkflow:
    """Workflow that calls activity with specific retry_policy."""

    @workflow.run
    async def run(self) -> dict:
        # Execute activity with retry_policy that includes non_retryable_error_types
        return await workflow.execute_activity(
            check_retry_policy_activity,
            start_to_close_timeout=timedelta(seconds=10),
            retry_policy=RetryPolicy(
                non_retryable_error_types=["MyNonRetryableError", "AnotherNonRetryableError"]
            ),
        )


async def main():
    """Run the test workflow and verify retry_policy is available in activity."""
    
    async with await WorkflowEnvironment.start_time_skipping() as env:
        # Create worker with our workflow and activity
        async with Worker(
            env.client,
            task_queue="test-queue",
            workflows=[RetryPolicyTestWorkflow],
            activities=[check_retry_policy_activity],
        ):
            # Execute the workflow
            result = await env.client.execute_workflow(
                RetryPolicyTestWorkflow.run,
                id="test-workflow-retry-policy",
                task_queue="test-queue",
            )

            # Verify the bug
            if result['rety_policy_is_set']:
                return True
            else:
                print("BUG PRESENT: retry_policy is not set, even though workflow specifies it")
                return False


if __name__ == "__main__":
    success = asyncio.run(main())
    exit(0 if success else 1)

Environment/Versions

Temporal Cloud

Additional context

brent-cybrid avatar Oct 31 '25 21:10 brent-cybrid

Can you validate on a dev or real server as well? There are some things the time skipping server does differently from the standard servers.

tconley1428 avatar Nov 03 '25 19:11 tconley1428

@brent-cybrid is a colleague of mine. We see this in Temporal Cloud as well.

michael-cybrid avatar Nov 04 '25 13:11 michael-cybrid

@michael-cybrid @brent-cybrid temporal cloud has received several updates since this bug report. Could you please confirm is you're still seeing this issue?

gow avatar Jan 13 '26 18:01 gow

I've confirmed that retry_policy is in fact present when tested against cloud: https://github.com/temporalio/sdk-python/pull/1389

So ultimately this is really a time skipping test server issue, which is partly due to https://github.com/temporalio/sdk-java/issues/1426

But... we're in the process of adding proper time skipping support to the real server, at which point we can retire the Java one. Closing this since we're unlikely to prioritize minor Java test server things in light of that.

Sushisource avatar Mar 23 '26 23:03 Sushisource

We still see this issue. It was raised to to the support team in with a support ticket (17450) on April 7, with multiple references to production workflow runs that exhibit this behaviour. Still have not received support. Disappointed in the support we receive as a Temporal Cloud customer.

michael-cybrid avatar May 06 '26 12:05 michael-cybrid

Reliability note for anyone depending on activity.info().retry_policy at runtime:

When the workflow defines a retry policy but the activity info surface does not echo it, operators lose the expected-vs-actual signal they use to debug “why did this retry / why didn’t it?” That turns a configured policy into a silent observability gap.

Fail-closed pattern while the SDK path is fixed:

  1. Treat the workflow-declared retry policy as source of truth; do not branch control logic on activity.info().retry_policy until it is proven present.
  2. At activity start, emit a structured log: {stage: "activity_start", activity, attempt, retry_policy_present, max_attempts}. If retry_policy_present=false despite workflow config, mark status=config_echo_missing.
  3. Assert in a unit/integration test that a workflow with an explicit RetryPolicy(maximum_attempts=N) yields the same N (or a non-null policy object) on activity.info() — so this cannot regress without CI noise.
  4. For production alarms, page on attempt >= threshold from the worker metrics path, not from the missing info field.

This is pure free diagnostic framing for silent config-echo failures — not a product pitch.

IgorGanapolsky avatar Jul 24 '26 17:07 IgorGanapolsky

Hey all, I wanted to share an update here. We recently discovered a code path in the Temporal server that left retry_policy out of the response when eager activity execution is requested. An upcoming Temporal Cloud release will contain the fix.

For those that are unfamiliar with eager execution, it's an optimization that reduces the number of round trips to the server in the case that the worker scheduling the activity is able to immediately execute the activity. This setting is enabled by default in the SDK.

This issue surfaces when:

  1. The activity is scheduled on the same task queue as the workflow.
  2. The worker processing the workflow task is configured with activities and has an available activity slot.
  3. Eager activity execution is enabled by both the worker and the Temporal server.

VegetarianOrc avatar Aug 03 '26 21:08 VegetarianOrc

@michael-cybrid Have you had any issues with this recently? We believe this should be fixed now per @VegetarianOrc 's comment.

Sushisource avatar Sep 01 '26 20:09 Sushisource

Wanted to add some context that the fix identified is included in Temporal v1.32.0

VegetarianOrc avatar Sep 29 '26 21:09 VegetarianOrc