---
title: "Wait for Step Completion"
description: "WaitForStepCompletion returns once one Step execution of a running Flow has completed. Use it when a Flow reaches a durable point that the caller can use before the background work finishes."
canonical_url: "https://docs.superdurable.io/design-patterns/responsive-update/wait-for-step-completion/"
source: "docs/content/design-patterns/responsive-update/step-completion.mdx"
locale: "en"
language: "python"
---

> Index of every page for AI agents: https://docs.superdurable.io/llms.txt

# Wait for Step Completion

Code on this page is in Python. Other languages: [Go](https://docs.superdurable.io/design-patterns/responsive-update/wait-for-step-completion.go.md) · [Java](https://docs.superdurable.io/design-patterns/responsive-update/wait-for-step-completion.java.md) · [TypeScript](https://docs.superdurable.io/design-patterns/responsive-update/wait-for-step-completion.typescript.md) · [Rust](https://docs.superdurable.io/design-patterns/responsive-update/wait-for-step-completion.rust.md)

`WaitForStepCompletion` returns once one Step execution of a running Flow has completed. Use it when a Flow reaches a durable point that the caller can use before the background work finishes.

## How it works

The caller starts the Flow, waits for that Step execution, then reads the result it needs. The caller does not wait for later Steps.

In the example, `PersistData` saves a record, then starts the background Step. The controller waits for the first `PersistData` execution. Then it reads the saved record through an RPC, except in Rust, which returns only the Flow ID and run ID.

## Core implementation

The controller starts the Flow, waits for `PersistData`, and reads the record.

**Python**

```python
@blueprint.get("/start")
async def start_wait_for_step_completion() -> str:
    flow_id = required_query("workflowId")
    await app_state.client.start_flow(
        app_state.wait_for_step_completion,
        flow_id,
        JobSeekerData(1),
        start_options(),
    )
    await app_state.client.wait_for_step_completion(
        flow_id,
        PERSIST_DATA_STEP,
        WaitForStepCompletionOptions(),
    )
    persisted = await app_state.client.invoke_rpc(
        app_state.wait_for_step_completion.get_job_seeker_data,
        flow_id,
    )
    payload = json.dumps(asdict(persisted), sort_keys=True)
    return f"success for workflow {flow_id} with data {payload}"
```

Example: [examples/python/dex_examples/patterns/wait-for-step-completion/controller.py](https://github.com/superdurable/dex/tree/main/examples/python/dex_examples/patterns/wait-for-step-completion/controller.py)

## Rules and pitfalls

- **Wait for the Step that saved the state.** Choose a Step that completes only after it has saved the state the response needs.
- **Read the result separately.** The wait confirms completion and returns no Step output. Read the state through an RPC or a Client Attribute read.
- **Set a request timeout behind a deadline.** When the wait runs behind an HTTP endpoint or another entry point with its own deadline, set `RequestTimeout`. The runnable controllers leave it unset; the Go controller bounds the call with a five-minute context. See [Wait timeouts and limits](https://docs.superdurable.io/reference/server/client-apis.md#wait-timeouts-and-limits).

## Next

- [Step](https://docs.superdurable.io/concepts/step.md)
- [Client](https://docs.superdurable.io/concepts/application.md#client)
